use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method replacePrivilege.
public void replacePrivilege(ApplicationPrivilege appPrivilege) throws EntitlementException {
if (delegatables.hasPrivilege(appPrivilege.getName())) {
validatePrivilege(appPrivilege);
Privilege[] privileges = toPrivilege(appPrivilege);
PrivilegeManager pm = PrivilegeManager.getInstance(getHiddenRealmDN(), dsameUserSubject);
pm.modify(privileges[0]);
cachePrivilege(privileges[0]);
pm.modify(privileges[1]);
cachePrivilege(privileges[1]);
} else {
throw new EntitlementException(326);
}
}
use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method toPrivilege.
/**
* Creates two privileges here
*/
private Privilege[] toPrivilege(ApplicationPrivilege appPrivilege) throws EntitlementException {
Privilege[] results = new Privilege[2];
try {
Privilege actualP = Privilege.getNewInstance();
actualP.setName(appPrivilege.getName());
actualP.setDescription(appPrivilege.getDescription());
Set<String> res = createDelegationResources(appPrivilege);
Entitlement entitlement = new Entitlement(APPL_NAME, res, getActionValues(appPrivilege.getActionValues()));
actualP.setEntitlement(entitlement);
Privilege ghostP = Privilege.getNewInstance();
ghostP.setName(GHOST_PRIVILEGE_NAME_PREFIX + appPrivilege.getName());
Set<String> ghostRes = new HashSet<String>();
String currentOrgDN = DNMapper.orgNameToDN(realm);
Object[] param = { currentOrgDN };
ghostRes.add(MessageFormat.format(SUN_AM_REALM_RESOURCE, param));
ghostRes.add(MessageFormat.format(SUN_IDREPO_RESOURCE, param));
entitlement = new Entitlement(APPL_NAME, ghostRes, getActionValues(ApplicationPrivilege.PossibleAction.READ));
ghostP.setEntitlement(entitlement);
Set<SubjectImplementation> subjects = appPrivilege.getSubjects();
Set<EntitlementSubject> eSubjects = new HashSet<EntitlementSubject>();
for (SubjectImplementation i : subjects) {
eSubjects.add((EntitlementSubject) i);
}
OrSubject orSubject = new OrSubject(eSubjects);
actualP.setSubject(orSubject);
actualP.setCondition(appPrivilege.getCondition());
ghostP.setSubject(orSubject);
ghostP.setCondition(appPrivilege.getCondition());
Set<String> applIndexes = new HashSet<String>();
applIndexes.addAll(appPrivilege.getApplicationNames());
actualP.setApplicationIndexes(applIndexes);
results[0] = actualP;
results[1] = ghostP;
} catch (UnsupportedEncodingException ex) {
String[] params = {};
throw new EntitlementException(324, params);
}
return results;
}
use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.
the class SetApplicationPrivilegeSubjects 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 };
Set<SubjectImplementation> newSubjects = getSubjects(rc);
boolean bAdd = isOptionSet(PARAM_ADD);
Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_APPLICATION_PRIVILEGE", params);
try {
ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
Set<SubjectImplementation> origSubjects = appPrivilege.getSubjects();
Set<SubjectImplementation> subjects = (bAdd) ? mergeSubjects(origSubjects, newSubjects) : newSubjects;
appPrivilege.setSubject(subjects);
apm.replacePrivilege(appPrivilege);
Object[] msgParam = { name };
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("update-application-privilege-succeeded"), msgParam));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_UPDATE_APPLICATION_PRIVILEGE", params);
} catch (EntitlementException ex) {
String[] paramExs = { realm, name, ex.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_UPDATE_APPLICATION_PRIVILEGE", paramExs);
throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.
the class ShowApplicationPrivilege 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 };
Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_APPLICATION_PRIVILEGE", params);
try {
ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
outputInfo("show-application-privilege-output-name", name);
String description = appPrivilege.getDescription();
if (description == null) {
description = "";
}
outputInfo("show-application-privilege-output-description", description);
outputInfo("show-application-privilege-output-actions", getDisplayAction(appPrivilege));
outputInfo("show-application-privilege-output-subjects", getSubjects(appPrivilege));
outputInfo("show-application-privilege-output-resources", getApplicationToResources(appPrivilege));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_SHOW_APPLICATION_PRIVILEGE", params);
} catch (EntitlementException ex) {
String[] paramExs = { realm, name, ex.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_SHOW_APPLICATION_PRIVILEGE", paramExs);
throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.
the class SetApplicationPrivilegeResources 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 };
try {
Map<String, Set<String>> mapAppToResources = getApplicationResourcesMap(rc, realm);
boolean bAdd = isOptionSet(PARAM_ADD);
Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_APPLICATION_PRIVILEGE", params);
ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
Map<String, Set<String>> origAppToResources = getApplicationToResources(appPrivilege);
Map map = (bAdd) ? mergeMap(origAppToResources, mapAppToResources) : mapAppToResources;
appPrivilege.setApplicationResources(map);
apm.replacePrivilege(appPrivilege);
Object[] msgParam = { name };
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("update-application-privilege-succeeded"), msgParam));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_UPDATE_APPLICATION_PRIVILEGE", params);
} catch (EntitlementException ex) {
String[] paramExs = { realm, name, ex.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_UPDATE_APPLICATION_PRIVILEGE", paramExs);
throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations