Spring Security Basic Authentication
来源:互联网 发布:linux kmod oracleasm 编辑:程序博客网 时间:2024/04/27 02:10
原文地址:http://www.javaarch.net/jiagoushi/696.htm
Spring Security Basic Authenticationspring security 配置<?xml version="1.0" encoding="UTF-8"?><beans:beans xmlns="http://www.springframework.org/schema/security"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:beans="http://www.springframework.org/schema/beans"xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <http use-expressions="true"><intercept-url pattern="/**" access="isAuthenticated()" /> <http-basic /></http> <authentication-manager><authentication-provider><user-service><user name="user1" password="user1Pass" authorities="ROLE_USER" /></user-service></authentication-provider></authentication-manager> </beans:beans> <http-basic>打开basic验证, 如果我们访问:curl -i http://localhost:8080/spring-security-basic-auth/homepage.html 会返回401 HTTP/1.1 401 UnauthorizedServer: Apache-Coyote/1.1Set-Cookie: JSESSIONID=E5A8D3C16B65A0A007CFAACAEEE6916B; Path=/spring-security-basic-auth/; HttpOnlyWWW-Authenticate: Basic realm="Spring Security Application"Content-Type: text/html;charset=utf-8Content-Length: 1061Date: Wed, 29 May 2013 15:14:08 GMT如果我们使用下面的url访问:curl -i --user user1:user1Pass http://localhost:8080/spring-security-basic-auth/homepage.html则返回200HTTP/1.1 200 OKServer: Apache-Coyote/1.1Set-Cookie: JSESSIONID=301225C7AE7C74B0892887389996785D; Path=/spring-security-basic-auth/; HttpOnlyContent-Type: text/html;charset=ISO-8859-1Content-Language: en-USContent-Length: 90Date: Wed, 29 May 2013 15:19:38 GMT我们也可以使用spring提供的扩展接口来实现验证结果自定义<http-basic entry-point-ref="myBasicAuthenticationEntryPoint" />@Componentpublic class MyBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint { @Overridepublic void commence (HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx) throws IOException, ServletException {response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\"");response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);PrintWriter writer = response.getWriter();writer.println("HTTP Status 401 - " + authEx.getMessage());} @Overridepublic void afterPropertiesSet() throws Exception {setRealmName("Baeldung");super.afterPropertiesSet();}}
- Spring Security Basic Authentication
- AngularJS+Spring Security using Basic Authentication
- Spring Security Authentication Provider
- spring security4学习(二)spring-boot结合spring security实现http basic Authentication
- Http Basic Authentication 与 ws-security: 加密,签名,证书等
- Spring Security 3.1 自定义 authentication provider
- Spring Security 3.1 自定义 authentication provider
- Spring Security 3.1 自定义 authentication provider
- Authentication(Spring Security 认证笔记)
- Spring Security手册更新cas, basic, acl
- Spring Security http basic 示例代码
- Hacking Custom Authentication Providers with Grails Spring Security
- SpringMVC Websockets Messaging User Authentication with Spring Security
- Security Basic
- Apache Security-2-Basic Authentication(基本认证)简介及实战练习
- Spring Boot Actuator、Spring security、http basic authority整合
- Implement basic HTTP authentication
- HTTP: Basic Authentication
- android学习笔记之手势翻页
- A Simple Quick LRC
- HDOJ 2057 A + B Again
- scandir扫描目录和文件
- Spring Security Form Login
- Spring Security Basic Authentication
- fprintf函数的用法
- 第十四周 项目一:动物怎么叫?(抽象类)
- Spring Security Logout
- HDU-1282回文数猜想
- 查看是否存在子节点;
- Spring rest对etag支持
- ERLANG日期与时间
- 搭建在win32和VS2005的cocos2d-x的开发环境