Skip to content

Commit

Permalink
set multiple AuthnContextClassRef (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
leleuj committed Feb 4, 2019
1 parent c14b5c7 commit 097e46b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions documentation/docs/release-notes.md
Expand Up @@ -16,6 +16,7 @@ title: Release notes:
- Renamed the `SAMLMessageStorage*` classes as `SAMLMessageStore*` (based on `Store`)

**v3.6.0**:
- Multiple authn context class refs can be set in the SAML protocol support

**v3.5.0**:

Expand Down
Expand Up @@ -105,7 +105,7 @@ public class SAML2Configuration extends InitializableObject {

private String spLogoutResponseBindingType = SAMLConstants.SAML2_POST_BINDING_URI;

private String authnContextClassRef = null;
private List<String> authnContextClassRefs = null;

private String nameIdPolicyFormat = null;

Expand Down Expand Up @@ -439,12 +439,12 @@ public void setSpLogoutResponseBindingType(final String spLogoutResponseBindingT
this.spLogoutResponseBindingType = spLogoutResponseBindingType;
}

public String getAuthnContextClassRef() {
return authnContextClassRef;
public List<String> getAuthnContextClassRefs() {
return authnContextClassRefs;
}

public void setAuthnContextClassRef(final String authnContextClassRef) {
this.authnContextClassRef = authnContextClassRef;
public void setAuthnContextClassRefs(final List<String> authnContextClassRefs) {
this.authnContextClassRefs = authnContextClassRefs;
}

public String getNameIdPolicyFormat() {
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class SAML2AuthnRequestBuilder implements SAML2ObjectBuilder<AuthnRequest

private String bindingType;

private String authnContextClassRef;
private List<String> authnContextClassRefs;

private String nameIdPolicyFormat;

Expand All @@ -71,7 +71,7 @@ public SAML2AuthnRequestBuilder(final SAML2Configuration cfg) {
this.forceAuth = cfg.isForceAuth();
this.comparisonType = getComparisonTypeEnumFromString(cfg.getComparisonType());
this.bindingType = cfg.getAuthnRequestBindingType();
this.authnContextClassRef = cfg.getAuthnContextClassRef();
this.authnContextClassRefs = cfg.getAuthnContextClassRefs();
this.nameIdPolicyFormat = cfg.getNameIdPolicyFormat();
this.passive = cfg.isPassive();
this.attributeConsumingServiceIndex = cfg.getAttributeConsumingServiceIndex();
Expand Down Expand Up @@ -101,10 +101,9 @@ protected final AuthnRequest buildAuthnRequest(final SAML2MessageContext context
final RequestedAuthnContext authnContext = new RequestedAuthnContextBuilder().buildObject();
authnContext.setComparison(comparisonType);

if (authnContextClassRef != null) {
final AuthnContextClassRef classRef = new AuthnContextClassRefBuilder().buildObject();
classRef.setAuthnContextClassRef(authnContextClassRef);
authnContext.getAuthnContextClassRefs().add(classRef);
if (authnContextClassRefs != null && !authnContextClassRefs.isEmpty()) {
final List<AuthnContextClassRef> refs = authnContext.getAuthnContextClassRefs();
authnContextClassRefs.forEach(r -> refs.add(buildAuthnContextClassRef(r)));
}
request.setRequestedAuthnContext(authnContext);
}
Expand Down Expand Up @@ -149,6 +148,12 @@ protected final AuthnRequest buildAuthnRequest(final SAML2MessageContext context
return request;
}

protected AuthnContextClassRef buildAuthnContextClassRef(final String authnContextClassRef) {
final AuthnContextClassRef classRef = new AuthnContextClassRefBuilder().buildObject();
classRef.setAuthnContextClassRef(authnContextClassRef);
return classRef;
}

@SuppressWarnings("unchecked")
protected final Issuer getIssuer(final String spEntityId) {
final SAMLObjectBuilder<Issuer> issuerBuilder = (SAMLObjectBuilder<Issuer>) this.builderFactory
Expand Down
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.zip.Inflater;
Expand Down Expand Up @@ -82,7 +83,8 @@ public void testNameIdPolicyFormat() {
public void testAuthnContextClassRef() {
final SAML2Client client = getClient();
client.getConfiguration().setComparisonType(AuthnContextComparisonTypeEnumeration.EXACT.toString());
client.getConfiguration().setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
client.getConfiguration()
.setAuthnContextClassRefs(Arrays.asList("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"));
final WebContext context = new JEEContext(new MockHttpServletRequest(), new MockHttpServletResponse());
final FoundAction action = (FoundAction) client.redirect(context);

Expand Down

0 comments on commit 097e46b

Please sign in to comment.