Java 如何在自定义安全领域(Glassfish)中使用自定义主体?
我遵循为我的glassfish创建自定义安全域的方法。这一切都很好,用户的身份验证是正确的。然而,问题如下:Java 如何在自定义安全领域(Glassfish)中使用自定义主体?,java,security,jakarta-ee,glassfish,Java,Security,Jakarta Ee,Glassfish,我遵循为我的glassfish创建自定义安全域的方法。这一切都很好,用户的身份验证是正确的。然而,问题如下: 用户凭据以字符串形式加密 领域解密此字符串并对数据库执行身份验证(works) 与在securityContext中将解密的值用作主体不同,加密的 字符串被传递 我已经尝试重写commit()方法来替换\u userPrincipal,或者使用getSubject().getPrincipals().add(new PrincipalImpl(“用户”)附加我自己的实现。两人都没有按
- 用户凭据以字符串形式加密
- 领域解密此字符串并对数据库执行身份验证(works)
- 与在securityContext中将解密的值用作主体不同,加密的 字符串被传递
\u userPrincipal
,或者使用getSubject().getPrincipals().add(new PrincipalImpl(“用户”)
附加我自己的实现。两人都没有按预期工作。基本上,问题很简单:如何在glassfish中的自定义安全领域中设置自己的主体,使其能够与注入的securityContext一起使用
我的环境:
- Glassfish 3.1.2.2(构建5)完整剖面
- 在身份验证之后运行的应用程序是基于JAX-RS1.1的应用程序
- SecurityContext是通过注入获得的
public class MyLoginModule extends AppservPasswordLoginModule {
@Override
protected void authenticateUser() throws LoginException {
if (!authenticate(_username, _password)) {
//Login fails
throw new LoginException("LoginFailed");
}
String[] myGroups = getGroupNames(_username);
commitUserAuthentication(myGroups);
}
private boolean authenticate(String username, String password) {
/*
Check the credentials against the authentication source, return true if authenticated, return false otherwise
*/
return true;
}
private String[] getGroupNames(String username) {
// Return the list of groups this user belongs to.
}
实现你的领域类
public class MyRealm extends AppservRealm {
@Override
public void init(Properties props)
throws BadRealmException, NoSuchRealmException {
//here you initialize the realm
}
@Override
public String getAuthType() {
return "Custom Realm";
}
}
C-在服务器中安装和配置领域和LoginModule
为此,您需要了解JSR196,并通过实现javax.security.auth.message.module.ServerAuthModule编写您自己的SAM。看看下面的链接。
由于这个问题是10个月前提出的,我甚至不能再告诉你我们有什么bug了。不幸的是,我也无法测试您的方法,因为我们使用了不同的解决方案。但既然你努力想回答这样一个老生常谈的问题,我还是会投票支持你的答案:)