Java Code Examples for org.opensaml.messaging.context.MessageContext#getSubcontext()
The following examples show how to use
org.opensaml.messaging.context.MessageContext#getSubcontext() .
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: AuthenticationHandlerSAML2.java From sling-whiteboard with Apache License 2.0 | 5 votes |
private boolean validateRelayState(HttpServletRequest req, MessageContext messageContext) { SAMLBindingContext bindingContext = messageContext.getSubcontext(SAMLBindingContext.class, true); String reportedRelayState = bindingContext.getRelayState(); SessionStorage relayStateStore = new SessionStorage(saml2ConfigService.getSaml2SessionAttr()); String savedRelayState = relayStateStore.getString(req); if (savedRelayState == null || savedRelayState.isEmpty()){ return false; } else if (savedRelayState.equals(reportedRelayState)){ return true; } return false; }
Example 2
Source File: SamlAssertionConsumerFunction.java From armeria with Apache License 2.0 | 5 votes |
@Override public HttpResponse serve(ServiceRequestContext ctx, AggregatedHttpRequest req, String defaultHostname, SamlPortConfig portConfig) { try { final MessageContext<Response> messageContext; if (cfg.endpoint().bindingProtocol() == SamlBindingProtocol.HTTP_REDIRECT) { messageContext = HttpRedirectBindingUtil.toSamlObject(req, SAML_RESPONSE, idpConfigs, defaultIdpConfig); } else { messageContext = HttpPostBindingUtil.toSamlObject(req, SAML_RESPONSE); } final String endpointUri = cfg.endpoint().toUriString(portConfig.scheme().uriText(), defaultHostname, portConfig.port()); final Response response = messageContext.getMessage(); final Assertion assertion = getValidatedAssertion(response, endpointUri); // Find a session index which is sent by an identity provider. final String sessionIndex = assertion.getAuthnStatements().stream() .map(AuthnStatement::getSessionIndex) .filter(Objects::nonNull) .findFirst().orElse(null); final SAMLBindingContext bindingContext = messageContext.getSubcontext(SAMLBindingContext.class); final String relayState = bindingContext != null ? bindingContext.getRelayState() : null; return ssoHandler.loginSucceeded(ctx, req, messageContext, sessionIndex, relayState); } catch (SamlException e) { return ssoHandler.loginFailed(ctx, req, null, e); } }
Example 3
Source File: MockSamlIdpServer.java From deprecated-security-advanced-modules with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public void handleSloGetRequestBase(HttpRequest request) { try { HttpServletRequest httpServletRequest = new FakeHttpServletRequest(request); HTTPRedirectDeflateDecoder decoder = new HTTPRedirectDeflateDecoder(); decoder.setParserPool(XMLObjectProviderRegistrySupport.getParserPool()); decoder.setHttpServletRequest(httpServletRequest); decoder.initialize(); decoder.decode(); MessageContext<SAMLObject> messageContext = decoder.getMessageContext(); if (!(messageContext.getMessage() instanceof LogoutRequest)) { throw new RuntimeException("Expected LogoutRequest; received: " + messageContext.getMessage()); } LogoutRequest logoutRequest = (LogoutRequest) messageContext.getMessage(); SAML2HTTPRedirectDeflateSignatureSecurityHandler signatureSecurityHandler = new SAML2HTTPRedirectDeflateSignatureSecurityHandler(); SignatureValidationParameters validationParams = new SignatureValidationParameters(); SecurityParametersContext securityParametersContext = messageContext .getSubcontext(SecurityParametersContext.class, true); SAMLPeerEntityContext peerEntityContext = messageContext.getSubcontext(SAMLPeerEntityContext.class, true); peerEntityContext.setEntityId(idpEntityId); peerEntityContext.setRole(org.opensaml.saml.saml2.metadata.SPSSODescriptor.DEFAULT_ELEMENT_NAME); SAMLProtocolContext protocolContext = messageContext.getSubcontext(SAMLProtocolContext.class, true); protocolContext.setProtocol(SAMLConstants.SAML20P_NS); validationParams.setSignatureTrustEngine(buildSignatureTrustEngine(this.spSignatureCertificate)); securityParametersContext.setSignatureValidationParameters(validationParams); signatureSecurityHandler.setHttpServletRequest(httpServletRequest); signatureSecurityHandler.initialize(); signatureSecurityHandler.invoke(messageContext); if (!this.authenticateUser.equals(logoutRequest.getNameID().getValue())) { throw new RuntimeException("Unexpected NameID in LogoutRequest: " + logoutRequest); } } catch (URISyntaxException | ComponentInitializationException | MessageDecodingException | MessageHandlerException e) { throw new RuntimeException(e); } }