KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > ejb > services > LocalServiceSessionBean


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package org.ejbca.core.ejb.services;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.Date JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Random JavaDoc;
22
23 import javax.ejb.CreateException JavaDoc;
24 import javax.ejb.EJBException JavaDoc;
25 import javax.ejb.FinderException JavaDoc;
26
27 import org.ejbca.core.ejb.BaseSessionBean;
28 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal;
29 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocalHome;
30 import org.ejbca.core.ejb.log.ILogSessionLocal;
31 import org.ejbca.core.ejb.log.ILogSessionLocalHome;
32 import org.ejbca.core.model.InternalResources;
33 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
34 import org.ejbca.core.model.authorization.AvailableAccessRules;
35 import org.ejbca.core.model.log.Admin;
36 import org.ejbca.core.model.log.LogEntry;
37 import org.ejbca.core.model.services.IInterval;
38 import org.ejbca.core.model.services.IWorker;
39 import org.ejbca.core.model.services.ServiceConfiguration;
40 import org.ejbca.core.model.services.ServiceExistsException;
41
42
43 /**
44  * Stores data used by web server clients.
45  * Uses JNDI name for datasource as defined in env 'Datasource' in ejb-jar.xml.
46  *
47  * @ejb.bean description="Session bean handling interface with service configuration"
48  * display-name="ServiceSessionSB"
49  * name="ServiceSession"
50  * jndi-name="ServiceSession"
51  * local-jndi-name="ServiceSessionLocal"
52  * view-type="both"
53  * type="Stateless"
54  * transaction-type="Container"
55  *
56  * @ejb.transaction type="Required"
57  *
58  * @weblogic.enable-call-by-reference True
59  *
60  * @ejb.env-entry name="DataSource"
61  * type="java.lang.String"
62  * value="${datasource.jndi-name-prefix}${datasource.jndi-name}"
63  *
64  *
65  * @ejb.env-entry
66  * description="Defines the JNDI name of the mail service used"
67  * name="MailJNDIName"
68  * type="java.lang.String"
69  * value="${mail.jndi-name}"
70  *
71  * @ejb.home extends="javax.ejb.EJBHome"
72  * local-extends="javax.ejb.EJBLocalHome"
73  * local-class="org.ejbca.core.ejb.services.IServiceSessionLocalHome"
74  * remote-class="org.ejbca.core.ejb.services.IServiceSessionHome"
75  *
76  * @ejb.interface extends="javax.ejb.EJBObject"
77  * local-extends="javax.ejb.EJBLocalObject"
78  * local-class="org.ejbca.core.ejb.services.IServiceSessionLocal"
79  * remote-class="org.ejbca.core.ejb.services.IServiceSessionRemote"
80  *
81  * @ejb.ejb-external-ref description="The Service entity bean"
82  * view-type="local"
83  * ref-name="ejb/ServiceDataLocal"
84  * type="Entity"
85  * home="org.ejbca.core.ejb.services.ServiceDataLocalHome"
86  * business="org.ejbca.core.ejb.services.ServiceDataLocal"
87  * link="ServiceData"
88  *
89  *
90  * @ejb.ejb-external-ref description="The Authorization Session Bean"
91  * view-type="local"
92  * ref-name="ejb/AuthorizationSessionLocal"
93  * type="Session"
94  * home="org.ejbca.core.ejb.authorization.IAuthorizationSessionLocalHome"
95  * business="org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal"
96  * link="AuthorizationSession"
97  *
98  *
99  * @ejb.ejb-external-ref description="The log session bean"
100  * view-type="local"
101  * ref-name="ejb/LogSessionLocal"
102  * type="Session"
103  * home="org.ejbca.core.ejb.log.ILogSessionLocalHome"
104  * business="org.ejbca.core.ejb.log.ILogSessionLocal"
105  * link="LogSession"
106  *
107  * @ejb.ejb-external-ref description="The CAAdmin Session Bean"
108  * view-type="local"
109  * ref-name="ejb/CAAdminSessionLocal"
110  * type="Session"
111  * home="org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome"
112  * business="org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal"
113  * link="CAAdminSession"
114  *
115  * @ejb.ejb-external-ref description="The Service Timer Session Bean"
116  * view-type="local"
117  * ref-name="ejb/ServiceTimerSessionLocal"
118  * type="Session"
119  * home="org.ejbca.core.ejb.services.IServiceTimerSessionLocalHome"
120  * business="org.ejbca.core.ejb.services.IServiceTimerSessionLocal"
121  * link="ServiceTimerSession"
122  *
123  * @jonas.bean ejb-name="ServiceSession"
124  */

