use of com.sun.identity.entitlement.util.SearchFilter 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);
}
}
Aggregations