Search in sources :

Example 51 with KeyRequirements

use of org.apache.cxf.sts.request.KeyRequirements in project cxf by apache.

the class SAMLProviderKeyTypeTest method testDefaultSaml2BearerDifferentSignatureAlgorithm.

/**
 * Create a default Saml2 Bearer Assertion using a different Signature algorithm
 */
@org.junit.Test
public void testDefaultSaml2BearerDifferentSignatureAlgorithm() throws Exception {
    if (!TestUtils.checkUnrestrictedPoliciesInstalled()) {
        return;
    }
    TokenProvider samlTokenProvider = new SAMLTokenProvider();
    TokenProviderParameters providerParameters = createProviderParameters(WSS4JConstants.WSS_SAML2_TOKEN_TYPE, STSConstants.BEARER_KEY_KEYTYPE);
    KeyRequirements keyRequirements = providerParameters.getKeyRequirements();
    // Default
    TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
    assertTrue(providerResponse != null);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
    Element token = (Element) providerResponse.getToken();
    String tokenString = DOM2Writer.nodeToString(token);
    assertTrue(tokenString.contains("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"));
    // Try with unsupported alternative
    String signatureAlgorithm = WSS4JConstants.DSA;
    keyRequirements.setSignatureAlgorithm(signatureAlgorithm);
    // This will fail as the requested signature algorithm is rejected
    providerResponse = samlTokenProvider.createToken(providerParameters);
    assertTrue(providerResponse != null);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
    token = (Element) providerResponse.getToken();
    tokenString = DOM2Writer.nodeToString(token);
    assertFalse(tokenString.contains(signatureAlgorithm));
    assertTrue(tokenString.contains("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"));
    // Supported alternative
    signatureAlgorithm = WSS4JConstants.RSA_SHA1;
    keyRequirements.setSignatureAlgorithm(signatureAlgorithm);
    // This will succeed as the requested signature algorithm is accepted
    providerResponse = samlTokenProvider.createToken(providerParameters);
    assertTrue(providerResponse != null);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
    token = (Element) providerResponse.getToken();
    tokenString = DOM2Writer.nodeToString(token);
    assertTrue(tokenString.contains(signatureAlgorithm));
}
Also used : Element(org.w3c.dom.Element) KeyRequirements(org.apache.cxf.sts.request.KeyRequirements)

Example 52 with KeyRequirements

use of org.apache.cxf.sts.request.KeyRequirements in project cxf by apache.

the class SAMLProviderKeyTypeTest method createProviderParameters.

private TokenProviderParameters createProviderParameters(String tokenType, String keyType) throws WSSecurityException {
    TokenProviderParameters parameters = new TokenProviderParameters();
    TokenRequirements tokenRequirements = new TokenRequirements();
    tokenRequirements.setTokenType(tokenType);
    parameters.setTokenRequirements(tokenRequirements);
    KeyRequirements keyRequirements = new KeyRequirements();
    keyRequirements.setKeyType(keyType);
    parameters.setKeyRequirements(keyRequirements);
    parameters.setPrincipal(new CustomTokenPrincipal("alice"));
    // Mock up message context
    MessageImpl msg = new MessageImpl();
    WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
    parameters.setMessageContext(msgCtx);
    parameters.setAppliesToAddress("http://dummy-service.com/dummy");
    // Add STSProperties object
    StaticSTSProperties stsProperties = new StaticSTSProperties();
    Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
    stsProperties.setEncryptionCrypto(crypto);
    stsProperties.setSignatureCrypto(crypto);
    stsProperties.setEncryptionUsername("myservicekey");
    stsProperties.setSignatureUsername("mystskey");
    stsProperties.setCallbackHandler(new PasswordCallbackHandler());
    stsProperties.setIssuer("STS");
    parameters.setStsProperties(stsProperties);
    parameters.setEncryptionProperties(new EncryptionProperties());
    return parameters;
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) Crypto(org.apache.wss4j.common.crypto.Crypto) TokenRequirements(org.apache.cxf.sts.request.TokenRequirements) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) PasswordCallbackHandler(org.apache.cxf.sts.common.PasswordCallbackHandler) EncryptionProperties(org.apache.cxf.sts.service.EncryptionProperties) KeyRequirements(org.apache.cxf.sts.request.KeyRequirements) StaticSTSProperties(org.apache.cxf.sts.StaticSTSProperties) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 53 with KeyRequirements

use of org.apache.cxf.sts.request.KeyRequirements in project cxf by apache.

the class SAMLProviderKeyTypeTest method testDefaultSaml2EncryptWith.

/**
 * Create a default Saml2 Symmetric Key Assertion using EncryptWith Algorithms.
 */
@org.junit.Test
public void testDefaultSaml2EncryptWith() throws Exception {
    TokenProvider samlTokenProvider = new SAMLTokenProvider();
    TokenProviderParameters providerParameters = createProviderParameters(WSS4JConstants.WSS_SAML2_TOKEN_TYPE, STSConstants.SYMMETRIC_KEY_KEYTYPE);
    KeyRequirements keyRequirements = providerParameters.getKeyRequirements();
    keyRequirements.setEncryptWith(WSS4JConstants.AES_128);
    keyRequirements.setKeySize(92);
    TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
    assertTrue(providerResponse != null);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
    keyRequirements.setKeySize(128);
    keyRequirements.setEncryptWith(WSS4JConstants.AES_256);
    providerResponse = samlTokenProvider.createToken(providerParameters);
    assertTrue(providerResponse != null);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
}
Also used : KeyRequirements(org.apache.cxf.sts.request.KeyRequirements)

