Jetspeed2 Security

Jetspeed2 Security
1. 安全架构
1.1.      概述
Jetspeed 2 security leverages J2EE authentication and authorization standards for both authentication and authorization through the implementation of a default LoginModule and a default authorization Policy.
Authentication establishes the identity of the user and populates the Subject with all the user principals. In a portal context, the populated Subject is added to the session in the org.apache.jetspeed.security.SecurityValve implementation. The Subject principals are then used to authorize the user's access to a given resource. It leverages JAAS authorization by checking the user's permission with the AccessController. More details on authorization are provided in the JAAS authorization section of this documentation.
1.2.      图示
The following diagram describes the high level security architecture:
2. 主要配置
Jetspeed 2 default security services configuration leverages a relational database as its default persitent datastore for security information. Jetspeed 2 security service provider interface provides a mechanism to replace the default datastore configured.
3 files are involved when configuring Jetspeed 2 security SPI. All the SPI configuration files are located under ${jetspeed-source-home}/portal/src/webapp/WEB-INF/assembly/ .
2.1.      security-atn.xml
This configuration file provides the login module configuration. Not everyone needs this, as some application may decide to use another login module other than the one provided.
2.2.      security-atz.xml
This configuration file configures the authorization policy, in J2's case RdbmsPolicy .
2.3.      security-managers.xml
This configuration file configures all the managers for security purpose.
2.4.      security-providers.xml
This configuration file configures the various providers and weaves the SPI together.
· AuthenticationProviderProxy : Configures the list of AuthenticationProvider and the default authenticator.
·                                                
·                   
·                       class="org.apache.jetspeed.security.impl.AuthenticationProviderProxyImpl">          
·                       
·                          
·                             
·                          
·                       
·                      DefaultAuthenticator
·                   
                        
· AuthenticationProvider : Configures the authentication providers for the current portal implementation. The example below configures the default authenticator that uses the RDBMS to manage/store user information.
·                                                
·                   
·                                     class="org.apache.jetspeed.security.impl.AuthenticationProviderImpl">                  
·                       DefaultAuthenticator
·                       The default authenticator
·                       login.conf
·                       
·                          
·                       
·                       
·                          
·                       
·                   
                       
· AuthorizationProvider : Configures the policies and instantiates the SecurityPolicies that are used for enforcing permissions. By default, Jetspeed 2 does not load any other security policies that may have been configured. In order to use default policies, set useDefaultPolicy to true
·                                                
·                   
·                                    class="org.apache.jetspeed.security.impl.AuthorizationProviderImpl">     
·                        
·                            
·                        
·                        
·                        false  
·                   
                       
2.5.      security-spi.xml
This configuration file contains configuration that are common to the authentication and authorization SPIs.
Bean
Description
org.apache.jetspeed.security.spi.SecurityAccess
Used internally by the default OJB based SPI. Provide access to common action/methods for the various SPI implementations. The SecurityAccess bean is used by both the Authentication and Authorization SPIs.
2.6.      security-spi-atn.xml
This configuration file contains all the configurations for configuring the authentication SPI.
Bean
Description
org.apache.jetspeed.security.spi.CredentialHandler
The CredentialHandler encapsulates the operations involving manipulation of credentials. The default implementation provides support for password protection as defined by the PasswordCredentialProvider ; as well as lifecycle management of credentials through InternalPasswordCredentialInterceptor which can be configured to manages parameters such as maximum number of authentication failures, maximum life span of a credential in days and how much history to retain for a given credential.
org.apache.jetspeed.security.spi.UserSecurityHandler
The UserSecurityHandler encapuslated all the operations around the user principals.
The following simple CredentialHandler configuration is currently provided by default with Jetspeed:
     class="org.apache.jetspeed.security.spi.impl.DefaultCredentialPasswordValidator"/>
 
     class="org.apache.jetspeed.security.spi.impl.MessageDigestCredentialPasswordEncoder">
     SHA-1      
      
 
     class="org.apache.jetspeed.security.spi.impl.InternalPasswordCredentialInterceptorsProxy">
    
      
         
        
 
        
        
      
    
 
     class="org.apache.jetspeed.security.spi.impl.DefaultPasswordCredentialProvider">
    
      
           
    
      
           
      
 
     class="org.apache.jetspeed.security.spi.impl.DefaultCredentialHandler">      
    
      
           
    
      
           
    
      
    
                 
