资源简介
这是shiro的学习过程中做的小示例
代码片段和文件信息
package com.shiro.test;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by GWCheng on 2016/3/6.
*/
public class Tutorial {
private static final transient Logger log = LoggerFactory.getLogger(Tutorial.class);
public static void main(String[] args) {
log.info(“My First Apache Shiro Application“);
//1.获取SecurityManager工厂,此处使用Ini配置文件初始化SecurityManager
IniSecurityManagerFactory factory = new IniSecurityManagerFactory(“classpath:shiro.ini“);
//2.得到SecurityManager实例 并绑定给SecurityUtils
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
// get the currently executing user:
Subject currentUser = SecurityUtils.getSubject();
// Do some stuff with a Session (no need for a web or EJB container!!!)
Session session = currentUser.getSession();
session.setAttribute(“someKey“ “aValue“);
String value = (String) session.getAttribute(“someKey“);
if (value.equals(“aValue“)) {
log.info(“Retrieved the correct value! [“ + value + “]“);
}
// let‘s login the current user so we can check against roles and permissions:
if (!currentUser.isAuthenticated()) {
UsernamePasswordToken token = new UsernamePasswordToken(“lonestarr“ “vespa“);
token.setRememberMe(true);
try {
currentUser.login(token);
} catch (UnknownAccountException uae) {
log.info(“There is no user with username of “ + token.getPrincipal());
} catch (IncorrectCredentialsException ice) {
log.info(“Password for account “ + token.getPrincipal() + “ was incorrect!“);
} catch (LockedAccountException lae) {
log.info(“The account for username “ + token.getPrincipal() + “ is locked. “ +
“Please contact your administrator to unlock it.“);
}
// ... catch more exceptions here (maybe custom ones specific to your application?
catch (AuthenticationException ae) {
//unexpected condition? error?
}
}
//say who they are:
//print their identifying principal (in this case a username):
log.info(“User [“ + currentUser.getPrincipal() + “] logged in successfully.“);
//test a role:
if (currentUser.hasRole(“schwartz“)) {
log.info(“May the Schwartz be with you!“);
} else {
log.info(“Hello mere mortal.“);
}
//test a typed permission (not instance-level)
if (curr
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10 2016-03-06 20:31 ShiroLearn\.idea\.name
文件 299 2016-03-06 20:38 ShiroLearn\.idea\artifacts\ShiroWeb_war.xm
文件 5303 2016-03-09 09:51 ShiroLearn\.idea\artifacts\ShiroWeb_war_exploded.xm
文件 1323 2016-03-07 16:37 ShiroLearn\.idea\compiler.xm
文件 76 2016-03-06 20:31 ShiroLearn\.idea\copyright\profiles_settings.xm
文件 200 2016-03-06 20:31 ShiroLearn\.idea\encodings.xm
文件 241 2016-03-08 14:49 ShiroLearn\.idea\inspectionProfiles\profiles_settings.xm
文件 751 2016-03-08 14:49 ShiroLearn\.idea\inspectionProfiles\Project_Default.xm
文件 560 2016-03-08 11:43 ShiroLearn\.idea\libraries\Java_EE_6_Java_EE_6.xm
文件 462 2016-03-07 17:27 ShiroLearn\.idea\libraries\Maven__antlr_antlr_2_7_7.xm
文件 514 2016-03-07 16:52 ShiroLearn\.idea\libraries\Maven__aopalliance_aopalliance_1_0.xm
文件 594 2016-03-06 20:43 ShiroLearn\.idea\libraries\Maven__commons_beanutils_commons_beanutils_1_8_3.xm
文件 605 2016-03-07 18:02 ShiroLearn\.idea\libraries\Maven__commons_fileupload_commons_fileupload_1_3_1.xm
文件 503 2016-03-07 18:02 ShiroLearn\.idea\libraries\Maven__commons_io_commons_io_2_4.xm
文件 558 2016-03-07 16:52 ShiroLearn\.idea\libraries\Maven__commons_logging_commons_logging_1_2.xm
文件 522 2016-03-07 17:27 ShiroLearn\.idea\libraries\Maven__com_fasterxm
文件 548 2016-03-08 11:37 ShiroLearn\.idea\libraries\Maven__com_google_code_kaptcha_kaptcha_2_3_2.xm
文件 493 2016-03-08 11:32 ShiroLearn\.idea\libraries\Maven__com_mchange_c3p0_0_9_5_2.xm
文件 598 2016-03-08 11:32 ShiroLearn\.idea\libraries\Maven__com_mchange_mchange_commons_java_0_2_11.xm
文件 462 2016-03-07 17:27 ShiroLearn\.idea\libraries\Maven__dom4j_dom4j_1_6_1.xm
文件 437 2016-03-08 11:33 ShiroLearn\.idea\libraries\Maven__jstl_jstl_1_2.xm
文件 462 2016-03-07 16:50 ShiroLearn\.idea\libraries\Maven__junit_junit_3_8_1.xm
文件 469 2016-03-08 11:56 ShiroLearn\.idea\libraries\Maven__log4j_log4j_1_2_17.xm
文件 574 2016-03-08 17:38 ShiroLearn\.idea\libraries\Maven__mysql_mysql_connector_java_5_1_36.xm
文件 519 2016-03-07 16:53 ShiroLearn\.idea\libraries\Maven__net_sf_ehcache_ehcache_2_10_0.xm
文件 547 2016-03-07 17:58 ShiroLearn\.idea\libraries\Maven__net_sf_ehcache_ehcache_core_2_5_0.xm
文件 556 2016-03-08 11:43 ShiroLearn\.idea\libraries\Maven__org_apache_commons_commons_lang3_3_4.xm
文件 654 2016-03-07 17:27 ShiroLearn\.idea\libraries\Maven__org_apache_geronimo_specs_geronimo_jta_1_1_spec_1_1_1.xm
文件 541 2016-03-06 20:43 ShiroLearn\.idea\libraries\Maven__org_apache_shiro_shiro_core_1_2_2.xm
文件 541 2016-03-07 17:55 ShiroLearn\.idea\libraries\Maven__org_apache_shiro_shiro_core_1_2_4.xm
............此处省略1197个文件信息
相关资源
- springMVC+myBatis增删改查小程序
- 软件体系架构PPT Spring SpringMVC Mybat
- ssm整合shrio框架
- spring MVC 项目商城
- springmvc的一个简单的框架
- ssm+bootstrap+angularJs案例
- 基于maven+springmvc+spring+mybatis对员工信
- springMVC+spring+Hibernate框架
- springmvc与mybatis整合对数据库的增删改
- SpringMVC + Spring + SpringData\\JPA 整合Dem
- springmvc+spring+mybatis
- SpringMVC +Mybatis完整
- springmvc代理经销商管理系统
- 基于SpringMVC+Maven开发网上书城系统
- springmvc restful风格 增删改查完整版
- 北京动力节点-Reyco郭-SpringMVC4
- SpringMVC+Echarts 读取后台数据进行图标
- springboot+springmvc+mybatis+layui实现登录用
- CC2650 CC2630 zstack例程程序加注中文注解
- ssm-crud(spring+springmvc+mybatis)
- springmvc+POI的Excel文件导入导出
- springMVC+mybatis实现分页、登录、增删改
- springMVC+mybatis实现登录和增删改查
- SpringMVC文件上传和的工具类完整项目
- mybatis+spring+springmvc+easyui做的一个登陆
- 在idea下使用maven构建spring+springMVC+hi
- 基于SSM航空票务系统
- 图书管理系统SpringMvc+mybatis
- ssm框架的缺陷管理系统
- 北京动力节点-北京动力节点 Reyco郭
评论
共有 条评论