org.opensaml.saml2.core.AuthnContextClassRef Java Examples

The following examples show how to use org.opensaml.saml2.core.AuthnContextClassRef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SamlAssertionProducer.java    From saml-generator with Apache License 2.0 6 votes vote down vote up
private AuthnStatement createAuthnStatement(final DateTime issueDate) {
	// create authcontextclassref object
	AuthnContextClassRefBuilder classRefBuilder = new AuthnContextClassRefBuilder();
	AuthnContextClassRef classRef = classRefBuilder.buildObject();
	classRef.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
	
	// create authcontext object
	AuthnContextBuilder authContextBuilder = new AuthnContextBuilder();
	AuthnContext authnContext = authContextBuilder.buildObject();
	authnContext.setAuthnContextClassRef(classRef);
	
	// create authenticationstatement object
	AuthnStatementBuilder authStatementBuilder = new AuthnStatementBuilder();
	AuthnStatement authnStatement = authStatementBuilder.buildObject();
	authnStatement.setAuthnInstant(issueDate);
	authnStatement.setAuthnContext(authnContext);
	
	return authnStatement;
}
 
Example #2
Source File: AuthnStatementGenerator.java    From MaxKey with Apache License 2.0 6 votes vote down vote up
public AuthnStatement generateAuthnStatement(DateTime authnInstant) {
	//Response/Assertion/AuthnStatement/AuthContext/AuthContextClassRef
	AuthnContextClassRef authnContextClassRef = new AuthnContextClassRefBuilder().buildObject();
	//urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
	authnContextClassRef.setAuthnContextClassRef(AuthnContext.PPT_AUTHN_CTX);

	//Response/Assertion/AuthnStatement/AuthContext
	AuthnContext authnContext = new AuthnContextBuilder().buildObject();
	authnContext.setAuthnContextClassRef(authnContextClassRef);

	//Response/Assertion/AuthnStatement
	AuthnStatement authnStatement = new AuthnStatementBuilder().buildObject();
	authnStatement.setAuthnContext(authnContext);
	authnStatement.setAuthnInstant(authnInstant);
	logger.debug("generateAuthnStatement authnInstant "+authnInstant);
	return authnStatement;

}
 
Example #3
Source File: SAMLUtils.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public static AuthnRequest buildAuthnRequestObject(final String authnId, final String spId, final String idpUrl, final String consumerUrl) {
    // Issuer object
    IssuerBuilder issuerBuilder = new IssuerBuilder();
    Issuer issuer = issuerBuilder.buildObject();
    issuer.setValue(spId);

    // AuthnContextClass
    AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
    AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject(
            SAMLConstants.SAML20_NS,
            "AuthnContextClassRef", "saml");
    authnContextClassRef.setAuthnContextClassRef(AuthnContext.PPT_AUTHN_CTX);

    // AuthnContext
    RequestedAuthnContextBuilder requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
    RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
    requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
    requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);

    // Creation of AuthRequestObject
    AuthnRequestBuilder authRequestBuilder = new AuthnRequestBuilder();
    AuthnRequest authnRequest = authRequestBuilder.buildObject();
    authnRequest.setID(authnId);
    authnRequest.setDestination(idpUrl);
    authnRequest.setVersion(SAMLVersion.VERSION_20);
    authnRequest.setForceAuthn(false);
    authnRequest.setIsPassive(false);
    authnRequest.setIssueInstant(new DateTime());
    authnRequest.setProtocolBinding(SAMLConstants.SAML2_POST_BINDING_URI);
    authnRequest.setAssertionConsumerServiceURL(consumerUrl);
    authnRequest.setProviderName(spId);
    authnRequest.setIssuer(issuer);
    authnRequest.setRequestedAuthnContext(requestedAuthnContext);

    return authnRequest;
}
 
Example #4
Source File: AuthnContextUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
    AuthnContext authnContext = (AuthnContext) parentObject;
    if (childObject instanceof AuthnContextClassRef) {
        authnContext.setAuthnContextClassRef((AuthnContextClassRef) childObject);
    } else if (childObject instanceof AuthnContextDecl) {
        authnContext.setAuthnContextDecl((AuthnContextDecl) childObject);
    } else if (childObject instanceof AuthnContextDeclRef) {
        authnContext.setAuthnContextDeclRef((AuthnContextDeclRef) childObject);
    } else if (childObject instanceof AuthenticatingAuthority) {
        authnContext.getAuthenticatingAuthorities().add((AuthenticatingAuthority) childObject);
    } else {
        super.processChildElement(parentObject, childObject);
    }
}
 