The above configuration requires not much more than that a password should not be empty and MessageDigest encode it using SHA-1.
Before the 2.0-M4 release, Jetspeed came configured with a much stricter configuration, but for first time users of the Portal this was a bit overwelming and also quite difficult to configure differently.
With the 2.0-M4 release, the previously provided, and rather complex, InternalPasswordCredentialInterceptor implementations are split up in single atomic interceptors which can much easier be configured indepedently.
An overview of the new interceptors and how related request processing pipeline valves can be configured to provide feedback to the user is provided in the Credentials Management document.
Since the "old" (pre 2.0-M4) interceptors are no longer provided with Jetspeed, the example below shows how to "restore" the old setup using the new interceptors:
     class="org.apache.jetspeed.security.spi.impl.SimpleCredentialPasswordValidator">
     6      
     2      
 
     class="org.apache.jetspeed.security.spi.impl.InternalPasswordCredentialInterceptorsProxy">
    
      
        
        
 
        
        
 
        
        
           3      
        
 
        
        
           60      
        
 
        
        
           3      
        
      
    
                 
And, make sure something like the following configuration is set for the security related valves in pipelines.xml:
      class="org.apache.jetspeed.security.impl.PasswordCredentialValveImpl"
      init-method="initialize">
 
  
  
     2
     3
     7
  
 
 
      class="org.apache.jetspeed.security.impl.LoginValidationValveImpl"
      init-method="initialize">
 
 3 
                 
Also, make sure the above valves are configured in the jetspeed-pipeline bean.
See the User Interaction section in the Credentials Management document for a description of these valves and their relation to the interceptors configuration.
2.7.      security-spi-atz.xml
This configuration file contains all the configurations for configuring the authorization SPI.
Bean
Description
org.apache.jetspeed.security.spi.RoleSecurityHandler
The RoleSecurityHandler encapsulates all the operations around the role principals.
org.apache.jetspeed.security.spi.GroupSecurityHandler
The GroupSecurityHandler encapsulates all the operations around the group principals.
org.apache.jetspeed.security.spi.SecurityMappingHandler
The SecurityMappingHandler encapsulates all the operations involving mapping between principals. It contains the logic managing hierarchy resolution for hierarchical principals (roles or groups). The default hierarchy resolution provided is a hierarchy by generalization (see overview for definitions). A contructor-arg can be added to the SecurityMappingHandler to change the hierarchy resolution strategy. Jetspeed 2 also support a hierarchy resolution by aggregation.
A sample SecurityMappingHandler configuration could be:
     class="org.apache.jetspeed.security.spi.impl.DefaultSecurityMappingHandler">         
  
     
  
  
  
                   
2.8.      结论和分析
配置文件
说明
分析
security-atn.xml
login module 配置文件
具体可参考:
提供了一个接口,可以实现不同的登陆模块,实现不同的登陆认证过程
此时在jetspeed2-security-{version}.jar中包含配置文件login.conf,其内容为:
Jetspeed {
org.apache.jetspeed.security.impl.DefaultLoginModule equired;
};
In order to override this configuration, you can place your own login.conf file in your web application class path under WEB-INF/classes. The location of the login.conf file is configured in the security-providers.xml as described below.
security-atz.xml
authorization policy 配置文件
JAAS认证策略的配置
security-managers.xml
UserManager GroupManager RoleManager PermissionManager 配置文件
配置四个对象的关系管理实现
security-providers.xml
AuthenticationProvider AuthenticationProviderProxy SecurityProvider AuthorizationProvider 授权认证提供者配置文件
 
说明:
1、  关于login module可参考:
http://portals.apache.org/jetspeed-2/multiproject/jetspeed-security/login-module.html
 
3. 分析
3.1.      登陆认证过程分析
3.1.1.         相关配置
主要参考security-*.xml等几个安全相关的配置文件,尤其关注security-providers.xml,里面存在如下设置:
 
         class="org.apache.jetspeed.security.impl.AuthenticationProviderImpl"
 >          
         DefaultAuthenticator
         The default authenticator
         login.conf
         
         
 
这里设置了提供的默认认证方式,此时:
DefaultAuthenticator——第一个参数是认证方式的名称,意义不大;
The default authenticator——第二个参数是认证方式的描述,意义不大;
login.conf——第三个参数是认证配置文件的路径,非常关键,这个文件可以在jetspeed-security-2.0.jar中找到,此时的配置为:
Jetspeed {
   org.apache.jetspeed.security.impl.DefaultLoginModule required;
};
表示配置了一个realm,名称为Jetspeed,实现类为org.apache.jetspeed.security.impl.DefaultLoginModule。此时回顾web.xml中的如下描述:
 
    FORM
    Jetspeed
   
      /login/login
      /login/error
   
 
