use of org.forgerock.openam.entitlement.configuration.SmsAttribute in project OpenAM by OpenRock.
the class ConfigureOAuth2 method getUrlResourceTypeId.
private String getUrlResourceTypeId(Subject adminSubject, String realm) throws EntitlementException, WorkflowException {
Application application = ApplicationManager.getApplication(adminSubject, realm, POLICY_APPLICATION_NAME);
if (application == null) {
ApplicationType applicationType = ApplicationTypeManager.getAppplicationType(adminSubject, ApplicationTypeManager.URL_APPLICATION_TYPE_NAME);
application = ApplicationManager.newApplication(POLICY_APPLICATION_NAME, applicationType);
}
Set<String> resourceTypeIds = application.getResourceTypeUuids();
ResourceTypeService resourceTypeService = InjectorHolder.getInstance(ResourceTypeService.class);
for (String id : resourceTypeIds) {
ResourceType resourceType = resourceTypeService.getResourceType(adminSubject, realm, id);
if (POLICY_RESOURCE_TYPE_NAME.equalsIgnoreCase(resourceType.getName())) {
return id;
}
}
QueryFilter<SmsAttribute> name = equalTo(SmsAttribute.newSearchableInstance("name"), POLICY_RESOURCE_TYPE_NAME);
Set<ResourceType> types = resourceTypeService.getResourceTypes(name, adminSubject, realm);
ResourceType resourceType;
if (types == null || types.isEmpty()) {
resourceType = ResourceType.builder().addPatterns(asSet("*://*:*/*/authorize?*")).addActions(new ImmutableMap.Builder<String, Boolean>().put("GET", true).put("POST", true).build()).setName(POLICY_RESOURCE_TYPE_NAME).setUUID(UUID.randomUUID().toString()).build();
resourceType = resourceTypeService.saveResourceType(adminSubject, realm, resourceType);
} else {
resourceType = types.iterator().next();
}
application.addAllResourceTypeUuids(asSet(resourceType.getUUID()));
application.setEntitlementCombiner(DenyOverride.class);
ApplicationManager.saveApplication(adminSubject, realm, application);
return resourceType.getUUID();
}
Aggregations