Search in sources :

Example 6 with ReceivedCredential

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

the class IssueOnbehalfofUnitTest 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);
    CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
    cryptoType.setAlias("myclientkey");
    X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
    ReceivedCredential receivedCredential = new ReceivedCredential();
    receivedCredential.setX509Cert(certs[0]);
    keyRequirements.setReceivedCredential(receivedCredential);
    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");
    stsProperties.setEncryptionUsername("myservicekey");
    stsProperties.setEncryptionCrypto(crypto);
    parameters.setStsProperties(stsProperties);
    parameters.setEncryptionProperties(new EncryptionProperties());
    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) CryptoType(org.apache.wss4j.common.crypto.CryptoType) StaticSTSProperties(org.apache.cxf.sts.StaticSTSProperties) MessageImpl(org.apache.cxf.message.MessageImpl) X509Certificate(java.security.cert.X509Certificate) TokenProviderParameters(org.apache.cxf.sts.token.provider.TokenProviderParameters) ReceivedCredential(org.apache.cxf.sts.request.ReceivedCredential)

Aggregations

ReceivedCredential (org.apache.cxf.sts.request.ReceivedCredential)6 CryptoType (org.apache.wss4j.common.crypto.CryptoType)6 X509Certificate (java.security.cert.X509Certificate)5 KeyRequirements (org.apache.cxf.sts.request.KeyRequirements)4 EncryptionProperties (org.apache.cxf.sts.service.EncryptionProperties)4 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)3 MessageImpl (org.apache.cxf.message.MessageImpl)3 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)3 TokenRequirements (org.apache.cxf.sts.request.TokenRequirements)3 TokenProviderParameters (org.apache.cxf.sts.token.provider.TokenProviderParameters)3 STSException (org.apache.cxf.ws.security.sts.provider.STSException)3 Crypto (org.apache.wss4j.common.crypto.Crypto)3 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)3 Element (org.w3c.dom.Element)2 Collection (java.util.Collection)1 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)1 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)1 Document (org.w3c.dom.Document)1