Search in sources :

Example 26 with SearchFilter

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);
    }
}
Also used : PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) FileNotFoundException(java.io.FileNotFoundException) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) IOException(java.io.IOException) EntitlementException(com.sun.identity.entitlement.EntitlementException) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) PrintWriter(java.io.PrintWriter)

Aggregations

SearchFilter (com.sun.identity.entitlement.util.SearchFilter)26 Test (org.testng.annotations.Test)18 QueryRequest (org.forgerock.json.resource.QueryRequest)9 HashSet (java.util.HashSet)8 JsonPointer (org.forgerock.json.JsonPointer)8 SSOException (com.iplanet.sso.SSOException)7 IdRepoException (com.sun.identity.idm.IdRepoException)7 Subject (javax.security.auth.Subject)6 EntitlementException (com.sun.identity.entitlement.EntitlementException)4 SearchAttribute (com.sun.identity.entitlement.util.SearchAttribute)4 SMSException (com.sun.identity.sm.SMSException)4 SSOToken (com.iplanet.sso.SSOToken)3 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)2 Date (java.util.Date)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AfterTest (org.testng.annotations.AfterTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 CLIException (com.sun.identity.cli.CLIException)1 IPrivilege (com.sun.identity.entitlement.IPrivilege)1 IPrivilegeManager (com.sun.identity.entitlement.IPrivilegeManager)1