shaun基于 pac4j 的安全框架
基于 pac4j 的安全框架
特性:
- 功能简单,易于集成。
- 无 session。
- 使用凭证(token) 进行身份验证(默认是 jwt)。
- 前后端不分离下,能依托pac4j的各种client快速集成三方登录(redirect跳转那种),例如oauth(qq,微信) 和 cas。
模块简介:
- shaun-core: 核心包
- shaun-spring-boot-starter: spring boot 快速启动包
- shaun-test-cookie: 前后端不分离下的测试演示
- shaun-test-stateless-cookie: 前后端分离下使用cookie存token的测试演示
- shaun-test-stateless-header: 前后端分离下使用request header携带token的测试演示
使用方法
- 引入shaun-spring-boot-starter。
<dependency> <groupId>com.baomidou</groupId> <artifactId>shaun-spring-boot-starter</artifactId> <version>${version}</version> </dependency>
- 登录后设置相关信息到SecurityManager。
@Service @AllArgsConstructor public class LoginServiceImpl implements LoginService { private final SecurityManager securityManager; @Override @Transactional public String login() { // 登录成功后把用户角色权限信息存储到profile中 final JwtProfile profile = new JwtProfile(); profile.setId(userId.toString()); if (roles.contains(AdminConst.SUPER_ADMIN)) { isAdmin = true; } else { profile.setPermissions(permissionService.selectPermissionsByUserId(userId).stream() .filter(x -> Objects.nonNull(x.getCode())).map(SysPermission::getCode).collect(Collectors.toSet())); profile.setRoles(new HashSet<>(roles)); } final String token = securityManager.login(profile, isAdmin); return token; }
- 设置yml启动信息。
shaun: salt: d614a4fdff6540c1a5b730afc5f9cc8f #非必须 exclude-path: - /v2/api-docs - /swagger-resources - /doc.html exclude-branch: - /wechat-auth - /webjars
- 注解拦截。
类似于shiro,shaun也默认支持使用注解在controller上拦截。
相关的注解有 @HasAuthorization
@HasPermission
@HasRole
。
@HasPermission(value = {"add","edit"},logical = Logical.BOTH) //同时存在 @HasPermission(value = {"add","edit"},logical = Logical.ANY) //任一存在
- 前后端交互。
默认配置下 前端登录后需要把后端返回的token存下,后续接口的请求头带上Authorization。
后端可以通过 TokenProfile profile = ProfileHolder.getProfile(); 获得用户信息。
评论
buji-pac4jShiro 的 pac4j 安全库
buji-pac4j项目是ShiroWeb应用程序的一个简单而强大的安全库,它支持身份验证和授权,还提供了诸如CSRF保护等高级功能。它基于Java8、Shiro1.4和pac4j安全引擎v2。
buji-pac4jShiro 的 pac4j 安全库
0
spring-security-pac4jSpring Security 的 pac4j 安全库
spring-security-pac4j项目是SpringSecurity(带或不带SpringBoot)Web应用程序的简单而强大的安全库。它支持身份验证和授权,还支持会话固定和CSRF保护等高级
spring-security-pac4jSpring Security 的 pac4j 安全库
0
基于Spring整合Shiro安全框架
Shiro安全框架Shiro网址「http://shiro.apache.org/」Shiro下载地址「http://www.apache.org/dyn/closer.cgi/shiro/1.5.1/shiro-root-1.5.1-source-release.zip(jdk1.8+ maven3.03+)」添加相应的依赖<packaging&...
不一样的菜鸟
0
wgf基于Golang的框架
文档(Documentation)中文EnglishWgf是什么?Hello,wgf是基于Golang的的编程框架。目标为提供一个尽可能统一的编程环境,提高工作效率。目前,wgf已完成对http、cl
wgf基于Golang的框架
0
JSecurityjava安全框架
JSecurity是一个强大,灵活的java安全框架。用于简洁地处理身份验证,授权,企业多个系统会话管理,加密服务等。此项目目前已改名Shiro
JSecurityjava安全框架
0