125 public class LocalServiceSessionBean extends BaseSessionBean {
126
127     /**
128      * The local home interface of service data source entity bean.
129      */

130     private transient ServiceDataLocalHome servicehome = null;
131     
132     /**
133      * The local interface of service timer session
134      */

135     private transient IServiceTimerSessionLocal serviceTimerSession = null;
136     
137
138     /**
139      * The local interface of authorization session bean
140      */

141     private transient IAuthorizationSessionLocal authorizationsession = null;
142
143     /**
144      * The remote interface of log session bean
145      */

146     private transient ILogSessionLocal logsession = null;
147     
148     /** Internal localization of logs and errors */
149     private static final InternalResources intres = InternalResources.getInstance();
150
151
152     /**
153      * The administrator that the services should be runned as.
154      */

155     Admin intAdmin = new Admin(Admin.TYPE_INTERNALUSER);
156     
157     /**
158      * Default create for SessionBean without any creation Arguments.
159      *
160      * @throws CreateException if bean instance can't be created
161      */

162     public void ejbCreate() throws CreateException JavaDoc {
163         
164     }
165     
166     
167
168  
169
170    /**
171     * Method that creates a worker from the service configuration.
172     *
173     * @param serviceConfiguration
174     * @param serviceName
175     * @return a worker object or null if the worker is missconfigured.
176     */

177     private IWorker getWorker(ServiceConfiguration serviceConfiguration, String JavaDoc serviceName) {
178         IWorker worker = null;
179         try {
180             worker = (IWorker) this.getClass().getClassLoader().loadClass(serviceConfiguration.getWorkerClassPath()).newInstance();
181             worker.init(intAdmin, serviceConfiguration, serviceName);
182         } catch (Exception JavaDoc e) {
183             String JavaDoc msg = intres.getLocalizedMessage("services.errorworkerconfig", serviceConfiguration.getWorkerClassPath(), serviceName);
184             log.error(msg,e);
185         }
186         
187         return worker;
188     }
189
190
191
192     /**
193      * Gets connection to log session bean
194      *
195      * @return Connection
196      */

197     private ILogSessionLocal getLogSession() {
198         if (logsession == null) {
199             try {
200                 ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME);
201                 logsession = logsessionhome.create();
202             } catch (CreateException JavaDoc e) {
203                 throw new EJBException JavaDoc(e);
204             }
205         }
206         return logsession;
207     } //getLogSession
208

209
210     /**
211      * Gets connection to service data bean
212      *
213      * @return ServiceDataLocalHome
214      */

215     private ServiceDataLocalHome getServiceDataHome() {
216         if (servicehome == null) {
217             servicehome = (ServiceDataLocalHome) getLocator().getLocalHome(ServiceDataLocalHome.COMP_NAME);
218         }
219         return servicehome;
220     } //getServiceDataHome
221

222     /**
223      * Gets connection to authorization session bean
224      *
225      * @return IAuthorizationSessionLocal
226      */

227     private IAuthorizationSessionLocal getAuthorizationSession() {
228         if (authorizationsession == null) {
229             try {
230                 IAuthorizationSessionLocalHome authorizationsessionhome = (IAuthorizationSessionLocalHome) getLocator().getLocalHome(IAuthorizationSessionLocalHome.COMP_NAME);
231                 authorizationsession = authorizationsessionhome.create();
232             } catch (CreateException JavaDoc e) {
233                 throw new EJBException JavaDoc(e);
234             }
235         }
236         return authorizationsession;
237     } //getAuthorizationSession
238

