Skip to content

Commit 23de431

Browse files
committed
CLOUDSTACK-8037: Fix attribute detection, tested to work with onelogin.com
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 2720a1b commit 23de431

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,27 @@ public String authenticate(final String command, final Map<String, Object[]> par
239239
}
240240
}
241241

242-
AttributeStatement attributeStatement = assertion.getAttributeStatements().get(0);
243-
List<Attribute> attributes = attributeStatement.getAttributes();
244-
245-
// Try capturing standard LDAP attributes
246-
for (Attribute attribute: attributes) {
247-
String attributeName = attribute.getName();
248-
String attributeValue = attribute.getAttributeValues().get(0).getDOM().getTextContent();
249-
if (attributeName.equalsIgnoreCase("uid") && uniqueUserId == null) {
250-
username = attributeValue;
251-
uniqueUserId = SAMLUtils.createSAMLId(username);
252-
} else if (attributeName.equalsIgnoreCase("givenName")) {
253-
firstName = attributeValue;
254-
} else if (attributeName.equalsIgnoreCase(("sn"))) {
255-
lastName = attributeValue;
256-
} else if (attributeName.equalsIgnoreCase("mail")) {
257-
email = attributeValue;
242+
List<AttributeStatement> attributeStatements = assertion.getAttributeStatements();
243+
if (attributeStatements != null && attributeStatements.size() > 0) {
244+
for (AttributeStatement attributeStatement: attributeStatements) {
245+
if (attributeStatement == null) {
246+
continue;
247+
}
248+
// Try capturing standard LDAP attributes
249+
for (Attribute attribute: attributeStatement.getAttributes()) {
250+
String attributeName = attribute.getName();
251+
String attributeValue = attribute.getAttributeValues().get(0).getDOM().getTextContent();
252+
if (attributeName.equalsIgnoreCase("uid") && uniqueUserId == null) {
253+
username = attributeValue;
254+
uniqueUserId = SAMLUtils.createSAMLId(username);
255+
} else if (attributeName.equalsIgnoreCase("givenName")) {
256+
firstName = attributeValue;
257+
} else if (attributeName.equalsIgnoreCase(("sn"))) {
258+
lastName = attributeValue;
259+
} else if (attributeName.equalsIgnoreCase("mail")) {
260+
email = attributeValue;
261+
}
262+
}
258263
}
259264
}
260265

0 commit comments

Comments
 (0)