ssm+shiro 注入失败

认证失败:Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - admin, rememberMe=false].  Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).--------------报错登陆异常

通过打印:定位到service注入失败

public class UserRealm extends AuthorizingRealm{
	
	@Autowired
	private static UserService userService/*=new UserServiceImpl()*/;
	
	
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	/**
	* 用于的权限的认证。
	* @param principalCollection
	* @return
	*/
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
		String username = principalCollection.getPrimaryPrincipal().toString() ;
		System.out.println(username);
		SimpleAuthorizationInfo info = new SimpleAuthorizationInfo() ;
		Set<String> roleName = userService.findRole(username) ;
		Set<String> permissions = userService.findPermission(username) ;
		info.setRoles(roleName);
		info.setStringPermissions(permissions);
		return info;
	}
	/**用户用户登陆*/
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
		System.out.println("进入验证了");
		//获取用户账号
		UsernamePasswordToken authcToken = (UsernamePasswordToken) token;  
		String username = authcToken.getUsername();
		if(username!=null &&!username.equals("")){
			System.out.println("查询用户");
			User user=userService.Login(username);
					//userService.Login(username);
			System.out.println("打印密码:"+user.getPassword());
			if(user !=null){
				AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getUsername(),user.getPassword(),"") ;
				return authenticationInfo ;
			}
		}
		return null;
	}		
}

将UserRealm修改后就ok了

参考:https://ask.csdn.net/questions/667229?sort=votes_count

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值