1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.api.core.security;
17
18 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_ALGORITHM;
19 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_ID;
20 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_KEY;
21 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_PROVIDER;
22 import static de.smartics.properties.api.core.security.SecurityConfigurationLoader.SECURITY_TRANSFORMATION;
23
24 import java.io.Serializable;
25 import java.util.Properties;
26
27 import javax.naming.Context;
28 import javax.naming.InitialContext;
29
30 import de.smartics.properties.api.core.app.JndiContext;
31
32
33
34
35
36 class SecurityConfigurationJndiLoader implements Serializable
37 {
38
39
40
41
42
43
44
45
46
47
48 private static final long serialVersionUID = 1L;
49
50
51
52
53
54
55
56
57
58
59 SecurityConfigurationJndiLoader()
60 {
61 }
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 Properties load() throws IllegalStateException
81 {
82 try
83 {
84
85 final Context context = new InitialContext();
86 final JndiContext lookup = JndiContext.boot(context);
87 final String sourceId = lookup.getSourceId();
88 final String key = lookup.lookup(SECURITY_KEY);
89 final String provider = lookup.lookup(SECURITY_PROVIDER);
90 final String algorithm = lookup.lookup(SECURITY_ALGORITHM);
91 final String transformation = lookup.lookup(SECURITY_TRANSFORMATION);
92 try
93 {
94 final Properties properties = new Properties();
95 properties.setProperty(SECURITY_ID, sourceId);
96 properties.setProperty(SECURITY_KEY, key);
97 properties.setProperty(SECURITY_PROVIDER, provider);
98 properties.setProperty(SECURITY_ALGORITHM, algorithm);
99 properties.setProperty(SECURITY_TRANSFORMATION, transformation);
100
101 return properties;
102 }
103 catch (final Exception e)
104 {
105 throw new IllegalStateException(String.format(
106 "Cannot configure security module from JNDI %s: %s", sourceId,
107 e.getMessage(), e));
108 }
109 }
110 catch (final Exception e)
111 {
112 throw new IllegalStateException(String.format(
113 "Cannot configure security module: %s", e.getMessage(), e));
114 }
115 }
116
117
118
119 }