Search in sources :

Example 11 with SMSException

use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.

the class AuthUtils method getGlobalAttributes.

/**
      * Returns <code>Map</code> attributes
      *
      * @param serviceName Service Name
      * @return <code>Map</code> of global attributes.
      */
public static Map getGlobalAttributes(String serviceName) {
    Map attrs = null;
    try {
        SSOToken dUserToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        ServiceSchemaManager scm = new ServiceSchemaManager(serviceName, dUserToken);
        ServiceSchema schema = scm.getGlobalSchema();
        if (schema != null) {
            attrs = schema.getAttributeDefaults();
        }
    } catch (SMSException smsExp) {
        utilDebug.error("AuthUtils.getGlobalAttributes: SMS Error", smsExp);
    } catch (SSOException ssoExp) {
        utilDebug.error("AuthUtils.getGlobalAttributes: SSO Error", ssoExp);
    }
    if (utilDebug.messageEnabled()) {
        utilDebug.message("AuthUtils.getGlobalAttributes: attrs=" + attrs);
    }
    return attrs;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) HashMap(java.util.HashMap) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 12 with SMSException

use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.

the class AllowedModulesChoiceValues method getChoiceValues.

/**
     * Returns choice values from  environment parameters
     * @param envParams map of environment parameters
     * @return choice values from  environment parameters
     */
public Map getChoiceValues(Map envParams) {
    // Get default choice values
    getChoiceValues();
    Set serviceNames = null;
    String orgDN = null;
    Map registeredServices = new HashMap();
    if (envParams != null) {
        orgDN = (String) envParams.get(Constants.ORGANIZATION_NAME);
    }
    if (orgDN == null || orgDN.length() == 0) {
        orgDN = SMSEntry.getRootSuffix();
    }
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    try {
        OrganizationConfigManager orgConfig = getOrgConfigManager(orgDN, adminToken);
        serviceNames = orgConfig.getAssignedServices();
    } catch (Exception e) {
    // this Exception should have been (or will be) caught by the
    // caller of of this plugin(console). it does not worth to
    // duplicate log/debug here.
    }
    if (serviceNames != null) {
        for (Iterator ite = choiceValues.keySet().iterator(); ite.hasNext(); ) {
            String value = (String) ite.next();
            if (serviceRegistered(value, serviceNames)) {
                registeredServices.put(value, value);
            } else {
                String serviceName = AuthUtils.getModuleServiceName(value);
                try {
                    new ServiceConfigManager(serviceName, adminToken);
                } catch (SMSException e) {
                    // services don't have template.
                    registeredServices.put(value, value);
                } catch (Exception e) {
                // SSO, do nothing
                }
            }
        }
    }
    return registeredServices;
}
Also used : Set(java.util.Set) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) SMSException(com.sun.identity.sm.SMSException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 13 with SMSException

use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.

the class ListXACML method getPolicies.

/**
     * Uses the Realm and Search Filters to identify all Privileges in the Entitlement
     * framework to export.
     *
     * @throws CLIException If there was an unexpected error.
     */
private void getPolicies() throws CLIException {
    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);
        }
    }
    PolicySet policySet = null;
    try {
        PrivilegeValidator privilegeValidator = new PrivilegeValidator(new RealmValidator(new OrganizationConfigManager(adminSSOToken, "/")));
        XACMLExportImport importExport = new XACMLExportImport(new XACMLExportImport.PrivilegeManagerFactory(), new XACMLReaderWriter(), privilegeValidator, new SearchFilterFactory(), PrivilegeManager.debug);
        policySet = importExport.exportXACML(realm, adminSubject, filters);
    } catch (EntitlementException e) {
        String[] args = { realm, e.getMessage() };
        debugError("ListXACML.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_POLICY_IN_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("ListXACML.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_POLICY_IN_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    if (policySet == null || policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) {
        String[] arg = { realm };
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-policy-in-realm-no-policies"), (Object[]) arg));
    } else {
        try {
            if (pwout != null) {
                pwout.write(XACMLPrivilegeUtils.toXML(policySet));
            } else {
                outputWriter.printlnMessage(XACMLPrivilegeUtils.toXML(policySet));
            }
        } catch (EntitlementException e) {
            throw new CLIException(e, ExitCodes.IO_EXCEPTION);
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_POLICY_IN_REALM", new String[] { realm });
        String[] arg = { realm };
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-policy-in-realm-succeed"), (Object[]) arg));
        if (pwout != null) {
            try {
                pwout.close();
                fout.close();
            } catch (IOException e) {
            //do nothing
            }
        }
    }
}
Also used : SearchFilterFactory(com.sun.identity.entitlement.xacml3.SearchFilterFactory) SMSException(com.sun.identity.sm.SMSException) FileNotFoundException(java.io.FileNotFoundException) XACMLExportImport(com.sun.identity.entitlement.xacml3.XACMLExportImport) IOException(java.io.IOException) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) PrivilegeValidator(com.sun.identity.entitlement.xacml3.validation.PrivilegeValidator) EntitlementException(com.sun.identity.entitlement.EntitlementException) FileOutputStream(java.io.FileOutputStream) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) CLIException(com.sun.identity.cli.CLIException) RealmValidator(com.sun.identity.entitlement.xacml3.validation.RealmValidator) XACMLReaderWriter(com.sun.identity.entitlement.xacml3.XACMLReaderWriter) PrintWriter(java.io.PrintWriter)

