Merge pull request #4474 from hmlnarik/KEYCLOAK-5254-NPE-in-SAMLIdentityProvider

KEYCLOAK-5254 Fix NPE - NameID format is optional
This commit is contained in:
Bill Burke 2017-09-23 20:39:50 -04:00 committed by GitHub
commit 9034708c99
2 changed files with 9 additions and 5 deletions

View file

@ -85,18 +85,20 @@ public class SAML2LogoutRequestBuilder implements SamlProtocolExtensionsAwareBui
}
public Document buildDocument() throws ProcessingException, ConfigurationException, ParsingException {
Document document = new SAML2Request().convert(createLogoutRequest());
Document document = SAML2Request.convert(createLogoutRequest());
return document;
}
private LogoutRequestType createLogoutRequest() throws ConfigurationException {
LogoutRequestType lort = new SAML2Request().createLogoutRequest(issuer);
LogoutRequestType lort = SAML2Request.createLogoutRequest(issuer);
NameIDType nameID = new NameIDType();
nameID.setValue(userPrincipal);
//Deal with NameID Format
String nameIDFormat = userPrincipalFormat;
nameID.setFormat(URI.create(nameIDFormat));
if (nameIDFormat != null) {
nameID.setFormat(URI.create(nameIDFormat));
}
lort.setNameID(nameID);
if (issuer != null) {

View file

@ -99,8 +99,10 @@ public class CreateLogoutRequestStepBuilder extends SamlDocumentStepBuilder<Logo
.issuer(issuer)
.sessionIndex(sessionIndex());
if (nameId() != null) {
builder = builder.userPrincipal(nameId().getValue(), nameId().getFormat().toString());
final NameIDType nameIdValue = nameId();
if (nameIdValue != null) {
builder = builder.userPrincipal(nameIdValue.getValue(), nameIdValue.getFormat() == null ? null : nameIdValue.getFormat().toString());
}
String documentAsString = DocumentUtil.getDocumentAsString(builder.buildDocument());