View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  package org.apache.directory.server.config.beans;
21  
22  
23  import java.util.Arrays;
24  import java.util.HashSet;
25  import java.util.Set;
26  
27  
28  import org.apache.directory.server.config.ConfigurationElement;
29  
30  
31  /**
32   * A bean used to store the hash interceptor configuration
33   *
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   */
36  public class HashInterceptorBean extends InterceptorBean
37  {
38      /** The hash algorithm */
39      @ConfigurationElement(attributeType = "ads-hashAlgorithm", isOptional = true, defaultValue = "SSHA-256" )
40      private String hashAlgorithm;
41  
42      /** The reference to the Password Policy component */
43      @ConfigurationElement(attributeType = "ads-hashAttribute", isOptional = true, defaultValues = {"2.5.4.35"} )
44      private Set<String> hashAttributes = new HashSet<>();
45  
46  
47      /**
48       * Creates a new AuthenticationInterceptorBean instance
49       */
50      public HashInterceptorBean()
51      {
52          super();
53      }
54  
55  
56      /**
57       * @param hashAttributes The attributes that need to be hashed
58       */
59      public void addHashAttributes( String[] hashAttributes )
60      {
61          if ( hashAttributes != null && hashAttributes.length > 0 ) 
62          {
63              if ( this.hashAttributes == null ) 
64              {
65                  this.hashAttributes = new HashSet<>();
66              }
67              this.hashAttributes.addAll( Arrays.asList( hashAttributes ) );
68          }
69      }
70  
71  
72      /**
73       * @return the hash algorithm
74       */
75      public String getHashAlgorithm()
76      {
77          return hashAlgorithm;
78      }
79  
80  
81      /**
82       * @return the attributes to hash
83       */
84      public Set<String> getHashAttributes()
85      {
86          return hashAttributes;
87      }
88  
89  
90      /**
91       * @param hashAlgorithm The hash algorithm to use
92       */
93      public void setHashAlgorithm( String hashAlgorithm )
94      {
95          this.hashAlgorithm = hashAlgorithm;
96      }
97  
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public String toString( String tabs )
104     {
105         StringBuilder sb = new StringBuilder();
106 
107         sb.append( tabs ).append( "HashInterceptor :\n" );
108         sb.append( super.toString( tabs + "  " ) );
109 
110         if ( hashAlgorithm != null )
111         {
112             sb.append( tabs ).append( "  hashAlgorithm : " )
113                     .append( hashAlgorithm ).append( "\n" );
114         }
115         if ( ( hashAttributes != null ) && !hashAttributes.isEmpty() )
116         {
117             sb.append( tabs ).append( "  hashAttributes :\n" );
118 
119             for ( String hashAttribute : hashAttributes )
120             {
121                 sb.append( tabs ).append( "    " ).append( hashAttribute );
122             }
123         }
124 
125         return sb.toString();
126     }
127 }