项目启动后,登录成功后才显示,然后就可以看到页面了,我调试的时候发现SecurityFilter不执行,UserRealm doGetAuthorizationInfo()方法不执行。问题出在哪里?感激的!.
谁能帮我弄清楚为什么会执行?
这是我的课:
public class UserRealm extends AuthorizingRealm {
@Resource
private UserService userService;
/**
* @param principalCollection
* @return
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
String username=principalCollection.getPrimaryPrincipal().toString();
SimpleAuthorizationInfo info=new SimpleAuthorizationInfo();
Set<String> roleName=userService.findRoles(username);
Set<String> permissions=userService.findPermissions(username);
info.setRoles(roleName);
info.setStringPermissions(permissions);
return info;
}
/**
* @param token
* @return
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String username=token.getPrincipal().toString();
User user=userService.findUserByUsername(username);
if(user!=null){
AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getUsername(),user.getPassword(),user.getUsername()) ;
return authenticationInfo;
}else {
return null;
}
}
}
筛选:
公共类 SecurityFilter 扩展 AccessControlFilter {
@Override
protected boolean isAccessAllowed(ServletRequest request,
ServletResponse response, Object mappedValue) throws Exception {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String url = httpServletRequest.getRequestURI();
if (null != token || isLoginRequest(request, response)) {
return false;
}
return true;
}
@Override
protected boolean onAccessDenied(ServletRequest request,
ServletResponse response) throws Exception {
saveRequestAndRedirectToLogin(request, response);
return false ;
}
}
领域:
公共类 UserRealm 扩展 AuthorizingRealm {
@资源
私人用户服务用户服务;
/** *
@param principalCollection
- @返回 */
@覆盖
受保护的 AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
字符串用户名=principalCollection.getPrimaryPrincipal().toString();
SimpleAuthorizationInfo info=new SimpleAuthorizationInfo();
设置 roleName=userService.findRoles(username);
设置权限=userService.findPermissions(username);
info.setRoles(角色名);
info.setStringPermissions(权限);
返回信息;
}
/** *
@param 令牌
- @返回
@throws AuthenticationException
*/
@覆盖
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
字符串用户名=token.getPrincipal().toString();
用户用户=userService.findUserByUsername(用户名);
如果(用户!=空){
AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getUsername(),user.getPassword(),user.getUsername()) ;
返回身份验证信息;}别的 {
返回空值;
}
}
}