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.core.authn;
21  
22  
23  import java.net.SocketAddress;
24  
25  import org.apache.directory.api.ldap.model.constants.AuthenticationLevel;
26  import org.apache.directory.api.ldap.model.exception.LdapAuthenticationException;
27  import org.apache.directory.api.ldap.model.name.Dn;
28  import org.apache.directory.server.core.api.LdapPrincipal;
29  import org.apache.directory.server.core.api.interceptor.context.BindOperationContext;
30  import org.apache.mina.core.session.IoSession;
31  
32  
33  /**
34   * An {@link Authenticator} that handles SASL connections (X.501 authentication
35   * level <tt>'strong'</tt>).  The principal has been authenticated during SASL
36   * negotiation; therefore, no additional authentication is necessary in this
37   * {@link Authenticator}.
38   * 
39   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
40   */
41  public class StrongAuthenticator extends AbstractAuthenticator
42  {
43      /**
44       * Creates a new instance.
45       */
46      public StrongAuthenticator()
47      {
48          super( AuthenticationLevel.STRONG );
49      }
50  
51  
52      /**
53       * Creates a new instance of SaslAuthenticator.
54       * 
55       * @param baseDn The base Dn
56       */
57      public StrongAuthenticator( Dn baseDn )
58      {
59          super( AuthenticationLevel.STRONG, baseDn );
60      }
61  
62  
63      /**
64       * User has already been authenticated during SASL negotiation. Set the authentication level
65       * to strong and return an {@link LdapPrincipal}.
66       */
67      @Override
68      public LdapPrincipal authenticate( BindOperationContext bindContext ) throws LdapAuthenticationException
69      {
70          // Possibly check if user account is disabled, other account checks.
71          LdapPrincipal/api/LdapPrincipal.html#LdapPrincipal">LdapPrincipal principal = new LdapPrincipal( getDirectoryService().getSchemaManager(), bindContext.getDn(),
72              AuthenticationLevel.STRONG );
73  
74          IoSession session = bindContext.getIoSession();
75  
76          if ( session != null )
77          {
78              SocketAddress clientAddress = session.getRemoteAddress();
79              principal.setClientAddress( clientAddress );
80              SocketAddress serverAddress = session.getServiceAddress();
81              principal.setServerAddress( serverAddress );
82          }
83  
84          return principal;
85      }
86  }