Search in sources :

Example 6 with AMAuthenticationManager

use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.

the class AuthPropertiesModelImpl method getServiceName.

/**
     * To get the service name from the instance name:
     *   1) get a handle to the AMAuthenicationInstance object
     *   2) from the AuthInstance object get the type of instance
     *   3) Use the instance type to get the schema for that type
     *   4) from the schema get the service name
     */
public String getServiceName(String instance) {
    String name = null;
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(getUserSSOToken(), currentRealm);
        AMAuthenticationInstance inst = mgr.getAuthenticationInstance(instance);
        if (inst != null) {
            AMAuthenticationSchema schema = mgr.getAuthenticationSchema(inst.getType());
            name = schema.getServiceName();
        } else {
            if (debug.warningEnabled()) {
                debug.warning("AuthPropertiesModel.getServiceName, " + " the requested instance " + instance + " does not exist.");
            }
        }
    } catch (AMConfigurationException ace) {
        if (debug.warningEnabled()) {
            debug.warning("problem getting service name for " + instance, ace);
        }
    }
    return name;
}
Also used : AMAuthenticationSchema(com.sun.identity.authentication.config.AMAuthenticationSchema) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 7 with AMAuthenticationManager

use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.

the class GetAuthInstance 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);
    String instanceName = getStringOptionValue(AuthOptions.AUTH_INSTANCE_NAME);
    String[] params = { realm, instanceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_AUTH_INSTANCE", params);
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
        AMAuthenticationInstance ai = mgr.getAuthenticationInstance(instanceName);
        if (ai != null) {
            IOutput outputWriter = getOutputWriter();
            Map attributeValues = ai.getAttributeValues();
            if ((attributeValues != null) && !attributeValues.isEmpty()) {
                AMAuthenticationSchema schema = mgr.getAuthenticationSchema(ai.getType());
                String serviceName = schema.getServiceName();
                outputWriter.printlnMessage(getResourceString("authentication-get-auth-instance-succeeded"));
                outputWriter.printlnMessage(FormatUtils.printAttributeValues(getResourceString("authentication-get-auth-instance-result"), attributeValues, CLIUtil.getPasswordFields(serviceName)));
            } else {
                outputWriter.printlnMessage(getResourceString("authentication-get-auth-instance-no-values"));
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_GET_AUTH_INSTANCE", params);
        } else {
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
            throw new CLIException(getResourceString("authentication-get-auth-instance-not-found"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    } catch (SSOException e) {
        debugError("GetAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        debugError("GetAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (AMConfigurationException e) {
        debugError("GetAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) AMAuthenticationSchema(com.sun.identity.authentication.config.AMAuthenticationSchema) CLIException(com.sun.identity.cli.CLIException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 8 with AMAuthenticationManager

use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.

the class ListAuthInstances 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);
    String[] params = { realm };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_AUTH_INSTANCES", params);
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
        Set instances = mgr.getAuthenticationInstances();
        if ((instances != null) && !instances.isEmpty()) {
            getOutputWriter().printlnMessage(getResourceString("authentication-list-auth-instance"));
            for (Iterator i = instances.iterator(); i.hasNext(); ) {
                AMAuthenticationInstance instance = (AMAuthenticationInstance) i.next();
                Object[] args = { instance.getName(), instance.getType() };
                getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("authentication-list-auth-instance-entry"), args));
            }
        } else {
            getOutputWriter().printlnMessage(getResourceString("authentication-list-auth-instance-empty"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_LIST_AUTH_INSTANCES", params);
    } catch (AMConfigurationException e) {
        debugError("ListAuthInstances.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AUTH_INSTANCES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) Iterator(java.util.Iterator) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) CLIException(com.sun.identity.cli.CLIException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 9 with AMAuthenticationManager

use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.

the class CreateAuthInstance 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);
    String name = getStringOptionValue(AuthOptions.AUTH_INSTANCE_NAME);
    String type = getStringOptionValue(AuthOptions.AUTH_INSTANCE_TYPE);
    String[] params = { realm, name, type };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_AUTH_INSTANCE", params);
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
        AMAuthenticationSchema as = mgr.getAuthenticationSchema(type);
        mgr.createAuthenticationInstance(name, type, as.getAttributeValues());
        getOutputWriter().printlnMessage(getResourceString("authentication-created-auth-instance-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_CREATE_AUTH_INSTANCE", params);
    } catch (AMConfigurationException e) {
        debugError("CreateAuthInstance.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_AUTH_INSTANCE", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AMAuthenticationSchema(com.sun.identity.authentication.config.AMAuthenticationSchema) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) CLIException(com.sun.identity.cli.CLIException) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 10 with AMAuthenticationManager

use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.

the class DeleteAuthInstances 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(AuthOptions.AUTH_INSTANCE_NAMES);
    String[] params = { realm, names.toString() };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_AUTH_INSTANCES", params);
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
        for (Iterator i = names.iterator(); i.hasNext(); ) {
            String name = (String) i.next();
            mgr.deleteAuthenticationInstance(name);
        }
        if (names.size() == 1) {
            getOutputWriter().printlnMessage(getResourceString("authentication-delete-auth-instance-succeeded"));
        } else {
            getOutputWriter().printlnMessage(getResourceString("authentication-delete-auth-instances-succeeded"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_AUTH_INSTANCES", params);
    } catch (AMConfigurationException e) {
        debugError("DeleteAuthInstances,handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AUTH_INSTANCES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Iterator(java.util.Iterator) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Aggregations

AMAuthenticationManager (com.sun.identity.authentication.config.AMAuthenticationManager)43 AMConfigurationException (com.sun.identity.authentication.config.AMConfigurationException)35 Set (java.util.Set)28 AMAuthenticationInstance (com.sun.identity.authentication.config.AMAuthenticationInstance)22 HashSet (java.util.HashSet)18 Iterator (java.util.Iterator)16 SSOToken (com.iplanet.sso.SSOToken)15 SSOException (com.iplanet.sso.SSOException)10 HashMap (java.util.HashMap)10 SMSException (com.sun.identity.sm.SMSException)9 Map (java.util.Map)8 AMAuthenticationSchema (com.sun.identity.authentication.config.AMAuthenticationSchema)7 CLIException (com.sun.identity.cli.CLIException)7 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)7 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)3 ServiceConfig (com.sun.identity.sm.ServiceConfig)3 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)3 AMException (com.iplanet.am.sdk.AMException)2 SessionException (com.iplanet.dpro.session.SessionException)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)2