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);
}
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);
}
}
}
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();
}
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);
}
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();
}
Aggregations