Search in sources :

Example 16 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class AMSDKRepo method authenticate.

public boolean authenticate(Callback[] credentials) throws IdRepoException, AuthLoginException {
    debug.message("AMSDKRepo: authenticate. ");
    // Obtain user name and password from credentials and authenticate
    String username = null;
    String password = null;
    for (int i = 0; i < credentials.length; i++) {
        if (credentials[i] instanceof NameCallback) {
            username = ((NameCallback) credentials[i]).getName();
            if (debug.messageEnabled()) {
                debug.message("LDPv3Repo:authenticate username: " + username);
            }
        } else if (credentials[i] instanceof PasswordCallback) {
            char[] passwd = ((PasswordCallback) credentials[i]).getPassword();
            if (passwd != null) {
                password = new String(passwd);
                debug.message("AMSDKRepo: authenticate passwd XXX.");
            }
        }
    }
    if (username == null || (username.length() == 0) || password == null) {
        Object[] args = { CLASS_NAME };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_TO_AUTHENTICATE, args);
    }
    ServerInstance svrCfg = getDsSvrCfg(LDAPUser.Type.AUTH_ADMIN);
    boolean ssl = (svrCfg.getConnectionType() == Server.Type.CONN_SSL);
    LDAPAuthUtils ldapAuthUtil;
    try {
        ldapAuthUtil = new LDAPAuthUtils(Collections.singleton(svrCfg.getServerName() + ":" + svrCfg.getPort()), Collections.<String>emptySet(), ssl, AMResourceBundleCache.getInstance().getResBundle(IdRepoBundle.BUNDLE_NAME, Locale.getDefaultLocale()), //BaseDN is set later based on whether authenticating user or agent
        "BASE_DN", debug);
    } catch (LDAPUtilException ldapUtilEx) {
        if (debug.messageEnabled()) {
            debug.message("AMSDKRepo: authenticate" + " LDAPUtilException: " + ldapUtilEx.getMessage());
        }
        Object[] args = { CLASS_NAME, username };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.ERROR_DURING_SEARCH, args);
    }
    ldapAuthUtil.setAuthDN(AdminUtils.getAdminDN());
    ldapAuthUtil.setAuthPassword(new String(AdminUtils.getAdminPassword()).toCharArray());
    ldapAuthUtil.setScope(SearchScope.SINGLE_LEVEL);
    if (authenticateIt(ldapAuthUtil, IdType.USER, username, password)) {
        if (debug.messageEnabled()) {
            debug.message("AMSDKRepo: IdType.USER authenticateIt=true");
        }
        return (true);
    }
    if (authenticateIt(ldapAuthUtil, IdType.AGENT, username, password)) {
        if (debug.messageEnabled()) {
            debug.message("AMSDKRepo: IdType.AGENT authenticateIt=true");
        }
        return (true);
    }
    return (false);
}
Also used : LDAPAuthUtils(org.forgerock.openam.ldap.LDAPAuthUtils) NameCallback(javax.security.auth.callback.NameCallback) IdRepoException(com.sun.identity.idm.IdRepoException) PasswordCallback(javax.security.auth.callback.PasswordCallback) LDAPUtilException(org.forgerock.openam.ldap.LDAPUtilException) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 17 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance 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)

Example 18 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class ServerConfigurationFactoryTest method shouldReturnInstanceBindDN.

@Test
public void shouldReturnInstanceBindDN() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound {
    // Given
    DSConfigMgr configMgr = mock(DSConfigMgr.class);
    ServerGroup serverGroup = mock(ServerGroup.class);
    given(configMgr.getServerGroup(anyString())).willReturn(serverGroup);
    ServerInstance mockInstance = mock(ServerInstance.class);
    given(configMgr.getServerInstance(anyString(), any(LDAPUser.Type.class))).willReturn(mockInstance);
    given(mockInstance.getAuthID()).willReturn("");
    ServerConfigurationFactory parser = new ServerConfigurationFactory(configMgr);
    // When
    String dn = parser.getServerConfiguration("", LDAPUser.Type.AUTH_ADMIN).getBindDN();
    // Then
    verify(mockInstance).getAuthID();
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ServerConfigurationFactory(org.forgerock.openam.sm.ServerConfigurationFactory) Matchers.anyString(org.mockito.Matchers.anyString) ServerInstance(com.iplanet.services.ldap.ServerInstance) Test(org.testng.annotations.Test)

Example 19 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class ServerConfigurationFactoryTest method shouldReturnRequestedServerGroup.

@Test
public void shouldReturnRequestedServerGroup() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound {
    // Given
    String test = "badger";
    ServerGroup mockGroup = mock(ServerGroup.class);
    ServerInstance mockInstance = mock(ServerInstance.class);
    DSConfigMgr mockConfig = mock(DSConfigMgr.class);
    given(mockConfig.getServerGroup(test)).willReturn(mockGroup);
    given(mockConfig.getServerInstance(anyString(), any(LDAPUser.Type.class))).willReturn(mockInstance);
    ServerConfigurationFactory parser = new ServerConfigurationFactory(mockConfig);
    // When
    parser.getServerConfiguration(test, LDAPUser.Type.AUTH_ADMIN);
    // Then
    verify(mockConfig).getServerGroup(test);
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ServerConfigurationFactory(org.forgerock.openam.sm.ServerConfigurationFactory) Matchers.anyString(org.mockito.Matchers.anyString) ServerInstance(com.iplanet.services.ldap.ServerInstance) Test(org.testng.annotations.Test)

Example 20 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class ServerGroupConfigurationTest method shouldReturnBindDNFromInstance.

@Test
public void shouldReturnBindDNFromInstance() {
    // Given
    ServerInstance mockInstance = mock(ServerInstance.class);
    ServerGroup mockGroup = mock(ServerGroup.class);
    ServerGroupConfiguration config = new ServerGroupConfiguration(mockGroup, mockInstance);
    // When
    config.getBindDN();
    // Then
    verify(mockInstance).getAuthID();
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) ServerInstance(com.iplanet.services.ldap.ServerInstance) Test(org.testng.annotations.Test)

Aggregations

ServerInstance (com.iplanet.services.ldap.ServerInstance)22 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)13 ServerGroup (com.iplanet.services.ldap.ServerGroup)11 Test (org.testng.annotations.Test)8 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)7 Server (com.iplanet.services.ldap.Server)4 IdRepoException (com.sun.identity.idm.IdRepoException)3 ServerConfigurationFactory (org.forgerock.openam.sm.ServerConfigurationFactory)3 LdapException (org.forgerock.opendj.ldap.LdapException)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 LoginException (javax.security.auth.login.LoginException)2 LDAPURL (org.forgerock.openam.ldap.LDAPURL)2 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)2 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)2 ShutdownManager (org.forgerock.util.thread.listener.ShutdownManager)2 Matchers.anyString (org.mockito.Matchers.anyString)2 EventException (com.iplanet.services.ldap.event.EventException)1 SSOToken (com.iplanet.sso.SSOToken)1