239     /**
240      * Gets connection to service timer session bean
241      *
242      * @return IServiceTimerSessionLocal
243      */

244     private IServiceTimerSessionLocal getServiceTimerSession() {
245         if (serviceTimerSession == null) {
246             try {
247                 IServiceTimerSessionLocalHome servicetimersessionhome = (IServiceTimerSessionLocalHome) getLocator().getLocalHome(IServiceTimerSessionLocalHome.COMP_NAME);
248                 serviceTimerSession = servicetimersessionhome.create();
249             } catch (CreateException JavaDoc e) {
250                 throw new EJBException JavaDoc(e);
251             }
252         }
253         return serviceTimerSession;
254     } //getServiceTimerSession
255

256     /**
257      * Adds a Service to the database.
258      *
259      * @throws ServiceExistsException if service already exists.
260      * @throws EJBException if a communication or other error occurs.
261      * @ejb.interface-method view-type="both"
262      */

263
264     public void addService(Admin admin, String JavaDoc name, ServiceConfiguration serviceConfiguration) throws ServiceExistsException {
265         debug(">addService(name: " + name + ")");
266         addService(admin,findFreeServiceId().intValue(),name,serviceConfiguration);
267         debug("<addService()");
268     } // addService
269

270
271     /**
272      * Adds a service to the database.
273      * Used for importing and exporting profiles from xml-files.
274      *
275      * @throws ServiceExistsException if service already exists.
276      * @throws EJBException if a communication or other error occurs.
277      * @ejb.interface-method view-type="both"
278      */

279
280     public void addService(Admin admin, int id, String JavaDoc name, ServiceConfiguration serviceConfiguration) throws ServiceExistsException {
281         debug(">addService(name: " + name + ", id: " + id + ")");
282         boolean success = false;
283         if(isAuthorizedToEditService(admin,serviceConfiguration)){
284             try {
285                 getServiceDataHome().findByName(name);
286             } catch (FinderException JavaDoc e) {
287                 try {
288                     getServiceDataHome().findByPrimaryKey(new Integer JavaDoc(id));
289                 } catch (FinderException JavaDoc f) {
290                     try {
291                         getServiceDataHome().create(new Integer JavaDoc(id), name, serviceConfiguration);
292                         success = true;
293                         
294                     } catch (CreateException JavaDoc g) {
295                         error("Unexpected error creating new service: ", g);
296                     }
297                 }
298             }
299             if (success){
300                 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_INFO_SERVICESEDITED, intres.getLocalizedMessage("services.serviceadded", name));
301             }else{
302                 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_ERROR_SERVICESEDITED, intres.getLocalizedMessage("services.erroraddingservice", name));
303             }
304             if (!success)
305                 throw new ServiceExistsException();
306         }else{
307             getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_SERVICES,new Date JavaDoc(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,intres.getLocalizedMessage("services.notauthorizedtoadd", name));
308         }
309         debug("<addService()");
310     } // addService
311

312     /**
313      * Updates service configuration, but does not re-set the timer
314      *
315      * @throws EJBException if a communication or other error occurs.
316      * @ejb.interface-method view-type="both"
317      */

318
319     public void changeService(Admin admin, String JavaDoc name, ServiceConfiguration serviceConfiguration) {
320         debug(">changeService(name: " + name + ")");
321         boolean success = false;
322         if(isAuthorizedToEditService(admin,serviceConfiguration)){
323             try {
324                 ServiceDataLocal htp = getServiceDataHome().findByName(name);
325                 htp.setServiceConfiguration(serviceConfiguration);
326                 success = true;
327             } catch (FinderException JavaDoc e) {
328                 error("Can not find service to change: "+name);
329             }
330             
331             if (success){
332                 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_INFO_SERVICESEDITED, intres.getLocalizedMessage("services.serviceedited", name));
333             }else{
334                 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_ERROR_SERVICESEDITED, intres.getLocalizedMessage("services.erroreditingservice", name));
335             }
336         }else{
337             getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_SERVICES,new Date JavaDoc(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,intres.getLocalizedMessage("services.notauthorizedtoedit", name));
338         }
339         
340         debug("<changeService()");
341     } // changeService
342

