use of org.apache.cxf.sts.operation.TokenIssueOperation in project OpenAM by OpenRock.
the class TokenIssueOperationProvider method get.
public IssueOperation get() {
//TODO: migrate to throwing providers
try {
TokenIssueOperation tokenIssueOperation = new TokenIssueOperation();
/*
The STS will not encrypt the issued tokens - the TokenGenerationService already offers functionality to
encrypt issued SAML assertions.
*/
tokenIssueOperation.setEncryptIssuedToken(false);
tokenIssueOperation.setStsProperties(stsPropertiesMBean);
tokenIssueOperation.setTokenStore(tokenStore);
/*
Set the tokenValidators which will be called to validate the tokens presented as ActAs or OnBehalfOf
elements
*/
tokenIssueOperation.setTokenValidators(getDelegationTokenValidators());
/*
Set the TokenDelegationHandlers (either empty if this sts instance will not process ActAs or OnBehalfOf elements,
or with the DefaultTokenDelegationHandler, or with user-specified custom handlers.
*/
tokenIssueOperation.setDelegationHandlers(tokenDelegationHandlers);
List<TokenProvider> tokenProviders = new ArrayList<TokenProvider>();
for (TokenType tokenType : issueTokenTypes) {
tokenProviders.add(operationFactory.getTokenProvider(tokenType));
}
tokenIssueOperation.setTokenProviders(tokenProviders);
return new TokenIssueOperationWrapper(tokenIssueOperation, threadLocalAMTokenCache);
} catch (STSInitializationException e) {
logger.error("Exception caught initializing a IssueOperation: " + e, e);
throw new RuntimeException(e);
}
}
use of org.apache.cxf.sts.operation.TokenIssueOperation in project cxf by apache.
the class DefaultSecurityTokenServiceProvider method createTokenIssueOperation.
private TokenIssueOperation createTokenIssueOperation() {
TokenIssueOperation issueOperation = new TokenIssueOperation();
populateAbstractOperation(issueOperation);
return issueOperation;
}
use of org.apache.cxf.sts.operation.TokenIssueOperation in project cxf by apache.
the class JexlIssueSamlClaimsTest method testIssueSaml2TokenOnBehalfOfSaml2DifferentRealmFederateClaims.
/**
* Test to successfully issue a SAML 2 token (realm "B") on-behalf-of a SAML 2 token which was issued by
* realm "A". The relationship type between realm A and B is: FederateClaims
*/
@org.junit.Test
public void testIssueSaml2TokenOnBehalfOfSaml2DifferentRealmFederateClaims() throws Exception {
TokenIssueOperation issueOperation = new TokenIssueOperation();
Map<String, RealmProperties> realms = createSamlRealms();
// Add Token Provider
SAMLTokenProvider samlTokenProvider = new SAMLTokenProvider();
samlTokenProvider.setRealmMap(realms);
samlTokenProvider.setAttributeStatementProviders(Collections.singletonList(new ClaimsAttributeStatementProvider()));
issueOperation.setTokenProviders(Collections.singletonList(samlTokenProvider));
TokenDelegationHandler delegationHandler = new SAMLDelegationHandler();
issueOperation.setDelegationHandlers(Collections.singletonList(delegationHandler));
// Add Token Validator
SAMLTokenValidator samlTokenValidator = new SAMLTokenValidator();
samlTokenValidator.setSamlRealmCodec(new IssuerSAMLRealmCodec());
issueOperation.setTokenValidators(Collections.singletonList(samlTokenValidator));
addService(issueOperation);
// Add Relationship list
Relationship rs = createRelationship();
// Add STSProperties object
Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
STSPropertiesMBean stsProperties = createSTSPropertiesMBean(crypto);
stsProperties.setRealmParser(new CustomRealmParser());
stsProperties.setRelationships(Collections.singletonList(rs));
issueOperation.setStsProperties(stsProperties);
// Set the ClaimsManager
ClaimsManager claimsManager = new ClaimsManager();
ClaimsHandler claimsHandler = new CustomClaimsHandler();
claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
issueOperation.setClaimsManager(claimsManager);
// Mock up a request
RequestSecurityTokenType request = createRequest(realms, crypto);
// Mock up message context
MessageImpl msg = new MessageImpl();
WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
msgCtx.put("url", "https");
List<RequestSecurityTokenResponseType> securityTokenResponseList = issueToken(issueOperation, request, null, msgCtx);
RequestSecurityTokenResponseType securityTokenResponse = securityTokenResponseList.get(0);
// Test the generated token.
Element assertion = null;
for (Object tokenObject : securityTokenResponse.getAny()) {
if (tokenObject instanceof JAXBElement<?> && REQUESTED_SECURITY_TOKEN.equals(((JAXBElement<?>) tokenObject).getName())) {
RequestedSecurityTokenType rstType = (RequestedSecurityTokenType) ((JAXBElement<?>) tokenObject).getValue();
assertion = (Element) rstType.getAny();
break;
}
}
assertNotNull(assertion);
String tokenString = DOM2Writer.nodeToString(assertion);
assertTrue(tokenString.contains("AttributeStatement"));
// subject unchanged
assertTrue(tokenString.contains("alice"));
// transformed claim (to uppercase)
assertTrue(tokenString.contains("DOE"));
assertTrue(tokenString.contains(ROLE_CLAIM.toString()));
// mapped role from admin to administrator
assertTrue(tokenString.contains("administrator"));
assertTrue(tokenString.contains("manager"));
assertFalse(tokenString.contains("user"));
assertFalse(tokenString.contains(ClaimTypes.EMAILADDRESS.toString()));
assertTrue(tokenString.contains(SAML2Constants.CONF_BEARER));
}
use of org.apache.cxf.sts.operation.TokenIssueOperation in project cas by apereo.
the class CoreWsSecuritySecurityTokenServiceConfiguration method transportIssueDelegate.
@RefreshScope
@Bean
public IssueOperation transportIssueDelegate() {
final WsFederationProperties.SecurityTokenService wsfed = casProperties.getAuthn().getWsfedIdp().getSts();
final WsFederationProperties.IdentityProvider idp = casProperties.getAuthn().getWsfedIdp().getIdp();
final ClaimsManager claimsManager = new ClaimsManager();
claimsManager.setClaimHandlers(CollectionUtils.wrap(new WrappingSecurityTokenServiceClaimsHandler(idp.getRealmName(), wsfed.getRealm().getIssuer())));
final TokenIssueOperation op = new TokenIssueOperation();
op.setTokenProviders(transportTokenProviders());
op.setServices(CollectionUtils.wrap(transportService()));
op.setStsProperties(transportSTSProperties());
op.setClaimsManager(claimsManager);
op.setTokenValidators(transportTokenValidators());
op.setEventListener(loggerListener());
op.setDelegationHandlers(delegationHandlers());
op.setEncryptIssuedToken(wsfed.isEncryptTokens());
return op;
}
Aggregations