此时使用的realm就是Jetspeed,关联起来了吧。
第三、第四个参数是回调
3.1.2.         调用过程
1、  * LoginServlet.java(doGet):触发登陆的submit;
2、  进入servlet container中触发FormAuthenticator.authenticate认证(请看配置设置:FORM);
3、  * org.apache.jetspeed.security.impl.DefaultLoginModule.java:根据web.xml配置的realm-name(Jetspeed)确定认证模块(login module),并调用login()方法,在该方法中调用顺序如下:
a)         设置回调;
b)        调用 org.apache.jetspeed.security.impl.UserManagerImp .java authenticate(this.username, password) 进行认证,继续跟进该方法:
                                       i.              除非当前用户是匿名用户,否则调用 org.apache.jetspeed.security.impl.AuthenticationProviderProxyImpl .java authenticate(userName, password, providerName) 方法进行认证,此时该 provider 会调用其 CredentialHandler (感觉就是 DAO, 此为 org.apache.jetspeed.security.spi.impl.DefaultCredentialHandler .java )的 authenticate(userName, password) 进行真正的验证。
3.2.      数据结构分析
从数据库模型来分析:
1、  :包含了用户、角色、组的信息,都认为是PRINCIPAL(主体);SECURITY_PRINCIPAL
2、  :用户的证书,默认为密码,这样设计表明一个PRINCIPAL可以有多个CREDENTIAL;SECURITY_CREDENTIAL
3、  :基于JAAS的权限的定义,目前分为FOLDER、PAGE、PORTLET等类型(可以扩展吗?)SECURITY_PERMISSION
3.3.      与传统机构部门、人员、角色、组设计的分析
从目前设计来看,存在如下问题:
1、              直接放在SECURITY_PRINCIPAL,也是一个PRINCIPAL,与用户、角色类似进行处理,显然不符合实际需要;GROUP
2、              这里的用户、角色关注的是“权限”的概念,并无业务概念,显然也存在一定的需求障碍( 根据 JSR168 用户信息可以很方便的扩展,这个需要再深入了解
4. 初步方案
4.1.      改良方案
通过修订/扩展上述PDM的几个表,并通过调整相关ojb的几个XML配置文件(请参考src_security/JETSPEED-INF/ojb/security_repository.xml),可以较为轻松的完成扩展。
但我个人并不倾向这么做,原因是:
1、  我们不熟悉OJB;
2、  我们并不打算在j2-admin中完善该管理过程——工作量不小,意义却不大;
3、  我们已经有比较好的机构用户管理模块,比如Ioa5中的实现。
4.2.      改革方案:与UUM的结合
从理论上说,这是可行的:
1、              可以通过实现GroupManager、UserManager、RoleManager接口,替换/扩展现有的几个默认实现(org.apache.jetspeed.security.impl.*ManagerImpl),达到控制几个对象的管理;
2、              可以通过替换/扩展现有的几个默认SPI实现(具体请参考org.apache.jetspeed.security.spi下的CredentialHandler、UserSecurityHandler、RoleSecurityHandler、GroupSecurityHandler等),达到DAO的效果,操作包括RDBMS/LDAP的数据访问和存取
5. 附件
5.1.      Login Module Implementation
The DefaultLoginModule implementation is illustrated by the class diagram below:
 
The roles of the classes used to implement the DefaultLoginModule are:
Class
Description
org.apache.jetspeed.security.impl.DefaultLoginModule
The javax.security.auth.spi.LoginModule implementation. The DefaultLoginModule authentication decision is encapsulated behind the UserManager interface which leverages the SPI implementation to decide which authenticator should be used in order to authenticate a user against a specific system of record. For more information on how to implement your own authenticator, see the authentication SPI documentation.
org.apache.jetspeed.security.LoginModuleProxy
A utility component used to expose the UserManager to the DefaultLoginModule .
org.apache.jetspeed.security.User
The User is an interface that holds the javax.security.auth.Subject and his/her java.util.prefs.Preferences . The UserManager upon user authentication populates the user subject with all user java.security.Principal . Jetspeed 2 implements 3 types of principals:
·   UserPrincipal: The principal holding the user unique identifier for the application.
·   RolePrincipal: The principal representing a role for the system.
·   GroupPrincipal: The principal representing a group for the system.
org.apache.jetspeed.security.UserManager
The interface exposing all user operations. This interfaces fronts the aggregates various SPI to provide developers with the ability to map users to their specific system of record.
 

你可能感兴趣的:(Jetspeed2)