0
这是我LdapTemplate类 公共LdapTemplate getLdapTemplete(字符串ldapID) {WAS服务器上的J2C别名有什么用途?
if (ldapID.equalsIgnoreCase(Constants.LDAP1))
{
if (ldapTemplate1 == null)
{
try
{
PasswordCredential passwordCredential = j2cAliasUtility.getAliasDetails(ldapID);
String managerDN = passwordCredential.getUserName();
String managerPwd = new String(passwordCredential.getPassword());
log.info("managerDN :"+managerDN+":: password : "+managerPwd);
LdapContextSource lcs = new LdapContextSource();
lcs.setUrl(ldapUrl1);
lcs.setUserDn(managerDN);
lcs.setPassword(managerPwd);
lcs.setDirObjectFactory(DefaultDirObjectFactory.class);
lcs.afterPropertiesSet();
ldapTemplate1 = new LdapTemplate(lcs);
log.info("ldap1 configured");
return ldapTemplate1;
}
catch (Exception e)
{
log.error("ldapContextCreater/getLdapTemplete/ldap2");
log.error("Error in getting ldap context", e);
}
}
return ldapTemplate1;
}
这是我J2CAliasUtility类 - 我不知道这是什么方法做它有什么回报?
public PasswordCredential getAliasDetails(String aliasName) throws Exception
{
PasswordCredential result = null;
try
{
// ----------WAS 6 change -------------
Map map = new HashMap();
map.put(com.ibm.wsspi.security.auth.callback.Constants.MAPPING_ALIAS, aliasName); //{com.ibm.mapping.authDataAlias=ldap1}
CallbackHandler cbh = (WSMappingCallbackHandlerFactory.getInstance()).getCallbackHandler(map, null);
LoginContext lc = new LoginContext("DefaultPrincipalMapping", cbh);
lc.login();
javax.security.auth.Subject subject = lc.getSubject();
java.util.Set creds = subject.getPrivateCredentials();
result = (PasswordCredential) creds.toArray()[0];
}
catch (Exception e)
{
log.info("APPLICATION ERROR: cannot load credentials for j2calias = " + aliasName);
log.error(" "+e);
throw new RuntimeException("Unable to get credentials");
}
return result;
}
因此,通过检索用户名和密码,您的意思是在LDAP服务器上存储的LDAP服务器登录凭证或用户凭证的凭证?在我的情况下,配置了3个ldap服务器,此代码验证ldap服务器并测试它们正在运行? –
你的问题是这个方法(J2CAliasUtility)做了什么,它返回了什么。从应用服务器中配置的指定认证别名开始,实用程序方法将检索用户的凭证并返回从其创建的javax.resource.spi.security.PasswordCredential(请参阅javadoc)。您的代码的其余部分似乎会采用这些凭据并创建一个LDAP上下文。之后,您的代码在上下文中所做的操作无法确定。 –