1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.changepw.protocol;
21
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import javax.security.auth.kerberos.KerberosPrincipal;
27
28 import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
29 import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory;
30 import org.apache.directory.server.kerberos.shared.messages.value.EncryptionKey;
31 import org.apache.directory.server.kerberos.shared.store.PrincipalStore;
32 import org.apache.directory.server.kerberos.shared.store.PrincipalStoreEntry;
33 import org.apache.directory.server.kerberos.shared.store.PrincipalStoreEntryModifier;
34
35
36
37
38
39
40
41
42
43
44 public class MapPrincipalStoreImpl implements PrincipalStore
45 {
46 private static Map<KerberosPrincipal, PrincipalStoreEntry> store = new HashMap<KerberosPrincipal, PrincipalStoreEntry>();
47
48 static
49 {
50 String principalName = "hnelson@EXAMPLE.COM";
51 String passPhrase = "secret";
52
53 PrincipalStoreEntry entry = getEntry( principalName, passPhrase );
54
55 store.put( entry.getPrincipal(), entry );
56
57 principalName = "kadmin/changepw@EXAMPLE.COM";
58 passPhrase = "secret";
59
60 entry = getEntry( principalName, passPhrase );
61
62 store.put( entry.getPrincipal(), entry );
63 }
64
65
66 public PrincipalStoreEntry getPrincipal( KerberosPrincipal principal ) throws Exception
67 {
68 PrincipalStoreEntry entry = store.get( principal );
69
70 return entry;
71 }
72
73
74 public String changePassword( KerberosPrincipal principal, String newPassword ) throws Exception
75 {
76 return principal.getName();
77 }
78
79
80 public String addPrincipal( PrincipalStoreEntry entry ) throws Exception
81 {
82 return null;
83 }
84
85
86 public String deletePrincipal( KerberosPrincipal principal ) throws Exception
87 {
88 return null;
89 }
90
91
92 public PrincipalStoreEntry[] getAllPrincipals( String realm ) throws Exception
93 {
94 return null;
95 }
96
97
98 private static PrincipalStoreEntry getEntry( String principalName, String passPhrase )
99 {
100 KerberosPrincipal clientPrincipal = new KerberosPrincipal( principalName );
101
102 PrincipalStoreEntryModifier modifier = new PrincipalStoreEntryModifier();
103 modifier.setPrincipal( clientPrincipal );
104
105 Map<EncryptionType, EncryptionKey> keyMap = KerberosKeyFactory.getKerberosKeys( principalName, passPhrase );
106
107 modifier.setKeyMap( keyMap );
108
109 return modifier.getEntry();
110 }
111 }