You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2015/08/12 16:38:08 UTC
[3/4] karaf git commit: [KARAF-3929] Avoid
StringIndexOutOfBoundsException if the user has no roles
[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 <ch...@die-schneider.net>
Authored: Wed Aug 12 16:25:37 2015 +0200
Committer: Christian Schneider <ch...@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>");
+ }
}
}