- 浏览: 839361 次
文章分类
- 全部博客 (365)
- java (124)
- spring mvc (21)
- spring (22)
- struts2 (6)
- jquery (27)
- javascript (24)
- mybatis/ibatis (8)
- hibernate (7)
- compass (11)
- lucene (26)
- flex (0)
- actionscript (0)
- webservice (8)
- rabbitMQ/Socket (15)
- jsp/freemaker (5)
- 数据库 (27)
- 应用服务器 (21)
- Hadoop (1)
- PowerDesigner (3)
- EJB (0)
- JPA (0)
- PHP (2)
- C# (0)
- .NET (0)
- html (2)
- xml (5)
- android (7)
- flume (1)
- zookeeper (0)
- 证书加密 (2)
- maven (1)
- redis (2)
- cas (11)
最新评论
-
zuxianghuang:
通过pom上传报错 Artifact upload faile ...
nexus上传了jar包.通过maven引用当前jar,不能取得jar的依赖 -
流年末年:
百度网盘的挂了吧???
SSO单点登录系列3:cas-server端配置认证方式实践(数据源+自定义java类认证) -
953434367:
UfgovDBUtil 是什么类
Java发HTTP POST请求(内容为xml格式) -
smilease:
帮大忙了,非常感谢
freemaker自动生成源代码 -
syd505:
十分感谢作者无私的分享,仔细阅读后很多地方得以解惑。
Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
package com.hd.security.service; |
002 |
003 |
import java.io.File; |
004 |
import java.util.HashMap; |
005 |
import java.util.Iterator; |
006 |
import java.util.List; |
007 |
import java.util.Map; |
008 |
import java.util.Set; |
009 |
010 |
import javax.annotation.Resource; |
011 |
012 |
import org.dom4j.Document; |
013 |
import org.dom4j.DocumentException; |
014 |
import org.dom4j.Element; |
015 |
import org.dom4j.io.SAXReader; |
016 |
import org.hibernate.SessionFactory; |
017 |
import org.springframework.dao.DataAccessException; |
018 |
import org.springframework.orm.hibernate3.support.HibernateDaoSupport; |
019 |
import org.springframework.security.userdetails.UserDetails; |
020 |
import org.springframework.security.userdetails.UserDetailsService; |
021 |
import org.springframework.security.userdetails.UsernameNotFoundException; |
022 |
import org.springframework.stereotype.Repository; |
023 |
024 |
import com.hd.comm.constants.Authtype; |
025 |
import com.hd.comm.constants.EncodeType; |
026 |
import com.hd.comm.constants.XmlAssistType; |
027 |
import com.hd.department.model.Authorities; |
028 |
import com.hd.department.model.Role; |
029 |
import com.hd.department.model.User; |
030 |
import com.hd.security.core.SecurityManager; |
031 |
import com.hd.util.SecurityAssist; |
032 |
import com.hd.util.SystemAssist; |
033 |
import com.hd.util.XmlAssist; |
034 |
035 |
@Repository ( "securityManager" ) |
036 |
public class SecurityManagerImpl extends HibernateDaoSupport implements UserDetailsService ,SecurityManager{ |
037 |
038 |
@Resource (name= "sf" ) |
039 |
public void setSuperSessionFactory(SessionFactory sessionFactory) { |
040 |
super .setSessionFactory(sessionFactory); |
041 |
} |
042 |
/** |
043 |
* 得到用户通过用户的CODE |
044 |
*/ |
045 |
@SuppressWarnings ( "unchecked" ) |
046 |
@Override |
047 |
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { |
048 |
|
049 |
List<User> users = getHibernateTemplate().find( "FROM syuser WHERE username = ? AND disabled = " + false , username);
|
050 |
if (users.isEmpty()) {
|
051 |
System.out.println( "User is not exist" ); |
052 |
throw new UsernameNotFoundException( "User " + username + " 没有相应的权限" );
|
053 |
} |
054 |
User user = users.get( 0 ); |
055 |
user.getAuthorities(); |
056 |
Set<Role> roles = user.getRoles(); |
057 |
for (Role role : roles){ |
058 |
System.out.println( "装在用户[" +user.getChineseName()+ "]角色 [" +role.getRoleName()+ "]权限集合" +role.getAuthorities()); |
059 |
} |
060 |
//创建用户菜单 |
061 |
createUserMenu(user); |
062 |
return user ; |
063 |
} |
064 |
/** |
065 |
* 得到是有URL资源 |
066 |
*/ |
067 |
@Override |
068 |
public Map<String, String> loadUrlAuthorities() { |
069 |
Map<String, String> urlAuthorities = new HashMap<String, String>();
|
070 |
@SuppressWarnings ( "unchecked" ) |
071 |
List<Authorities> urlResources = getHibernateTemplate().find( "FROM Authorities WHERE authtype = ?" , Authtype.URL);
|
072 |
for (Authorities resource : urlResources) {
|
073 |
urlAuthorities.put(resource.getAuthCode(), resource.getAuthValue());
|
074 |
}
|
075 |
return urlAuthorities;
|
076 |
} |
077 |
@SuppressWarnings ( "rawtypes" ) |
078 |
@Override |
079 |
public void createUserMenu(User user) { |
080 |
try { |
081 |
//装在MENU总文件准备筛选 |
082 |
SAXReader reader = new SAXReader(); |
083 |
Document allMenuDoc = reader.read( new File(SystemAssist.getSysRootPath()+XmlAssistType.SYSALLMENU.showInfo)); |
084 |
String path = SystemAssist.getSysRootPath()+XmlAssistType.USERMENU.showInfo+user.getUsername()+ "-menu.xml" ; |
085 |
if (! "admin" .equals(user.getUsername())){ |
086 |
Authtype[] authtypes = new Authtype[ 1 ]; |
087 |
authtypes[ 0 ] = Authtype.MENU; |
088 |
Set<Authorities> authorities = SecurityAssist.getCurrentUserAuth(authtypes,user); |
089 |
List list = allMenuDoc.selectNodes( "//*[@id]" ); |
090 |
Iterator it = list.iterator();
|
091 |
while (it.hasNext()) {
|
092 |
Element elt = (Element)it.next(); |
093 |
boolean boo = false ; |
094 |
for (Authorities auth : authorities){ |
095 |
if (elt.attribute( "id" ).getValue().equals(auth.getAuthValue())){ |
096 |
boo = true ; |
097 |
} |
098 |
} |
099 |
if (!boo){ |
100 |
elt.detach();
|
101 |
} |
102 |
} |
103 |
XmlAssist.createXML(allMenuDoc, EncodeType.UTF8.showInfo, path); |
104 |
} else { |
105 |
XmlAssist.createXML(allMenuDoc, EncodeType.UTF8.showInfo, path); |
106 |
} |
107 |
} catch (DocumentException e) { |
108 |
System.out.println(e); |
109 |
}
|
110 |
} |
111 |
- spring_security3-开发指南-实例.zip (72.3 KB)
- 下载次数: 4
发表评论
-
Spring事务的传播行为和隔离级别
2015-01-23 09:15 575Spring事务的传播行为和隔离级别[transaction ... -
Spring3.2.8+Mybatis3.2.6+Maven 整合配置
2015-01-06 14:01 1410 -
采用AOP+log4j记录项目日志
2014-10-28 16:39 464关于AOP,我之前对AOP ... -
Spring Security3.1实践
2014-05-07 14:45 988说明下: 本篇博客时间久远,数 ... -
SpringMVC3.0+MyIbatis3.0(分页示例)
2013-10-30 17:24 2178参考资料 1 ibatis2.x与mybatis ... -
网上的一篇spring security详解教程,觉得不错,转过来了
2013-07-30 22:16 1313先来谈一谈Acegi的基础知识,Acegi的架构比较复杂,但 ... -
Spring Security3配置使用
2013-07-30 16:48 3446使用Spring Security3的 ... -
SSH项目中加入spring security(二)--加入自定义数据表
2013-07-30 13:32 1001上一篇中基本的spring security已经加入到项 ... -
SSH项目中加入spring security(一)
2013-07-30 13:30 1527很久没有写过博客了,最近项目中 ... -
Spring定时任务的几种实现
2013-01-22 18:27 830近日项目开发中需要执行一些定时任务,比如需要在 ... -
spring security权限管理手册升级至spring security-3.1.3
2012-12-08 12:57 1937企业应用 费了半天劲,终于把原来基于spri ... -
在Spring、Hibernate中使用Ehcache缓存
2012-11-02 21:49 890前一篇http://www.blogjava.n ... -
不重复配置——利用Spring通用化配置
2012-10-17 09:40 961还记得 如下这种配置吗: 1、struts2作用域 ... -
Ehcache 整合Spring 使用页面、对象缓存
2012-10-16 09:44 762Ehcache在很多项目中都出现过,用法也比较简单。一般的 ... -
Spring AOP 中的通知
2012-09-16 13:32 12002010-08-29 16:54:18| ... -
Spring Security3十五日研究
2012-09-12 10:22 1907前言 南朝《述 ... -
Spring MVC和Struts2的区别
2012-09-08 08:59 10111. 机制:spring mvc的入口是servlet,而st ... -
跟我学spring3.0 电子书
2012-08-30 13:13 1169好东西 收藏!学习! -
Spring Bean Scope 有状态的Bean 无状态的Bean
2012-08-30 08:58 2420在Spring的Bean配置中 ... -
Spring的初始化过程
2012-06-14 13:54 1180Spring 的几个接口 1.InitializingB ...
相关推荐
spring security2.5 jar 和spring security2.5 整合必须的jar包
精通Spring2.5pdf书籍proSpring2.5
spring2.5 定时器任务 spring2.5 定时器任务 spring2.5 定时器任务 spring2.5 定时器任务
spring 2.5 spring 2.5帮助文档 spring 2.5中文帮助文档 spring帮助文档 spring文档
Spring2.5中文框架开发手册Spring2.5中文框架开发手册Spring2.5中文框架开发手册
这是一个struts 1.2 + spring 2.5 + hibernate 3.2框架demo, 运行环境为eclipse 3.2 + tomcat 5.5 + oracle 11g
spring2.5是根据Sping2.5官方文档生成 chm格式
spring2.5中文文档 spring2.5中文文档
eclipse搭建spring2.5eclipse搭建spring2.5eclipse搭建spring2.5
压缩文件中包含spring2.5 用到的所有jar文件;提供给大家下载使用
最近做的Spring 2.5 AOP 例子,保留下以后复习说不定用得上. 1.使用类扫描功能这个有点意思.使用时方便了许多. 2.XML配置方式
Spring2.5的源代码,需要认真研究!
MyBatis_3参考手册, spring2.5参考手册MyBatis_3参考手册, spring2.5参考手册MyBatis_3参考手册, spring2.5参考手册MyBatis_3参考手册, spring2.5参考手册MyBatis_3参考手册, spring2.5参考手册MyBatis_3参考手册, ...
spring2.5需要的jarspring2.5需要的jarspring2.5需要的jarspring2.5需要的jar
Spring2.5支持更多的java注释,使用起来更方便
精通spring2.5精通spring2.5精通spring2.5精通spring2.5精通spring2.5
Spring2.5的国际化配置 基于浏览器语言的国际化配置 使用Spring的MVC,并且配置中有配置Resource文件 <!-- 资源文件绑定器 --> <bean id="messageSource" class="org.springframework.context.support....
Spring Framework 开发参考手册