343     /**
344      * Adds a service with the same content as the original.
345      *
346      * @throws ServiceExistsException if service already exists.
347      * @throws EJBException if a communication or other error occurs.
348      * @ejb.interface-method view-type="both"
349      */

350     public void cloneService(Admin admin, String JavaDoc oldname, String JavaDoc newname) throws ServiceExistsException {
351         debug(">cloneService(name: " + oldname + ")");
352         ServiceConfiguration servicedata = null;
353         try {
354             ServiceDataLocal htp = getServiceDataHome().findByName(oldname);
355             servicedata = (ServiceConfiguration) htp.getServiceConfiguration().clone();
356             if(isAuthorizedToEditService(admin,servicedata)){
357                 try {
358                     addService(admin, newname, servicedata);
359                     getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_INFO_SERVICESEDITED, intres.getLocalizedMessage("services.servicecloned", newname,oldname));
360                 } catch (ServiceExistsException f) {
361                     getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_ERROR_SERVICESEDITED, intres.getLocalizedMessage("services.errorcloningservice", newname, oldname));
362                     throw f;
363                 }
364             }else{
365                 getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_SERVICES,new Date JavaDoc(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE, intres.getLocalizedMessage("services.notauthorizedtoedit", oldname));
366             }
367         } catch (FinderException JavaDoc e) {
368             error("Error cloning service: ", e);
369             throw new EJBException JavaDoc(e);
370         } catch (CloneNotSupportedException JavaDoc e) {
371             error("Error cloning service: ", e);
372             throw new EJBException JavaDoc(e);
373         }
374
375         debug("<cloneService()");
376     } // cloneService
377

378     /**
379      * Removes a service from the database.
380      *
381      * @throws EJBException if a communication or other error occurs.
382      * @ejb.interface-method view-type="both"
383      */

384     public boolean removeService(Admin admin, String JavaDoc name) {
385         debug(">removeService(name: " + name + ")");
386         boolean retval = false;
387         try {
388             ServiceDataLocal htp = getServiceDataHome().findByName(name);
389             ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
390             if(isAuthorizedToEditService(admin,serviceConfiguration)){
391               IWorker worker = getWorker(serviceConfiguration, name);
392               if(worker != null){
393                   getServiceTimerSession().cancelTimer(htp.getId());
394               }
395               htp.remove();
396               getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_INFO_SERVICESEDITED, intres.getLocalizedMessage("services.serviceremoved", name));
397               retval = true;
398             }else{
399                 getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_SERVICES,new Date JavaDoc(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE, intres.getLocalizedMessage("services.notauthorizedtoedit", name));
400             }
401         } catch (Exception JavaDoc e) {
402             getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_ERROR_SERVICESEDITED, intres.getLocalizedMessage("services.errorremovingservice", name), e);
403         }
404         debug("<removeService)");
405         
406         return retval;
407     } // removeService
408

409     /**
410      * Renames a service
411      *
412      * @throws ServiceExistsException if service already exists.
413      * @throws EJBException if a communication or other error occurs.
414      * @ejb.interface-method view-type="both"
415      */

