abc01230123abc的gravatar头像
abc01230123abc 2015-01-04 12:50:32

spring security验证成功后为什么不能跳转到方法?

这是spring-security.xml文件

<http auto-config="true">
    <access-denied-handler error-page="/accessDenied" />

    <form-login login-page="/login" 
        authentication-success-handler-ref="mySuccessHandler"
        authentication-failure-url="/loginError" />

    <logout invalidate-session="true" logout-success-url="/main"
        logout-url="/logout" delete-cookies="JSESSIONID" />
    <remember-me key="j_spring_security_rememberme"/>

    <intercept-url pattern="/**" access="ROLE_ADMIN"/>
    <session-management invalid-session-url="/login"
        session-fixation-protection="none">
        <concurrency-control max-sessions="1"
            error-if-maximum-exceeded="false" />
    </session-management>
    <session-management
        session-authentication-strategy-ref="sas" />
</http>


<!-- 验证成功后跳转的方法 -->
<beans:bean id="mySuccessHandler" class="mocha.cms.security.LoginSuccessHandle" >
</beans:bean>


<!-- authentication-manager 设置alias别名 -->
<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="defaultUserDetailServiceImpl">
        <password-encoder hash="md5" base64="false">
            <salt-source user-property="username" />
        </password-encoder>
    </authentication-provider>
</authentication-manager>

 <beans:bean id="defaultUserDetailServiceImpl" class="mocha.cms.security.MyUserDetailServiceImpl" /> 

点击登录按钮,跳转到MyUserDetailServiceImpl,执行完以后,并没有跳到LoginSuccessHandle方法

 

这是MyUserDetailServiceImpl.java

 

Collection<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();

        AdminVo loginAdmin =  adminService.getAdminByName(username);
        if(loginAdmin == null){
   throw new UsernameNotFoundException(username);
  }       

        List<String> permissionIdList = ImmutableList.copyOf(Splitter. on( ",").omitEmptyStrings().split(loginAdmin.getPermissionId()));
  
        for (String permissionId : permissionIdList) {
           auths.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
            
  }
        boolean enables = true;
        boolean accountNonExpired = true;
        boolean credentialsNonExpired = true;
        boolean accountNonLocked = true;


        User user = new User(username, loginAdmin.getPassword(), enables, accountNonExpired, credentialsNonExpired, accountNonLocked,
          auths);

        return user;
所有回答列表(3)
abc01230123abc的gravatar头像
abc01230123abc  LV6 2015年1月4日

我解决了,是密码加密的方式问题,我没有使用salt,所以要去掉 <salt-source user-property="username" />

评论(0) 最佳答案
w3387916的gravatar头像
w3387916  LV4 2015年1月5日

....

狼行天下的gravatar头像
狼行天下  LV18 2015年1月12日

求学习教程

顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友