shiro使用jdbc_realm登录验证

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

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.lihua</groupId><artifactId>shiro01</artifactId><packaging>war</packaging><version>0.0.1-SNAPSHOT</version><name>shiro01 Maven Webapp</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-core</artifactId><version>1.2.4</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.16</version></dependency><dependency><groupId>c3p0</groupId><artifactId>c3p0</artifactId><version>0.9.1.2</version></dependency><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.37</version></dependency></dependencies><build><finalName>shiro01</finalName></build>
</project>

jdbc_realm.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/shiro_jdbc_realm
dataSource.user=root
dataSource.password=root
jdbcRealm.dataSource=$dataSource
securityManager.realms=$jdbcRealm

JdbcRealm.java

package test;import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;public class JdbcRealm {public static void main(String[] args) {//读取配置文件,初始化SecurityManager工厂Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:jdbc_realm.ini");//获取SecurityManager实例SecurityManager securityManager = factory.getInstance();//把SecurityManager绑定到SecurityUtilsSecurityUtils.setSecurityManager(securityManager);//得到当前执行的用户Subject subject = SecurityUtils.getSubject();//创建token令牌  用户名/密码形式UsernamePasswordToken token = new UsernamePasswordToken("test", "test");try {//用户登录subject.login(token);System.out.println("登录成功");} catch (Exception e) {e.printStackTrace();System.out.println("登录失败");}//用户注销subject.logout();}}

注意:数据库的表必须叫: users  字段为 id,userName, password

转载于:https://my.oschina.net/u/1474779/blog/618193

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/459121.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java 公因数_Java程序(最大公因数与最小公倍数)

package 求两个数的公约数和公倍数;import java.util.Scanner;public class MN{public static void swap(int a,int b)//交换位置{int k;if(a{ka;ab;bk;}}static int shu(int a,int b)//循环寻找最大公约数{int k,y;swap(a,b);while(a%b!0){ya%b;ab;by;}return b;}static int s…

vs2010中MEX文件建立与调试

*************************************************** 更多精彩&#xff0c;欢迎进入&#xff1a;http://shop115376623.taobao.com *************************************************** http://item.taobao.com/item.htm?spma1z10.5-c.w4002-9510581626.24.ZO6sko&id4…

Javascript 严格模式详解

一、概述 除了正常运行模式&#xff0c;ECMAscript 5添加了第二种运行模式&#xff1a;"严格模式"&#xff08;strict mode&#xff09;。顾名思义&#xff0c;这种模式使得Javascript在更严格的条件下运行。 设立"严格模式"的目的&#xff0c;主要有以下几…

python类介绍_面向对象 Python的类 介绍

python中定义类的方法很简单&#xff0c;用关键字class&#xff0c; 其中可以包含函数 用 def#!/usr/bin/env python# -*- coding:UTF-8 -*-class Test_N:""" class get a name and count string or number """def __init__(self, n):self.name …

使用tableView崩溃

2019独角兽企业重金招聘Python工程师标准>>> 1错误2 正确 转载于:https://my.oschina.net/u/2601834/blog/618892

visuall assist x 破解方法

*************************************************** 更多精彩&#xff0c;欢迎进入&#xff1a;http://shop115376623.taobao.com *************************************************** 转自&#xff1a;http://blog.csdn.net/cazicaquw/article/details/6717126 试用期过了…

python笔记1

1.字典不包含从左到右的顺序 2.If for 表达式&#xff1a;for x in xx:表达式 写为 表达式 for x in xx 3.元组&#xff0c;字符串 不可变性 &#xff08;1&#xff09;t.index&#xff08;&#xff09; t.count() &#xff08;2&#xff09;T[0]1 #change #error &#xf…

Java实现连连看源代码文档_Java实现游戏连连看(有源代码)

Java实现游戏连连看(有源代码) JAVA语言实现连连看游戏 1.课程设计目的 Java语言是当今流行的网络编程语言&#xff0c;它具有面向对象、跨平台、分布应用等特点。面向对象的开发方法是当今世界最流行的开发方法&#xff0c;它不仅具有更贴近自然的语义&#xff0c;而且有利于软…

C语言中auto,register,extern,static【转】

*************************************************** 更多精彩&#xff0c;欢迎进入&#xff1a;http://shop115376623.taobao.com *************************************************** 语言中提供了存储说明符auto&#xff0c;register&#xff0c;extern&#xff0c;stat…

Oracle if else if for case

------------------游标forif else if DECLARE cursor s_cursor is SELECT * from emp;--定义游标 beginfor r in s_cursor loop--循环if r.deptno10--if判断then dbms_output.put_line(名字:||r.ename||sal||r.sal);else if r.deptno20then dbms_output.put_line(名字:||r.ena…

java汉字转化accic_Java自主学习贴

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼2019-08-25链表学习续实现数据内容查询功能interface ILink{//创建一个接口用于定义方法标准//定义增加方法public void add(E e) ;//定义获取元素个数方法public int getLength();//判断是否为空集合public boolean isEmpty();//定…

SEO的十种赚钱方式

我深深的想要通过的自己的SEO技术赚钱。其实&#xff0c;掌握一门技术是次要方面&#xff0c;学会把技术变现才是重中之重&#xff0c;所以你说学习SEO重要吗?挺重要&#xff0c;但绝不是最重要的。学SEO的赚钱方式才是最重要的。那么SEO都有哪些赚钱方式呢?我罗列了十种赚钱…

sizeof详解

*************************************************** 更多精彩&#xff0c;欢迎进入&#xff1a;http://shop115376623.taobao.com *************************************************** sizeof&#xff08;&#xff09;功能&#xff1a;计算数据空间的字节数 #include<…

关于C/C++中的“auto”关键字

C/C 98标准 C03标准 早在C98标准中就存在了auto关键字&#xff0c;那时的auto用于声明变量为自动变量&#xff0c;自动变量意为拥有自动的生命期。此用法是多余的&#xff0c;因为即使定义变量时不加"auto"&#xff0c;变量也会有自动的生命期。用法如下&#xff1a;…

学java的人都是什么性格_什么样的人适合学习Java编程

展开全部下面咱们说一下Java更适合那些人群第一种&#xff0c;理工科专业。如果你大学时学的是理工科专业&#xff0c;对Java有一定的了解&#xff0c;那么你还是比较适合学Java的&#xff0c;如果你大学期间学过Java那就更好了&#xff0c;现在再学习只会事半功倍。因为学习Ja…

C++浅拷贝和深拷贝的区别

*************************************************** 更多精彩&#xff0c;欢迎进入&#xff1a;http://shop115376623.taobao.com *************************************************** c默认的拷贝构造函数是浅拷贝 浅拷贝就是对象的数据成员之间的简单赋值&#xff0c; 如…

Innodb ibdata数据文件误删,如何恢复

Innodb的ibdata数据文件误删除后的操作流程&#xff1a;注意&#xff1a;误删除后&#xff0c;你的数据库是还可以工作的&#xff0c;数据照样可以写入&#xff0c;切记&#xff0c;千万不要把mysqld进程杀死&#xff0c;否则就没法挽救了。首先找到mysqld的进程pid&#xff0c…

redis的java客户端名称_java里常用的redis客户端简介

zepto返回顶部动画点击返回顶部 function goTop(acceleration, time) { acceleration acceleration || 0.1; time time || 16; v ...Jetty Maven Plugin配置官方文档:http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#maven-config-https 1 ...p…

Python初步

准备在工作之余看看Python的东西 收录一些资料 Python初学者&#xff08;零基础学习Python、Python入门&#xff09;常见问题&#xff1a;书籍推荐、资料、社区 http://blog.csdn.net/xiaowanggedege/article/details/8566606 小甲鱼零基础入门学习Python(全87集) http://pan.b…

java arraylist string_在Java ArrayList String中使用contains

你是对的。 ArrayList.contains()testingequals()&#xff0c;而不是对象标识&#xff1a;返回true当且仅当此列表包含至less一个元素e&#xff0c;使得(o null&#xff1f;e null&#xff1a;o.equals(e))如果你有一个NullPointerExceptionexception&#xff0c;请validatio…