use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.
the class SAML2TokenGenerationImplTest method getRestSTSInstanceConfig.
private RestSTSInstanceConfig getRestSTSInstanceConfig(boolean signAssertion) throws UnsupportedEncodingException {
Map<String, String> context = new HashMap<>();
context.put(AMSTSConstants.OPEN_ID_CONNECT_ID_TOKEN_AUTH_TARGET_HEADER_KEY, "oidc_id_token");
AuthTargetMapping mapping = AuthTargetMapping.builder().addMapping(TokenType.USERNAME, "service", "ldapService").addMapping(TokenType.OPENIDCONNECT, "module", "oidc", context).build();
DeploymentConfig deploymentConfig = DeploymentConfig.builder().uriElement("boborealm/inst1").authTargetMapping(mapping).build();
Map<String, String> attributes = new HashMap<>();
attributes.put("email", "mail");
SAML2Config saml2Config = SAML2Config.builder().attributeMap(attributes).nameIdFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent").spEntityId("http://host.com/sp/entity/id").signAssertion(signAssertion).keystoreFile("/keystore.jks").keystorePassword("changeit".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).encryptionKeyAlias("test").signatureKeyAlias("test").signatureKeyPassword("changeit".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).idpId("da_idp").build();
return RestSTSInstanceConfig.builder().deploymentConfig(deploymentConfig).saml2Config(saml2Config).addSupportedTokenTransform(TokenType.X509, TokenType.SAML2, !AMSTSConstants.INVALIDATE_INTERIM_OPENAM_SESSION).addSupportedTokenTransform(TokenType.USERNAME, TokenType.SAML2, AMSTSConstants.INVALIDATE_INTERIM_OPENAM_SESSION).addSupportedTokenTransform(TokenType.OPENAM, TokenType.SAML2, !AMSTSConstants.INVALIDATE_INTERIM_OPENAM_SESSION).addSupportedTokenTransform(TokenType.OPENIDCONNECT, TokenType.SAML2, AMSTSConstants.INVALIDATE_INTERIM_OPENAM_SESSION).build();
}
use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.
the class RestSTSInstanceConfig method marshalFromAttributeMap.
/*
When we are marshaling back from a Map<String, Set<String>>, this Map contains all of the values, also those
contributed by encapsulated complex objects. So the structure must be 'un-flattened', where the top-level map
is passed to encapsulated complex-objects, so that they may re-constitute themselves, and then the top-level json entry
key is set to point at these re-constituted complex objects.
Not that the marshalToAttributeMap first calls toJson to obtain the map representation, albeit with hierarchical
elements, which must be subsequently flattened. The 'flattening' performed by the marshalToAttributeMap must then
be 'inverted' by this method, where all complex objects are re-constituted, using the state in the flattened map.
*/
public static RestSTSInstanceConfig marshalFromAttributeMap(Map<String, Set<String>> attributeMap) {
DeploymentConfig deploymentConfig = DeploymentConfig.marshalFromAttributeMap(attributeMap);
Map<String, Object> jsonAttributes = MapMarshallUtils.toJsonValueMap(attributeMap);
jsonAttributes.remove(DEPLOYMENT_CONFIG);
jsonAttributes.put(DEPLOYMENT_CONFIG, deploymentConfig.toJson());
SAML2Config saml2Config = SAML2Config.marshalFromAttributeMap(attributeMap);
if (saml2Config != null) {
jsonAttributes.remove(SAML2_CONFIG);
jsonAttributes.put(SAML2_CONFIG, saml2Config.toJson());
}
OpenIdConnectTokenConfig openIdConnectTokenConfig = OpenIdConnectTokenConfig.marshalFromAttributeMap(attributeMap);
if (openIdConnectTokenConfig != null) {
jsonAttributes.remove(OIDC_ID_TOKEN_CONFIG);
jsonAttributes.put(OIDC_ID_TOKEN_CONFIG, openIdConnectTokenConfig.toJson());
}
/*
The SUPPORTED_TOKEN_TRANSFORMS, CUSTOM_TOKEN_TRANSFORMS, CUSTOM_TOKEN_VALIDATORS, and CUSTOM_TOKEN_PROVIDERS
are currently each in a String representation in the Set<String> map entry corresponding
to their respective key. I need to marshal each back into a TokenTransformConfig instance, and then
call toJson on each, and put them in a JsonValue wrapping a list.
*/
ArrayList<JsonValue> jsonTranslationsList = new ArrayList<>();
JsonValue jsonTranslations = new JsonValue(jsonTranslationsList);
jsonAttributes.remove(SUPPORTED_TOKEN_TRANSFORMS);
jsonAttributes.put(SUPPORTED_TOKEN_TRANSFORMS, jsonTranslations);
Set<String> stringTokenTranslations = attributeMap.get(SUPPORTED_TOKEN_TRANSFORMS);
for (String translation : stringTokenTranslations) {
jsonTranslationsList.add(TokenTransformConfig.fromSMSString(translation).toJson());
}
ArrayList<JsonValue> jsonCustomTranslationsList = new ArrayList<>();
JsonValue jsonCustomTranslations = new JsonValue(jsonCustomTranslationsList);
jsonAttributes.remove(CUSTOM_TOKEN_TRANSFORMS);
jsonAttributes.put(CUSTOM_TOKEN_TRANSFORMS, jsonCustomTranslations);
Set<String> stringCustomTranslations = attributeMap.get(CUSTOM_TOKEN_TRANSFORMS);
for (String translation : stringCustomTranslations) {
jsonCustomTranslationsList.add(TokenTransformConfig.fromSMSString(translation).toJson());
}
ArrayList<JsonValue> jsonCustomValidatorsList = new ArrayList<>();
JsonValue jsonCustomValidators = new JsonValue(jsonCustomValidatorsList);
jsonAttributes.remove(CUSTOM_TOKEN_VALIDATORS);
jsonAttributes.put(CUSTOM_TOKEN_VALIDATORS, jsonCustomValidators);
Set<String> stringCustomValidators = attributeMap.get(CUSTOM_TOKEN_VALIDATORS);
for (String validator : stringCustomValidators) {
jsonCustomValidatorsList.add(CustomTokenOperation.fromSMSString(validator).toJson());
}
ArrayList<JsonValue> jsonCustomProvidersList = new ArrayList<>();
JsonValue jsonCustomProviders = new JsonValue(jsonCustomProvidersList);
jsonAttributes.remove(CUSTOM_TOKEN_PROVIDERS);
jsonAttributes.put(CUSTOM_TOKEN_PROVIDERS, jsonCustomProviders);
Set<String> stringCustomProviders = attributeMap.get(CUSTOM_TOKEN_PROVIDERS);
for (String provider : stringCustomProviders) {
jsonCustomProvidersList.add(CustomTokenOperation.fromSMSString(provider).toJson());
}
return fromJson(new JsonValue(jsonAttributes));
}
use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.
the class SoapSTSInstanceStateServiceListenerTest method createInstanceConfig.
private SoapSTSInstanceConfig createInstanceConfig(String amDeploymentUrl) throws UnsupportedEncodingException {
AuthTargetMapping mapping = AuthTargetMapping.builder().addMapping(TokenType.USERNAME, "service", "ldap").build();
SoapDeploymentConfig deploymentConfig = SoapDeploymentConfig.builder().portQName(AMSTSConstants.STANDARD_STS_PORT_QNAME).serviceQName(AMSTSConstants.STANDARD_STS_SERVICE_NAME).wsdlLocation("wsdl_loc").realm("realm").amDeploymentUrl(amDeploymentUrl).uriElement(DEPLOYMENT_URL_ELEMENT).authTargetMapping(mapping).build();
SoapSTSKeystoreConfig keystoreConfig = SoapSTSKeystoreConfig.builder().keystoreFileName("stsstore.jks").keystorePassword("stsspass".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).encryptionKeyAlias("mystskey").signatureKeyAlias("mystskey").encryptionKeyPassword("stskpass".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).signatureKeyPassword("stskpass".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).build();
Map<String, String> attributes = new HashMap<>();
attributes.put("email", "mail");
SAML2Config saml2Config = SAML2Config.builder().attributeMap(attributes).nameIdFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent").spEntityId("http://host.com/sp/entity/id").idpId("da_idp").build();
SoapSTSInstanceConfig.SoapSTSInstanceConfigBuilderBase<?> builder = SoapSTSInstanceConfig.builder();
builder.addSecurityPolicyTokenValidationConfiguration(TokenType.OPENAM, false);
builder.addIssueTokenType(TokenType.SAML2);
return builder.deploymentConfig(deploymentConfig).soapSTSKeystoreConfig(keystoreConfig).saml2Config(saml2Config).build();
}
use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.
the class StatementProviderImplTest method testCustomProvider.
@Test
public void testCustomProvider() throws TokenCreationException {
SAML2Config config = SAML2Config.builder().customConditionsProviderClassName("org.forgerock.openam.sts.tokengeneration.saml2.statements.DefaultConditionsProvider").spEntityId("http://host.com/sp/entity/id").idpId("da_idp").build();
StatementProvider statementProvider = Guice.createInjector(new MyModule()).getInstance(StatementProvider.class);
assertTrue(statementProvider.getConditionsProvider(config) instanceof DefaultConditionsProvider);
}
use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.
the class StatementProviderImplTest method testSpeciousProvider.
@Test(expectedExceptions = TokenCreationException.class)
public void testSpeciousProvider() throws TokenCreationException {
SAML2Config config = SAML2Config.builder().customConditionsProviderClassName("faux_class_name").spEntityId("http://host.com/sp/entity/id").idpId("da_idp").build();
StatementProvider statementProvider = Guice.createInjector(new MyModule()).getInstance(StatementProvider.class);
statementProvider.getConditionsProvider(config);
}
Aggregations