KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > factory > EJBSecurityManagerFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * EJBSecurityManagerFactory.java
26  *
27  * Created on June 9, 2003, 5:42 PM
28  */

29
30 package com.sun.enterprise.security.factory;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Map JavaDoc;
36
37 import com.sun.enterprise.SecurityManager;
38 import com.sun.enterprise.deployment.Descriptor;
39 import com.sun.enterprise.deployment.EjbDescriptor;
40 import com.sun.enterprise.security.application.EJBSecurityManager;
41
42 import java.util.logging.Level JavaDoc;
43 /**
44  * EJB Security Manager Factory Implementation
45  * @author Harpreet Singh
46  */

47 public final class EJBSecurityManagerFactory
48     extends AbstractSecurityManagerFactory {
49     private Map JavaDoc CONTEXT_ID = new HashMap JavaDoc();
50
51     /** Creates a new instance of EJBSecurityManagerFactory */
52     private EJBSecurityManagerFactory() {
53     }
54     
55     public static SecurityManagerFactory getInstance() {
56         if(_theFactory == null){
57             _theFactory = (SecurityManagerFactory)new EJBSecurityManagerFactory();
58         }
59         return _theFactory;
60     }
61
62     public SecurityManager JavaDoc getSecurityManager(String JavaDoc contextId){
63         if (_poolHas(contextId)){
64             return (SecurityManager JavaDoc)_poolGet(contextId);
65         }
66         return null;
67     }
68     
69     public SecurityManager JavaDoc createSecurityManager(Descriptor descriptor) {
70         SecurityManager JavaDoc ejbSM = null;
71         String JavaDoc contextId = null;
72         String JavaDoc appName = null;
73         try {
74             ejbSM = EJBSecurityManager.getInstance(descriptor);
75             // if the descriptor is not a EjbDescriptor the EJBSM will
76
// throw an exception. So the following will always work.
77
EjbDescriptor ejbdes = (EjbDescriptor) descriptor;
78             appName = ejbdes.getApplication().getRegistrationName();
79             contextId = EJBSecurityManager.getContextID(ejbdes);
80             if(_logger.isLoggable(Level.FINE)){
81                 _logger.log(Level.FINE,
82                 "[EJB-Security] EJB Security:Creating EJBSecurityManager for contextId = "
83                 +contextId);
84             }
85
86         } catch (Exception JavaDoc e){
87             _logger.log(Level.FINE,
88             "[EJB-Security] FATAl Exception. Unable to create EJBSecurityManager: "
89             + e.getMessage() );
90             throw new RuntimeException JavaDoc(e);
91         }
92
93     synchronized (CONTEXT_ID) {
94         List JavaDoc lst = (List JavaDoc)CONTEXT_ID.get(appName);
95         if(lst == null){
96         lst = new ArrayList JavaDoc();
97         CONTEXT_ID.put(appName, lst);
98         }
99         if (!lst.contains(contextId)) {
100         lst.add(contextId);
101         }
102     }
103
104         _poolPut(contextId, ejbSM);
105         return ejbSM;
106     }
107
108     public String JavaDoc[] getAndRemoveContextIdForEjbAppName(String JavaDoc appName){
109     synchronized(CONTEXT_ID) {
110             List JavaDoc contextId = (List JavaDoc) CONTEXT_ID.get(appName);
111             if (contextId == null) {
112                 return null;
113             }
114             String JavaDoc[] rvalue = new String JavaDoc[contextId.size()];
115             rvalue = (String JavaDoc[])contextId.toArray(rvalue);
116
117         CONTEXT_ID.remove(appName);
118         return rvalue;
119     }
120     }
121 }
122
Popular Tags