Example #5
Source File: RequestedAuthnContextUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
        throws UnmarshallingException {
    RequestedAuthnContext rac = (RequestedAuthnContext) parentSAMLObject;
    if (childSAMLObject instanceof AuthnContextClassRef) {
        rac.getAuthnContextClassRefs().add((AuthnContextClassRef) childSAMLObject);
    } else if (childSAMLObject instanceof AuthnContextDeclRef) {
        rac.getAuthnContextDeclRefs().add((AuthnContextDeclRef) childSAMLObject);
    } else {
        super.processChildElement(parentSAMLObject, childSAMLObject);
    }
}
 
Example #6
Source File: RequestedAuthnContextImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public List<AuthnContextClassRef> getAuthnContextClassRefs() {
    return this.authnContextClassRefs;
}
 
Example #7
Source File: SAML2SSOManager.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
protected AuthnRequest buildAuthnRequest(HttpServletRequest request) throws SSOAgentException {

        IssuerBuilder issuerBuilder = new IssuerBuilder();
        Issuer issuer =
                issuerBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:assertion",
                        "Issuer", "samlp");
        issuer.setValue(ssoAgentConfig.getSAML2().getSPEntityId());

		/* NameIDPolicy */
        NameIDPolicyBuilder nameIdPolicyBuilder = new NameIDPolicyBuilder();
        NameIDPolicy nameIdPolicy = nameIdPolicyBuilder.buildObject();
        nameIdPolicy.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent");
        nameIdPolicy.setSPNameQualifier("Issuer");
        nameIdPolicy.setAllowCreate(true);

		/* AuthnContextClass */
        AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
        AuthnContextClassRef authnContextClassRef =
                authnContextClassRefBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:assertion",
                        "AuthnContextClassRef",
                        "saml");
        authnContextClassRef.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");

		/* AuthnContex */
        RequestedAuthnContextBuilder requestedAuthnContextBuilder =
                new RequestedAuthnContextBuilder();
        RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
        requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
        requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);

        DateTime issueInstant = new DateTime();

		/* Creation of AuthRequestObject */
        AuthnRequestBuilder authRequestBuilder = new AuthnRequestBuilder();
        AuthnRequest authRequest =
                authRequestBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:protocol",
                        "AuthnRequest", "samlp");

        authRequest.setForceAuthn(ssoAgentConfig.getSAML2().isForceAuthn());
        authRequest.setIsPassive(ssoAgentConfig.getSAML2().isPassiveAuthn());
        authRequest.setIssueInstant(issueInstant);
        authRequest.setProtocolBinding(ssoAgentConfig.getSAML2().getHttpBinding());
        authRequest.setAssertionConsumerServiceURL(ssoAgentConfig.getSAML2().getACSURL());
        authRequest.setIssuer(issuer);
        authRequest.setNameIDPolicy(nameIdPolicy);
        authRequest.setRequestedAuthnContext(requestedAuthnContext);
        authRequest.setID(SSOAgentUtils.createID());
        authRequest.setVersion(SAMLVersion.VERSION_20);
        authRequest.setDestination(ssoAgentConfig.getSAML2().getIdPURL());
        if (request.getAttribute(Extensions.LOCAL_NAME) != null) {
            authRequest.setExtensions((Extensions) request.getAttribute(Extensions.LOCAL_NAME));
        }

		/* Requesting Attributes. This Index value is registered in the IDP */
        if (ssoAgentConfig.getSAML2().getAttributeConsumingServiceIndex() != null &&
                ssoAgentConfig.getSAML2().getAttributeConsumingServiceIndex().trim().length() > 0) {
            authRequest.setAttributeConsumingServiceIndex(Integer.parseInt(
                    ssoAgentConfig.getSAML2().getAttributeConsumingServiceIndex()));
        }

        return authRequest;
    }
 
