shiro 没有跳转到 successUrl 对于的地址什么原因?求答案!!!!

青苗 发布于 2012/03/15 22:28
阅读 3K+
收藏 1

请问走到   

return new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), getName());

  这骤然后页面也没有跳转到 successUrl 对于的地址什么原因?求答案!!!


 controller 请求   

	@RequestMapping("/s/invalidLogin.do")
	public ModelAndView GoAdminLogin(HttpServletRequest request,HttpServletResponse response) {
        User user = new User();
		ServletRequestDataBinder bind = new ServletRequestDataBinder(user);
		bind.bind(request);
		//1. 接受提交user和证书:
		AuthenticationToken token = new UsernamePasswordToken(user.getUser_name(), user.getPassword());
        try {
    		//2. 获取当前Subject:
    		Subject currentUser = SecurityUtils.getSubject();
    		//3. 登录: 
    		currentUser.login(token);
    		System.out.println("User is authenticated:  " + currentUser.isAuthenticated());
        } catch (AuthenticationException e) {
        	LOGGER.debug("Error authenticating.", e);
        	return new ModelAndView("admin/admin_login");
        }
        return new ModelAndView("redirect:/s/adminIndex.do");
	}


 配置   

 <bean id="shiroFilter"
	      class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
		<property name="securityManager" ref="securityManager" />
		<!-- /s/* 拦截、登入 -->
 		<property name="loginUrl" value="/s/invalidLogin.do" />
 		<!-- 成功登入  -->
		<property name="successUrl" value="/s/adminIndex.do" />
		<!-- 未经授权跳转  -->
		<property name="unauthorizedUrl" value="/s/unauthorized.do" />
		<!-- 过滤器链定义 -->
		<property name="filterChainDefinitions">
			<value>
	            /login = anon 
                /res/* = anon 
                /avoid/* = anon 
	            /user/** = authc 
	            /role/edit/** = perms[role:edit] 
	            /role/save = perms[role:edit] 
	            /role/list = perms[role:view] 
                /** = authc 
        	</value>
		</property>
	</bean>


 Real   

public class MyRealm extends AuthorizingRealm{
	
	/**
	 * 认证回调函数,登录时调用.
	 */
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
		UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
		if (token.getUsername() != null) {
			User user = getUserByName(token.getUsername());
			return new SimpleAuthenticationInfo(user.getUser_name(), user.getPassword(), getName());
		} else {
			return null;
		}
	}

	/**
	 * 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用.
	 */
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
		String loginName = (String) principals.fromRealm(getName()).iterator().next();
		User user = getUserByName(loginName);
		if (user != null) {
			SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//			info.addRoles(user.getRoleNameList());
//			for (Role role : user.getRoleList()) {
//				info.addStringPermissions(role.getPermissionNameList());
//			}
			return info;
		} else {
			return null;
		}
	}

	/**
	 * 更新用户授权信息缓存.
	 */
	public void clearCachedAuthorizationInfo(String principal) {
		SimplePrincipalCollection principals = new SimplePrincipalCollection(principal, getName());
		clearCachedAuthorizationInfo(principals);
	}

	/**
	 * 清除所有用户授权信息缓存.
	 */
	public void clearAllCachedAuthorizationInfo() {
		Cache<Object, AuthorizationInfo> cache = getAuthorizationCache();
		if (cache != null) {
			for (Object key : cache.keys()) {
				cache.remove(key);
			}
		}
	}
	
	/**
	 * 根据用户名获取用户信息
	 * @param userName
	 * @return
	 */
	private User getUserByName(String userName){
		User user = null;
		try {
			UserService userService = (UserService) ApplicationContextHelper.getBean(UserServiceImpl.class);
			user = userService.getUserByUserName(userName);
		} catch (BaseException e) {
			e.printStackTrace();
		}
		return user;
	}

}


加载中
0
青苗
青苗
搞定结贴!!
青苗
青苗
我是filter过滤位置调到别的filter前面搞定的...
g
gzone2one
大哥您好,我也遇到这个问题,请问是怎么解决的,请教一下,非常感谢!
0
wangxiang243
wangxiang243
我把shirofilter放到最前面了,怎么还是不跳到对应的successurl啊
返回顶部
顶部