package com.yeshun.service;
import java.util.ArrayList;
import java.util.Collection;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import com.yeshun.util.Md5Util;
public class MyUserDetailService implements UserDetailsService {
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
//这里就不连接数据库了 手动验证用户 及赋予权限
/**
* UserInfo user = userDao.getUser(username);
* if(user == null){
* throw new UsernameNotFoundException("用户不存在,请重新输入!");
* }else{
* // to do
* // 根据用户名得到用户的密码 ,得到用户的权限
* }
*/
/**
* 这里默认密码
* 假如配置文件加上了<password-encoder hash="md5" />
* String password = Md5Util.MD5("123456");
*/
String password = "123456";
Collection<GrantedAuthority> auths=new ArrayList<GrantedAuthority>();
GrantedAuthorityImpl auth=new GrantedAuthorityImpl("ROLE_ADMIN");
auths.add(auth);
// GrantedAuthorityImpl auth1=new GrantedAuthorityImpl("ROLE_USER");
// auths.add(auth1);
boolean enabled = true;
boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
// User(String username, String password, boolean enabled, boolean accountNonExpired,
// boolean credentialsNonExpired, boolean accountNonLocked, Collection<GrantedAuthority> authorities)
User user = new User(username,
password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, auths);
//假如 数据库是md5加密的 那在配置文件里加上<password-encoder hash="md5" />
return user;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
security.rar (79个子文件)
security
.project 1KB
.mystrutsdata 240B
.mymetadata 297B
src
struts.xml 927B
applicationContext-security.xml 2KB
com
yeshun
service
MyUserDetailService.java 2KB
action
BaseAction.java 889B
UserAction.java 2KB
TestAction.java 333B
util
Md5Util.java 840B
WebRoot
WEB-INF
classes
struts.xml 927B
applicationContext-security.xml 2KB
com
yeshun
service
MyUserDetailService.class 2KB
action
BaseAction.class 1KB
UserAction.class 3KB
TestAction.class 730B
util
Md5Util.class 1KB
lib
org.springframework.web.portlet-3.1.0.RC1.jar 181KB
org.springframework.expression-3.1.0.RC1.jar 172KB
spring-security-core-3.0.7.RELEASE.jar 305KB
org.springframework.context.support-3.1.0.RC1.jar 98KB
spring-security-config-3.0.7.RELEASE-sources.jar 144KB
spring-security-acl-3.0.7.RELEASE.jar 76KB
org.springframework.web-3.1.0.RC1.jar 526KB
org.springframework.transaction-3.1.0.RC1.jar 241KB
org.springframework.beans-3.1.0.RC1.jar 573KB
org.springframework.test-3.1.0.RC1.jar 223KB
spring-security-cas-client-3.0.7.RELEASE-sources.jar 21KB
spring-security-ldap-3.0.7.RELEASE.jar 84KB
org.springframework.web.struts-3.1.0.RC1.jar 31KB
jstl-1.2.jar 405KB
log4j-1.2.14.jar 359KB
slf4j-log4j12-1.6.0.jar 10KB
org.springframework.context-3.1.0.RC1.jar 788KB
xwork-core-2.1.6.jar 1.49MB
spring-security-openid-3.0.7.RELEASE.jar 17KB
spring-security-openid-3.0.7.RELEASE-sources.jar 15KB
org.springframework.jdbc-3.1.0.RC1.jar 392KB
org.springframework.core-3.1.0.RC1.jar 429KB
org.springframework.oxm-3.1.0.RC1.jar 68KB
spring-security-acl-3.0.7.RELEASE-sources.jar 80KB
freemarker-2.3.15.jar 859KB
antlr-2.7.6.jar 433KB
org.springframework.instrument-3.1.0.RC1.jar 7KB
org.springframework.aspects-3.1.0.RC1.jar 47KB
struts2-core-2.1.8.1.jar 738KB
slf4j-api-1.6.0.jar 25KB
spring-security-cas-client-3.0.7.RELEASE.jar 19KB
spring-security-config-3.0.7.RELEASE.jar 181KB
spring-security-taglibs-3.0.7.RELEASE.jar 18KB
org.springframework.instrument.tomcat-3.1.0.RC1.jar 11KB
commons-fileupload-1.2.1.jar 56KB
spring-security-aspects-3.0.7.RELEASE-sources.jar 3KB
spring-security-web-3.0.7.RELEASE-sources.jar 228KB
spring-security-aspects-3.0.7.RELEASE.jar 7KB
spring-security-ldap-3.0.7.RELEASE-sources.jar 63KB
org.springframework.jms-3.1.0.RC1.jar 190KB
commons-logging-api-1.1.jar 44KB
org.springframework.aop-3.1.0.RC1.jar 324KB
org.springframework.asm-3.1.0.RC1.jar 52KB
spring-security-core-3.0.7.RELEASE-sources.jar 334KB
spring-security-taglibs-3.0.7.RELEASE-sources.jar 14KB
org.springframework.web.servlet-3.1.0.RC1.jar 550KB
org.springframework.orm-3.1.0.RC1.jar 369KB
ognl-2.7.3.jar 234KB
jstl-1.1.2.jar 20KB
spring-security-web-3.0.7.RELEASE.jar 238KB
web.xml 1KB
index.jsp 1KB
welcome.jsp 826B
js
META-INF
MANIFEST.MF 36B
welcomeUser.jsp 830B
login.jsp 1KB
image
css
403.jsp 803B
.myeclipse
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.jdt.core.prefs 330B
org.eclipse.wst.jsdt.ui.superType.name 6B
.jsdtscope 500B
.classpath 5KB
共 79 条
- 1
bacckom
- 粉丝: 5
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页