我自己回答了这个问题。
我使用过滤器和JBoss的一个定义LoginModule解决了集成:
的过滤器(它必须四郎过滤器的调用之后被应用):
public class ShiroJAASIntegrationFilter implements Filter{
static Logger logger = Logger.getLogger(ShiroJAASIntegrationFilter.class);
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest)arg0;
Principal userPrincipal = httpServletRequest.getUserPrincipal();
HttpSession session = httpServletRequest.getSession(false);
if(userPrincipal!=null){
if(session!= null && session.getAttribute("shiroAuthenticated")==null){
String name = userPrincipal.getName();
try {
httpServletRequest.login(name,"");
session.setAttribute("shiroAuthenticated",true);
} catch (ServletException e) {
logger.debug("Unable to authenticate user" + e.getMessage());
}
}
}
arg2.doFilter(arg0, arg1);
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
登录模块,它只是套作为认证的用户:
public class ShiroJAASLoginModule extends UsernamePasswordLoginModule {
/**
* Always return true.
*/
protected boolean validatePassword(String inputPassword,
String expectedPassword) {
return true;
}
protected Group[] getRoleSets() throws LoginException {
//TODO: if needed, add roles
Group[] roleSets = { new SimpleGroup("Roles") };
roleSets[0].addMember(new SimplePrincipal(getUsername()));
return roleSets;
}
@Override
protected String getUsersPassword() throws LoginException {
return null;
}
}
模块必须在standalone.xml定义:
<security-domain name="shiro" cache-type="default">
<authentication>
<login-module code="web.security.shiroJaasIntegration.ShiroJAASLoginModule" flag="required"/>
</authentication>
</security-domain>
最后,在应用程序jboss-web中定义安全域。xml:
<jboss-web>
<security-domain>shiro</security-domain>
</jboss-web>
我面临着同样的例外。你记得具体造成这个问题的具体原因以及这个代码如何解决这个问题吗? –