1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package davmail.http;
20
21 import org.apache.log4j.Logger;
22
23 import javax.security.auth.login.AppConfigurationEntry;
24 import javax.security.auth.login.Configuration;
25 import java.util.HashMap;
26
27
28
29
30
31
32
33
34
35
36
37
38 public class KerberosLoginConfiguration extends Configuration {
39 protected static final Logger LOGGER = Logger.getLogger(KerberosLoginConfiguration.class);
40 protected static final AppConfigurationEntry[] CLIENT_LOGIN_MODULE;
41 protected static final AppConfigurationEntry[] SERVER_LOGIN_MODULE;
42
43 static {
44 HashMap<String, String> clientLoginModuleOptions = new HashMap<>();
45 if (LOGGER.isDebugEnabled()) {
46 clientLoginModuleOptions.put("debug", "true");
47 }
48
49 clientLoginModuleOptions.put("useTicketCache", "true");
50 clientLoginModuleOptions.put("renewTGT", "true");
51
52 String krb5ccName = System.getenv().get("KRB5CCNAME");
53 if (krb5ccName != null && !krb5ccName.isEmpty()) {
54 clientLoginModuleOptions.put("ticketCache", krb5ccName);
55 }
56
57
58
59 CLIENT_LOGIN_MODULE = new AppConfigurationEntry[]{new AppConfigurationEntry(
60 "com.sun.security.auth.module.Krb5LoginModule",
61 AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
62 clientLoginModuleOptions)};
63
64 HashMap<String, String> serverLoginModuleOptions = new HashMap<>();
65 if (LOGGER.isDebugEnabled()) {
66 serverLoginModuleOptions.put("debug", "true");
67 }
68
69 serverLoginModuleOptions.put("isInitiator", "false");
70 serverLoginModuleOptions.put("useKeyTab", "false");
71 serverLoginModuleOptions.put("storeKey", "true");
72 SERVER_LOGIN_MODULE = new AppConfigurationEntry[]{new AppConfigurationEntry(
73 "com.sun.security.auth.module.Krb5LoginModule",
74 AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
75 serverLoginModuleOptions)};
76 }
77
78 @Override
79 public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
80 if ("spnego-client".equals(name)) {
81 return CLIENT_LOGIN_MODULE;
82 } else if ("spnego-server".equals(name)) {
83 return SERVER_LOGIN_MODULE;
84 } else {
85 return null;
86 }
87 }
88
89 @Override
90 public void refresh() {
91
92 }
93 }