View Javadoc
1   /*
2    * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
3    * Copyright (C) 2010  Mickael Guessant
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  
20  package davmail.http;
21  
22  import org.apache.http.auth.AuthScheme;
23  import org.apache.http.auth.AuthSchemeFactory;
24  import org.apache.http.auth.AuthSchemeProvider;
25  import org.apache.http.params.HttpParams;
26  import org.apache.http.protocol.HttpContext;
27  
28  /**
29   * Override native SPNegoSchemeFactory to load DavMail specific Kerberos settings.
30   */
31  public class DavMailSPNegoSchemeFactory implements AuthSchemeFactory, AuthSchemeProvider {
32  
33      private final boolean stripPort;
34      private final boolean useCanonicalHostname;
35  
36      /**
37       * @since 4.4
38       */
39      public DavMailSPNegoSchemeFactory(final boolean stripPort, final boolean useCanonicalHostname) {
40          super();
41          this.stripPort = stripPort;
42          this.useCanonicalHostname = useCanonicalHostname;
43      }
44  
45      public DavMailSPNegoSchemeFactory(final boolean stripPort) {
46          super();
47          this.stripPort = stripPort;
48          this.useCanonicalHostname = true;
49      }
50  
51      public DavMailSPNegoSchemeFactory() {
52          this(true, true);
53      }
54  
55      public boolean isStripPort() {
56          return stripPort;
57      }
58  
59      public boolean isUseCanonicalHostname() {
60          return useCanonicalHostname;
61      }
62  
63      @Override
64      public AuthScheme newInstance(final HttpParams params) {
65          return new DavMailSPNegoScheme(this.stripPort, this.useCanonicalHostname);
66      }
67  
68      @Override
69      public AuthScheme create(final HttpContext context) {
70          return new DavMailSPNegoScheme(this.stripPort, this.useCanonicalHostname);
71      }
72  
73  }