use of org.apache.cxf.sts.common.CustomAttributeProvider in project cxf by apache.
the class SAMLProviderCustomTest method testCustomSaml1AttributeAssertion.
/**
* Create a custom Saml1 Attribute Assertion.
*/
@org.junit.Test
public void testCustomSaml1AttributeAssertion() throws Exception {
TokenProvider samlTokenProvider = new SAMLTokenProvider();
TokenProviderParameters providerParameters = createProviderParameters(WSS4JConstants.WSS_SAML_TOKEN_TYPE, STSConstants.BEARER_KEY_KEYTYPE);
List<AttributeStatementProvider> customProviderList = new ArrayList<>();
customProviderList.add(new CustomAttributeProvider());
((SAMLTokenProvider) samlTokenProvider).setAttributeStatementProviders(customProviderList);
assertTrue(samlTokenProvider.canHandleToken(WSS4JConstants.WSS_SAML_TOKEN_TYPE));
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(providerResponse.getTokenId()));
assertTrue(tokenString.contains("AttributeStatement"));
assertFalse(tokenString.contains("AuthenticationStatement"));
assertTrue(tokenString.contains("alice"));
assertTrue(tokenString.contains("http://cxf.apache.org/sts/custom"));
}
use of org.apache.cxf.sts.common.CustomAttributeProvider in project cxf by apache.
the class SAMLProviderCustomTest method testCustomSaml2CombinedAssertion.
/**
* Create a custom Saml2 Authentication and Attribute Assertion.
*/
@org.junit.Test
public void testCustomSaml2CombinedAssertion() throws Exception {
TokenProvider samlTokenProvider = new SAMLTokenProvider();
TokenProviderParameters providerParameters = createProviderParameters(WSS4JConstants.WSS_SAML2_TOKEN_TYPE, STSConstants.BEARER_KEY_KEYTYPE);
List<AuthenticationStatementProvider> customProviderList = new ArrayList<>();
customProviderList.add(new CustomAuthenticationProvider());
((SAMLTokenProvider) samlTokenProvider).setAuthenticationStatementProviders(customProviderList);
List<AttributeStatementProvider> customAttributeProviderList = new ArrayList<>();
customAttributeProviderList.add(new CustomAttributeProvider());
((SAMLTokenProvider) samlTokenProvider).setAttributeStatementProviders(customAttributeProviderList);
assertTrue(samlTokenProvider.canHandleToken(WSS4JConstants.WSS_SAML2_TOKEN_TYPE));
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(providerResponse.getTokenId()));
assertTrue(tokenString.contains("AttributeStatement"));
assertTrue(tokenString.contains("AuthnStatement"));
assertTrue(tokenString.contains("alice"));
}
Aggregations