dlestrat    2004/10/03 17:14:56

  Modified:    components/security/src/java/org/apache/jetspeed/security/impl
                        SecurityProviderImpl.java UserManagerImpl.java
                        AuthenticationProviderImpl.java
  Added:       components/security/src/java/org/apache/jetspeed/security/impl
                        DefaultLoginModule.java LoginModuleProxyImpl.java
                        AuthorizationProviderImpl.java
                        UserSecurityProviderImpl.java
  Removed:     components/security/src/java/org/apache/jetspeed/security/impl
                        RdbmsLoginModule.java
  Log:
  http://nagoya.apache.org/jira/browse/JS2-133
  
  Revision  Changes    Path
  1.5       +15 -52    
jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/SecurityProviderImpl.java
  
  Index: SecurityProviderImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/SecurityProviderImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SecurityProviderImpl.java 19 Sep 2004 19:04:11 -0000      1.4
  +++ SecurityProviderImpl.java 4 Oct 2004 00:14:56 -0000       1.5
  @@ -14,17 +14,12 @@
    */
   package org.apache.jetspeed.security.impl;
   
  -import java.security.Policy;
  -
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  -
   import org.apache.jetspeed.security.SecurityProvider;
  +import org.apache.jetspeed.security.UserSecurityProvider;
   import org.apache.jetspeed.security.spi.CredentialHandler;
   import org.apache.jetspeed.security.spi.GroupSecurityHandler;
   import org.apache.jetspeed.security.spi.RoleSecurityHandler;
   import org.apache.jetspeed.security.spi.SecurityMappingHandler;
  -import org.apache.jetspeed.security.spi.UserSecurityHandler;
   
   /**
    * @author <a href="">David Le Strat </a>
  @@ -33,73 +28,41 @@
   public class SecurityProviderImpl implements SecurityProvider
   {
   
  -    private static final Log log = LogFactory.getLog(SecurityProviderImpl.class);
  -
       /** The [EMAIL PROTECTED] CredentialHandler}. */
       private CredentialHandler credHandler;
   
  -    /** The [EMAIL PROTECTED] UserSecurityHandler}. */
  -    private UserSecurityHandler userSecurityHandler;
  +    /** The [EMAIL PROTECTED] UserSecurityProvider}. */
  +    private UserSecurityProvider userSecurityProvider;
   
       /** The [EMAIL PROTECTED] RoleSecurityHandler}. */
       private RoleSecurityHandler roleSecurityHandler;
   
       /** The [EMAIL PROTECTED] GroupSecurityHandler}. */
       private GroupSecurityHandler groupSecurityHandler;
  -    
  +
       /** The [EMAIL PROTECTED] SecurityMappingHandler}. */
       private SecurityMappingHandler securityMappingHandler;
   
       /**
        * <p>
  -     * Constructor configuring the security services with the correct
  -     * security handlers.
  +     * Constructor configuring the security services with the correct security
  +     * handlers.
        * </p>
        * 
        * @param credHandler The credential handler.
  -     * @param userSecurityHandler The user security handler.
  +     * @param userSecurityProvider The user security provider.
        * @param roleSecurityHandler The role security handler.
        * @param groupSecurityHandler The group security handler.
        * @param securityMappingHandler The security mapping handler.
        */
  -    public SecurityProviderImpl(CredentialHandler credHandler, UserSecurityHandler 
userSecurityHandler,
  -            RoleSecurityHandler roleSecurityHandler, GroupSecurityHandler 
groupSecurityHandler, SecurityMappingHandler securityMappingHandler)
  +    public SecurityProviderImpl(CredentialHandler credHandler, UserSecurityProvider 
userSecurityProvider,
  +            RoleSecurityHandler roleSecurityHandler, GroupSecurityHandler 
groupSecurityHandler,
  +            SecurityMappingHandler securityMappingHandler)
       {
           // The credential handler.
           this.credHandler = credHandler;
           // The user security handler.
  -        this.userSecurityHandler = userSecurityHandler;
  -        // The role security handler.
  -        this.roleSecurityHandler = roleSecurityHandler;
  -        // The group security handler.
  -        this.groupSecurityHandler = groupSecurityHandler;
  -        // The security mapping handler.
  -        this.securityMappingHandler = securityMappingHandler;
  -    }
  -    
  -    /**
  -     * <p>
  -     * Constructor configuring the security services with the correct
  -     * [EMAIL PROTECTED] Policy}and security handlers.
  -     * </p>
  -     * 
  -     * @param policy The policy.
  -     * @param credHandler The credential handler.
  -     * @param userSecurityHandler The user security handler.
  -     * @param roleSecurityHandler The role security handler.
  -     * @param groupSecurityHandler The group security handler.
  -     * @param securityMappingHandler The security mapping handler.
  -     */
  -    public SecurityProviderImpl(Policy policy, CredentialHandler credHandler, 
UserSecurityHandler userSecurityHandler,
  -            RoleSecurityHandler roleSecurityHandler, GroupSecurityHandler 
groupSecurityHandler, SecurityMappingHandler securityMappingHandler)
  -    {
  -        // The policy.
  -        Policy.setPolicy(policy);
  -        Policy.getPolicy().refresh();
  -        // The credential handler.
  -        this.credHandler = credHandler;
  -        // The user security handler.
  -        this.userSecurityHandler = userSecurityHandler;
  +        this.userSecurityProvider = userSecurityProvider;
           // The role security handler.
           this.roleSecurityHandler = roleSecurityHandler;
           // The group security handler.
  @@ -117,11 +80,11 @@
       }
   
       /**
  -     * @see org.apache.jetspeed.security.SecurityProvider#getUserSecurityHandler()
  +     * @see org.apache.jetspeed.security.SecurityProvider#getUserSecurityProvider()
        */
  -    public UserSecurityHandler getUserSecurityHandler()
  +    public UserSecurityProvider getUserSecurityProvider()
       {
  -        return this.userSecurityHandler;
  +        return this.userSecurityProvider;
       }
   
       /**
  @@ -139,7 +102,7 @@
       {
           return this.groupSecurityHandler;
       }
  -     
  +
       /**
        * @see 
org.apache.jetspeed.security.SecurityProvider#getSecurityMappingHandler()
        */
  
  
  
  1.12      +11 -11    
jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/UserManagerImpl.java
  
  Index: UserManagerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/UserManagerImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- UserManagerImpl.java      25 Sep 2004 23:03:17 -0000      1.11
  +++ UserManagerImpl.java      4 Oct 2004 00:14:56 -0000       1.12
  @@ -36,9 +36,9 @@
   import org.apache.jetspeed.security.User;
   import org.apache.jetspeed.security.UserManager;
   import org.apache.jetspeed.security.UserPrincipal;
  +import org.apache.jetspeed.security.UserSecurityProvider;
   import org.apache.jetspeed.security.spi.CredentialHandler;
   import org.apache.jetspeed.security.spi.SecurityMappingHandler;
  -import org.apache.jetspeed.security.spi.UserSecurityHandler;
   import org.apache.jetspeed.util.ArgUtil;
   
   /**
  @@ -53,8 +53,8 @@
   {
       private static final Log log = LogFactory.getLog(UserManagerImpl.class);
   
  -    /** The user security handler. */
  -    private UserSecurityHandler userSecurityHandler = null;
  +    /** The user security provider. */
  +    private UserSecurityProvider userSecurityProvider = null;
   
       /** The security mapping handler. */
       private SecurityMappingHandler securityMappingHandler = null;
  @@ -67,7 +67,7 @@
        */
       public UserManagerImpl(SecurityProvider securityProvider)
       {
  -        this.userSecurityHandler = securityProvider.getUserSecurityHandler();
  +        this.userSecurityProvider = securityProvider.getUserSecurityProvider();
           this.securityMappingHandler = securityProvider.getSecurityMappingHandler();
           this.credentialHandler = securityProvider.getCredentialHandler();
       }
  @@ -82,7 +82,7 @@
       {
           
securityProvider.getSecurityMappingHandler().setRoleHierarchyResolver(roleHierarchyResolver);
           
securityProvider.getSecurityMappingHandler().setGroupHierarchyResolver(groupHierarchyResolver);
  -        this.userSecurityHandler = securityProvider.getUserSecurityHandler();
  +        this.userSecurityProvider = securityProvider.getUserSecurityProvider();
           this.securityMappingHandler = securityProvider.getSecurityMappingHandler();
           this.credentialHandler = securityProvider.getCredentialHandler();
       }
  @@ -149,7 +149,7 @@
               if ((null != preferences) && 
preferences.absolutePath().equals(fullPath))
               {
                   // Add user principal.
  -                userSecurityHandler.setUserPrincipal(userPrincipal);
  +                userSecurityProvider.setUserPrincipal(userPrincipal);
                   // Set security credentials
                   PasswordCredential pwdCredential = new PasswordCredential(username, 
password.toCharArray());
                   credentialHandler.setPrivatePasswordCredential(null, pwdCredential);
  @@ -188,7 +188,7 @@
   
           UserPrincipal userPrincipal = new UserPrincipalImpl(username);
           String fullPath = userPrincipal.getFullPath();
  -        userSecurityHandler.removeUserPrincipal(userPrincipal);
  +        userSecurityProvider.removeUserPrincipal(userPrincipal);
           if (!userExists(username))
           {
               // Remove preferences
  @@ -217,7 +217,7 @@
       {
           ArgUtil.notNull(new Object[] { username }, new String[] { "username" }, 
"userExists(java.lang.String)");
   
  -        Principal principal = userSecurityHandler.getUserPrincipal(username);
  +        Principal principal = userSecurityProvider.getUserPrincipal(username);
           boolean userExists = (null != principal);
           if (log.isDebugEnabled())
           {
  @@ -237,7 +237,7 @@
           Set principals = new HashSet();
           String fullPath = (new UserPrincipalImpl(username)).getFullPath();
   
  -        Principal userPrincipal = userSecurityHandler.getUserPrincipal(username);
  +        Principal userPrincipal = userSecurityProvider.getUserPrincipal(username);
           if (null == userPrincipal)
           {
               throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST + " " 
+ username);
  @@ -261,7 +261,7 @@
       public Iterator getUsers(String filter) throws SecurityException
       {
           List users = new LinkedList();
  -        Iterator userPrincipals = userSecurityHandler.getUserPrincipals(filter);
  +        Iterator userPrincipals = userSecurityProvider.getUserPrincipals(filter);
           while (userPrincipals.hasNext())
           {
               String username = ((Principal) userPrincipals.next()).getName();
  
  
  
  1.2       +16 -26    
jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/AuthenticationProviderImpl.java
  
  Index: AuthenticationProviderImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/AuthenticationProviderImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AuthenticationProviderImpl.java   18 Sep 2004 19:33:58 -0000      1.1
  +++ AuthenticationProviderImpl.java   4 Oct 2004 00:14:56 -0000       1.2
  @@ -15,6 +15,8 @@
   package org.apache.jetspeed.security.impl;
   
   import java.net.URL;
  +import java.util.ArrayList;
  +import java.util.List;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -22,36 +24,29 @@
   import org.apache.jetspeed.components.util.system.SystemResourceUtil;
   import org.apache.jetspeed.components.util.system.ClassLoaderSystemResourceUtilImpl;
   import org.apache.jetspeed.security.AuthenticationProvider;
  -import org.apache.jetspeed.security.SecurityProvider;
  -import org.apache.jetspeed.security.UserManager;
   
   /**
  - * @author <a href="">David Le Strat </a>
  - *  
  + * @see org.apache.jetspeed.security.AuthenticationProvider
  + * @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat </a> 
    */
   public class AuthenticationProviderImpl implements AuthenticationProvider
   {
   
  +    /** The logger. */
       private static final Log log = 
LogFactory.getLog(AuthenticationProviderImpl.class);
   
  -    /** The [EMAIL PROTECTED] SecurityProvider}instance. */
  -    static AuthenticationProvider authenticationProvider;
  -
  -    /** The [EMAIL PROTECTED] UserManager}. */
  -    private UserManager userMgr;
  -
  +    /** The list of login modules. */
  +    private List loginModules = new ArrayList();
  +    
       /**
        * <p>
        * Constructor configuring the security service with the correct
  -     * <code>java.security.auth.login.config</code> and providing a bridge
  -     * between the login module and the security components.
  +     * <code>java.security.auth.login.config</code>.
        * </p>
        * 
        * @param loginConfig The login module config.
  -     * @param userMgr The user manager.
  -
        */
  -    public AuthenticationProviderImpl(String loginConfig, UserManager userMgr)
  +    public AuthenticationProviderImpl(String loginConfig)
       {
           ClassLoader cl = Thread.currentThread().getContextClassLoader();
           SystemResourceUtil resourceUtil = new ClassLoaderSystemResourceUtilImpl(cl);
  @@ -70,21 +65,16 @@
               if (log.isDebugEnabled())
                   log.debug("java.security.auth.login.config = " + 
loginConfigUrl.toString());
               System.setProperty("java.security.auth.login.config", 
loginConfigUrl.toString());
  +            // TODO This is incorect but will do for now.
  +            loginModules.add(loginConfigUrl.toString());
           }
  -        // The user manager.
  -        this.userMgr = userMgr;
  -        
  -        // Hack providing access to the UserManager in the LoginModule.
  -        // TODO Can we fix this?
  -        AuthenticationProviderImpl.authenticationProvider = this;
       }
  -
  +   
       /**
  -     * @see org.apache.jetspeed.security.SecurityProvider#getUserManager()
  +     * @see org.apache.jetspeed.security.AuthenticationProvider#getLoginModules()
        */
  -    public UserManager getUserManager()
  +    public List getLoginModules()
       {
  -        return this.userMgr;
  +        return this.loginModules;
       }
  -
   }
  
  
  
  1.1                  
jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/DefaultLoginModule.java
  
  Index: DefaultLoginModule.java
  ===================================================================
  /* Copyright 2004 Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.security.impl;
  
  import java.util.Map;
  
  import javax.security.auth.Subject;
  import javax.security.auth.callback.Callback;
  import javax.security.auth.callback.CallbackHandler;
  import javax.security.auth.callback.NameCallback;
  import javax.security.auth.callback.PasswordCallback;
  import javax.security.auth.login.LoginException;
  import javax.security.auth.spi.LoginModule;
  
  import org.apache.jetspeed.security.LoginModuleProxy;
  import org.apache.jetspeed.security.UserManager;
  
  /**
   * <p>LoginModule implementation that authenticates a user
   * against a relational database. OJB based implementation.</p>
   * <p>When a user is successfully authenticated, the user principal
   * are added to the current subject.</p>
   * <p>The LoginModule also recognizes the debug option.</p>
   * <p>Configuration files should provide:</p>
   * <pre><code>
   * Jetspeed {
   *   org.apache.jetspeed.security.impl.DefaultLoginModule required debug=true;
   * };
   * </code></pre>
   * @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat</a>
   */
  public class DefaultLoginModule implements LoginModule
  {
  
      /** <p>LoginModule debug mode is turned off by default.</p> */
      private boolean debug;
  
      /** <p>The authentication status.</p> */
      private boolean success;
  
      /** <p>The commit status.</p> */
      private boolean commitSuccess;
  
      /** <p>The Subject to be authenticated.</p> */
      private Subject subject;
  
      /** <p>A CallbackHandler for communicating with the end user (prompting for 
usernames and passwords, for example).</p> */
      private CallbackHandler callbackHandler;
  
      /** <p>State shared with other configured LoginModules.</p> */
      private Map sharedState;
  
      /** <p>Options specified in the login Configuration for this particular 
LoginModule.</p> */
      private Map options;
  
      /** <p>InternalUserPrincipal manager service.</p> */
      private UserManager ums;
  
      /** <p>The user name.</p> */
      private String username;
  
      /**
       * <p>The default login module constructor.</p>
       */
      public DefaultLoginModule()
      {
          LoginModuleProxy loginModuleProxy = LoginModuleProxyImpl.loginModuleProxy;
          this.ums = loginModuleProxy.getUserManager();
          debug = false;
          success = false;
          commitSuccess = false;
          username = null;
      }
  
      /**
       * @see javax.security.auth.spi.LoginModule#abort()
       */
      public boolean abort() throws LoginException
      {
          // Clean out state
          success = false;
          commitSuccess = false;
          username = null;
          if (callbackHandler instanceof PassiveCallbackHandler)
          {
              ((PassiveCallbackHandler) callbackHandler).clearPassword();
          }
          logout();
          return true;
      }
  
      /**
       * @see javax.security.auth.spi.LoginModule#commit()
       */
      public boolean commit() throws LoginException
      {
          if (success)
          {
              if (subject.isReadOnly())
              {
                  throw new LoginException("Subject is Readonly");
              }
              try
              {
                  // TODO We should get the user profile here and had it in cache so 
that we do not have to retrieve it again.
                  // TODO Ideally the User should be available from the session.  Need 
discussion around this.
                  
subject.getPrincipals().addAll(ums.getUser(username).getSubject().getPrincipals());
  
                  username = null;
                  commitSuccess = true;
  
                  if (callbackHandler instanceof PassiveCallbackHandler)
                  {
                      ((PassiveCallbackHandler) callbackHandler).clearPassword();
                  }
  
              }
              catch (Exception ex)
              {
                  ex.printStackTrace(System.out);
                  throw new LoginException(ex.getMessage());
              }
          }
  
          return commitSuccess;
      }
  
      /**
       * @see javax.security.auth.spi.LoginModule#login()
       */
      public boolean login() throws LoginException
      {
          if (callbackHandler == null)
          {
              throw new LoginException("Error: no CallbackHandler available " + "to 
garner authentication information from the user");
          }
          try
          {
              // Setup default callback handlers.
              Callback[] callbacks = new Callback[] { new NameCallback("Username: "), 
new PasswordCallback("Password: ", false)};
  
              callbackHandler.handle(callbacks);
  
              username = ((NameCallback) callbacks[0]).getName();
              String password = new String(((PasswordCallback) 
callbacks[1]).getPassword());
  
              ((PasswordCallback) callbacks[1]).clearPassword();
  
              success = ums.authenticate(this.username, password);
  
              callbacks[0] = null;
              callbacks[1] = null;
              if (!success)
              {
                  throw new LoginException("Authentication failed: Password does not 
match");
              }
  
              return (true);
          }
          catch (LoginException ex)
          {
              throw ex;
          }
          catch (Exception ex)
          {
              success = false;
              throw new LoginException(ex.getMessage());
          }
      }
  
      /**
       * @see javax.security.auth.spi.LoginModule#logout()
       */
      public boolean logout() throws LoginException
      {
          // TODO Can we set subject to null?
          subject.getPrincipals().clear();
          subject.getPrivateCredentials().clear();
          subject.getPublicCredentials().clear();
          success = false;
          commitSuccess = false;
  
          return true;
      }
  
      /**
       * @see 
javax.security.auth.spi.LoginModule#initialize(javax.security.auth.Subject, 
javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map)
       */
      public void initialize(Subject subject, CallbackHandler callbackHandler, Map 
sharedState, Map options)
      {
          this.subject = subject;
          this.callbackHandler = callbackHandler;
          this.sharedState = sharedState;
          this.options = options;
  
          // Initialize debug mode if configure option.
          if (options.containsKey("debug"))
          {
              debug = "true".equalsIgnoreCase((String) options.get("debug"));
          }
      }
  
  }
  
  
  
  1.1                  
jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/LoginModuleProxyImpl.java
  
  Index: LoginModuleProxyImpl.java
  ===================================================================
  /* Copyright 2004 Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.security.impl;
  
  import org.apache.jetspeed.security.LoginModuleProxy;
  import org.apache.jetspeed.security.UserManager;
  
  /**
   * @see org.apache.jetspeed.security.LoginModuleProxy
   * @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat </a>
   */
  public class LoginModuleProxyImpl implements LoginModuleProxy
  {
  
      /** The [EMAIL PROTECTED] LoginModuleProxy}instance. */
      static LoginModuleProxy loginModuleProxy;
  
      /** The [EMAIL PROTECTED] UserManager}. */
      private UserManager userMgr;
  
      /**
       * <p>
       * Constructor providing a bridge between the login module and the user
       * manager.
       * </p>
       * 
       * @param loginConfig The login module config.
       * @param userMgr The user manager.
       *  
       */
      public LoginModuleProxyImpl(UserManager userMgr)
      {
          // The user manager.
          this.userMgr = userMgr;
  
          // Hack providing access to the UserManager in the LoginModule.
          // TODO Can we fix this?
          LoginModuleProxyImpl.loginModuleProxy = this;
      }
  
      /**
       * @see org.apache.jetspeed.security.LoginModuleProxy#getUserManager()
       */
      public UserManager getUserManager()
      {
          return this.userMgr;
      }
  
  }
  
  
  1.1                  
jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/AuthorizationProviderImpl.java
  
  Index: AuthorizationProviderImpl.java
  ===================================================================
  /* Copyright 2004 Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
  package org.apache.jetspeed.security.impl;
  
  import java.security.Policy;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.jetspeed.security.AuthorizationProvider;
  
  /**
   * @see org.apache.jetspeed.security.AuthorizationProvider
   * @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat </a> 
   */
  public class AuthorizationProviderImpl implements AuthorizationProvider
  {
  
      /** The list of [EMAIL PROTECTED] Policy}. */
      private List policies = new ArrayList();
      
      public AuthorizationProviderImpl(Policy policy)
      {
          // The policy.
          Policy.setPolicy(policy);
          Policy.getPolicy().refresh();
          
          policies.add(policy);
      }
      
      /**
       * @see org.apache.jetspeed.security.AuthorizationProvider#getPolicies()
       */
      public List getPolicies()
      {
          return policies;
      }
  
  }
  
  
  
  1.1                  
jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/UserSecurityProviderImpl.java
  
  Index: UserSecurityProviderImpl.java
  ===================================================================
  /* Copyright 2004 Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
  package org.apache.jetspeed.security.impl;
  
  import java.security.Principal;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.jetspeed.security.SecurityException;
  import org.apache.jetspeed.security.UserPrincipal;
  import org.apache.jetspeed.security.UserSecurityProvider;
  import org.apache.jetspeed.security.spi.UserSecurityHandler;
  
  /**
   * @see org.apache.jetspeed.security.UserSecurityProvider
   * @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat</a>
   */
  public class UserSecurityProviderImpl implements UserSecurityProvider
  {
      /** The list of [EMAIL PROTECTED] UserSecurityHandler}. */
      private List userSecurityHandlers = new ArrayList();
      
      /**
       * <p>Constructor providing the configured [EMAIL PROTECTED] 
UserSecurityHandler}.</p>
       */
      public UserSecurityProviderImpl(List userSecurityHandlers)
      {
          this.userSecurityHandlers = userSecurityHandlers;
      }
      
      /**
       * @see 
org.apache.jetspeed.security.UserSecurityProvider#getUserSecurityHandlers()
       */
      public List getUserSecurityHandlers()
      {
          return this.userSecurityHandlers;
      }
  
      /**
       * @see 
org.apache.jetspeed.security.spi.UserSecurityHandler#getUserPrincipal(java.lang.String)
       */
      public Principal getUserPrincipal(String username)
      {
          Principal userPrincipal = null;
          
          for (int i = 0; i < userSecurityHandlers.size(); i++)
          {
              UserSecurityHandler userSecurityHandler = (UserSecurityHandler) 
userSecurityHandlers.get(i);
              userPrincipal = userSecurityHandler.getUserPrincipal(username);
          }
              
          return userPrincipal;
      }
  
      /**
       * @see 
org.apache.jetspeed.security.spi.UserSecurityHandler#getUserPrincipals(java.lang.String)
       */
      public Iterator getUserPrincipals(String filter)
      {
          Iterator userPrincipals = (new ArrayList()).iterator();
          
          for (int i = 0; i < userSecurityHandlers.size(); i++)
          {
              UserSecurityHandler userSecurityHandler = (UserSecurityHandler) 
userSecurityHandlers.get(i);
              userPrincipals = userSecurityHandler.getUserPrincipals(filter);
          }
  
          return userPrincipals;
      }
  
      /**
       * @see 
org.apache.jetspeed.security.spi.UserSecurityHandler#setUserPrincipal(org.apache.jetspeed.security.UserPrincipal)
       */
      public void setUserPrincipal(UserPrincipal userPrincipal) throws 
SecurityException
      {
          for (int i = 0; i < userSecurityHandlers.size(); i++)
          {
              UserSecurityHandler userSecurityHandler = (UserSecurityHandler) 
userSecurityHandlers.get(i);
              userSecurityHandler.setUserPrincipal(userPrincipal);
          }
      }
  
      /**
       * @see 
org.apache.jetspeed.security.spi.UserSecurityHandler#removeUserPrincipal(org.apache.jetspeed.security.UserPrincipal)
       */
      public void removeUserPrincipal(UserPrincipal userPrincipal) throws 
SecurityException
      {
          for (int i = 0; i < userSecurityHandlers.size(); i++)
          {
              UserSecurityHandler userSecurityHandler = (UserSecurityHandler) 
userSecurityHandlers.get(i);
              userSecurityHandler.removeUserPrincipal(userPrincipal);
          }
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to