我已经配置了自定义登录模块
在ApplicationRealm的guest组中增加了一个Application用户jmsuser。但我仍然得到"禁止"在结果页。
Standalone-full.xml
<default-security-domain value="MyLoginModule"/>
<security-domain name="MyLoginModule" cache-type="default">
<authentication>
<login-module code="com.auth.MyLoginModule" flag="required"/>
</authentication>
</security-domain>
web . xml
<security-role>
<role-name>guest</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name></web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>guest</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>MyLoginModule</realm-name>
</login-config>
jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>MyLoginModule</security-domain>
</jboss-web>
MyLoginModule.java
public boolean login() throws LoginException
{
//returns true;
}
Audit.log
11:17:51,560 TRACE [org.jboss.security] (default task-2) PBOX000224: End getAppConfigurationEntry(MyLoginModule), AuthInfo: AppConfigurationEntry[]:
[0]
LoginModule Class: com.auth.MyLoginModule
ControlFlag: LoginModuleControlFlag: required
Options:
11:19:16,232 TRACE [org.jboss.security] (default task-2) PBOX000210: defaultLogin, login context: javax.security.auth.login.LoginContext@8ba05ec, subject: Subject(1075984995).principals=com.auth.MyLoginModulePrincipal@1936852516(MyLoginModulePrincipal: jmsuser)
11:19:18,863 TRACE [org.jboss.security] (default task-2) PBOX000207: updateCache, input subject: Subject(1075984995).principals=com.auth.MyLoginModulePrincipal@1936852516(MyLoginModulePrincipal: jmsuser), cached subject: Subject(689516194).principals=com.auth.MyLoginModulePrincipal@1936852516(MyLoginModulePrincipal: jmsuser)
11:19:18,865 TRACE [org.jboss.security] (default task-2) PBOX000208: Inserted cache info: org.jboss.security.authentication.JBossCachedAuthenticationManager$DomainInfo@6a06d399
11:19:18,866 TRACE [org.jboss.security] (default task-2) PBOX000201: End isValid, result = true
11:19:18,879 TRACE [org.jboss.security] (default task-2) PBOX000354: Setting security roles ThreadLocal: null
更新:我在主题中添加了主体和角色,但仍然被禁止。PFB更新MyLoginModule类
private Principal userPrincipal;
private RolePrincipal rolePrincipal;
private List<String> userGroups;
...
public login(){
//returns true;
}
@Override
public boolean commit() throws LoginException {
if (!isAuthenticated) {
return false;
} else {
userPrincipal = new Principal(username);
subject.getPrincipals().add(userPrincipal);
if (userGroups != null && userGroups.size() > 0) {
for (String groupName : userGroups) {
rolePrincipal = new RolePrincipal(groupName);
subject.getPrincipals().add(rolePrincipal);
}
}
commitSucceeded = true;
return true;
}
}
private List<String> getRoles() {
List<String> roleList = new ArrayList<>();
roleList.add("guest");
return roleList;
}
如果您只想使用ApplicationRealm
和在其属性文件中定义的用户/角色,那么只需从部署中删除jboss-web.xml
。它将自动使用other
安全域(默认的)-它使用ApplicationRealm
作为用户存储库。
如果你想在一个新的安全域中使用你自己的登录模块,你不需要触摸ApplicationRealm
。
你需要在你的自定义登录模块中做的是:
-
验证用户(向Subject添加带有用户名的主体)
-
为Subject
中的
Roles
组添加一些角色如果您使用用户名/密码认证,那么最简单的方法是扩展抽象的PicketBox类org.jboss.security.auth.spi.UsernamePasswordLoginModule
查看JBoss EAP安全指南获取如何为JBoss应用服务器实现自定义登录模块的详细信息。
您的模块是否直接或间接扩展AbstractServerLoginModule
?
- 如果是,则需要设置
loginOk = true
- 如果没有
commit
也需要返回true