use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class CreateApplicationPrivilege 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 name = getStringOptionValue(PARAM_NAME);
String[] params = { realm, name };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_APPLICATION_PRIVILEGE", params);
String description = getStringOptionValue(PARAM_DESCRIPTION);
ApplicationPrivilege.PossibleAction actions = getActions();
Set<SubjectImplementation> subjects = getSubjects(rc);
try {
Map<String, Set<String>> mapAppToResources = getApplicationResourcesMap(rc, realm);
Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
ApplicationPrivilege appPrivilege = new ApplicationPrivilege(name);
appPrivilege.setDescription(description);
appPrivilege.setActionValues(actions);
appPrivilege.setApplicationResources(mapAppToResources);
appPrivilege.setSubject(subjects);
apm.addPrivilege(appPrivilege);
Object[] msgParam = { name };
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-application-privilege-succeeded"), msgParam));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_CREATE_APPLICATION_PRIVILEGE", params);
} catch (EntitlementException ex) {
String[] paramExs = { realm, name, ex.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_PRIVILEGE", paramExs);
throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (CLIException ex) {
String[] paramExs = { realm, name, ex.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_PRIVILEGE", paramExs);
throw ex;
}
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class CreateApplicationType 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 appTypeName = getStringOptionValue(PARAM_APPL_TYPE_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 = { appTypeName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_APPLICATION_TYPE", params);
try {
Map<String, Boolean> actions = getActions(attributeValues);
Class searchIndex = getClassAttribute(ATTR_SEARCH_INDEX, attributeValues);
Class saveIndex = getClassAttribute(ATTR_SAVE_INDEX, attributeValues);
Class resourceComp = getClassAttribute(ATTR_RESOURCE_COMPARATOR, attributeValues);
ApplicationType applType = new ApplicationType(appTypeName, actions, searchIndex, saveIndex, resourceComp);
ApplicationTypeManager.saveApplicationType(getAdminSubject(), applType);
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-application-type-succeeded"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_CREATE_APPLICATION_TYPE", params);
} catch (ClassCastException e) {
String[] paramExs = { appTypeName, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (EntitlementException e) {
String[] paramExs = { appTypeName, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (InstantiationException e) {
String[] paramExs = { appTypeName, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IllegalAccessException e) {
String[] paramExs = { appTypeName, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (CLIException e) {
String[] paramExs = { appTypeName, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
throw e;
}
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldHandleEntitlementExceptions.
@Test
public void shouldHandleEntitlementExceptions() throws EntitlementException {
// Given...
given(request.getAction()).willReturn("evaluate");
Context context = buildContextStructure("/abc");
EntitlementException eE = new EntitlementException(EntitlementException.INVALID_VALUE);
given(requestFactory.buildRequest(PolicyAction.EVALUATE, context, request)).willThrow(eE);
given(request.getRequestType()).willReturn(RequestType.ACTION);
// When...
Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
verify(requestFactory).buildRequest(PolicyAction.EVALUATE, context, request);
verify(request).getRequestType();
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
verifyNoMoreInteractions(request, requestFactory, policyRequest, factory, evaluator, parser);
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldRejectNullPolicyIdInDelete.
@Test
public void shouldRejectNullPolicyIdInDelete() throws Exception {
// Given
String id = null;
DeleteRequest request = mock(DeleteRequest.class);
willThrow(new EntitlementException(EntitlementException.MISSING_PRIVILEGE_NAME)).given(mockStore).delete(id);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportCreatePolicyStoreErrors.
@Test
public void shouldReportCreatePolicyStoreErrors() throws Exception {
// Given
String id = "uniqueId";
JsonValue json = new JsonValue("");
CreateRequest request = mockCreateRequest(id, json);
Privilege policy = mockPrivilege(id, 123l);
given(mockParser.parsePolicy(id, json)).willReturn(policy);
willThrow(new EntitlementException(EntitlementException.INVALID_APPLICATION_CLASS)).given(mockStore).create(policy);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(InternalServerErrorException.class);
}
Aggregations