use of org.opensaml.saml.saml2.core.impl.RequestedAuthnContextBuilder in project cloudstack by apache.
the class SAMLUtils method buildAuthnRequestObject.
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;
}
use of org.opensaml.saml.saml2.core.impl.RequestedAuthnContextBuilder in project ddf by codice.
the class IdpHandler method createAndSignAuthnRequest.
private String createAndSignAuthnRequest(boolean isPost, boolean wantSigned) throws ServletException {
String spIssuerId = getSpIssuerId();
String spAssertionConsumerServiceUrl = getSpAssertionConsumerServiceUrl(spIssuerId);
AuthnRequest authnRequest = authnRequestBuilder.buildObject();
Issuer issuer = issuerBuilder.buildObject();
issuer.setValue(spIssuerId);
authnRequest.setIssuer(issuer);
authnRequest.setAssertionConsumerServiceURL(spAssertionConsumerServiceUrl);
authnRequest.setID("_" + UUID.randomUUID().toString());
authnRequest.setVersion(SAMLVersion.VERSION_20);
authnRequest.setIssueInstant(new DateTime());
authnRequest.setDestination(idpMetadata.getSingleSignOnLocation());
authnRequest.setProtocolBinding(idpMetadata.getSingleSignOnBinding());
authnRequest.setNameIDPolicy(SamlpRequestComponentBuilder.createNameIDPolicy(true, SAML2Constants.NAMEID_FORMAT_PERSISTENT, spIssuerId));
RequestedAuthnContextBuilder requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject();
authnContextClassRef.setAuthnContextClassRef(SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
authnContextClassRef = authnContextClassRefBuilder.buildObject();
authnContextClassRef.setAuthnContextClassRef(SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
authnContextClassRef = authnContextClassRefBuilder.buildObject();
authnContextClassRef.setAuthnContextClassRef(SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
authnContextClassRef = authnContextClassRefBuilder.buildObject();
authnContextClassRef.setAuthnContextClassRef(SAML2Constants.AUTH_CONTEXT_CLASS_REF_SMARTCARD_PKI);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
authnContextClassRef = authnContextClassRefBuilder.buildObject();
authnContextClassRef.setAuthnContextClassRef(SAML2Constants.AUTH_CONTEXT_CLASS_REF_SOFTWARE_PKI);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
authnContextClassRef = authnContextClassRefBuilder.buildObject();
authnContextClassRef.setAuthnContextClassRef(SAML2Constants.AUTH_CONTEXT_CLASS_REF_SPKI);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
authnContextClassRef = authnContextClassRefBuilder.buildObject();
authnContextClassRef.setAuthnContextClassRef(SAML2Constants.AUTH_CONTEXT_CLASS_REF_TLS_CLIENT);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
authnRequest.setRequestedAuthnContext(requestedAuthnContext);
return serializeAndSign(isPost, wantSigned, authnRequest);
}
Aggregations