(八)shiro之jdbcRealm
- pom.xml
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.shyroke.www</groupId>
- <artifactId>firstShiro</artifactId>
- <packaging>war</packaging>
- <version>0.0.1-SNAPSHOT</version>
- <name>firstShiro Maven Webapp</name>
- <url>http://maven.apache.org</url>
- <properties>
- <shiro.version>1.3.2</shiro.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.21</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- <version>1.7.21</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>1.1.7</version>
- <scope>runtime</scope>
- </dependency>
- <!-- Shiro dependencies: -->
- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-core</artifactId>
- <version>${shiro.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-web</artifactId>
- <version>${shiro.version}</version>
- </dependency>
- <dependency>
- <groupId>c3p0</groupId>
- <artifactId>c3p0</artifactId>
- <version>0.9.1.2</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>6.0.6</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.25</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <finalName>firstShiro</finalName>
- </build>
- </project>
- shiro.ini
- [main]
- jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm
- dataSource=com.mchange.v2.c3p0.ComboPooledDataSource
- dataSource.driverClass=com.mysql.jdbc.Driver
- dataSource.jdbcUrl=jdbc:mysql://localhost:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
- dataSource.user=root
- dataSource.password=""
- jdbcRealm.dataSource=$dataSource
- 本例中使用连接池。
- 注:密码为空就填双引号,但是不能不填。
- 测试类
- public class TestMain {
- public static void main(String[] args) {
- Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:shiro.ini");
- SecurityManager securityManager=factory.getInstance();
- SecurityUtils.setSecurityManager(securityManager);
- Subject subject=SecurityUtils.getSubject();
- UsernamePasswordToken token=new UsernamePasswordToken("admin", "12342");
- try {
- subject.login(token);
- System.out.println("登录成功");
- } catch (UnknownAccountException e) {
- System.out.println("用户名错误");
- }catch(IncorrectCredentialsException e){
- System.out.println("密码错误");
- }
- System.out.println(securityManager);
- }
- }
- 数据库。注意:这里的userName和password不能修改为其他名字,而且表明users也不能修改.
- 结果:
(八)shiro之jdbcRealm的更多相关文章
- shiro之jdbcRealm
Shiro认证过程 创建SecurityManager--->主体提交认证--->SecurityManager认证--->Authenticsto认证--->Realm验证 ...
- 5、Shiro之jdbcRealm认证授权
登录认证: 注意,下面我是以连接orcal数据库为例的依赖,如果各位同仁使用的是骑她数据库,可以换成对应数据库的依赖(数据源不用换) Pom.xml增加依赖: <!--引入连接orcal的jar ...
- java开源安全框架-------Apache Shiro--第二天
身份验证 即在应用中谁能证明他就是他本人.一般提供如他们的身份ID一些标志信息来表明他就是他本人,如提供身份证.用户名.密码来证明 在shiro中,用户需要提供principals(身份)和crede ...
- 10_SpringBoot更加详细
一. 原理初探 1.1 自动装配 1.1.1 pom.xml spring-boot-dependencies: 核心依赖在父工程中 我们在写入或者引入一些SpringBoot依赖的时候, 不需要指定 ...
- shiro(三),使用第三方jdbcRealm连接数据库操作
这里采用第三方实现好的JdbcRealm连接数据库:首先来看一下源码: 接着前面的说:就把这个类当做我们自己写的就好了,我们需要实例化它,然后给他注入一个数据源 下面是ini文件配置 [main] # ...
- Apache shiro集群实现 (八) web集群时session同步的3种方法
Apache shiro集群实现 (一) shiro入门介绍 Apache shiro集群实现 (二) shiro 的INI配置 Apache shiro集群实现 (三)shiro身份认证(Shiro ...
- shiro实战系列(八)之安全管理器
Apache Shiro 提供安全框架界独一无二的东西:一个完整的企业级 Session 解决方案,从最简单的命令行及智能手机 应用到最大的集群企业 Web 应用程序. 这对许多应用有着很大的影响 ...
- Shiro身份认证-JdbcRealm
Subject 认证主体 Subject认证主体包含两个信息 Principals : 身份,可以是用户名.邮箱.手机号等,用来标识一个登录主体身份. Credentials : 凭证,常见有密码,数 ...
- shiro框架学习-4- Shiro内置JdbcRealm
1. JdbcRealm 数据库准备 JdbcRealm就是用户的角色,权限都从数据库中读取,也就是用来进行用户认证授权的安全数据源更换为从数据库中读取,其他没有差别,首先在数据库创建三张表: CR ...
随机推荐
- redis之为什么redis是单线程?
官方FAQ表示,因为Redis是基于内存的操作,CPU不是Redis的瓶颈,Redis的瓶颈最有可能是机器内存的大小或者网络带宽.既然单线程容易实现,而且CPU不会成为瓶颈,那就顺理成章地采用单线程的 ...
- Mybatis 中的转义字符(转帖)
下文来自:https://www.cnblogs.com/dato/p/7028723.html 在此感谢作者的辛勤付出. 记录以下mybatis中的转义字符,方便以后自己看一下 Mybatis转义 ...
- P5663 加工零件
P5663 加工零件 题解 暴力搜索 搜索显然会TLE #include<iostream> #include<cstdio> #include<cstdlib> ...
- 【转】nodejs获取post请求发送的formData数据
前端post请求发送formData的类型数据时,需要服务端引入中间件body-parser,主要原因是post请求发送的数据,是在http的body里面,所以需要进行解析,否则获取不到数据(数据为空 ...
- LC 450. Delete Node in a BST
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Retur ...
- NewLife.XCode 上手指南
想了解什么是XCode 在这里我不对XCode做过多介绍,XCode曾经是一个轻量级ORM组件,现在是一个重量级数据映射框架,支持实体对象数据到不同媒体的数据映射,提供面向对象的方式操作数据库,解决9 ...
- Linux -- Reactor
结构 1. handles 资源的标志.这些资源通常包含网络连接,文件,定时器,同步对象等.handles 被用在注册服务器来标记socket,以便同步事件复用(Synchronous Event D ...
- 123457123457#1#-----com.threeapp.circlerunner01----儿童旋转跑酷游戏
com.threeapp.circlerunner01----儿童旋转跑酷游戏
- ContextCleaner ——Spark 应用程序的垃圾回收器
ContextCleaner是一个Spark服务,负责在应用程序范围内清除 shuffles, RDDs, broadcasts, accumulators和checkpointed RDDs,目的是 ...
- 未清SO关闭处理
使用: SD_SALESDOCUMENT_CHANGE 关闭订单 DATA: ls_header_in LIKE bapisdhd1 . DATA: ls_header_inx LIKE bap ...