We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { //获取当前用户 UserDto user = (UserDto) SecurityUtils.getSubject().getSession().getAttribute("user"); //把principals放session中,key=userId value=principals SecurityUtils.getSubject().getSession().setAttribute(String.valueOf(user.getId()),SecurityUtils.getSubject().getPrincipals()); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); //赋予角色 for(RoleDto role:user.getRoles()){ info.addRole(role.getName()); } //赋予权限 for(PermissionDto permission:user.getPermissions()){ //System.out.println(permission.getName()); info.addStringPermission(permission.getName()); } return info; } @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; String userName = token.getUsername(); User user = userDao.findUserByUsername(userName); UserDto userDto = convertToDto(user); if(user != null){ //登陆成功 Session session = SecurityUtils.getSubject().getSession(); session.setAttribute("user",userDto); return new SimpleAuthenticationInfo( userName, //用户 user.getPassword(), //密码 getName() //realm name ); } else { throw new UnknownAccountException(); } }
Bean(name = "shiroFilter") public ShiroFilterFactoryBean shiroFilterFactoryBean(){ ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager()); Map<String, Filter> filters = new LinkedHashMap<String,Filter>(); LogoutFilter logoutFilter = new LogoutFilter(); logoutFilter.setRedirectUrl("/login"); shiroFilterFactoryBean.setFilters(filters); shiroFilterFactoryBean.setLoginUrl("/notAuthc"); Map<String,String> filterChainDefinitionManager = new LinkedHashMap<String,String>(); filterChainDefinitionManager.put("/logout","logout"); filterChainDefinitionManager.put("/userInfo","authc"); filterChainDefinitionManager.put("/jobs/**","perms[WORDCOUNT:CREATE]"); filterChainDefinitionManager.put("/admin/**","roles[Admin]"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionManager); shiroFilterFactoryBean.setSuccessUrl("/"); shiroFilterFactoryBean.setUnauthorizedUrl("/notAuthz"); return shiroFilterFactoryBean; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
对于访问后端服务器的所有请求,都要进行认证和鉴权
对于登录到系统的用户,首先要进行认证和授权。
服务器要配置Filter链以进行认证和鉴权,对用户的访问和重定向等进行限制
一个用户访问后端接口的完整过程
The text was updated successfully, but these errors were encountered: