From 197f51e50f3dea3cffe556a40e4d4d37271138c1 Mon Sep 17 00:00:00 2001 From: Hynek Mlnarik Date: Mon, 5 Dec 2016 07:24:38 +0100 Subject: [PATCH] KEYCLOAK-3950 Fix NPE on request for NameIDPolicy without format ... and two more one-line issues --- .../java/org/keycloak/protocol/saml/SamlService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/services/src/main/java/org/keycloak/protocol/saml/SamlService.java b/services/src/main/java/org/keycloak/protocol/saml/SamlService.java index c404ef8eee..b69e57e490 100755 --- a/services/src/main/java/org/keycloak/protocol/saml/SamlService.java +++ b/services/src/main/java/org/keycloak/protocol/saml/SamlService.java @@ -248,9 +248,9 @@ public class SamlService extends AuthorizationEndpointBase { String bindingType = getBindingType(requestAbstractType); if (samlClient.forcePostBinding()) bindingType = SamlProtocol.SAML_POST_BINDING; - String redirect = null; + String redirect; URI redirectUri = requestAbstractType.getAssertionConsumerServiceURL(); - if (redirectUri != null && !"null".equals(redirectUri)) { // "null" is for testing purposes + if (redirectUri != null && ! "null".equals(redirectUri.toString())) { // "null" is for testing purposes redirect = RedirectUtils.verifyRedirectUri(uriInfo, redirectUri.toString(), realm, client); } else { if (bindingType.equals(SamlProtocol.SAML_POST_BINDING)) { @@ -279,8 +279,9 @@ public class SamlService extends AuthorizationEndpointBase { // Handle NameIDPolicy from SP NameIDPolicyType nameIdPolicy = requestAbstractType.getNameIDPolicy(); - if (nameIdPolicy != null && !samlClient.forceNameIDFormat()) { - String nameIdFormat = nameIdPolicy.getFormat().toString(); + final URI nameIdFormatUri = nameIdPolicy == null ? null : nameIdPolicy.getFormat(); + if (nameIdFormatUri != null && ! samlClient.forceNameIDFormat()) { + String nameIdFormat = nameIdFormatUri.toString(); // TODO: Handle AllowCreate too, relevant for persistent NameID. if (isSupportedNameIdFormat(nameIdFormat)) { clientSession.setNote(GeneralConstants.NAMEID_FORMAT, nameIdFormat); @@ -345,7 +346,7 @@ public class SamlService extends AuthorizationEndpointBase { AuthenticationManager.AuthResult authResult = authManager.authenticateIdentityCookie(session, realm, false); if (authResult != null) { String logoutBinding = getBindingType(); - if ("true".equals(samlClient.forcePostBinding())) + if (samlClient.forcePostBinding()) logoutBinding = SamlProtocol.SAML_POST_BINDING; boolean postBinding = Objects.equals(SamlProtocol.SAML_POST_BINDING, logoutBinding);