Example 14 with SMSException

use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.

the class DeleteDataStores method handleRequest.

/**
     * Handles request.
     *
     * @param rc Request Context.
     * @throws CLIException if request cannot be processed.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    List names = (List) rc.getOption(DatastoreOptions.DATASTORE_NAMES);
    validateRealm(realm);
    String[] params = { realm, names.toString() };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_DATASTORES", params);
    try {
        ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminSSOToken);
        ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
        if (cfg != null) {
            for (Iterator i = names.iterator(); i.hasNext(); ) {
                cfg.removeSubConfig((String) i.next());
            }
            if (names.size() > 1) {
                getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastores-succeeded"));
            } else {
                getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastore-succeeded"));
            }
        } else {
            getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastore-not-found"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_DATASTORES", params);
    } catch (SMSException e) {
        debugError("DeleteDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("DeleteDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 15 with SMSException

use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.

the class ListDataStores method handleRequest.

/**
     * Handles request.
     *
     * @param rc Request Context.
     * @throws CLIException if request cannot be processed.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    validateRealm(realm);
    String[] params = { realm };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_DATASTORES", params);
    try {
        ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminSSOToken);
        ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
        Set names = (cfg != null) ? cfg.getSubConfigNames() : Collections.EMPTY_SET;
        if ((names != null) && !names.isEmpty()) {
            getOutputWriter().printlnMessage(getResourceString("datastore-list-datastores-succeeded"));
            for (Iterator i = names.iterator(); i.hasNext(); ) {
                String name = (String) i.next();
                getOutputWriter().printlnMessage(name);
            }
        } else {
            getOutputWriter().printlnMessage(getResourceString("datastore-list-datastores-no-entries"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_LIST_DATASTORES", params);
    } catch (SMSException e) {
        debugError("ListDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("ListDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Aggregations

SMSException (com.sun.identity.sm.SMSException)704 SSOException (com.iplanet.sso.SSOException)525 Set (java.util.Set)272 HashSet (java.util.HashSet)200 SSOToken (com.iplanet.sso.SSOToken)185 Map (java.util.Map)166 ServiceConfig (com.sun.identity.sm.ServiceConfig)164 HashMap (java.util.HashMap)158 CLIException (com.sun.identity.cli.CLIException)149 ServiceSchema (com.sun.identity.sm.ServiceSchema)138 Iterator (java.util.Iterator)133 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)131 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)104 IOutput (com.sun.identity.cli.IOutput)96 IdRepoException (com.sun.identity.idm.IdRepoException)86 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)84 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)83 AttributeSchema (com.sun.identity.sm.AttributeSchema)66 IOException (java.io.IOException)55 List (java.util.List)51