Example 54 with KeyRequirements

use of org.apache.cxf.sts.request.KeyRequirements in project cxf by apache.

the class SCTProviderTest method createProviderParameters.

private TokenProviderParameters createProviderParameters(String tokenType) throws WSSecurityException {
    TokenProviderParameters parameters = new TokenProviderParameters();
    TokenRequirements tokenRequirements = new TokenRequirements();
    tokenRequirements.setTokenType(tokenType);
    parameters.setTokenRequirements(tokenRequirements);
    KeyRequirements keyRequirements = new KeyRequirements();
    parameters.setKeyRequirements(keyRequirements);
    parameters.setTokenStore(tokenStore);
    parameters.setPrincipal(new CustomTokenPrincipal("alice"));
    // Mock up message context
    MessageImpl msg = new MessageImpl();
    WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
    parameters.setMessageContext(msgCtx);
    parameters.setAppliesToAddress("http://dummy-service.com/dummy");
    // Add STSProperties object
    StaticSTSProperties stsProperties = new StaticSTSProperties();
    Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
    stsProperties.setSignatureCrypto(crypto);
    stsProperties.setSignatureUsername("mystskey");
    stsProperties.setCallbackHandler(new PasswordCallbackHandler());
    stsProperties.setIssuer("STS");
    parameters.setStsProperties(stsProperties);
    parameters.setEncryptionProperties(new EncryptionProperties());
    return parameters;
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) Crypto(org.apache.wss4j.common.crypto.Crypto) TokenRequirements(org.apache.cxf.sts.request.TokenRequirements) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) PasswordCallbackHandler(org.apache.cxf.sts.common.PasswordCallbackHandler) EncryptionProperties(org.apache.cxf.sts.service.EncryptionProperties) KeyRequirements(org.apache.cxf.sts.request.KeyRequirements) StaticSTSProperties(org.apache.cxf.sts.StaticSTSProperties) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 55 with KeyRequirements

use of org.apache.cxf.sts.request.KeyRequirements in project cxf by apache.

the class SAMLTokenRenewerLifetimeTest method createProviderParameters.

private TokenProviderParameters createProviderParameters(String tokenType, String keyType, Crypto crypto, String signatureUsername, CallbackHandler callbackHandler) throws WSSecurityException {
    TokenProviderParameters parameters = new TokenProviderParameters();
    TokenRequirements tokenRequirements = new TokenRequirements();
    tokenRequirements.setTokenType(tokenType);
    parameters.setTokenRequirements(tokenRequirements);
    KeyRequirements keyRequirements = new KeyRequirements();
    keyRequirements.setKeyType(keyType);
    parameters.setKeyRequirements(keyRequirements);
    parameters.setPrincipal(new CustomTokenPrincipal("alice"));
    // Mock up message context
    MessageImpl msg = new MessageImpl();
    WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
    parameters.setMessageContext(msgCtx);
    parameters.setAppliesToAddress("http://dummy-service.com/dummy");
    // Add STSProperties object
    StaticSTSProperties stsProperties = new StaticSTSProperties();
    stsProperties.setSignatureCrypto(crypto);
    stsProperties.setSignatureUsername(signatureUsername);
    stsProperties.setCallbackHandler(callbackHandler);
    stsProperties.setIssuer("STS");
    parameters.setStsProperties(stsProperties);
    parameters.setEncryptionProperties(new EncryptionProperties());
    parameters.setTokenStore(tokenStore);
    return parameters;
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) TokenRequirements(org.apache.cxf.sts.request.TokenRequirements) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) EncryptionProperties(org.apache.cxf.sts.service.EncryptionProperties) KeyRequirements(org.apache.cxf.sts.request.KeyRequirements) StaticSTSProperties(org.apache.cxf.sts.StaticSTSProperties) MessageImpl(org.apache.cxf.message.MessageImpl) TokenProviderParameters(org.apache.cxf.sts.token.provider.TokenProviderParameters)

Aggregations

KeyRequirements (org.apache.cxf.sts.request.KeyRequirements)70 TokenRequirements (org.apache.cxf.sts.request.TokenRequirements)63 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)54 MessageImpl (org.apache.cxf.message.MessageImpl)54 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)54 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)54 EncryptionProperties (org.apache.cxf.sts.service.EncryptionProperties)46 Crypto (org.apache.wss4j.common.crypto.Crypto)37 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)36 TokenProviderParameters (org.apache.cxf.sts.token.provider.TokenProviderParameters)28 STSException (org.apache.cxf.ws.security.sts.provider.STSException)10 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)7 ReceivedKey (org.apache.cxf.sts.request.ReceivedKey)4 CryptoType (org.apache.wss4j.common.crypto.CryptoType)4 Element (org.w3c.dom.Element)4 X509Certificate (java.security.cert.X509Certificate)3 RequestRequirements (org.apache.cxf.sts.request.RequestRequirements)3 TokenValidatorParameters (org.apache.cxf.sts.token.validator.TokenValidatorParameters)3 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)3 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)3