use of org.opensaml.saml2.core.AuthnRequest in project verify-hub by alphagov.
the class IdaAuthnRequestToAuthnRequestTransformer method apply.
@Override
public AuthnRequest apply(TInput originalRequestToIdp) {
AuthnRequest authnRequest = samlObjectFactory.createAuthnRequest();
authnRequest.setID(originalRequestToIdp.getId());
authnRequest.setIssueInstant(originalRequestToIdp.getIssueInstant());
authnRequest.setDestination(originalRequestToIdp.getDestination().toASCIIString());
authnRequest.setProtocolBinding(SAMLConstants.SAML2_POST_BINDING_URI);
Issuer issuer = samlObjectFactory.createIssuer(originalRequestToIdp.getIssuer());
authnRequest.setIssuer(issuer);
supplementAuthnRequestWithDetails(originalRequestToIdp, authnRequest);
return authnRequest;
}
use of org.opensaml.saml2.core.AuthnRequest in project verify-hub by alphagov.
the class SamlMessageSenderHandlerTest method generateAuthnRequestFromHub_shouldAddExternalCommunicationEvent.
@Test
public void generateAuthnRequestFromHub_shouldAddExternalCommunicationEvent() {
SessionId sessionId = SessionId.createNewSessionId();
String expectedSamlMessageId = UUID.randomUUID().toString();
when(sessionProxy.getAuthnRequestFromHub(any(SessionId.class))).thenReturn(new AuthnRequestFromHubContainerDto(samlRequest, postEndPoint, true));
AuthnRequest authnRequest = anAuthnRequest().withId(expectedSamlMessageId).build();
when(authnRequestTransformer.apply(samlRequest)).thenReturn(authnRequest);
SamlMessage authnResponse = samlMessageSenderHandler.generateAuthnRequestFromHub(sessionId, principalIpAddressAsSeenByHub);
assertThat(authnResponse.getSamlMessage()).isEqualTo(samlRequest);
assertThat(authnResponse.getPostEndpoint()).isEqualTo(postEndPoint.toString());
assertThat(authnResponse.getRegistration().isPresent()).isTrue();
assertThat(authnResponse.getRegistration().get()).isTrue();
assertThat(authnResponse.getSamlMessageType()).isEqualTo(SamlMessageType.SAML_REQUEST);
assertThat(authnResponse.getRelayState().isPresent()).isTrue();
assertThat(authnResponse.getRelayState().get()).isEqualTo(sessionId.getSessionId());
verify(externalCommunicationEventLogger).logIdpAuthnRequest(expectedSamlMessageId, sessionId, postEndPoint, principalIpAddressAsSeenByHub);
}
use of org.opensaml.saml2.core.AuthnRequest in project ddf by codice.
the class IdpHandler method createAndSignAuthnRequest.
private String createAndSignAuthnRequest(boolean isPost, boolean wantSigned) throws AuthenticationFailureException {
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(SamlProtocol.POST_BINDING);
authnRequest.setNameIDPolicy(SamlpRequestComponentBuilder.createNameIDPolicy(true, SAML2Constants.NAMEID_FORMAT_PERSISTENT, spIssuerId));
RequestedAuthnContextBuilder requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
for (String authContextClass : authContextClasses) {
if (StringUtils.isNotEmpty(authContextClass)) {
AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject();
authnContextClassRef.setAuthnContextClassRef(authContextClass);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
}
}
authnRequest.setRequestedAuthnContext(requestedAuthnContext);
return serializeAndSign(isPost, wantSigned, authnRequest);
}
use of org.opensaml.saml2.core.AuthnRequest in project oxCore by GluuFederation.
the class AuthRequest method getEnvelopedSignatureRequest.
/**
* This will generate an Enveloped Digital Signature xml String that you can use
* for a POST SAML AuthnRequest.
*
* @param assertionConsumerServiceUrl
* @param relayState
* optional
* @return
* @throws WSSecurityException
* @throws SecurityException
* @throws MarshallingException
* @throws org.opensaml.xml.signature.SignatureException
* @throws IOException
* @throws TransformerException
* @throws XMLStreamException
* @throws ParserConfigurationException
*/
public String getEnvelopedSignatureRequest(String assertionConsumerServiceUrl, String relayState) throws WSSecurityException, SecurityException, MarshallingException, org.opensaml.xml.signature.SignatureException, IOException, TransformerException, XMLStreamException, ParserConfigurationException {
String samlRequest = getRequest(false, assertionConsumerServiceUrl);
AuthnRequest authReq = (AuthnRequest) string2XMLObject(samlRequest);
Credential credential = this.samlSettings.getCredential();
org.opensaml.xml.signature.Signature signature = (org.opensaml.xml.signature.Signature) Configuration.getBuilderFactory().getBuilder(org.opensaml.xml.signature.Signature.DEFAULT_ELEMENT_NAME).buildObject(org.opensaml.xml.signature.Signature.DEFAULT_ELEMENT_NAME);
signature.setSigningCredential(credential);
signature.setSignatureAlgorithm(this.samlSettings.getSigAlgUrl());
signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
SecurityConfiguration secConfig = Configuration.getGlobalSecurityConfiguration();
SecurityHelper.prepareSignatureParams(signature, credential, secConfig, null);
authReq.setSignature(signature);
Configuration.getMarshallerFactory().getMarshaller(authReq).marshall(authReq);
Signer.signObject(signature);
String signedRequest = convertDocumentToString(authReq.getDOM().getOwnerDocument());
LOG.info("\n\n**************************\nSigned Post AuthnRequest:\n" + signedRequest + "\n**************************\n\n");
return signedRequest;
}
use of org.opensaml.saml2.core.AuthnRequest in project cas by apereo.
the class SSOPostProfileCallbackHandlerController method handleCallbackProfileRequest.
/**
* Handle callback profile request.
*
* @param response the response
* @param request the request
* @throws Exception the exception
*/
@GetMapping(path = SamlIdPConstants.ENDPOINT_SAML2_SSO_PROFILE_POST_CALLBACK)
protected void handleCallbackProfileRequest(final HttpServletResponse response, final HttpServletRequest request) throws Exception {
LOGGER.info("Received SAML callback profile request [{}]", request.getRequestURI());
final AuthnRequest authnRequest = retrieveSamlAuthenticationRequestFromHttpRequest(request);
if (authnRequest == null) {
LOGGER.error("Can not validate the request because the original Authn request can not be found.");
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
final String ticket = CommonUtils.safeGetParameter(request, CasProtocolConstants.PARAMETER_TICKET);
if (StringUtils.isBlank(ticket)) {
LOGGER.error("Can not validate the request because no [{}] is provided via the request", CasProtocolConstants.PARAMETER_TICKET);
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
final Pair<AuthnRequest, MessageContext> authenticationContext = buildAuthenticationContextPair(request, authnRequest);
final Assertion assertion = validateRequestAndBuildCasAssertion(response, request, authenticationContext);
buildSamlResponse(response, request, authenticationContext, assertion);
}
Aggregations