KEYCLOAK-5254 Fix NPE - NameID format is optional

This commit is contained in:
Hynek Mlnarik 2017-09-14 14:59:05 +02:00
parent 685acb786a
commit 9098105a64
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());