`

spring security 3中的10个典型用法小结

阅读更多
spring security 3比较庞大,但功能很强,下面小结下spring security 3中值得
注意的10个典型用法

1)多个authentication-provide可以同时使用


<authentication-manager alias='authenticationManager'>
  <authentication-provider>
   <user-service>
    <user authorities='ROLE_GUEST' name='guest' password=''/>
   </user-service>
  </authentication-provider>
  <authentication-provider>
   <jdbc-user-service data-source-ref='dataSource'/>
  </authentication-provider>
 </authentication-manager>


2 传统的<security:http>
 
<security:http>
 <security:intercept-url pattern='/admin/**' access='hasRole('ROLE_ADMIN')'/>
 <security:intercept-url pattern='/account/**' access='hasRole('ROLE_USER')' />
 <security:intercept-url pattern='/**' access='hasRole('ROLE_ANONYMOUS')' />
 <!-- other elements removed for clarity -->
</security:http>


3 可以使用一大堆密码加密器:
   aseDigestPasswordEncoder
BasePasswordEncoder
LdapShaPasswordEncoder
Md4PasswordEncoder,
Md5PasswordEncoder
MessageDigestPasswordEncoder
MessageDigestPasswordEncoder
PlaintextPasswordEncoder
ShaPasswordEncoder

4 SPRING security的标签
  

<sec:authorize access='hasRole('supervisor')'>
This content will only be visible to users who have
the 'supervisor' authority in their list of <tt>GrantedAuthority</tt>s.
</sec:authorize>


  这是根据角色判断是否显示
 
还可以根据URL判断是否显示
 
<sec:authorize url='/admin'>
This content will only be visible to users who are authorized to send requests to the '/admin' URL.
</sec:authorize>


5 方法级的鉴别
   @PreAuthorize  @PostAuthorize  @Secure

  要启用上面三者,要
<global-method-security pre-post-annotations='enabled' />

这三个是在方法调用前,先鉴别是否有权限使用,比如
  
public interface IUserService 

{
@PreAuthorize("hasRole('ROLE_USER')")

 public void changePassword(String username, password);
}


   感觉这个其实不是很常用
6 同5,可以使用JSR-250 注解去做
   <global-method-security jsr250-annotations=”enabled”/>

  @RolesAllowed({“ROLE_USER”,”ROLE_ADMIN”})
@PermitAll
@DenyAll

这样使用:
    @RolesAllowed({"ROLE_ADMIN","ROLE_USER"})
public void deleteUser(String username);
   这个东西反正没用到,具体见手册


7 配置open-id,步骤
  

<form action='j_spring-openid-security-check' method='post'>
 <label for='openid_idenifier'>Login</label>: 
 <input id='openid_identifier' name='openid_identifier' type='text'/>
 <input type='submit' value='Login' />
</form>


   <http auto-config='true'>
<openid-login/>

</http>
   当然要加上:spring-security-openid.jar

8 spring secruity能使用ldap
  <ldap-server ldif='classpath:my-ldif-file.ldif' id='localserver' />

当然要加上:spring-security-openid.jar

9 使用远程 ldap-server
   <ldap-server url='ldap://myServer/dc=captaindebug,dc=com:389' id='ldapExternal'
  manager-dn='uid=admin,ou=users,ou=systems' manager-password='s3cret'/>

  8和9还没用过,估计配置起来还有更多东西

10 使用https
   <http auto-config='true' use-expressions='true'>
    <intercept-url pattern='/login' requires-channel='https'/>
   
</https>

  这个比较简单,用requires-channel='https'

  
7
2
分享到:
评论
2 楼 Dead_knight 2013-02-18  
tywo45 写道
请教博主一个spring security的问题

http://192.168.20.92:8080/pubang-caigou/materieloffer/myMaterieloffer.action?id=3232

在url后面加上这个id=3232就拦截不了,不知道有没有好办法解决,我的spring security版本是3.1.2的

如果是自定义MetadataSource,需要配置
<property name="stripQueryStringFromUrls" value="true"></property>

只有当stripQueryStringFromUrls属性为true,才会过滤掉参数串
1 楼 tywo45 2012-12-28  
请教博主一个spring security的问题

http://192.168.20.92:8080/pubang-caigou/materieloffer/myMaterieloffer.action?id=3232

在url后面加上这个id=3232就拦截不了,不知道有没有好办法解决,我的spring security版本是3.1.2的

相关推荐

    Spring Security3中文文档

    Spring Security3是Spring框架中的一个模块,它提供了全面的安全服务,旨在为Web和非Web应用程序提供访问控制、认证、授权等功能。Spring Security3通过其强大的配置能力和丰富的特性,帮助开发者构建安全的应用程序...

    springSecurityTest.zip

    总结起来,"springSecurityTest.zip"文件提供了一个完整的环境,让你可以动手实践Spring Security的基础用法。通过学习其中的代码、笔记和文档,你将理解Spring Security如何与Spring框架协同工作,如何设置认证和...

    Spring Security 3系列文章——入门篇(一)

    3. 如果认证成功,Spring Security创建一个`Authentication`对象并存储在Security Context中。 4. 接下来的请求会被安全拦截器检查,判断用户是否有访问资源的权限。 ### 4. 权限控制 Spring Security使用访问决策...

    springSecurity总结及示例代码

    在提供的压缩包中,可能包含了Spring Security的基本配置、自定义登录页面、权限控制等示例代码,你可以参考这些代码了解Spring Security的具体用法。 总之,Spring Security 是一个强大而灵活的框架,它提供了一...

    Spring+Security+安全权限管理手册

    ### Spring Security 安全...以上是对《Spring+Security+安全权限管理手册》中部分章节的知识点总结。通过学习这些内容,开发者可以深入了解Spring Security的各种特性和应用场景,从而更好地构建安全可靠的应用程序。

    spring-security-helloworld-annotation

    总结,"spring-security-helloworld-annotation"项目是一个很好的起点,它展示了Spring Security如何通过注解实现Web应用的安全控制。通过理解和实践这个示例,开发者可以快速掌握Spring Security的基本用法,进而为...

    spring的用法总结大全.doc

    Spring Security是一个强大的安全框架,用于保护Spring应用免受各种安全威胁。它可以实现认证(Authentication)、授权(Authorization)等功能,同时支持OAuth2和其他安全协议。 【Spring Cloud】 Spring Cloud是...

    demo-security

    《深入理解Spring Security 4.2.3:基于实战项目“demo-security”》 Spring Security是Java领域中广泛使用...这个实战项目不仅有助于学习Spring Security的基本用法,还能帮助开发者提升在实际项目中的安全防护能力。

    spring-framework 中文文档.pdf

    随着时间的发展,Spring 不断进化,增加了更多高级功能和模块,如Spring MVC、Spring Security等。目前最新的版本为6.0.8-SNAPSHOT,这个版本引入了许多新的特性和改进,进一步增强了框架的功能性和灵活性。 ##### ...

    Struts2,spring2.5与jpa的整合示例

    3. 在Spring Security中配置用户、角色和权限,实现认证和授权。 4. 在Action、Service或DAO层中使用Spring Security的注解进行权限控制。 5. 实现具体的业务逻辑,使用JPA操作数据库。 **总结** Struts2、Spring...

    Spring ACEGI手册(部份)

    Spring ACEGI是Spring Security的前身,它是一个强大的、高度可配置的安全框架,专为Java企业级应用设计。这个框架旨在提供全面的身份验证、授权和服务层安全功能,允许开发者轻松地在Spring应用中实现复杂的安全...

    Spring2.0中文文档

    下面将从几个方面来总结和解释Spring 2.0的主要知识点。 ### 一、Spring框架概述 Spring框架是一个开源的Java平台,它为开发企业级应用提供了一种简洁的方式。Spring的核心特性包括依赖注入(Dependency Injection...

    spring-framework-4.2.1.RELEASE官方完整包加官方文档

    3. **Web MVC增强**:Spring的MVC框架在4.2.1版本中进行了优化,如支持WebSocket、RESTful API设计,以及更强大的数据绑定和验证功能。同时,模板引擎的集成也更加完善,如FreeMarker、Thymeleaf等。 4. **数据访问...

    Spring_3.x企业应用开发实战 目录

    - **定义与作用**:Spring 是一个开源的轻量级 Java 开发框架,它主要的目标是解决企业级应用开发中的复杂性问题。Spring 提供了全面的基础架构支持,简化了开发过程。 - **特点**:非侵入式设计、可测试性强、...

    spring_boot maven关联的所有jar

    Spring Boot 是一个由 Pivotal Team 开发的 Java 框架,旨在简化Spring应用程序的初始设置和日常开发。它提供了预配置的依赖项、自动配置功能以及内嵌的HTTP服务器,如Tomcat或Jetty,让开发者可以快速地创建独立...

    spring快速入门教程.pdf

    本教程将引导初学者逐步掌握Spring的核心概念和基本用法,帮助你快速上手并投入实际项目开发。 一、Spring概述 Spring框架是由Rod Johnson创建的,旨在简化企业级Java应用的开发。它提供了一个全面的基础设施,涵盖...

    acegi-security-1.0.7-osgi.jar.zip

    Acegi Security是一个已退役的安全框架,它在Java社区中曾被广泛使用,特别是在Spring框架的早期版本中。这个"acegi-security-1.0.7-osgi.jar.zip"压缩包包含的是Acegi Security 1.0.7版本,适配于OSGi(Open ...

    spring-framework-2.5.4.zip

    Spring Security(原名Acegi)在2.5.4中提供了一套全面的安全管理框架,涵盖了认证、授权、会话管理等多个方面,帮助开发者构建安全的应用。 总结来说,Spring Framework 2.5.4是一个强大且成熟的版本,它在依赖...

    最新ACEGI2.0教程

    - **教程示例**:通过一个简单的示例项目,演示Spring Security的基本用法及其主要功能。 - **联系人管理应用**:详细介绍如何在实际的应用场景中使用Spring Security实现用户管理、权限控制等功能。 #### 四、社区...

    Spring In Action(Third Edition)

    **Spring In Action(Third Edition)** 这本书主要介绍了 **Spring 3.0** 的新特性和用法,同时也涵盖了 **Spring Security 2.0** 和 **Spring WebFlow 2.0** 的相关内容。下面我们将根据提供的部分目录来详细分析书...

Global site tag (gtag.js) - Google Analytics