use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class PrivilegeResource method privileges.
@GET
@Produces("application/json")
public String privileges(@Context HttpHeaders headers, @Context HttpServletRequest request, @QueryParam("realm") @DefaultValue("/") String realm, @QueryParam("filter") List filters) {
try {
Subject caller = getCaller(request);
PrivilegeManager pm = PrivilegeManager.getInstance(realm, caller);
Set<String> privilegeNames = pm.searchNames(getFilters(filters));
JSONObject jo = new JSONObject();
jo.put(RESULT, privilegeNames);
return createResponseJSONString(200, headers, jo);
} catch (JSONException e) {
PrivilegeManager.debug.error("PrivilegeResource.privileges", e);
throw getWebApplicationException(e, MimeType.JSON);
} catch (RestException e) {
PrivilegeManager.debug.error("PrivilegeResource.privileges", e);
throw getWebApplicationException(headers, e, MimeType.JSON);
} catch (EntitlementException e) {
PrivilegeManager.debug.error("PrivilegeResource.privileges", e);
throw getWebApplicationException(headers, e, MimeType.JSON);
}
}
use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class ListXACML method getPolicyNames.
/**
* Indicates the names of the Privileges that match both the Realm and Search Filters
* provided.
*
* @throws CLIException If there was an unexpected error.
*/
private void getPolicyNames() throws CLIException {
String currentPrivilegeName = null;
try {
PrivilegeManager pm = PrivilegeManager.getInstance(realm, adminSubject);
String[] parameters = new String[1];
parameters[0] = realm;
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_TO_GET_POLICY_NAMES_IN_REALM", parameters);
Set<SearchFilter> filterSet = getFilters(filters);
Set<String> privilegeNames = pm.searchNames(filterSet);
if ((privilegeNames != null) && !privilegeNames.isEmpty()) {
FileOutputStream fout = null;
PrintWriter pwout = null;
if (outfile != null) {
try {
fout = new FileOutputStream(outfile, true);
pwout = new PrintWriter(fout, true);
} catch (FileNotFoundException e) {
debugError("ListXACML.handleXACMLPolicyRequest", e);
try {
if (fout != null) {
fout.close();
}
} catch (IOException ex) {
//do nothing
}
throw new CLIException(e, ExitCodes.IO_EXCEPTION);
} catch (SecurityException e) {
debugError("ListXACML.handleXACMLPolicyRequest", e);
try {
if (fout != null) {
fout.close();
}
} catch (IOException ex) {
//do nothing
}
throw new CLIException(e, ExitCodes.IO_EXCEPTION);
}
}
String[] params = new String[2];
params[0] = realm;
StringBuilder buff = new StringBuilder();
for (Iterator i = privilegeNames.iterator(); i.hasNext(); ) {
currentPrivilegeName = (String) i.next();
buff.append(currentPrivilegeName).append("\n");
}
if (pwout != null) {
pwout.write(buff.toString());
} else {
outputWriter.printlnMessage(buff.toString());
}
if (pwout != null) {
try {
pwout.close();
fout.close();
} catch (IOException e) {
//do nothing
}
}
} else {
String[] arg = { realm };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-policy-names-in-realm-no-policies"), (Object[]) arg));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "GOT_POLICY_NAMES_IN_REALM", parameters);
String[] arg = { realm };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-policy-names-in-realm-succeed"), (Object[]) arg));
} catch (EntitlementException e) {
String[] args = { realm, currentPrivilegeName, e.getMessage() };
debugError("ListXACML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_POLICY_NAMES_IN_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class DeleteXACML method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
Subject adminSubject = SubjectUtils.createSubject(adminSSOToken);
String realm = getStringOptionValue(IArgument.REALM_NAME);
// FIXME: change to use entitlementService.xacmlPrivilegEnabled()
EntitlementConfiguration ec = EntitlementConfiguration.getInstance(adminSubject, "/");
if (!ec.migratedToEntitlementService()) {
String[] args = { realm, "ANY", "list-xacml not supported in legacy policy mode" };
debugError("DeleteXACML.handleRequest(): " + "delete-xacml not supported in legacy policy mode");
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_POLICY_IN_REALM", args);
throw new CLIException(getResourceString("delete-xacml-not-supported-in-legacy-policy-mode"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, "delete-xacml");
}
List policyNames = (List) rc.getOption(ARGUMENT_POLICY_NAMES);
String file = getStringOptionValue(IArgument.FILE);
if (policyNames == null) {
policyNames = new ArrayList();
}
if (file != null) {
policyNames.addAll(AttributeValues.parseValues(file));
}
if (policyNames.isEmpty()) {
throw new CLIException(getResourceString("missing-policy-names"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
IOutput outputWriter = getOutputWriter();
String currentPolicyName = null;
try {
PrivilegeManager pm = PrivilegeManager.getInstance(realm, adminSubject);
String[] params = new String[2];
params[0] = realm;
for (Iterator i = policyNames.iterator(); i.hasNext(); ) {
currentPolicyName = (String) i.next();
params[1] = currentPolicyName;
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_POLICY_IN_REALM", params);
pm.remove(currentPolicyName);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_POLICY_IN_REALM", params);
}
String[] arg = { realm };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("delete-policy-in-realm-succeed"), (Object[]) arg));
} catch (EntitlementException e) {
String[] args = { realm, currentPolicyName, e.getMessage() };
debugError("DeleteXACML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_POLICY_IN_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method removePrivilege.
public void removePrivilege(String name) throws EntitlementException {
if (isDsameUser() || delegatables.hasPrivilege(name)) {
PrivilegeManager pm = PrivilegeManager.getInstance(getHiddenRealmDN(), dsameUserSubject);
pm.remove(name);
pm.remove(GHOST_PRIVILEGE_NAME_PREFIX + name);
readables.removePrivilege(name);
modifiables.removePrivilege(name);
delegatables.removePrivilege(name);
} else {
throw new EntitlementException(326);
}
}
use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method addPrivilege.
public void addPrivilege(ApplicationPrivilege appPrivilege) throws EntitlementException {
validatePrivilege(appPrivilege);
Privilege[] privileges = toPrivilege(appPrivilege);
PrivilegeManager pm = PrivilegeManager.getInstance(getHiddenRealmDN(), dsameUserSubject);
for (Privilege p : privileges) {
pm.add(p);
}
cachePrivilege(privileges[0]);
}
Aggregations