package org.qin.ying.lian.system.service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
public class MyUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter{
// public static final String VALIDATE_CODE = "validateCode";
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
// @Autowired
// private UserDao userDao;
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
if (!request.getMethod().equals("POST")) {
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
}
//检测验证码
// checkValidateCode(request);
String username = obtainUsername(request);
String password = obtainPassword(request);
//验证用户账号与密码是否对应
username = username.trim();
// User users = userDao.findByName(username);
//
// if(users == null) {
//
//// throw new AuthenticationServiceException("用户名或者密码错误!");
//
// throw new BadCredentialsException("用户不存在");
// }
//UsernamePasswordAuthenticationToken实现 Authentication
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
// Place the last username attempted into HttpSession for views
// 允许子类设置详细属性
setDetails(request, authRequest);
// 运行UserDetailsService的loadUserByUsername 再次封装Authentication
return this.getAuthenticationManager().authenticate(authRequest);
}
// protected void checkValidateCode(HttpServletRequest request) {
// HttpSession session = request.getSession();
//
// String sessionValidateCode = obtainSessionValidateCode(session);
// //让上一次的验证码失效
// session.setAttribute(VALIDATE_CODE, null);
// String validateCodeParameter = obtainValidateCodeParameter(request);
// if (StringUtils.isEmpty(validateCodeParameter) || !sessionValidateCode.equalsIgnoreCase(validateCodeParameter)) {
// throw new AuthenticationServiceException("验证码错误!");
// }
// }
//
// private String obtainValidateCodeParameter(HttpServletRequest request) {
// Object obj = request.getParameter(VALIDATE_CODE);
// return null == obj ? "" : obj.toString();
// }
//
// protected String obtainSessionValidateCode(HttpSession session) {
// Object obj = session.getAttribute(VALIDATE_CODE);
// return null == obj ? "" : obj.toString();
// }
@Override
protected String obtainUsername(HttpServletRequest request) {
Object obj = request.getParameter(USERNAME);
return null == obj ? "" : obj.toString();
}
@Override
protected String obtainPassword(HttpServletRequest request) {
Object obj = request.getParameter(PASSWORD);
return null == obj ? "" : obj.toString();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
使用Spring+SpringSecurity+SpringMVC的web框架小demo
共140个文件
jar:99个
xml:8个
class:7个
5星 · 超过95%的资源 需积分: 9 91 下载量 111 浏览量
2014-08-28
10:44:19
上传
评论 2
收藏 46.06MB RAR 举报
温馨提示
这个是基于Spring的一个小例子 , 主要是为了帮助大家学习SpringSecurity和SpringMvc, 1.不用再数据库建表, 2.使用了SS提供的登录方式,在输入用户名和密码时,进入到服务器后台java文件, 3.判断如果是用户名是admin 密码123,就赋予管理员权限,进入到中心页, 4.如果不是admin,就跳转到 无权访问页面, 5.还有可以使用SpringMVC进行前后台的交互 还有可以使用自定义的过滤器来实现登录, 有不懂的问题 可以加我
资源推荐
资源详情
资源评论
收起资源包目录
使用Spring+SpringSecurity+SpringMVC的web框架小demo (140个子文件)
MyUsernamePasswordAuthenticationFilter.class 3KB
AccountDetails.class 2KB
MySavedRequestAwareAuthenticationSuccessHandler.class 2KB
MyUserDetailsService.class 2KB
IndexServlet.class 1KB
MyLogoutSuccessHandler.class 948B
AccountController.class 658B
.classpath 9KB
org.eclipse.wst.common.component 459B
org.eclipse.wst.jsdt.ui.superType.container 49B
404.html 978B
denied.html 624B
sessionTimeOut.html 248B
ooxml-schemas-1.0.jar 13.36MB
cxf-2.3.0.jar 4.89MB
hibernate-3.5.2.GA.jar 3.73MB
xmlbeans-2.4.0.jar 2.6MB
lombok.jar 1.85MB
poi-3.7-20101029.jar 1.6MB
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar 1.57MB
bcprov-ext-jdk15-141.jar 1.56MB
ojdbc14.jar 1.47MB
ant.jar 1.23MB
testng-jdk15.jar 1.17MB
ehcache-core-2.4.6.jar 991KB
jxl.jar 726KB
mysql-connector-java-5.1.11-bin.jar 715KB
org.springframework.context-3.0.6.RELEASE.jar 655KB
javassist-3.9.0.GA.jar 583KB
dbunit-2.4.7.jar 572KB
commons.collections-3.2.1.jar 569KB
google-collect-1.0.jar 564KB
org.springframework.beans-3.0.6.RELEASE.jar 544KB
poi-ooxml-3.7-20101029.jar 487KB
log4j-1.2.16.jar 470KB
mail-1.4.1.jar 437KB
xmlsec-1.4.3.jar 437KB
antlr-2.7.7.jar 435KB
quartz-1.8.3.jar 435KB
xstream-1.3.1.jar 421KB
jstl-1.2.0.jar 410KB
org.springframework.web.servlet-3.0.6.RELEASE.jar 410KB
taglibs.standard-1.1.2.jar 389KB
org.springframework.web-3.0.6.RELEASE.jar 389KB
jackson.mapper-1.4.2.jar 377KB
org.springframework.jdbc-3.0.6.RELEASE.jar 377KB
org.springframework.core-3.0.6.RELEASE.jar 373KB
backport-3.1.0.jar 328KB
org.springframework.orm-3.0.6.RELEASE.jar 327KB
wss4j-1.5.9.jar 323KB
org.springframework.aop-3.0.6.RELEASE.jar 314KB
dom4j-1.6.1.jar 307KB
spring-security-core-3.0.7.RELEASE.jar 305KB
jtds-1.2.2.jar 288KB
cglib-2.2.jar 272KB
commons-jexl-2.1.1.jar 261KB
commons-lang-2.4.jar 256KB
spring-security-web-3.0.7.RELEASE.jar 238KB
junit-4.8.1.jar 231KB
commons.beanutils-1.8.0.jar 228KB
org.springframework.transaction-3.0.6.RELEASE.jar 226KB
hibernate.validator-4.0.2.GA.jar 222KB
org.springframework.test-3.0.6.RELEASE.jar 200KB
concurrent-1.3.4.jar 189KB
dozer.osgi-5.2.0.jar 187KB
pinyin4j-2.5.0.jar 184KB
spring-security-config-3.0.7.RELEASE.jar 181KB
org.springframework.jms-3.0.6.RELEASE.jar 181KB
thumbnailator-0.4.2-all.jar 172KB
org.springframework.web.portlet-3.0.6.RELEASE.jar 172KB
org.springframework.expression-3.0.6.RELEASE.jar 166KB
json-lib-2.4-jdk15.jar 155KB
hibernate-jpamodelgen-1.0.0.Final.jar 155KB
jxls-core-1.0.1.jar 151KB
jdom.jar 150KB
jackson-1.4.2.jar 147KB
XmlSchema-1.4.7.jar 145KB
wsdl4j-1.6.2.jar 145KB
commons.digester-1.8.1.jar 144KB
sitemesh-3.0-alpha-2.jar 136KB
commons.dbcp-1.2.2.osgi.jar 120KB
wangzz-core.jar 119KB
aspectj.runtime-1.6.5.RELEASE.jar 115KB
commons.io-1.4.0.jar 108KB
el-6.0.20.jar 102KB
org.springframework.context.support-3.0.6.RELEASE.jar 99KB
hibernate-jpa-2.0-api-1.0.0.Final.jar 99KB
ezmorph-1.0.6.jar 84KB
javax.servlet.jar 82KB
jetty-plus-7.1.6.v20100715.jar 71KB
activation-1.1.1.jar 68KB
commons.pool-1.3.0.jar 61KB
commons.logging-1.1.1.jar 60KB
org.springframework.oxm-3.0.6.RELEASE.jar 60KB
commons-codec-1.4.jar 57KB
commons.fileupload-1.2.0.jar 53KB
org.springframework.asm-3.0.6.RELEASE.jar 52KB
validation-api-1.0.0.GA.jar 46KB
asm-3.2.jar 42KB
json-20070829.jar 41KB
共 140 条
- 1
- 2
资源评论
- u0144651732018-09-04东西不错,但不是我想要的。
- u0114623812014-09-18灰常好的东西. 已经看过了
- IT佳佳2018-02-20非常好的代码,简单易懂,其实我就想看系统如何区分普通和管理员访问资源的权限代码,例子很不错,需要耗费些时间慢慢理解了
程序员chin
- 粉丝: 17
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功