当前位置: 首页 > 工具软件 > J2C > 使用案例 >

java通过J2C获取用户名密码_WAS服务器上的J2C别名有什么用途?

仲鸿风
2023-12-01

这是我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;

}

 类似资料: