2.1 Spring Security是什么?

2016-06-11 00:24:36 17,128 4

Spring Security为J2EE企业级应用提供了全面的安全服务。这里有一个特别的强调的地方,应用是基于Spring框架开发的。如果你没有使用过Spring来开发J2EE应用,我们强烈的建议你尝试一下。对于Spring框架的熟悉(特别是依赖注入原则),会让你在学习 Spring Security的时候更加容易上手。

人们使用 Spring Security的原因有很多,但是大部分项目是发现 Java EE的Servlet 规范或者EJB规范对企业级应用场景提供的安全特性不够深入。提到这些规范,要认识到的一点是,在war包或者ear包的级别上,这些安全机制是不可以移植的。意思就是,如果我们使用了不同的服务器环境,我们通常需要为新的服务器环境重新配置或者开发系统的安全机制。使用Spring Security可以克服这些问题,并且可以给你带来大量的其他有用的、可以自定义的特性。

你可能已经知道,应用级别的安全主要分为“验证( authentication) ”和“(授权) authorization ”两个部分。这也是Spring Security主要需要处理的两个部分。“ Authentication ”指的是建立规则( principal )的过程。规则可以是一个用户、设备、或者其他可以在我们的应用中执行某种操作的其他系统。" Authorization "指的是判断某个 principal 在我们的应用是否允许执行某个操作。在 进行授权判断之前,要求其所要使用到的规则必须在验证过程中已经建立好了。这些概念是通用的,并不是只针对"Spring Security"。

在验证(Authentication )层面, Spring Security 提供了不同的验证模型。大部分的authentication模型来自于第三方或者权威机构或者由一些相关的标准制定组织(如IETF)开发。此外,Spring Security也提供了一些验证特性。特别的,Spring Security目前支持对以下所有验证方式的整合:

  • HTTP BASIC authentication headers (an IETF RFC-based standard)

  • HTTP Digest authentication headers (an IETF RFC-based standard)

  • HTTP X.509 client certificate exchange (an IETF RFC-based standard)

  • LDAP (a very common approach to cross-platform authentication needs, especially in large environments)

  • Form-based authentication (for simple user interface needs)

  • OpenID authentication

  • Authentication based on pre-established request headers (such as Computer Associates Siteminder)

  • JA-SIG Central Authentication Service (otherwise known as CAS, which is a popular open source single sign-on system)

  • Transparent authentication context propagation for Remote Method Invocation (RMI) and HttpInvoker (a Spring remoting protocol)

  • Automatic "remember-me" authentication (so you can tick a box to avoid re-authentication for a predetermined period of time)

  • Anonymous authentication (allowing every unauthenticated call to automatically assume a particular security identity)

  • Run-as authentication (which is useful if one call should proceed with a different security identity)

  • Java Authentication and Authorization Service (JAAS)

  • JEE container autentication (so you can still use Container Managed Authentication if desired)

  • Kerberos

  • Java Open Source Single Sign On (JOSSO) *

  • OpenNMS Network Management Platform *

  • AppFuse *

  • AndroMDA *

  • Mule ESB *

  • Direct Web Request (DWR) *

  • Grails *

  • Tapestry *

  • JTrac *

  • Jasypt *

  • Roller *

  • Elastic Path *

  • Atlassian Crowd *

  • Your own authentication systems (see below)

注:*号标记的部分由第三方提供。

很多独立软件厂家(ISV)接受 Spring Security 的原因就是可以灵活的选择验证模型。这样无论客户的需求是什么,他们都可以快速的整合进自己的解决方案,不需要进行太多额外的研究或者要求客户改变他们的运行环境。如果上述 验证模型都不能满足我们的需求,由于Spring Security是一个开放的平台,我们也可以很容易的就编写出自己的验证机制。许多Spring Security的 企业用户需要将一些并不遵循任何安全标准的"遗留"系统中整合进安全特性,Spring Security很适合用来处理这类系统。

除了验证机制, Spring Security 也提供了一系列的授权能力。主要感兴趣的是以下三个方面:

1、对web请求进行授权

2、授权某个方法是否可以被调用

3、授权访问单个领域对象实例

为了理解其中的不同,考虑一下Servlet规范web模式安全中的授权能力、EJB容器管理的安全、文件系统安全。SpringSecurity对于这些重要的方面提供了深入的支持,在接下来的章节中我们将进行讲解。


上一篇:2.0 介绍 下一篇:2.2 历史