416     public void renameService(Admin admin, String JavaDoc oldname, String JavaDoc newname) throws ServiceExistsException {
417         debug(">renameService(from " + oldname + " to " + newname + ")");
418         boolean success = false;
419         try {
420             getServiceDataHome().findByName(newname);
421         } catch (FinderException JavaDoc e) {
422             try {
423                 ServiceDataLocal htp = getServiceDataHome().findByName(oldname);
424                 if(isAuthorizedToEditService(admin,htp.getServiceConfiguration())){
425                   htp.setName(newname);
426                   success = true;
427                 }else{
428                     getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_SERVICES,new Date JavaDoc(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE, intres.getLocalizedMessage("services.notauthorizedtoedit", oldname));
429                 }
430             } catch (FinderException JavaDoc g) {
431             }
432         }
433
434         if (success){
435             getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_INFO_SERVICESEDITED, intres.getLocalizedMessage("services.servicerenamed", oldname, newname));
436         }else{
437             getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_SERVICES, new java.util.Date JavaDoc(), null, null, LogEntry.EVENT_ERROR_SERVICESEDITED, intres.getLocalizedMessage("services.errorrenamingservice", oldname, newname));
438         }
439         if (!success)
440             throw new ServiceExistsException();
441         debug("<renameService()");
442     } // renameService
443

444     /**
445      * Retrives a Collection of id:s (Integer) to authorized services.
446      * Currently is the only check if the superadmin can see them all
447      *
448      * @return Collection of id:s (Integer)
449      * @ejb.interface-method view-type="both"
450      */

451     public Collection JavaDoc getAuthorizedServiceIds(Admin admin) {
452         Collection JavaDoc returnval = new ArrayList JavaDoc();
453
454         // If superadmin return all service
455
try{
456               getAuthorizationSession().isAuthorizedNoLog(admin, AvailableAccessRules.ROLE_SUPERADMINISTRATOR);
457               returnval = getServiceIdToNameMap(admin).keySet();
458             }catch (AuthorizationDeniedException e1) {
459                 log.debug("AuthorizationDeniedException: ", e1);
460             }
461  
462         return returnval;
463     } // getAuthorizedServiceIds
464

465     /**
466      * Method creating a hashmap mapping service id (Integer) to service name (String).
467      *
468      * @ejb.transaction type="Supports"
469      * @ejb.interface-method view-type="both"
470      */

471     public HashMap JavaDoc getServiceIdToNameMap(Admin admin) {
472         HashMap JavaDoc returnval = new HashMap JavaDoc();
473         Collection JavaDoc result = null;
474
475         try {
476             result = getServiceDataHome().findAll();
477             Iterator JavaDoc i = result.iterator();
478             while (i.hasNext()) {
479                 ServiceDataLocal next = (ServiceDataLocal) i.next();
480                 returnval.put(next.getId(), next.getName());
481             }
482         } catch (FinderException JavaDoc e) {
483         }
484         return returnval;
485     } // getServiceIdToNameMap
486

487
488     /**
489      * Retrives a named service.
490      *
491      * @returns the service configuration or null if it doesn't exist.
492      * @ejb.transaction type="Supports"
493      * @ejb.interface-method view-type="both"
494      */

495     public ServiceConfiguration getService(Admin admin, String JavaDoc name) {
496         ServiceConfiguration returnval = null;
497
498         try {
499             returnval = (getServiceDataHome().findByName(name)).getServiceConfiguration();
500         } catch (FinderException JavaDoc e) {
501             // return null if we cant find it
502
}
503         return returnval;
504     } // getService
505

506     /**
507      * Finds a service configuration by id.
508      *
509      * @returns the service configuration or null if it doesn't exist.
510      * @ejb.transaction type="Supports"
511      * @ejb.interface-method view-type="both"
512      */

513     public ServiceConfiguration getServiceConfiguration(Admin admin, int id) {
514         ServiceConfiguration returnval = null;
515
516         try {
517             returnval = (getServiceDataHome().findByPrimaryKey(new Integer JavaDoc(id))).getServiceConfiguration();
518         } catch (FinderException JavaDoc e) {
519             // return null if we cant find it
520
}
521         return returnval;
522     } // getServiceConfiguration
523

524
525
526     /**
527      * Returns a service id, given it's service name
528      *
529      * @return the id or 0 if the service cannot be found.
530      * @ejb.transaction type="Supports"
531      * @ejb.interface-method view-type="both"
532      */

