Search in sources :

Example 1 with SecurityToken

use of org.apache.cxf.ws.security.tokenstore.SecurityToken in project OpenAM by OpenRock.

the class SoapSTSConsumer method validateTokenSuiteInternal.

private void validateTokenSuiteInternal(List<EndpointSpecification> endpoints, List<TokenSpecification> tokenSpecs, SecurityToken token) throws SoapSTSConsumerException {
    for (EndpointSpecification endpoint : endpoints) {
        for (TokenSpecification tokenSpec : tokenSpecs) {
            SecurityToken localToken = token;
            if (localToken == null) {
                localToken = issueTokenInternal(endpoint, tokenSpec, ALLOW_TOKEN_RENEWAL);
            }
            validateToken(endpoint, localToken);
        }
    }
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken)

Example 2 with SecurityToken

use of org.apache.cxf.ws.security.tokenstore.SecurityToken in project cas by apereo.

the class SecurityTokenServiceAuthenticationPostProcessor method invokeSecurityTokenServiceForToken.

private void invokeSecurityTokenServiceForToken(final AuthenticationTransaction transaction, final AuthenticationBuilder builder, final WSFederationRegisteredService rp, final SecurityTokenServiceClient sts) {
    final UsernamePasswordCredential up = transaction.getCredentials().stream().filter(UsernamePasswordCredential.class::isInstance).map(UsernamePasswordCredential.class::cast).findFirst().orElse(null);
    if (up != null) {
        try {
            sts.getProperties().put(SecurityConstants.USERNAME, up.getUsername());
            final String uid = credentialCipherExecutor.encode(up.getUsername());
            sts.getProperties().put(SecurityConstants.PASSWORD, uid);
            final SecurityToken token = sts.requestSecurityToken(rp.getAppliesTo());
            final String tokenStr = EncodingUtils.encodeBase64(SerializationUtils.serialize(token));
            builder.addAttribute(WSFederationConstants.SECURITY_TOKEN_ATTRIBUTE, tokenStr);
        } catch (final Exception e) {
            throw new AuthenticationException(e.getMessage());
        }
    }
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) UnauthorizedSsoServiceException(org.apereo.cas.services.UnauthorizedSsoServiceException)

Example 3 with SecurityToken

use of org.apache.cxf.ws.security.tokenstore.SecurityToken in project ddf by codice.

the class SAMLAssertionHandlerTest method testGetNormalizedTokenSuccessWithHeader.

/**
     * This test ensures the proper functionality of SAMLAssertionHandler's
     * method, getNormalizedToken(), when given a valid HttpServletRequest.
     */
@Test
public void testGetNormalizedTokenSuccessWithHeader() throws Exception {
    SAMLAssertionHandler handler = new SAMLAssertionHandler();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain chain = mock(FilterChain.class);
    Element assertion = readDocument("/saml.xml").getDocumentElement();
    String assertionId = assertion.getAttributeNodeNS(null, "ID").getNodeValue();
    SecurityToken samlToken = new SecurityToken(assertionId, assertion, null);
    SamlAssertionWrapper wrappedAssertion = new SamlAssertionWrapper(samlToken.getToken());
    String saml = wrappedAssertion.assertionToString();
    doReturn("SAML " + RestSecurity.deflateAndBase64Encode(saml)).when(request).getHeader(SecurityConstants.SAML_HEADER_NAME);
    HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
    assertNotNull(result);
    assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) FilterChain(javax.servlet.FilterChain) Element(org.w3c.dom.Element) HttpServletResponse(javax.servlet.http.HttpServletResponse) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 4 with SecurityToken

use of org.apache.cxf.ws.security.tokenstore.SecurityToken in project ddf by codice.

the class SAMLAssertionHandlerTest method testGetNormalizedTokenFromSession.

@Test
public void testGetNormalizedTokenFromSession() throws Exception {
    SAMLAssertionHandler handler = new SAMLAssertionHandler();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain chain = mock(FilterChain.class);
    when(request.getCookies()).thenReturn(null);
    HttpSession session = mock(HttpSession.class);
    when(request.getSession(false)).thenReturn(session);
    when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("foo");
    SecurityTokenHolder tokenHolder = mock(SecurityTokenHolder.class);
    when(session.getAttribute(SecurityConstants.SAML_ASSERTION)).thenReturn(tokenHolder);
    SecurityToken securityToken = mock(SecurityToken.class);
    when(tokenHolder.getSecurityToken("foo")).thenReturn(securityToken);
    when(securityToken.getToken()).thenReturn(readDocument("/saml.xml").getDocumentElement());
    HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
    assertNotNull(result);
    assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) SecurityTokenHolder(ddf.security.common.SecurityTokenHolder) HttpSession(javax.servlet.http.HttpSession) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 5 with SecurityToken

use of org.apache.cxf.ws.security.tokenstore.SecurityToken in project ddf by codice.

the class SAMLAssertionHandlerTest method testGetNormalizedTokenSuccessWithCookie.

/**
     * This test ensures the proper functionality of SAMLAssertionHandler's
     * method, getNormalizedToken(), when given a valid HttpServletRequest.
     * Uses legacy SAML cookie
     */
@Test
public void testGetNormalizedTokenSuccessWithCookie() throws Exception {
    SAMLAssertionHandler handler = new SAMLAssertionHandler();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain chain = mock(FilterChain.class);
    Element assertion = readDocument("/saml.xml").getDocumentElement();
    String assertionId = assertion.getAttributeNodeNS(null, "ID").getNodeValue();
    SecurityToken samlToken = new SecurityToken(assertionId, assertion, null);
    SamlAssertionWrapper wrappedAssertion = new SamlAssertionWrapper(samlToken.getToken());
    String saml = wrappedAssertion.assertionToString();
    Cookie cookie = new Cookie(SecurityConstants.SAML_COOKIE_NAME, RestSecurity.deflateAndBase64Encode(saml));
    when(request.getCookies()).thenReturn(new Cookie[] { cookie });
    HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
    assertNotNull(result);
    assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Cookie(javax.servlet.http.Cookie) FilterChain(javax.servlet.FilterChain) Element(org.w3c.dom.Element) HttpServletResponse(javax.servlet.http.HttpServletResponse) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Aggregations

SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)187 Element (org.w3c.dom.Element)57 Test (org.junit.Test)47 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)35 Subject (ddf.security.Subject)32 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)28 SecurityAssertion (ddf.security.assertion.SecurityAssertion)27 QName (javax.xml.namespace.QName)26 Fault (org.apache.cxf.interceptor.Fault)23 SecurityManager (ddf.security.service.SecurityManager)22 TokenStoreException (org.apache.cxf.ws.security.tokenstore.TokenStoreException)18 TokenStore (org.apache.cxf.ws.security.tokenstore.TokenStore)17 SOAPException (javax.xml.soap.SOAPException)16 Message (org.apache.cxf.message.Message)16 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)16 IssuedToken (org.apache.wss4j.policy.model.IssuedToken)15 CollectionPermission (ddf.security.permission.CollectionPermission)14 Bus (org.apache.cxf.Bus)14 Document (org.w3c.dom.Document)14 ArrayList (java.util.ArrayList)13