1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.sun.security.sasl;
26
27 import java.security.AccessController;
28 import java.security.PrivilegedAction;
29
30 /**
31 * The SASL provider.
32 * Provides client support for
33 * - EXTERNAL
34 * - PLAIN
35 * - CRAM-MD5
36 * - DIGEST-MD5
37 * - GSSAPI/Kerberos v5
38 * - NTLM
39 * And server support for
40 * - CRAM-MD5
41 * - DIGEST-MD5
42 * - GSSAPI/Kerberos v5
43 * - NTLM
44 */
45
46 public final class Provider extends java.security.Provider {
47
48 private static final long serialVersionUID = 8622598936488630849L;
49
50 private static final String info = "Sun SASL provider" +
51 "(implements client mechanisms for: " +
52 "DIGEST-MD5, GSSAPI, EXTERNAL, PLAIN, CRAM-MD5, NTLM;" +
53 " server mechanisms for: DIGEST-MD5, GSSAPI, CRAM-MD5, NTLM)";
54
55 public Provider() {
56 super("SunSASL", 1.9d, info);
57
58 AccessController.doPrivileged(new PrivilegedAction<Void>() {
59 public Void run() {
60 // Client mechanisms
61 put("SaslClientFactory.DIGEST-MD5",
62 "com.sun.security.sasl.digest.FactoryImpl");
63 put("SaslClientFactory.NTLM",
64 "com.sun.security.sasl.ntlm.FactoryImpl");
65 put("SaslClientFactory.GSSAPI",
66 "com.sun.security.sasl.gsskerb.FactoryImpl");
67
68 put("SaslClientFactory.EXTERNAL",
69 "com.sun.security.sasl.ClientFactoryImpl");
70 put("SaslClientFactory.PLAIN",
71 "com.sun.security.sasl.ClientFactoryImpl");
72 put("SaslClientFactory.CRAM-MD5",
73 "com.sun.security.sasl.ClientFactoryImpl");
74
75 // Server mechanisms
76 put("SaslServerFactory.CRAM-MD5",
77 "com.sun.security.sasl.ServerFactoryImpl");
78 put("SaslServerFactory.GSSAPI",
79 "com.sun.security.sasl.gsskerb.FactoryImpl");
80 put("SaslServerFactory.DIGEST-MD5",
81 "com.sun.security.sasl.digest.FactoryImpl");
82 put("SaslServerFactory.NTLM",
83 "com.sun.security.sasl.ntlm.FactoryImpl");
84 return null;
85 }
86 });
87 }
88 }
|
1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.sun.security.sasl;
26
27 import java.security.AccessController;
28 import java.security.PrivilegedAction;
29 import java.security.NoSuchAlgorithmException;
30 import java.security.InvalidParameterException;
31 import java.security.ProviderException;
32
33 /**
34 * The SASL provider.
35 * Provides client support for
36 * - EXTERNAL
37 * - PLAIN
38 * - CRAM-MD5
39 * - DIGEST-MD5
40 * - NTLM
41 * And server support for
42 * - CRAM-MD5
43 * - DIGEST-MD5
44 * - NTLM
45 */
46
47 public final class Provider extends java.security.Provider {
48
49 private static final long serialVersionUID = 8622598936488630849L;
50
51 private static final String info = "Sun SASL provider" +
52 "(implements client mechanisms for: " +
53 "DIGEST-MD5, EXTERNAL, PLAIN, CRAM-MD5, NTLM;" +
54 " server mechanisms for: DIGEST-MD5, CRAM-MD5, NTLM)";
55
56 private static final class ProviderService
57 extends java.security.Provider.Service {
58 ProviderService(java.security.Provider p, String type, String algo,
59 String cn) {
60 super(p, type, algo, cn, null, null);
61 }
62
63 @Override
64 public Object newInstance(Object ctrParamObj)
65 throws NoSuchAlgorithmException {
66 String type = getType();
67 if (ctrParamObj != null) {
68 throw new InvalidParameterException
69 ("constructorParameter not used with " + type + " engines");
70 }
71
72 String algo = getAlgorithm();
73 try {
74 // DIGEST-MD5, NTLM uses same impl class for client and server
75 if (algo.equals("DIGEST-MD5")) {
76 return new com.sun.security.sasl.digest.FactoryImpl();
77 }
78 if (algo.equals("NTLM")) {
79 return new com.sun.security.sasl.ntlm.FactoryImpl();
80 }
81 if (type.equals("SaslClientFactory")) {
82 if (algo.equals("EXTERNAL") || algo.equals("PLAIN") ||
83 algo.equals("CRAM-MD5")) {
84 return new com.sun.security.sasl.ClientFactoryImpl();
85 }
86 } else if (type.equals("SaslServerFactory")) {
87 if (algo.equals("CRAM-MD5")) {
88 return new com.sun.security.sasl.ServerFactoryImpl();
89 }
90 }
91 } catch (Exception ex) {
92 throw new NoSuchAlgorithmException("Error constructing " +
93 type + " for " + algo + " using SunSASL", ex);
94 }
95 throw new ProviderException("No impl for " + algo +
96 " " + type);
97 }
98 }
99
100 public Provider() {
101 super("SunSASL", 1.9d, info);
102
103 final Provider p = this;
104 AccessController.doPrivileged(new PrivilegedAction<Void>() {
105 public Void run() {
106 // Client mechanisms
107 putService(new ProviderService(p, "SaslClientFactory",
108 "DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl"));
109 putService(new ProviderService(p, "SaslClientFactory",
110 "NTLM", "com.sun.security.sasl.ntlm.FactoryImpl"));
111 putService(new ProviderService(p, "SaslClientFactory",
112 "EXTERNAL", "com.sun.security.sasl.ClientFactoryImpl"));
113 putService(new ProviderService(p, "SaslClientFactory",
114 "PLAIN", "com.sun.security.sasl.ClientFactoryImpl"));
115 putService(new ProviderService(p, "SaslClientFactory",
116 "CRAM-MD5", "com.sun.security.sasl.ClientFactoryImpl"));
117
118 // Server mechanisms
119 putService(new ProviderService(p, "SaslServerFactory",
120 "CRAM-MD5", "com.sun.security.sasl.ServerFactoryImpl"));
121 putService(new ProviderService(p, "SaslServerFactory",
122 "DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl"));
123 putService(new ProviderService(p, "SaslServerFactory",
124 "NTLM", "com.sun.security.sasl.ntlm.FactoryImpl"));
125 return null;
126 }
127 });
128 }
129 }
|