karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [3/4] karaf git commit: [KARAF-3929] Avoid StringIndexOutOfBoundsException if the user has no roles
Date Wed, 12 Aug 2015 14:38:08 GMT
[KARAF-3929] Avoid StringIndexOutOfBoundsException if the user has no roles


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/b5817f6c
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/b5817f6c
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/b5817f6c

Branch: refs/heads/master
Commit: b5817f6c6d5d3dcac96ecc1b2610be78495c7a9c
Parents: 51f5a25
Author: Christian Schneider <chris@die-schneider.net>
Authored: Wed Aug 12 16:25:37 2015 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Wed Aug 12 16:25:37 2015 +0200

----------------------------------------------------------------------
 .../modules/syncope/SyncopeLoginModule.java     | 34 +++++++++++---------
 1 file changed, 18 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/b5817f6c/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModule.java
b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModule.java
index 47cbd0f..248512d 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModule.java
@@ -117,24 +117,26 @@ public class SyncopeLoginModule extends AbstractKarafLoginModule {
     protected List<String> extractingRoles(String response) throws Exception {
         List<String> roles = new ArrayList<String>();
         if (response != null && !response.isEmpty()) {
-            // extract the <memberships> element
+            // extract the <memberships> element if it exists
             int index = response.indexOf("<memberships>");
-            response = response.substring(index + "<memberships>".length());
-            index = response.indexOf("</memberships>");
-            response = response.substring(0, index);
-
-            // looking for the roleName elements
-            index = response.indexOf("<roleName>");
-            while (index != -1) {
-                response = response.substring(index + "<roleName>".length());
-                int end = response.indexOf("</roleName>");
-                if (end == -1) {
-                    index = -1;
-                }
-                String role = response.substring(0, end);
-                roles.add(role);
-                response = response.substring(end + "</roleName>".length());
+            if (index != -1) {
+                response = response.substring(index + "<memberships>".length());
+                index = response.indexOf("</memberships>");
+                response = response.substring(0, index);
+    
+                // looking for the roleName elements
                 index = response.indexOf("<roleName>");
+                while (index != -1) {
+                    response = response.substring(index + "<roleName>".length());
+                    int end = response.indexOf("</roleName>");
+                    if (end == -1) {
+                        index = -1;
+                    }
+                    String role = response.substring(0, end);
+                    roles.add(role);
+                    response = response.substring(end + "</roleName>".length());
+                    index = response.indexOf("<roleName>");
+                }
             }
 
         }


Mime
View raw message