use of org.apache.cxf.sts.common.PasswordCallbackHandler in project cxf by apache.
the class SAMLTokenRenewerLifetimeTest method createRenewerParameters.
private TokenRenewerParameters createRenewerParameters() throws WSSecurityException {
TokenRenewerParameters parameters = new TokenRenewerParameters();
TokenRequirements tokenRequirements = new TokenRequirements();
parameters.setTokenRequirements(tokenRequirements);
parameters.setKeyRequirements(new 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());
parameters.setTokenStore(tokenStore);
return parameters;
}
use of org.apache.cxf.sts.common.PasswordCallbackHandler in project cxf by apache.
the class SAMLTokenRenewerRealmTest method testRealmA.
/**
* Test a SAML 1.1 Assertion created in realm "A".
*/
@org.junit.Test
public void testRealmA() throws Exception {
// Create a RenewTarget consisting of a SAML Assertion
Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
CallbackHandler callbackHandler = new PasswordCallbackHandler();
TokenProviderParameters providerParameters = createProviderParameters(WSS4JConstants.WSS_SAML_TOKEN_TYPE, STSConstants.BEARER_KEY_KEYTYPE, crypto, "mystskey", callbackHandler);
Element samlToken = createSAMLAssertion(providerParameters, "A", 50, true, true);
// Sleep to expire the token
Thread.sleep(100);
Document doc = samlToken.getOwnerDocument();
samlToken = (Element) doc.appendChild(samlToken);
TokenValidator samlTokenValidator = new SAMLTokenValidator();
SAMLRealmCodec samlRealmCodec = new IssuerSAMLRealmCodec();
((SAMLTokenValidator) samlTokenValidator).setSamlRealmCodec(samlRealmCodec);
TokenValidatorParameters validatorParameters = createValidatorParameters();
ReceivedToken renewTarget = new ReceivedToken(samlToken);
TokenRequirements tokenRequirements = validatorParameters.getTokenRequirements();
tokenRequirements.setValidateTarget(renewTarget);
validatorParameters.setToken(renewTarget);
// Validate the token
TokenValidatorResponse validatorResponse = samlTokenValidator.validateToken(validatorParameters);
assertNotNull(validatorResponse);
assertNotNull(validatorResponse.getToken());
assertTrue(validatorResponse.getToken().getState() == STATE.EXPIRED);
assertEquals("A", validatorResponse.getTokenRealm());
// Renew the Assertion
TokenRenewerParameters renewerParameters = new TokenRenewerParameters();
renewerParameters.setAppliesToAddress("http://dummy-service.com/dummy");
renewerParameters.setStsProperties(validatorParameters.getStsProperties());
renewerParameters.setPrincipal(new CustomTokenPrincipal("alice"));
renewerParameters.setMessageContext(validatorParameters.getMessageContext());
renewerParameters.setKeyRequirements(validatorParameters.getKeyRequirements());
renewerParameters.setTokenRequirements(validatorParameters.getTokenRequirements());
renewerParameters.setTokenStore(validatorParameters.getTokenStore());
renewerParameters.setToken(validatorResponse.getToken());
TokenRenewer samlTokenRenewer = new SAMLTokenRenewer();
samlTokenRenewer.setVerifyProofOfPossession(false);
samlTokenRenewer.setAllowRenewalAfterExpiry(true);
Map<String, RealmProperties> samlRealms = getSamlRealms();
((SAMLTokenRenewer) samlTokenRenewer).setRealmMap(samlRealms);
String realm = validatorResponse.getTokenRealm();
assertTrue(samlTokenRenewer.canHandleToken(validatorResponse.getToken(), realm));
TokenRenewerResponse renewerResponse = samlTokenRenewer.renewToken(renewerParameters);
assertNotNull(renewerResponse);
assertNotNull(renewerResponse.getToken());
// Now validate it again
ReceivedToken validateTarget = new ReceivedToken(renewerResponse.getToken());
tokenRequirements.setValidateTarget(validateTarget);
validatorParameters.setToken(validateTarget);
validatorResponse = samlTokenValidator.validateToken(validatorParameters);
assertNotNull(validatorResponse);
assertNotNull(validatorResponse.getToken());
assertTrue(validatorResponse.getToken().getState() == STATE.VALID);
}
use of org.apache.cxf.sts.common.PasswordCallbackHandler in project cxf by apache.
the class SAMLTokenRenewerRealmTest method testRealmB.
/**
* Test a SAML 1.1 Assertion created in realm "B".
*/
@org.junit.Test
public void testRealmB() throws Exception {
// Create a RenewTarget consisting of a SAML Assertion
Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
CallbackHandler callbackHandler = new PasswordCallbackHandler();
TokenProviderParameters providerParameters = createProviderParameters(WSS4JConstants.WSS_SAML_TOKEN_TYPE, STSConstants.BEARER_KEY_KEYTYPE, crypto, "mystskey", callbackHandler);
Element samlToken = createSAMLAssertion(providerParameters, "B", 50, true, true);
// Sleep to expire the token
Thread.sleep(100);
Document doc = samlToken.getOwnerDocument();
samlToken = (Element) doc.appendChild(samlToken);
TokenValidator samlTokenValidator = new SAMLTokenValidator();
SAMLRealmCodec samlRealmCodec = new IssuerSAMLRealmCodec();
((SAMLTokenValidator) samlTokenValidator).setSamlRealmCodec(samlRealmCodec);
TokenValidatorParameters validatorParameters = createValidatorParameters();
ReceivedToken renewTarget = new ReceivedToken(samlToken);
TokenRequirements tokenRequirements = validatorParameters.getTokenRequirements();
tokenRequirements.setValidateTarget(renewTarget);
validatorParameters.setToken(renewTarget);
// Validate the token
TokenValidatorResponse validatorResponse = samlTokenValidator.validateToken(validatorParameters);
assertNotNull(validatorResponse);
assertNotNull(validatorResponse.getToken());
assertTrue(validatorResponse.getToken().getState() == STATE.EXPIRED);
assertEquals("B", validatorResponse.getTokenRealm());
// Renew the Assertion
TokenRenewerParameters renewerParameters = new TokenRenewerParameters();
renewerParameters.setAppliesToAddress("http://dummy-service.com/dummy");
renewerParameters.setStsProperties(validatorParameters.getStsProperties());
renewerParameters.setPrincipal(new CustomTokenPrincipal("alice"));
renewerParameters.setMessageContext(validatorParameters.getMessageContext());
renewerParameters.setKeyRequirements(validatorParameters.getKeyRequirements());
renewerParameters.setTokenRequirements(validatorParameters.getTokenRequirements());
renewerParameters.setTokenStore(validatorParameters.getTokenStore());
renewerParameters.setToken(validatorResponse.getToken());
TokenRenewer samlTokenRenewer = new SAMLTokenRenewer();
samlTokenRenewer.setVerifyProofOfPossession(false);
samlTokenRenewer.setAllowRenewalAfterExpiry(true);
Map<String, RealmProperties> samlRealms = getSamlRealms();
((SAMLTokenRenewer) samlTokenRenewer).setRealmMap(samlRealms);
String realm = validatorResponse.getTokenRealm();
assertTrue(samlTokenRenewer.canHandleToken(validatorResponse.getToken(), realm));
TokenRenewerResponse renewerResponse = samlTokenRenewer.renewToken(renewerParameters);
assertNotNull(renewerResponse);
assertNotNull(renewerResponse.getToken());
// Now validate it again
ReceivedToken validateTarget = new ReceivedToken(renewerResponse.getToken());
tokenRequirements.setValidateTarget(validateTarget);
validatorParameters.setToken(validateTarget);
validatorResponse = samlTokenValidator.validateToken(validatorParameters);
assertNotNull(validatorResponse);
assertNotNull(validatorResponse.getToken());
assertTrue(validatorResponse.getToken().getState() == STATE.VALID);
}
use of org.apache.cxf.sts.common.PasswordCallbackHandler in project cxf by apache.
the class JWTTokenValidatorRealmTest method createValidatorParameters.
private TokenValidatorParameters createValidatorParameters() throws WSSecurityException {
TokenValidatorParameters parameters = new TokenValidatorParameters();
TokenRequirements tokenRequirements = new TokenRequirements();
tokenRequirements.setTokenType(STSConstants.STATUS);
parameters.setTokenRequirements(tokenRequirements);
KeyRequirements keyRequirements = new KeyRequirements();
parameters.setKeyRequirements(keyRequirements);
parameters.setPrincipal(new CustomTokenPrincipal("alice"));
// Mock up message context
MessageImpl msg = new MessageImpl();
WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
parameters.setMessageContext(msgCtx);
// 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.setTokenStore(tokenStore);
return parameters;
}
use of org.apache.cxf.sts.common.PasswordCallbackHandler in project cxf by apache.
the class JWTTokenValidatorRealmTest method createProviderParameters.
private TokenProviderParameters createProviderParameters() throws WSSecurityException {
TokenProviderParameters parameters = new TokenProviderParameters();
TokenRequirements tokenRequirements = new TokenRequirements();
tokenRequirements.setTokenType(JWTTokenProvider.JWT_TOKEN_TYPE);
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());
stsProperties.setEncryptionCrypto(crypto);
stsProperties.setEncryptionUsername("myservicekey");
stsProperties.setCallbackHandler(new PasswordCallbackHandler());
return parameters;
}
Aggregations