Example #8
Source File: DefaultSAML2SSOManager.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
private RequestedAuthnContext buildRequestedAuthnContext(AuthnRequest inboundAuthnRequest) throws SAMLSSOException {
    
    /* AuthnContext */
    RequestedAuthnContextBuilder requestedAuthnContextBuilder = null;
    RequestedAuthnContext requestedAuthnContext = null;
    
    String includeAuthnContext = properties
            .get(IdentityApplicationConstants.Authenticator.SAML2SSO.INCLUDE_AUTHN_CONTEXT);
    
    if (StringUtils.isNotEmpty(includeAuthnContext) && "as_request".equalsIgnoreCase(includeAuthnContext)) {
        if (inboundAuthnRequest != null) {
            RequestedAuthnContext incomingRequestedAuthnContext = inboundAuthnRequest.getRequestedAuthnContext();
            if (incomingRequestedAuthnContext != null) {
                requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
                requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
                requestedAuthnContext.setDOM(incomingRequestedAuthnContext.getDOM());
            }
        }
    } else if (StringUtils.isEmpty(includeAuthnContext) || "yes".equalsIgnoreCase(includeAuthnContext)) {
        requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
        requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
        /* AuthnContextClass */
        AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
        AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder
                .buildObject(SAMLConstants.SAML20_NS,
                        AuthnContextClassRef.DEFAULT_ELEMENT_LOCAL_NAME,
                        SAMLConstants.SAML20_PREFIX);

        String authnContextClassProp = properties
                .get(IdentityApplicationConstants.Authenticator.SAML2SSO.AUTHENTICATION_CONTEXT_CLASS);

        if (StringUtils.isNotEmpty(authnContextClassProp)) {
            authnContextClassRef.setAuthnContextClassRef(IdentityApplicationManagementUtil
                    .getSAMLAuthnContextClasses().get(authnContextClassProp));
        } else {
            authnContextClassRef.setAuthnContextClassRef(AuthnContext.PPT_AUTHN_CTX);
        }

        /* Authentication Context Comparison Level */
        String authnContextComparison = properties
                .get(IdentityApplicationConstants.Authenticator.SAML2SSO.AUTHENTICATION_CONTEXT_COMPARISON_LEVEL);

        if (StringUtils.isNotEmpty(authnContextComparison)) {
            if (AuthnContextComparisonTypeEnumeration.EXACT.toString().equalsIgnoreCase(
                    authnContextComparison)) {
                requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
            } else if (AuthnContextComparisonTypeEnumeration.MINIMUM.toString().equalsIgnoreCase(
                    authnContextComparison)) {
                requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.MINIMUM);
            } else if (AuthnContextComparisonTypeEnumeration.MAXIMUM.toString().equalsIgnoreCase(
                    authnContextComparison)) {
                requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.MAXIMUM);
            } else if (AuthnContextComparisonTypeEnumeration.BETTER.toString().equalsIgnoreCase(
                    authnContextComparison)) {
                requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.BETTER);
            }
        } else {
            requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
        }
        requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
    }
    return requestedAuthnContext;
}
 
Example #9
Source File: AuthnContextImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void setAuthnContextClassRef(AuthnContextClassRef newAuthnContextClassRef) {
    this.authnContextClassRef = prepareForAssignment(this.authnContextClassRef, newAuthnContextClassRef);
}
 
Example #10
Source File: AuthnContextImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public AuthnContextClassRef getAuthnContextClassRef() {
    return authnContextClassRef;
}
 
Example #11
Source File: AuthnContextClassRefSchemaValidator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void validate(AuthnContextClassRef authnContextClassRef) throws ValidationException {
    validateClassRef(authnContextClassRef);
}
 
Example #12
Source File: AuthnContextClassRefBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public AuthnContextClassRef buildObject(String namespaceURI, String localName, String namespacePrefix) {
    return new AuthnContextClassRefImpl(namespaceURI, localName, namespacePrefix);
}
 
Example #13
Source File: AuthnContextClassRefBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public AuthnContextClassRef buildObject() {
    return buildObject(SAMLConstants.SAML20_NS, AuthnContextClassRef.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20_PREFIX);
}
 
Example #14
Source File: AuthnContextClassRefMarshaller.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException {
    AuthnContextClassRef authnContextClassRef = (AuthnContextClassRef) samlObject;
    XMLHelper.appendTextContent(domElement, authnContextClassRef.getAuthnContextClassRef());
}
 
Example #15
Source File: AuthnContextClassRefUnmarshaller.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
protected void processElementContent(XMLObject samlObject, String elementContent) {
    AuthnContextClassRef authnContextClassRef = (AuthnContextClassRef) samlObject;
    authnContextClassRef.setAuthnContextClassRef(elementContent);
}
 
Example #16
Source File: RequestedAuthnContextImpl.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor.
 * 
 * @param namespaceURI the namespace the element is in
 * @param elementLocalName the local name of the XML element this Object represents
 * @param namespacePrefix the prefix for the given namespace
 */
protected RequestedAuthnContextImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
    super(namespaceURI, elementLocalName, namespacePrefix);
    authnContextClassRefs = new XMLObjectChildrenList<AuthnContextClassRef>(this);
    authnContextDeclRefs = new XMLObjectChildrenList<AuthnContextDeclRef>(this);
}
 
Example #17
Source File: AuthnContextClassRefSchemaValidator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Checks that the AuthnContextClassRef is present.
 * 
 * @param authnCCR
 * @throws ValidationException
 */
protected void validateClassRef(AuthnContextClassRef authnCCR) throws ValidationException {
    if (DatatypeHelper.isEmpty(authnCCR.getAuthnContextClassRef())) {
        throw new ValidationException("AuthnContextClassRef required");
    }
}