/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.wenc.core.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.wenc.core.po.Perms;
import com.wenc.core.po.Role;
import com.wenc.core.po.User;
import com.wenc.test.dao.PersonDAO;
@Component
public class SampleRealmService extends AuthorizingRealm {
private static Logger logger =Logger.getLogger(SampleRealmService.class);
@Autowired
private PersonDAO personDAO;
public SampleRealmService() {
logger.info("-------AAA1------------------");
setName("sampleRealmService");
// setCredentialsMatcher(new Sha256CredentialsMatcher());
}
/**
* 身份验证
* 创 建 人: 文超
* 创建时间: 2014-2-14 下午1:37:50
* @param authcToken 登陆Action封装的令牌
* @return
* @throws AuthenticationException
* @see [类、类#方法、类#成员]
*/
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
/**查询对应的用户是否存在*/
User user =personDAO.getUser(token.getUsername(), token.getPassword().toString());
logger.info(user);
if( user != null ) {
return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), getName());
} else {
return null;
}
}
/**
* 授权
* 注意:统一在struts的拦截器中处理,见UserPermissionInterceptor.java
* 创 建 人: 文超
* 创建时间: 2014-2-14 下午1:38:42
* @param principals
* @return
* @see [类、类#方法、类#成员]
*/
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Integer userId = (Integer) principals.fromRealm(getName()).iterator().next();
logger.info("用户ID:"+userId);
User user = personDAO.getUser(userId);
if( user != null ) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
for( Role role : user.getRoles() ) {
info.addRole(role.getName());
Set<Perms> set= role.getPermissions();
logger.info(set);
List<String> temp=new ArrayList<String>();
for(Perms perm:set){
temp.add(perm.getActionName());
}
info.addStringPermissions( temp );
}
return info;
} else {
return null;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Test_Web.rar (86个子文件)
Test_Web
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 414B
org.eclipse.wst.common.component 658B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 522B
org.eclipse.jdt.core.prefs 364B
src
test
java
com
wenc
test
junit
TestPersonService.java 782B
main
resources
config
properties
deploy.properties 2KB
spring
appCtx-common.xml 9KB
log4j.properties 3KB
struts.xml 1KB
java
com
wenc
core
dao
BaseDAO.java 922B
BaseDAOImpl.java 3KB
po
Perms.java 2KB
User.java 2KB
Role.java 2KB
web
interceptor
UserPermissionInterceptor.java 1KB
BaseAction.java 609B
service
SampleRealmService.java 4KB
test
dao
PersonDAO.java 713B
PersonDAOImpl.java 1KB
po
Person.java 1KB
service
web
PersonAction.java 3KB
PersonService.java 1KB
.project 1KB
WebRoot
index2.jsp 813B
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 3KB
classes
config
properties
deploy.properties 2KB
spring
appCtx-common.xml 9KB
log4j.properties 3KB
com
wenc
core
dao
BaseDAO.class 520B
BaseDAOImpl.class 4KB
po
User.class 2KB
Perms.class 2KB
Role.class 2KB
web
interceptor
UserPermissionInterceptor.class 2KB
BaseAction.class 312B
service
SampleRealmService.class 4KB
test
dao
PersonDAO.class 287B
PersonDAOImpl.class 2KB
po
Person.class 2KB
service
PersonService.class 970B
web
PersonAction.class 3KB
junit
TestPersonService.class 1KB
struts.xml 1KB
lib
jboss-transaction-api_1.1_spec-1.0.0.Final.jar 11KB
slf4j-api-1.6.0.jar 25KB
dom4j-1.6.1.jar 307KB
struts2-spring-plugin-2.3.7.jar 21KB
log4j-1.2.16.jar 470KB
aopalliance-1.0.jar 4KB
antlr-2.7.7.jar 435KB
spring-orm-3.2.2.RELEASE.jar 378KB
spring-web-3.2.2.RELEASE.jar 612KB
freemarker-2.3.19.jar 909KB
jboss-logging-3.1.0.GA.jar 59KB
commons-logging-1.1.1.jar 59KB
struts2-core-2.3.7.jar 775KB
spring-beans-3.2.2.RELEASE.jar 593KB
ognl-3.0.5.jar 222KB
spring-expression-3.2.2.RELEASE.jar 191KB
hibernate-commons-annotations-4.0.2.Final.jar 80KB
aspectjweaver.jar 1.8MB
mysql-connector-java-5.1.26.jar 836KB
hibernate-core-4.2.2.Final.jar 4.41MB
spring-jdbc-3.2.2.RELEASE.jar 396KB
aspectjrt.jar 112KB
javassist-3.17.1-GA.jar 695KB
commons-fileupload-1.2.2.jar 58KB
xwork-core-2.3.7.jar 622KB
hibernate-jpa-2.0-api-1.0.1.Final.jar 100KB
shiro-all-1.2.2.jar 523KB
spring-context-3.2.2.RELEASE.jar 842KB
spring-test-3.2.2.RELEASE.jar 445KB
druid-0.2.8.jar 1.47MB
commons-lang3-3.1.jar 308KB
spring-core-3.2.2.RELEASE.jar 846KB
slf4j-log4j12-1.6.0.jar 10KB
spring-aop-3.2.2.RELEASE.jar 328KB
spring-tx-3.2.2.RELEASE.jar 236KB
login.jsp 616B
index.jsp 876B
error.jsp 287B
main
.classpath 1KB
doc
数据库结构.sql 3KB
build
共 86 条
- 1
wenchaosongping
- 粉丝: 3
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页