533     public int getServiceId(Admin admin, String JavaDoc name) {
534         int returnval = 0;
535
536         try {
537             Integer JavaDoc id = (getServiceDataHome().findByName(name)).getId();
538             returnval = id.intValue();
539         } catch (FinderException JavaDoc e) {
540         }
541
542         return returnval;
543     } // getServiceId
544

545     /**
546      * Returns a Service name given its id.
547      *
548      * @return the name or null if id doesnt exists
549      * @throws EJBException if a communication or other error occurs.
550      * @ejb.transaction type="Supports"
551      * @ejb.interface-method view-type="both"
552      */

553     public String JavaDoc getServiceName(Admin admin, int id) {
554         debug(">getServiceName(id: " + id + ")");
555         String JavaDoc returnval = null;
556         ServiceDataLocal htp = null;
557         try {
558             htp = getServiceDataHome().findByPrimaryKey(new Integer JavaDoc(id));
559             if (htp != null) {
560                 returnval = htp.getName();
561             }
562         } catch (FinderException JavaDoc e) {
563         }
564
565         debug("<getServiceName()");
566         return returnval;
567     } // getServiceName
568

569     
570     /**
571      * Activates the timer for a named service. The service must alrteady be previously added.
572      *
573      * @param admin The administrator performing the action
574      * @param name the name of the service for which to activate the timer
575      * @throws EJBException if a communication or other error occurs.
576      * @ejb.transaction type="Supports"
577      * @ejb.interface-method view-type="both"
578      */

579     public void activateServiceTimer(Admin admin, String JavaDoc name) {
580         debug(">activateServiceTimer(name: " + name + ")");
581         try {
582             ServiceDataLocal htp = getServiceDataHome().findByName(name);
583             ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
584             if(isAuthorizedToEditService(admin,serviceConfiguration)){
585                 IWorker worker = getWorker(serviceConfiguration, name);
586                 if(worker != null){
587                     getServiceTimerSession().cancelTimer(htp.getId());
588                     if(serviceConfiguration.isActive() && worker.getNextInterval() != IInterval.DONT_EXECUTE){
589                         getServiceTimerSession().addTimer(worker.getNextInterval() *1000, htp.getId());
590                     }
591                 }
592             }else{
593                 getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_SERVICES,new Date JavaDoc(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,intres.getLocalizedMessage("services.notauthorizedtoedit", name));
594             }
595         } catch (FinderException JavaDoc e) {
596             log.error("Can not find service: "+name);
597         }
598         debug("<activateServiceTimer()");
599     } // getServiceName
600

601     
602     /**
603      * Method to check if an admin is authorized to edit a service
604      * The following checks are performed.
605      *
606      * 1. If the admin is an super administrator
607      *
608      * @return true if the administrator is authorized
609      */

610     private boolean isAuthorizedToEditService(Admin admin, ServiceConfiguration serviceConfiguraion) {
611         try {
612             if(getAuthorizationSession().isAuthorizedNoLog(admin,AvailableAccessRules.ROLE_SUPERADMINISTRATOR)){
613                 return true;
614             }
615         } catch (AuthorizationDeniedException e) {}
616         
617         return false;
618     }
619
620
621     private Integer JavaDoc findFreeServiceId() {
622         Random JavaDoc ran = (new Random JavaDoc((new Date JavaDoc()).getTime()));
623         int id = ran.nextInt();
624         boolean foundfree = false;
625
626         while (!foundfree) {
627             try {
628                 if (id > 1)
629                     getServiceDataHome().findByPrimaryKey(new Integer JavaDoc(id));
630                 id = ran.nextInt();
631             } catch (FinderException JavaDoc e) {
632                 foundfree = true;
633             }
634         }
635         return new Integer JavaDoc(id);
636     } // findFreeServiceId
637

638
639 } // LocalServiceSessionBean
640
Popular Tags