View Javadoc

1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8   *
9   *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17  package org.apache.jetspeed.security.spi.impl;
18  
19  import java.util.Collection;
20  import java.util.List;
21  
22  import org.apache.jetspeed.security.SecurityException;
23  import org.apache.jetspeed.security.om.InternalCredential;
24  import org.apache.jetspeed.security.om.InternalUserPrincipal;
25  import org.apache.jetspeed.security.spi.InternalPasswordCredentialInterceptor;
26  import org.apache.jetspeed.security.spi.PasswordCredentialProvider;
27  
28  /***
29   * <p>
30   * Provides a wrapper around a list of interceptors so multiple interceptors can
31   * be used with the {@link DefaultCredentialHandler}.
32   * Each interceptor will be invoked sequentially.
33   * </p>
34   * 
35   * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
36   * @version $Id$
37   */
38  public class InternalPasswordCredentialInterceptorsProxy implements InternalPasswordCredentialInterceptor
39  {
40      private InternalPasswordCredentialInterceptor[] interceptors;
41  
42      public InternalPasswordCredentialInterceptorsProxy(List interceptors)
43      {
44          this.interceptors = (InternalPasswordCredentialInterceptor[]) interceptors
45                  .toArray(new InternalPasswordCredentialInterceptor[interceptors.size()]);
46      }
47  
48      /***
49       * @see org.apache.jetspeed.security.spi.InternalPasswordCredentialInterceptor#afterLoad(org.apache.jetspeed.security.spi.PasswordCredentialProvider, java.lang.String, org.apache.jetspeed.security.om.InternalCredential)
50       */
51      public boolean afterLoad(PasswordCredentialProvider pcProvider, String userName, InternalCredential credential)
52              throws SecurityException
53      {
54          boolean updated = false;
55          for (int i = 0; i < interceptors.length; i++)
56          {
57              if (interceptors[i] != null && interceptors[i].afterLoad(pcProvider, userName, credential))
58              {
59                  updated = true;
60              }
61          }
62          return updated;
63      }
64  
65      /***
66       * @see org.apache.jetspeed.security.spi.InternalPasswordCredentialInterceptor#afterAuthenticated(org.apache.jetspeed.security.om.InternalUserPrincipal, java.lang.String, org.apache.jetspeed.security.om.InternalCredential, boolean)
67       */
68      public boolean afterAuthenticated(InternalUserPrincipal internalUser, String userName,
69              InternalCredential credential, boolean authenticated) throws SecurityException
70      {
71          boolean updated = false;
72          for (int i = 0; i < interceptors.length; i++)
73          {
74              if (interceptors[i] != null
75                      && interceptors[i].afterAuthenticated(internalUser, userName, credential, authenticated))
76              {
77                  updated = true;
78              }
79          }
80          return updated;
81      }
82  
83      /***
84       * @see org.apache.jetspeed.security.spi.InternalPasswordCredentialInterceptor#beforeCreate(org.apache.jetspeed.security.om.InternalUserPrincipal, java.util.Collection, java.lang.String, InternalCredential, java.lang.String)
85       */
86      public void beforeCreate(InternalUserPrincipal internalUser, Collection credentials, String userName,
87              InternalCredential credential, String password) throws SecurityException
88      {
89          for (int i = 0; i < interceptors.length; i++)
90          {
91              if (interceptors[i] != null)
92              {
93                  interceptors[i].beforeCreate(internalUser, credentials, userName, credential, password);
94              }
95          }
96      }
97  
98      /***
99       * @see org.apache.jetspeed.security.spi.InternalPasswordCredentialInterceptor#beforeSetPassword(org.apache.jetspeed.security.om.InternalUserPrincipal, java.util.Collection, java.lang.String, org.apache.jetspeed.security.om.InternalCredential, java.lang.String, boolean)
100      */
101     public void beforeSetPassword(InternalUserPrincipal internalUser, Collection credentials, String userName,
102             InternalCredential credential, String password, boolean authenticated) throws SecurityException
103     {
104         for (int i = 0; i < interceptors.length; i++)
105         {
106             if (interceptors[i] != null)
107             {
108                 interceptors[i].beforeSetPassword(internalUser, credentials, userName, credential, password,
109                         authenticated);
110             }
111         }
112     }
113 }