集成ACEGI 进行权限控制
一. 简单介绍
1.1 本文目的
1.2 安装与配置
二. 开始集成到自己的程序中
2.1 将用户和角色放在数据库中
Acegi Security interface implemented by end users -->
2 <bean id="userDetailsService"
3 class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl">
4 <property name="userProperties">
5 <bean
6 class="org.springframework.beans.factory.config.PropertiesFactoryBean">
7 <property name="location"
8 value="classpath:sers.properties" />
9 </bean>
10 </property>
11 </bean>
12
13
2.1.1 直接使用JdbcDaoImpl 访问数据库中的用户信息
2 <value>
3 SELECT email, password, enabled from user u where email = ?
4 </value>
5 </property>
6 <property name="authoritiesByUsernameQuery">
7 <value>
8 SELECT u.email, r.role_name FROM user_role ur, user u, role r WHERE
9 ur.user_id = u.user_id and ur.role_id = r.role_id and u.email = ?
10 </value>
11 </property>
2.1.2 扩展JdbcDaoImpl获取更多用户信息
2 2 # Structure for the `role` table :
3 3 #
4 4 DROP TABLE IF EXISTS `role`;
5 5 CREATE TABLE `role` (
6 6 `role_id` int(11) NOT NULL auto_increment,
7 7 `role_name` varchar(50) default NULL,
8 8 `description` varchar(20) default NULL,
9 9 `enabled` tinyint(1) NOT NULL default '1',
10 10 PRIMARY KEY (`role_id`)
11 11 );
12 12 #
13 13 # Structure for the `user` table :
14 14 #
15 15 DROP TABLE IF EXISTS `user`;
16 16 CREATE TABLE `user` (
17 17 `user_id` int(11) NOT NULL auto_increment,
18 18 `company_id` int(11) default NULL,
19 19 `email` varchar(200) default NULL,
20 20 `password` varchar(10) default NULL,
21 21 `enabled` tinyint(1) default NULL,
22 22 PRIMARY KEY (`user_id`)
23 23 );
24 24 #
25 25 # Structure for the `user_role` table :
26 26 #
27 27 DROP TABLE IF EXISTS `user_role`;
28 28 CREATE TABLE `user_role` (
29 29 `user_role_id` int(11) NOT NULL auto_increment,
30 30 `user_id` varchar(50) NOT NULL,
31 31 `role_id` int(11) NOT NULL,
32 32 PRIMARY KEY (`user_role_id`)
33 33 );
2 import org.acegisecurity.GrantedAuthority;
3 import org.acegisecurity.userdetails.User;
4 /**
5 * The class <code>UserDetailsImpl</code> extends the
* org.acegisecurity.userdetails.User class, and provides
* additional userId, companyId information
6 * @author wade
7 *
8 * @see IUserDetails, User
9 */
10 public class UserDetailsImpl extends User implements IUserDetails{
11 private int user_id;
12 private int company_id;
13 private String username;
14 private GrantedAuthority[] authorities;
15 public UserDetailsImpl(String username, String password, boolean enabled,
16 boolean accountNonExpired, boolean credentialsNonExpired,
17 boolean accountNonLocked, GrantedAuthority[] authorities)
18 throws IllegalArgumentException {
19 super(username, password, enabled, accountNonExpired, credentialsNonExpired,
20 accountNonLocked, authorities);
21 setUsername(username);
22 setAuthorities(authorities);
23 }
24 public UserDetailsImpl(int userid, int companyid, String username,
String password, boolean enabled,
25 boolean accountNonExpired, boolean credentialsNonExpired,
26 boolean accountNonLocked, GrantedAuthority[] authorities)
27 throws IllegalArgumentException {
28 super(username, password, enabled, accountNonExpired, credentialsNonExpired,
29 accountNonLocked, authorities);
30 this.user_id = userid;
31 this.company_id = companyid;
32 setUsername(username);
33 setAuthorities(authorities);
34 }
35 public int getUserId() {
36 return user_id;
37 }
38 public void setUserId(int user_id) {
39 this.user_id = user_id;
40 }
41 public int getCompanyId() {
42 return company_id;
43 }
44 public void setCompanyId(int company_id) {
45 this.company_id = company_id;
46 }
47 public String getUsername() {
48 return username;
49 }
50 public void setUsername(String username) {
51 this.username = username;
52 }
53 public GrantedAuthority[] getAuthorities() {
54 return authorities;
55 }
56 public void setAuthorities(GrantedAuthority[] authorities) {
57 this.authorities = authorities;
58 }
59 }
SELECT u.user_id, u.company_id, email, password, enabledFROM role r, user_role ur, user uWHERE r.role_id = ur.role_idand ur.user_id = u.user_idand email = ?limit 1
SELECT u.email, r.role_nameFROM user_role ur, user u, role rWHERE ur.user_id = u.user_idand ur.role_id = r.role_idand u.email = ?
转载于:https://blog.51cto.com/77857/150344
集成ACEGI 进行权限控制相关推荐
- SpringBoot集成Shiro进行权限控制和管理
1 . 添加依赖 <dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-sp ...
- springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制【转】
项目结构: 1.maven项目的pom中引入shiro所需的jar包依赖关系 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
- Spring Boot Web应用集成Keycloak进阶之细粒度权限控制
[](()资源管理 ======================================================================= 资源管理主要用来定义资源服务器的哪些 ...
- PowerBI Report Server 集成,自定义身份验证,数据权限控制
AD认证的集成模式 AD(或者Windows)认证是PBI的默认认证方式.在这种方式下,需要第三方应用也采用了AD的认证方式才可以正常的和PBI RS做集成.注意,这种方式要求第三方系统采用了AD的认 ...
- 基于RESTful API 怎么设计用户权限控制?
作者:JC_Huang http://www.jianshu.com/p/db65cf48c111 1 前言 有人说,每个人都是平等的: 也有人说,人生来就是不平等的: 在人类社会中,并没有绝对的 ...
- 在ASP.NET MVC里对Web Page网页进行权限控制
我们在ASP.NET MVC开发时,有时候还是得设计ASP.NET的Web Page网页(.aspx和.aspx.cs),来实现一些ASP.NET MVC无法实现的功能,如此篇<Visual S ...
- Spring Security 实战干货: RBAC权限控制概念的理解
点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 作者 | 码农小胖哥 来源 | 公众号「码农小胖哥」 1 ...
- SAP CO模块权限控制
SAP CO中成本中心费用处理的基本流程为: ①平时/期末FI/HR/MM/SD过帐-> ②费用的分配分摊(Tcode:KSV5/KSU5)-> ③成本中心实际费用分割(Tcode:KSS ...
- SpringBoot-Security 具体案例、 实现安全框架、权限控制、aop切入
SpringBoot-Security 具体案例. 实现安全框架.权限控制.aop切入 SpringBoot-Security介绍 Security 官方序言 安全是一个不断变化的目标,追求一个全 ...
最新文章
- JavaScript时间日期格式转化
- Spring Boot(十二)单元测试JUnit
- onenote创建快速笔记--此分区尚不可用,它是从其他设备添加的,该设备同步后才将可用
- dom4j.jar有什么作用?
- c/c++入门教程 - 1.基础c/c++ - 1.0 Visual Studio 2019安装环境搭建
- 解决终端SSH连接服务器一段时间不操作之后卡死的问题
- 解决vscode中getch()函数报错。C语言。getch()的头文件。
- C语言算三角形外心坐标,三角形外心坐标公式(含C语言代码)
- python实现触摸精灵功能_FRIDA脚本系列(三)超神篇:百度AI“调教”抖音AI
- 图片短链接生成器在线
- java jsp使用flash播放mp4,jsp页面添加视频播放
- redis实现队列的几种方式(LPUSH/BRPOP,发布/订阅模式,stream)
- 华为鸿蒙与小米新系统,华为鸿蒙系统硬刚谷歌!小米也发布新系统:却选择和谷歌系统互补...
- python写法和c很像_另一个Python和C程序的对比
- Android 键盘属性
- Ubuntu使用gedit时报waring
- Tomcat双向SSL认证及CA数字证书安装和配置QQ即时通信协议窥探
- 介词短语就这三类用法
- 计算机屏幕关机按钮没有了怎么办,电脑每次关机图标不见了怎么办啊
- 京东2018校园招聘一面、二面