Kai*_*Kai 6 java security glassfish java-ee
我按照说明为我的glassfish创建了一个自定义安全领域.一切正常,用户正确认证.但问题如下:
我已经尝试覆盖commit()方法来替换_userPrincipal或附加我自己的实现getSubject().getPrincipals().add(new PrincipalImpl("user")).两者都没有按预期工作.基本上这个问题很简单:如何在glassfish中的自定义安全领域中设置我自己的主体,这样可以将它与注入的securityContext一起使用?
我的环境:
我已经尝试重写 commit() 方法来替换 _userPrincipal 或使用 getSubject().getPrincipals().add(new PrimaryImpl("user")) 附加我自己的实现。两者都没有按预期工作。
您遇到什么类型的错误?
无论如何,我认为你的问题在于这个过程的第三步。SecurityContext 仅将 BASIC_AUTH、FORM_AUTH、CLIENT_CERT_AUTH、DIGEST_AUTH 定义为 AuthenticationScheme,因此 SecurityContext 可能无法看到您的安全方案或类型的实现。但您可以尝试这些步骤,我希望它们对您有用。
A- 实现 Java 身份验证和授权服务 (JAAS) LoginModule 或扩展 com.sun.appserv.security.AppservPasswordLoginModule
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.
}
Run Code Online (Sandbox Code Playgroud)
B- 实现你的领域类。
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";
}
}
Run Code Online (Sandbox Code Playgroud)
C- 在服务器中安装并配置领域和 LoginModule。
为此,您需要查看 JSR 196 并通过实现 javax.security.auth.message.module.ServerAuthModule 编写您自己的 SAM。看看下面的链接。 https://blogs.oracle.com/enterprisetechtips/entry/adding_authentication_mechanisms_to_the
| 归档时间: |
|
| 查看次数: |
1556 次 |
| 最近记录: |