Search in sources :

Example 1 with AuthContext

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

the class InitializeSystem method getSSOToken.

public SSOToken getSSOToken(String bindPwd) throws LoginException, InvalidAuthContextException {
    SSOToken ssoToken = null;
    String userRootSuffix = bData.getUserBaseDN();
    AuthPrincipal principal = new AuthPrincipal("cn=dsameuser,ou=DSAME Users," + userRootSuffix);
    AuthContext ac = new AuthContext(userRootSuffix, principal, bindPwd.toCharArray());
    if (ac.getLoginStatus() == AuthContext.AUTH_SUCCESS) {
        ssoToken = ac.getSSOToken();
    }
    return ssoToken;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AuthContext(com.sun.identity.authentication.internal.AuthContext) AuthPrincipal(com.sun.identity.authentication.internal.AuthPrincipal)

Example 2 with AuthContext

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

the class ServerConfigMgr method changePassword.

/**
     * Checks and sets the password
     */
private void changePassword(String userType, String oldPassword, String newPassword) throws Exception {
    String fileEncPassword = getUserPassword(userType);
    String userDN = getUserDN(userType);
    if ((fileEncPassword == null) || (fileEncPassword.length() == 0) || (userDN == null) || (userDN.length() == 0)) {
        debug.error("Null password or user DN for user type: " + userType + " from file: " + configFile);
        throw new XMLException(i18n.getString("dscfg-corrupted-serverconfig"));
    }
    // Verify old password
    if (!oldPassword.equals(AccessController.doPrivileged(new DecodeAction(fileEncPassword)))) {
        throw new Exception(i18n.getString("dscfg-old-passwd-donot-match"));
    }
    if (isAMSDKConfigured) {
        // this is to check if updating of DS is required.
        try {
            new AuthContext(new AuthPrincipal(userDN), newPassword.toCharArray());
            if (debug.messageEnabled()) {
                debug.message("DN: " + userDN + " new password is already updated in the directory");
            }
        } catch (LoginException lee) {
            try {
                AuthContext ac = new AuthContext(new AuthPrincipal(userDN), oldPassword.toCharArray());
                PersistentObject user = UMSObject.getObject(ac.getSSOToken(), new Guid(userDN));
                if (debug.messageEnabled()) {
                    debug.message("For DN: " + userDN + " changing password in directory");
                }
                user.setAttribute(new Attr("userPassword", newPassword));
                user.save();
            } catch (LoginException le) {
                if (debug.warningEnabled()) {
                    debug.warning("For DN: " + userDN + " new and old passwords donot match with directory");
                }
                throw new Exception(i18n.getString("dscfg-invalid-password") + "\n" + le.getMessage());
            }
        }
    }
    setUserPassword(userType, newPassword);
}
Also used : XMLException(com.iplanet.services.util.XMLException) DecodeAction(com.sun.identity.security.DecodeAction) AuthContext(com.sun.identity.authentication.internal.AuthContext) LoginException(javax.security.auth.login.LoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) PersistentObject(com.iplanet.ums.PersistentObject) AuthPrincipal(com.sun.identity.authentication.internal.AuthPrincipal) Guid(com.iplanet.ums.Guid) LoginException(javax.security.auth.login.LoginException) FileNotFoundException(java.io.FileNotFoundException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) XMLException(com.iplanet.services.util.XMLException) IOException(java.io.IOException) ConfiguratorException(com.sun.identity.setup.ConfiguratorException)

Example 3 with AuthContext

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

the class AdminTokenAction method getSSOToken.

private SSOToken getSSOToken() {
    // Please NEVER make this method public!!!!!!!!!!
    // This can only be used in server site. 
    SSOToken ssoAuthToken = null;
    try {
        //call method directly
        if (AdminUtils.getAdminPassword() != null) {
            String adminDN = AdminUtils.getAdminDN();
            String adminPassword = new String(AdminUtils.getAdminPassword());
            if (!authInitialized && (SystemProperties.isServerMode() || SystemProperties.get(AMADMIN_MODE) != null)) {
                // Use internal auth context to get the SSOToken
                AuthContext ac = new AuthContext(new AuthPrincipal(adminDN), adminPassword.toCharArray());
                internalAppSSOToken = ssoAuthToken = ac.getSSOToken();
            } else {
                // Copy the authentication state
                boolean authInit = authInitialized;
                if (authInit) {
                    authInitialized = false;
                }
                // Obtain SSOToken using AuthN service
                ssoAuthToken = new SystemAppTokenProvider(adminDN, adminPassword).getAppSSOToken();
                // Restore the authentication state
                if (authInit && ssoAuthToken != null) {
                    authInitialized = true;
                }
            }
        }
    } catch (NoClassDefFoundError ne) {
        debug.error("AdminTokenAction::getSSOToken Not found AdminDN and AdminPassword.", ne);
    } catch (Throwable t) {
        debug.error("AdminTokenAction::getSSOToken Exception reading from serverconfig.xml", t);
    }
    return ssoAuthToken;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AuthContext(com.sun.identity.authentication.internal.AuthContext) AuthPrincipal(com.sun.identity.authentication.internal.AuthPrincipal)

Example 4 with AuthContext

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

the class Bootstrap method getSSOToken.

private static SSOToken getSSOToken(String basedn, String bindUser, String bindPwd) throws LoginException, InvalidAuthContextException {
    SSOToken ssoToken = null;
    AuthPrincipal principal = new AuthPrincipal(bindUser);
    AuthContext ac = new AuthContext(basedn, principal, bindPwd.toCharArray());
    if (ac.getLoginStatus() == AuthContext.AUTH_SUCCESS) {
        ssoToken = ac.getSSOToken();
    }
    return ssoToken;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AuthContext(com.sun.identity.authentication.internal.AuthContext) AuthPrincipal(com.sun.identity.authentication.internal.AuthPrincipal)

Example 5 with AuthContext

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

the class ImportConfig method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.err.println("usage: serverAdmin import xmlFile");
        System.exit(1);
    }
    if (args[0].equals("import")) {
        try {
            FileInputStream fisSchema = new FileInputStream(args[1]);
            DSConfigMgr cfgMgr = DSConfigMgr.getDSConfigMgr();
            ServerInstance sInst = cfgMgr.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
            authPcpl = new AuthPrincipal(sInst.getAuthID());
            AuthContext authCtx = new AuthContext(authPcpl, sInst.getPasswd().toCharArray());
            SSOToken userSSOToken = authCtx.getSSOToken();
            ServiceManager smsMgr = new ServiceManager(userSSOToken);
            smsMgr.registerServices(fisSchema);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e);
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceManager(com.sun.identity.sm.ServiceManager) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) AuthContext(com.sun.identity.authentication.internal.AuthContext) AuthPrincipal(com.sun.identity.authentication.internal.AuthPrincipal) ServerInstance(com.iplanet.services.ldap.ServerInstance) FileInputStream(java.io.FileInputStream)

Aggregations

AuthContext (com.sun.identity.authentication.internal.AuthContext)5 AuthPrincipal (com.sun.identity.authentication.internal.AuthPrincipal)5 SSOToken (com.iplanet.sso.SSOToken)4 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)1 ServerInstance (com.iplanet.services.ldap.ServerInstance)1 XMLException (com.iplanet.services.util.XMLException)1 SSOException (com.iplanet.sso.SSOException)1 Guid (com.iplanet.ums.Guid)1 PersistentObject (com.iplanet.ums.PersistentObject)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 DecodeAction (com.sun.identity.security.DecodeAction)1 ConfiguratorException (com.sun.identity.setup.ConfiguratorException)1 ServiceManager (com.sun.identity.sm.ServiceManager)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 LoginException (javax.security.auth.login.LoginException)1