Search in sources :

Example 1 with InvalidAuthContextException

use of com.sun.identity.authentication.internal.InvalidAuthContextException in project OpenAM by OpenRock.

the class ImportServiceConfiguration 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);
    String xmlFile = getStringOptionValue(IArgument.XML_FILE);
    String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
    try {
        encryptSecret = CLIUtil.getFileContent(getCommandManager(), encryptSecret).trim();
    } catch (CLIException clie) {
    //There is no encryptSecret file
    }
    validateEncryptSecret(xmlFile, encryptSecret);
    // disable notification
    SystemProperties.initializeProperties(Constants.SMS_ENABLE_DB_NOTIFICATION, "true");
    SystemProperties.initializeProperties("com.sun.am.event.connection.disable.list", "sm,aci,um");
    // disable error debug messsage
    SystemProperties.initializeProperties(Constants.SYS_PROPERTY_INSTALL_TIME, "true");
    IOutput outputWriter = getOutputWriter();
    try (Connection ldConnection = getLDAPConnection()) {
        InitializeSystem initSys = CommandManager.initSys;
        SSOToken ssoToken = initSys.getSSOToken(getAdminPassword());
        DirectoryServerVendor.Vendor vendor = DirectoryServerVendor.getInstance().query(ldConnection);
        if (!vendor.name.equals(DirectoryServerVendor.OPENDJ) && !vendor.name.equals(DirectoryServerVendor.OPENDS) && !vendor.name.equals(DirectoryServerVendor.ODSEE)) {
            throw new CLIException(getResourceString("import-service-configuration-unknown-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        loadLDIF(vendor, ldConnection);
        String ouServices = "ou=services," + initSys.getRootSuffix();
        if (this.isOuServicesExists(ssoToken, ouServices)) {
            System.out.print(getResourceString("import-service-configuration-prompt-delete") + " ");
            String value = (new BufferedReader(new InputStreamReader(System.in))).readLine();
            value = value.trim();
            if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("yes")) {
                outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
                deleteOuServicesDescendents(ssoToken, ouServices);
                importData(xmlFile, encryptSecret, ssoToken);
            }
        } else {
            outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
            importData(xmlFile, encryptSecret, ssoToken);
        }
    } catch (SMSException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (LdapException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (LoginException e) {
        throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
    } catch (InvalidAuthContextException e) {
        throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) InputStreamReader(java.io.InputStreamReader) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) InitializeSystem(com.sun.identity.cli.InitializeSystem) IOutput(com.sun.identity.cli.IOutput) BufferedReader(java.io.BufferedReader) CLIException(com.sun.identity.cli.CLIException) DirectoryServerVendor(com.sun.identity.sm.DirectoryServerVendor) LoginException(javax.security.auth.login.LoginException) LdapException(org.forgerock.opendj.ldap.LdapException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException)

Example 2 with InvalidAuthContextException

use of com.sun.identity.authentication.internal.InvalidAuthContextException in project OpenAM by OpenRock.

the class UpgradeUtils method ldapLoginInternal.

/**
     * Returns the ssoToken used for admin operations.
     * NOTE: this might be replaced later.
     *
     * @param bindUser the user distinguished name.
     * @param bindPwd the user password
     * @return the <code>SSOToken</code>
     */
private static SSOToken ldapLoginInternal(String bindUser, String bindPwd) {
    String classMethod = "UpgradeUtils:ldapLoginInternal : ";
    SSOToken ssoToken = null;
    try {
        com.sun.identity.authentication.internal.AuthContext ac = getLDAPAuthContext(bindUser, bindPwd);
        if (ac.getLoginStatus() == AUTH_SUCCESS) {
            ssoToken = ac.getSSOToken();
        } else {
            ssoToken = null;
        }
    } catch (LoginException le) {
        debug.error(classMethod + "Error creating SSOToken", le);
    } catch (InvalidAuthContextException iace) {
        ssoToken = null;
        debug.error(classMethod + "Error creating SSOToken", iace);
    }
    return ssoToken;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) LoginException(javax.security.auth.login.LoginException) ByteString(org.forgerock.opendj.ldap.ByteString) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException)

Example 3 with InvalidAuthContextException

use of com.sun.identity.authentication.internal.InvalidAuthContextException in project OpenAM by OpenRock.

the class Authenticator method ldapLoginInternal.

private SSOToken ldapLoginInternal(CommandManager mgr, String bindUser, String bindPwd) throws CLIException {
    SSOToken ssoToken = null;
    ResourceBundle rb = mgr.getResourceBundle();
    try {
        com.sun.identity.authentication.internal.AuthContext ac = getLDAPAuthContext(bindUser, bindPwd);
        if (ac.getLoginStatus() == com.sun.identity.authentication.internal.AuthContext.AUTH_SUCCESS) {
            ssoToken = ac.getSSOToken();
            AMIdentity amid = new AMIdentity(ssoToken, ssoToken.getPrincipal().getName(), IdType.USER, "/", null);
            ssoToken.setProperty(Constants.UNIVERSAL_IDENTIFIER, amid.getUniversalId());
        } else {
            throw new CLIException(rb.getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
        }
    } catch (LoginException le) {
        String[] params = { bindUser, le.getMessage() };
        LogWriter.log(mgr, LogWriter.LOG_ERROR, Level.INFO, "FAILED_LOGIN", params, null);
        throw new CLIException(rb.getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
    } catch (SSOException e) {
        String[] params = { bindUser, e.getMessage() };
        LogWriter.log(mgr, LogWriter.LOG_ERROR, Level.INFO, "FAILED_LOGIN", params, null);
        throw new CLIException(e, ExitCodes.LDAP_LOGIN_FAILED);
    } catch (InvalidAuthContextException iace) {
        String[] params = { bindUser, iace.getMessage() };
        LogWriter.log(mgr, LogWriter.LOG_ERROR, Level.INFO, "FAILED_LOGIN", params, null);
        throw new CLIException(rb.getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
    }
    return ssoToken;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AMIdentity(com.sun.identity.idm.AMIdentity) LoginException(javax.security.auth.login.LoginException) ResourceBundle(java.util.ResourceBundle) SSOException(com.iplanet.sso.SSOException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException)

Aggregations

SSOToken (com.iplanet.sso.SSOToken)3 InvalidAuthContextException (com.sun.identity.authentication.internal.InvalidAuthContextException)3 LoginException (javax.security.auth.login.LoginException)3 SSOException (com.iplanet.sso.SSOException)2 CLIException (com.sun.identity.cli.CLIException)1 IOutput (com.sun.identity.cli.IOutput)1 InitializeSystem (com.sun.identity.cli.InitializeSystem)1 AMIdentity (com.sun.identity.idm.AMIdentity)1 DirectoryServerVendor (com.sun.identity.sm.DirectoryServerVendor)1 SMSException (com.sun.identity.sm.SMSException)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ResourceBundle (java.util.ResourceBundle)1 ByteString (org.forgerock.opendj.ldap.ByteString)1 Connection (org.forgerock.opendj.ldap.Connection)1 LdapException (org.forgerock.opendj.ldap.LdapException)1