View Javadoc

1   /* Copyright 2004, 2005 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity.providers.dao.salt;
17  
18  import org.acegisecurity.providers.dao.SaltSource;
19  import org.acegisecurity.userdetails.UserDetails;
20  
21  import org.springframework.beans.factory.InitializingBean;
22  
23  
24  /***
25   * Uses a static system-wide <code>String</code> as the salt.
26   * 
27   * <P>
28   * Does not supply a different salt for each {@link User}. This means users
29   * sharing the same password will still have the same digested password. Of
30   * benefit is the digested passwords will at least be more protected than if
31   * stored without any salt.
32   * </p>
33   *
34   * @author Ben Alex
35   * @version $Id: SystemWideSaltSource.java,v 1.6 2005/11/29 13:10:12 benalex Exp $
36   */
37  public class SystemWideSaltSource implements SaltSource, InitializingBean {
38      //~ Instance fields ========================================================
39  
40      private String systemWideSalt;
41  
42      //~ Methods ================================================================
43  
44      public Object getSalt(UserDetails user) {
45          return this.systemWideSalt;
46      }
47  
48      public void setSystemWideSalt(String systemWideSalt) {
49          this.systemWideSalt = systemWideSalt;
50      }
51  
52      public String getSystemWideSalt() {
53          return this.systemWideSalt;
54      }
55  
56      public void afterPropertiesSet() throws Exception {
57          if ((this.systemWideSalt == null) || "".equals(this.systemWideSalt)) {
58              throw new IllegalArgumentException("A systemWideSalt must be set");
59          }
60      }
61  }