use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class SetApplication method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
@Override
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
String realm = getStringOptionValue(IArgument.REALM_NAME);
String appName = getStringOptionValue(PARAM_APPL_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
if ((datafile == null) && (attrValues == null)) {
throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
}
Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
String[] params = { realm, appName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_APPLICATION", params);
Subject adminSubject = getAdminSubject();
try {
Application appl = ApplicationManager.getApplication(adminSubject, realm, appName);
Object[] param = { appName };
if (appl == null) {
throw new CLIException(MessageFormat.format(getResourceString("set-application-not-found"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
setApplicationAttributes(appl, attributeValues, false);
ApplicationManager.saveApplication(getAdminSubject(), realm, appl);
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("set-application-modified"), param));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_SET_APPLICATION", params);
} catch (EntitlementException e) {
String[] paramExs = { realm, appName, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_SET_APPLICATION", paramExs);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (CLIException e) {
String[] paramExs = { realm, appName, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_SET_APPLICATION", paramExs);
throw e;
}
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class ApplicationPrivilegeBase method getApplicationResourcesMap.
protected Map<String, Set<String>> getApplicationResourcesMap(RequestContext rc, String realm) throws CLIException, EntitlementException {
String appName = getStringOptionValue(PARAM_APPL_NAME);
Subject subject = SubjectUtils.createSubject(getAdminSSOToken());
Application application = ApplicationManager.getApplication(subject, realm, appName);
if (application == null) {
String[] param = { appName };
throw new CLIException(MessageFormat.format(getResourceString("privilege-application-application-invalid"), (Object[]) param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
Set<String> delResources = new HashSet<String>();
List<String> resources = rc.getOption(PARAM_RESOURCES);
// if resources is not provided, delegate all resources
if ((resources == null) || resources.isEmpty()) {
delResources.addAll(getAllBaseResources(subject, realm, application));
} else {
delResources.addAll(resources);
}
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
map.put(appName, delResources);
return map;
}
use of com.sun.identity.entitlement.Application 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();
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class PolicyV1FilterTest method resourceTypeAssociationOnUpdate.
/**
* Verifies that the appropriate resource type is associated with the policy being updated.
*/
@Test
public void resourceTypeAssociationOnUpdate() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
UpdateRequest updateRequest = mock(UpdateRequest.class);
JsonValue jsonValue = json(object(field("applicationName", "testApp")));
given(updateRequest.getContent()).willReturn(jsonValue);
given(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
Application application = mock(Application.class);
given(applicationService.getApplication("testApp")).willReturn(application);
Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-hij"));
given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterUpdate(context, updateRequest, requestHandler);
// Then
assertThat(promise).succeeded();
verify(applicationServiceFactory).create(subject, "/abc");
verify(applicationService).getApplication("testApp");
assertThat(jsonValue.get("resourceTypeUuid").asString()).isEqualTo("abc-def-hij");
assertThat(promise.get().getContent().contains("resourceTypeUuid")).isFalse();
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class PrivilegeUtils method entitlementToRule.
private static Set<Rule> entitlementToRule(String realm, Entitlement entitlement) throws PolicyException, SSOException, EntitlementException {
Set<Rule> rules = new HashSet<Rule>();
String appName = entitlement.getApplicationName();
String realmName = LDAPUtils.isDN(realm) ? DNMapper.orgNameToRealmName(realm) : realm;
Application application = ApplicationManager.getApplication(PolicyConstants.SUPER_ADMIN_SUBJECT, realmName, appName);
if (application == null) {
Object[] params = { appName, realm };
throw new EntitlementException(105, params);
}
String serviceName = application.getApplicationType().getName();
Set<String> resourceNames = entitlement.getResourceNames();
Map<String, Boolean> actionValues = entitlement.getActionValues();
Map av = pravToPav(actionValues, serviceName);
if (resourceNames != null) {
String entName = entitlement.getName();
if (entName == null) {
entName = "entitlement";
}
Rule rule = new Rule(entName, serviceName, null, av);
rule.setResourceNames(resourceNames);
rule.setApplicationName(appName);
rules.add(rule);
}
return rules;
}
Aggregations