|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| package org.globus.cas.impl.service; |
|
12 |
| |
|
13 |
| import javax.security.auth.Subject; |
|
14 |
| |
|
15 |
| import org.globus.gsi.jaas.JaasGssUtil; |
|
16 |
| |
|
17 |
| import org.apache.axis.MessageContext; |
|
18 |
| import org.apache.axis.message.addressing.EndpointReferenceType; |
|
19 |
| |
|
20 |
| import java.security.cert.X509Certificate; |
|
21 |
| |
|
22 |
| import org.globus.gsi.gssapi.GlobusGSSCredentialImpl; |
|
23 |
| |
|
24 |
| import java.util.Set; |
|
25 |
| import java.util.Iterator; |
|
26 |
| import java.util.StringTokenizer; |
|
27 |
| |
|
28 |
| import org.globus.wsrf.config.ConfigException; |
|
29 |
| |
|
30 |
| import org.globus.wsrf.utils.FaultHelper; |
|
31 |
| |
|
32 |
| import org.globus.wsrf.security.SecurityManager; |
|
33 |
| import org.globus.wsrf.security.SecurityException; |
|
34 |
| |
|
35 |
| import org.globus.wsrf.impl.security.descriptor.ServiceSecurityConfig; |
|
36 |
| |
|
37 |
| import org.globus.cas.faults.CasFault; |
|
38 |
| |
|
39 |
| import org.globus.cas.types.ObjectData; |
|
40 |
| |
|
41 |
| import org.globus.cas.impl.CasConstants; |
|
42 |
| import org.globus.cas.impl.CasException; |
|
43 |
| |
|
44 |
| import org.globus.cas.impl.databaseAccess.CasDBStorage; |
|
45 |
| import org.globus.cas.impl.databaseAccess.CasDBOptions; |
|
46 |
| import org.globus.cas.impl.databaseAccess.CasDBException; |
|
47 |
| import org.globus.cas.impl.databaseAccess.UserDataHandler; |
|
48 |
| import org.globus.cas.impl.databaseAccess.ObjectDataHandler; |
|
49 |
| import org.globus.cas.impl.databaseAccess.ServiceTypeActionHandler; |
|
50 |
| |
|
51 |
| import javax.naming.Context; |
|
52 |
| import javax.naming.InitialContext; |
|
53 |
| import javax.naming.NamingException; |
|
54 |
| |
|
55 |
| import org.globus.mds.servicegroup.client.ServiceGroupRegistrationParameters; |
|
56 |
| |
|
57 |
| import org.globus.wsrf.ResourceContext; |
|
58 |
| import org.globus.wsrf.ResourceContextException; |
|
59 |
| |
|
60 |
| import org.globus.wsrf.config.ContainerConfig; |
|
61 |
| import org.globus.wsrf.utils.AddressingUtils; |
|
62 |
| |
|
63 |
| import org.globus.wsrf.impl.security.authentication.Constants; |
|
64 |
| import org.globus.wsrf.impl.servicegroup.client.MDSConfiguration; |
|
65 |
| import org.globus.wsrf.impl.servicegroup.client.ServiceGroupRegistrationClient; |
|
66 |
| |
|
67 |
| import org.apache.commons.logging.Log; |
|
68 |
| import org.apache.commons.logging.LogFactory; |
|
69 |
| |
|
70 |
| import org.globus.util.I18n; |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| public class CasService { |
|
75 |
| |
|
76 |
| static Log logger = LogFactory.getLog(CasService.class.getName()); |
|
77 |
| |
|
78 |
| private static I18n i18n = |
|
79 |
| I18n.getI18n("org.globus.cas.impl.service.errors", |
|
80 |
| CasService.class.getClassLoader()); |
|
81 |
| |
|
82 |
| private static final String DB_CONFIGURATION = "databaseConfiguration"; |
|
83 |
| |
|
84 |
0
| public CasService() throws CasException {
|
|
85 |
0
| logger.debug("Initialize database");
|
|
86 |
| |
|
87 |
0
| CasDBOptions casDbOptions = null;
|
|
88 |
0
| ResourceContext ctx = null;
|
|
89 |
0
| try {
|
|
90 |
0
| ctx = ResourceContext.getResourceContext();
|
|
91 |
| } catch (ResourceContextException exp) { |
|
92 |
0
| throw new CasException(exp);
|
|
93 |
| } |
|
94 |
| |
|
95 |
0
| try {
|
|
96 |
0
| Context initialContext = new InitialContext();
|
|
97 |
0
| casDbOptions = (CasDBOptions)initialContext
|
|
98 |
| .lookup(org.globus.wsrf.Constants.JNDI_SERVICES_BASE_NAME |
|
99 |
| + ctx.getService() + "/" + DB_CONFIGURATION); |
|
100 |
| } catch (NamingException exp) { |
|
101 |
0
| throw new CasException(exp);
|
|
102 |
| } |
|
103 |
| |
|
104 |
0
| try {
|
|
105 |
0
| CasDBStorage.setupDBConnection(casDbOptions);
|
|
106 |
| } |
|
107 |
| catch (CasDBException exp) { |
|
108 |
0
| logger.error(i18n.getMessage("dbConnErr"), exp);
|
|
109 |
0
| throw new CasException(i18n.getMessage("dbConnErr")
|
|
110 |
| + exp.getMessage(), exp); |
|
111 |
| } |
|
112 |
0
| logger.debug("initialize policies called");
|
|
113 |
0
| try {
|
|
114 |
0
| CasConstants.initializePolicies();
|
|
115 |
| } catch (CasDBException exp) { |
|
116 |
0
| logger.error(i18n.getMessage("policyInitErr"));
|
|
117 |
0
| throw new CasException(i18n.getMessage("policyInitErr")
|
|
118 |
| + exp.getMessage(), exp); |
|
119 |
| } |
|
120 |
| |
|
121 |
| |
|
122 |
0
| logger.debug("Initializing security in CAS");
|
|
123 |
0
| try {
|
|
124 |
0
| ServiceSecurityConfig.initialize(CasConstants.SERVICE_NAME);
|
|
125 |
| } catch (ConfigException exp) { |
|
126 |
0
| String str = i18n.getMessage("secDescInitErr");
|
|
127 |
0
| logger.error(str, exp);
|
|
128 |
0
| throw new CasException(str, exp);
|
|
129 |
| } catch (SecurityException exp) { |
|
130 |
0
| String str = i18n.getMessage("secDescInitErr");
|
|
131 |
0
| logger.error(str, exp);
|
|
132 |
0
| throw new CasException(str, exp);
|
|
133 |
| } |
|
134 |
| |
|
135 |
0
| Subject subject = null;
|
|
136 |
0
| try {
|
|
137 |
0
| SecurityManager manager = SecurityManager.getManager();
|
|
138 |
0
| subject = manager.getServiceSubject(CasConstants.SERVICE_NAME);
|
|
139 |
| } catch (SecurityException exp) { |
|
140 |
0
| String err = i18n.getMessage("serverSubErr");
|
|
141 |
0
| logger.error(err, exp);
|
|
142 |
0
| throw new CasException(err, exp);
|
|
143 |
| } |
|
144 |
| |
|
145 |
0
| GlobusGSSCredentialImpl credential =
|
|
146 |
| (GlobusGSSCredentialImpl)JaasGssUtil.getCredential(subject); |
|
147 |
0
| if (credential == null) {
|
|
148 |
0
| String errMesg = i18n.getMessage("noCredFound");
|
|
149 |
0
| logger.error(errMesg);
|
|
150 |
0
| throw new CasException(errMesg);
|
|
151 |
| } |
|
152 |
0
| String subjectDN = credential.getGlobusCredential().getIdentity();
|
|
153 |
| |
|
154 |
0
| CasResource resource = null;
|
|
155 |
0
| try {
|
|
156 |
0
| ResourceContext context = ResourceContext.getResourceContext();
|
|
157 |
0
| resource = (CasResource)context.getResource();
|
|
158 |
| } catch (Exception exp) { |
|
159 |
0
| String err = i18n.getMessage("retrResourceErr");
|
|
160 |
0
| logger.error(err, exp);
|
|
161 |
0
| throw new CasException(err, exp);
|
|
162 |
| } |
|
163 |
0
| resource.setServerDN(subjectDN);
|
|
164 |
| |
|
165 |
0
| registerToMDS();
|
|
166 |
| |
|
167 |
| } |
|
168 |
| |
|
169 |
| |
|
170 |
0
| public static String getCallerNickname() throws CasFault {
|
|
171 |
| |
|
172 |
0
| Subject callerSubject =
|
|
173 |
| (Subject)MessageContext.getCurrentContext() |
|
174 |
| .getProperty(Constants.PEER_SUBJECT); |
|
175 |
0
| if (callerSubject != null) {
|
|
176 |
0
| Set publicCreds = callerSubject.getPublicCredentials();
|
|
177 |
0
| if (publicCreds != null) {
|
|
178 |
0
| Iterator iter = publicCreds.iterator();
|
|
179 |
0
| if (iter.hasNext()) {
|
|
180 |
0
| X509Certificate[] certs = (X509Certificate[])iter.next();
|
|
181 |
| |
|
182 |
0
| if (certs != null) {
|
|
183 |
0
| String issuer = certs[0].getIssuerDN().getName();
|
|
184 |
0
| logger.debug("Issuer" + issuer);
|
|
185 |
| } |
|
186 |
| } |
|
187 |
| } |
|
188 |
| } |
|
189 |
| |
|
190 |
0
| String subjectDN = SecurityManager.getManager().getCaller();
|
|
191 |
0
| return getCasNickname(subjectDN);
|
|
192 |
| } |
|
193 |
| |
|
194 |
| |
|
195 |
0
| public static String getCasNickname(String subjectDN) throws CasFault {
|
|
196 |
0
| try {
|
|
197 |
0
| String userNick = UserDataHandler.getUserNickname(subjectDN);
|
|
198 |
0
| if (userNick == null) {
|
|
199 |
0
| String errMesg = i18n.getMessage("subjectDNMapErr", subjectDN);
|
|
200 |
0
| logger.error(errMesg);
|
|
201 |
0
| throw makeFault(errMesg);
|
|
202 |
| } |
|
203 |
0
| return userNick;
|
|
204 |
| } |
|
205 |
| catch (CasDBException exp) { |
|
206 |
0
| String err = i18n.getMessage("retrUserNickErr", subjectDN);
|
|
207 |
0
| logger.error(err, exp);
|
|
208 |
0
| throw makeFault(err + exp.getMessage(), exp);
|
|
209 |
| } |
|
210 |
| } |
|
211 |
| |
|
212 |
| |
|
213 |
0
| public static String getObjectId(String objSpec) throws CasFault {
|
|
214 |
| |
|
215 |
0
| String baseErrMsg = i18n.getMessage("retrObjDataErr", objSpec);
|
|
216 |
0
| StringTokenizer strTok =
|
|
217 |
| new StringTokenizer(objSpec.trim(), |
|
218 |
| CasConstants.OBJECTSPEC_DELIMITER); |
|
219 |
0
| if (strTok.countTokens() != 2) {
|
|
220 |
0
| String errMesg =
|
|
221 |
| i18n.getMessage("malFormedObjStr", |
|
222 |
| CasConstants.OBJECTSPEC_DELIMITER); |
|
223 |
0
| logger.error(errMesg);
|
|
224 |
0
| throw makeFault(baseErrMsg + errMesg);
|
|
225 |
| } |
|
226 |
0
| String objectNamespace = strTok.nextToken();
|
|
227 |
0
| String objectName = strTok.nextToken();
|
|
228 |
0
| try {
|
|
229 |
0
| int objId = ObjectDataHandler.getObjectId(objectName,
|
|
230 |
| objectNamespace); |
|
231 |
0
| if (objId <= 0) {
|
|
232 |
0
| String errMsg = i18n.getMessage("doesNotExist", new Object[]
|
|
233 |
| { "Object", objSpec }); |
|
234 |
0
| logger.error(errMsg);
|
|
235 |
0
| throw makeFault(baseErrMsg + errMsg);
|
|
236 |
| } |
|
237 |
0
| objSpec = Integer.toString(objId);
|
|
238 |
| } |
|
239 |
| catch (CasDBException e) { |
|
240 |
0
| logger.error(i18n.getMessage("objIdErr", objSpec), e);
|
|
241 |
0
| throw makeFault(baseErrMsg + e.getMessage(), e);
|
|
242 |
| } |
|
243 |
0
| return objSpec;
|
|
244 |
| } |
|
245 |
| |
|
246 |
| |
|
247 |
0
| public static String getServiceActionId(String actionSpec)
|
|
248 |
| throws CasFault { |
|
249 |
| |
|
250 |
0
| String baseErrMsg = "Retrieving service action data failed.\n";
|
|
251 |
0
| logger.debug("parsing actionSpec to get serviceActionId");
|
|
252 |
0
| StringTokenizer strTok =
|
|
253 |
| new StringTokenizer(actionSpec, |
|
254 |
| CasConstants.SERVICEACTION_DELIMITER); |
|
255 |
0
| if (strTok.countTokens() != 2) {
|
|
256 |
0
| String errMesg =
|
|
257 |
| i18n.getMessage("malFormedServiceAct", |
|
258 |
| CasConstants.SERVICEACTION_DELIMITER); |
|
259 |
0
| logger.error(errMesg);
|
|
260 |
0
| throw makeFault(baseErrMsg + errMesg);
|
|
261 |
| } |
|
262 |
0
| try {
|
|
263 |
0
| int serviceActionId =
|
|
264 |
| ServiceTypeActionHandler |
|
265 |
| .getServiceActionId(strTok.nextToken(), |
|
266 |
| strTok.nextToken()); |
|
267 |
0
| if (serviceActionId == -1) {
|
|
268 |
0
| String errMesg = i18n.getMessage("doesNotExist", new Object[]
|
|
269 |
| { "Service/Action" , |
|
270 |
| actionSpec }); |
|
271 |
0
| logger.error(errMesg);
|
|
272 |
0
| throw makeFault(baseErrMsg + errMesg);
|
|
273 |
| } |
|
274 |
0
| actionSpec = Integer.toString(serviceActionId);
|
|
275 |
| } catch (CasDBException exp) { |
|
276 |
0
| String errMesg = i18n.getMessage("serviceActionData", actionSpec);
|
|
277 |
0
| logger.error(errMesg, exp);
|
|
278 |
0
| throw makeFault(baseErrMsg + errMesg + exp.getMessage(), exp);
|
|
279 |
| } |
|
280 |
0
| return actionSpec;
|
|
281 |
| } |
|
282 |
| |
|
283 |
| |
|
284 |
0
| public static String getServiceActionMapping(String serviceId)
|
|
285 |
| throws CasFault { |
|
286 |
| |
|
287 |
0
| String baseErrMsg = i18n.getMessage("retrErr",
|
|
288 |
| "service action mapping"); |
|
289 |
0
| logger.debug("parsing serviceActionId to serviceType/action");
|
|
290 |
0
| String serviceAction = null;
|
|
291 |
0
| try {
|
|
292 |
0
| serviceAction =
|
|
293 |
| ServiceTypeActionHandler.getServiceActionMapping( |
|
294 |
| Integer.parseInt(serviceId)); |
|
295 |
| } |
|
296 |
| catch (CasDBException exp) { |
|
297 |
0
| logger.error(i18n.getMessage("serviceActionMap"), exp);
|
|
298 |
0
| throw makeFault(baseErrMsg + exp.getMessage(), exp);
|
|
299 |
| } |
|
300 |
| |
|
301 |
0
| if (serviceAction == null) {
|
|
302 |
0
| logger.error(baseErrMsg);
|
|
303 |
0
| throw makeFault(baseErrMsg);
|
|
304 |
| } |
|
305 |
0
| return serviceAction;
|
|
306 |
| } |
|
307 |
| |
|
308 |
| |
|
309 |
0
| public static String getObjectData(String objectId) throws CasFault {
|
|
310 |
| |
|
311 |
0
| String baseErrMsg = i18n.getMessage("retrErr", "object data");
|
|
312 |
0
| try {
|
|
313 |
0
| ObjectData objData =
|
|
314 |
| ObjectDataHandler.retrieveObjectForId(objectId); |
|
315 |
0
| if (objData == null) {
|
|
316 |
0
| logger.error(baseErrMsg);
|
|
317 |
0
| throw makeFault(baseErrMsg);
|
|
318 |
| } |
|
319 |
0
| return objData.getObjectNamespace() +
|
|
320 |
| CasConstants.OBJECTSPEC_DELIMITER + objData.getObjectName(); |
|
321 |
| } |
|
322 |
| catch (CasDBException exp) { |
|
323 |
0
| logger.error(baseErrMsg, exp);
|
|
324 |
0
| throw makeFault(baseErrMsg + exp.getMessage(), exp);
|
|
325 |
| } |
|
326 |
| } |
|
327 |
| |
|
328 |
0
| public static CasFault makeFault(String errorMsg) {
|
|
329 |
0
| return makeFault(errorMsg, null);
|
|
330 |
| } |
|
331 |
| |
|
332 |
0
| public static CasFault makeFault(String errMsg, Exception exp) {
|
|
333 |
| |
|
334 |
0
| CasFault fault = new CasFault();
|
|
335 |
0
| FaultHelper helper = new FaultHelper(fault);
|
|
336 |
0
| if (errMsg != null) {
|
|
337 |
0
| helper.setDescription(errMsg);
|
|
338 |
| } |
|
339 |
0
| if (exp != null) {
|
|
340 |
0
| helper.addFaultCause(exp);
|
|
341 |
| } |
|
342 |
| |
|
343 |
0
| return (CasFault)helper.getFault();
|
|
344 |
| } |
|
345 |
| |
|
346 |
0
| public void registerToMDS() {
|
|
347 |
| |
|
348 |
0
| try {
|
|
349 |
| |
|
350 |
0
| ResourceContext rCtx = ResourceContext.getResourceContext();
|
|
351 |
| |
|
352 |
| |
|
353 |
0
| Context ctx = new InitialContext();
|
|
354 |
0
| String config = org.globus.wsrf.Constants.JNDI_SERVICES_BASE_NAME +
|
|
355 |
| rCtx.getService() + "/mdsConfiguration"; |
|
356 |
0
| MDSConfiguration mdsConfiguration =
|
|
357 |
| (MDSConfiguration) ctx.lookup(config); |
|
358 |
| |
|
359 |
| |
|
360 |
0
| if(mdsConfiguration.getRegAsBoolean()) {
|
|
361 |
0
| logger.info(i18n.getMessage("mdsEnabled"));
|
|
362 |
| |
|
363 |
| |
|
364 |
0
| EndpointReferenceType epr =
|
|
365 |
| AddressingUtils.createEndpointReference(null); |
|
366 |
| |
|
367 |
| |
|
368 |
0
| ServiceGroupRegistrationClient.register(
|
|
369 |
| rCtx, |
|
370 |
| epr, |
|
371 |
| "/etc/globus_cas_service/registration.xml"); |
|
372 |
| } else { |
|
373 |
0
| logger.debug(i18n.getMessage("mdsSuppressed"));
|
|
374 |
| } |
|
375 |
| } catch(Exception e) { |
|
376 |
0
| logger.error(i18n.getMessage("mdsRegErr"),e);
|
|
377 |
| } |
|
378 |
| |
|
379 |
| } |
|
380 |
| |
|
381 |
| } |