use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class STSInstanceConfig method marshalFromAttributeMap.
public static STSInstanceConfig marshalFromAttributeMap(Map<String, Set<String>> attributeMap) {
Map<String, Object> jsonAttributes = MapMarshallUtils.toJsonValueMap(attributeMap);
/*
If SAML2Config state is not present, null will be returned. That will tell me that no SAML2Config
had been present initially.
*/
SAML2Config saml2Config = SAML2Config.marshalFromAttributeMap(attributeMap);
if (saml2Config != null) {
jsonAttributes.put(SAML2_CONFIG, saml2Config.toJson());
}
OpenIdConnectTokenConfig openIdConnectTokenConfig = OpenIdConnectTokenConfig.marshalFromAttributeMap(attributeMap);
if (openIdConnectTokenConfig != null) {
jsonAttributes.put(OIDC_ID_TOKEN_CONFIG, openIdConnectTokenConfig.toJson());
}
return fromJson(new JsonValue(jsonAttributes));
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class RestSTSInstanceConfig method fromJson.
public static RestSTSInstanceConfig fromJson(JsonValue json) {
if (json == null) {
throw new NullPointerException("JsonValue cannot be null!");
}
STSInstanceConfig baseConfig = STSInstanceConfig.fromJson(json);
RestSTSInstanceConfigBuilderBase<?> builder = RestSTSInstanceConfig.builder().saml2Config(baseConfig.getSaml2Config()).oidcIdTokenConfig(baseConfig.getOpenIdConnectTokenConfig()).persistIssuedTokensInCTS(baseConfig.persistIssuedTokensInCTS()).deploymentConfig(DeploymentConfig.fromJson(json.get(DEPLOYMENT_CONFIG)));
JsonValue supportedTranslations = json.get(SUPPORTED_TOKEN_TRANSFORMS);
if (!supportedTranslations.isNull()) {
if (!supportedTranslations.isList()) {
throw new IllegalStateException("Unexpected value for the " + SUPPORTED_TOKEN_TRANSFORMS + " field: " + supportedTranslations.asString());
}
List<TokenTransformConfig> transformConfigList = new ArrayList<>();
for (Object translation : supportedTranslations.asList()) {
transformConfigList.add(TokenTransformConfig.fromJson(new JsonValue(translation)));
}
builder.setSupportedTokenTransforms(transformConfigList);
}
JsonValue customTranslations = json.get(CUSTOM_TOKEN_TRANSFORMS);
if (!customTranslations.isNull()) {
if (!customTranslations.isList()) {
throw new IllegalStateException("Unexpected value for the " + CUSTOM_TOKEN_TRANSFORMS + " field: " + customTranslations.asString());
}
List<TokenTransformConfig> transformConfigList = new ArrayList<>();
for (Object translation : customTranslations.asList()) {
transformConfigList.add(TokenTransformConfig.fromJson(new JsonValue(translation)));
}
builder.setCustomTokenTransforms(transformConfigList);
}
JsonValue customValidators = json.get(CUSTOM_TOKEN_VALIDATORS);
if (!customValidators.isNull()) {
if (!customValidators.isList()) {
throw new IllegalStateException("Unexpected value for the " + CUSTOM_TOKEN_VALIDATORS + " field: " + customValidators.asString());
}
List<CustomTokenOperation> customValidatorsList = new ArrayList<>();
for (Object translation : customValidators.asList()) {
customValidatorsList.add(CustomTokenOperation.fromJson(new JsonValue(translation)));
}
builder.setCustomValidators(customValidatorsList);
}
JsonValue customProviders = json.get(CUSTOM_TOKEN_PROVIDERS);
if (!customProviders.isNull()) {
if (!customProviders.isList()) {
throw new IllegalStateException("Unexpected value for the " + CUSTOM_TOKEN_PROVIDERS + " field: " + customProviders.asString());
}
List<CustomTokenOperation> customProvidersList = new ArrayList<>();
for (Object translation : customProviders.asList()) {
customProvidersList.add(CustomTokenOperation.fromJson(new JsonValue(translation)));
}
builder.setCustomProviders(customProvidersList);
}
return builder.build();
}
use of org.forgerock.json.JsonValue 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.json.JsonValue in project OpenAM by OpenRock.
the class SoapDelegationConfig method marshalFromAttributeMap.
public static SoapDelegationConfig marshalFromAttributeMap(Map<String, Set<String>> attributeMap) {
//first check to see if the relevant attributes are present, indicating that a non-null instance can be created
if (CollectionUtils.isEmpty(attributeMap.get(DELEGATION_TOKEN_VALIDATORS)) && CollectionUtils.isEmpty(attributeMap.get(CUSTOM_DELEGATION_TOKEN_HANDLERS))) {
return null;
}
Map<String, Object> jsonAttributes = MapMarshallUtils.toJsonValueMap(attributeMap);
/*
The DELEGATION_TOKEN_VALIDATORS are currently each in a String representation in the Set<String> map entry corresponding
to the DELEGATION_TOKEN_VALIDATORS key. I need to marshal each back into a TokenValidationConfig instance, and then
call toJson on each, and put them in a JsonValue wrapping a list.
*/
if (attributeMap.get(DELEGATION_TOKEN_VALIDATORS) != null) {
ArrayList<JsonValue> jsonValidationConfigList = new ArrayList<>();
JsonValue jsonTranslations = new JsonValue(jsonValidationConfigList);
jsonAttributes.remove(DELEGATION_TOKEN_VALIDATORS);
jsonAttributes.put(DELEGATION_TOKEN_VALIDATORS, jsonTranslations);
Set<String> stringTokenTranslations = attributeMap.get(DELEGATION_TOKEN_VALIDATORS);
for (String translation : stringTokenTranslations) {
jsonValidationConfigList.add(TokenValidationConfig.fromSMSString(translation).toJson());
}
}
/*
Ultimately, the CUSTOM_DELEGATION_TOKEN_HANDLERS is a set, but it's set type gets stripped by the MapMarshalUtils.toJsonValueMap
method. Thus it is a 'complex' object, which must be reconstituted in this method. Note also that the map may not
have an entry if the instance was first marshaled to json, which is the first step in marshaling to an attribute map.
*/
if (attributeMap.get(CUSTOM_DELEGATION_TOKEN_HANDLERS) != null) {
Set<String> jsonHandlerSet = new HashSet<>();
JsonValue jsonHandlerTypes = new JsonValue(jsonHandlerSet);
jsonAttributes.remove(CUSTOM_DELEGATION_TOKEN_HANDLERS);
jsonAttributes.put(CUSTOM_DELEGATION_TOKEN_HANDLERS, jsonHandlerTypes);
Set<String> handlerClasses = attributeMap.get(CUSTOM_DELEGATION_TOKEN_HANDLERS);
for (String handlerClass : handlerClasses) {
jsonHandlerSet.add(handlerClass);
}
}
return fromJson(new JsonValue(jsonAttributes));
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class RestSTSInstanceConfigTest method testFieldPersistenceJsonMapMarshalRoundTrip.
@Test
public void testFieldPersistenceJsonMapMarshalRoundTrip() throws IOException {
RestSTSInstanceConfig config = createInstanceConfig("/bob", WITH_TLS_OFFLOAD_CONFIG, WITH_SAML2_CONFIG, WITH_OIDC_CONFIG, !WITH_CUSTOM_VALIDATOR, !WITH_CUSTOM_PROVIDER, WITH_CTS_TOKEN_PERSISTENCE);
Map<String, Set<String>> attributeMap = config.marshalToAttributeMap();
JsonValue jsonMap = new JsonValue(attributeMap);
assertEquals(config.persistIssuedTokensInCTS(), RestSTSInstanceConfig.marshalFromJsonAttributeMap(jsonMap).persistIssuedTokensInCTS());
config = createInstanceConfig("/bob", WITH_TLS_OFFLOAD_CONFIG, WITH_SAML2_CONFIG, WITH_OIDC_CONFIG, !WITH_CUSTOM_VALIDATOR, !WITH_CUSTOM_PROVIDER, !WITH_CTS_TOKEN_PERSISTENCE);
attributeMap = config.marshalToAttributeMap();
jsonMap = new JsonValue(attributeMap);
System.out.println("After marshalling to attribute map: " + attributeMap);
assertEquals(config.persistIssuedTokensInCTS(), RestSTSInstanceConfig.marshalFromJsonAttributeMap(jsonMap).persistIssuedTokensInCTS());
config = createInstanceConfig("/bob", WITH_TLS_OFFLOAD_CONFIG, WITH_SAML2_CONFIG, WITH_OIDC_CONFIG, !WITH_CUSTOM_VALIDATOR, !WITH_CUSTOM_PROVIDER, WITH_CTS_TOKEN_PERSISTENCE);
assertEquals(config.persistIssuedTokensInCTS(), RestSTSInstanceConfig.marshalFromAttributeMap(config.marshalToAttributeMap()).persistIssuedTokensInCTS());
config = createInstanceConfig("/bob", WITH_TLS_OFFLOAD_CONFIG, WITH_SAML2_CONFIG, WITH_OIDC_CONFIG, !WITH_CUSTOM_VALIDATOR, !WITH_CUSTOM_PROVIDER, !WITH_CTS_TOKEN_PERSISTENCE);
System.out.println("After marshalling to attribute map: " + config.marshalToAttributeMap());
assertEquals(config.persistIssuedTokensInCTS(), RestSTSInstanceConfig.marshalFromAttributeMap(config.marshalToAttributeMap()).persistIssuedTokensInCTS());
}
Aggregations