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);
}
}
}
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());
}
}
}
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());
}
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());
}
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());
}
Aggregations