KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > authorize > PolicyContextHandlerImpl


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 package com.sun.enterprise.security.authorize;
25
26 import java.security.SecurityPermission JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Set JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.security.jacc.PolicyContextHandler JavaDoc;
33
34 /**
35  * This class is created by the container and handed over to the
36  * JACC provider. This lets the jacc provider to use the information
37  * in making authorization decisions, if it wishes to do so.
38  * @author Harpreet Singh
39  * @author Shing Wai Chan
40  */

41 public class PolicyContextHandlerImpl implements PolicyContextHandler JavaDoc {
42
43     public static final String JavaDoc HTTP_SERVLET_REQUEST =
44         "javax.servlet.http.HttpServletRequest";
45     public static final String JavaDoc SOAP_MESSAGE = "javax.xml.soap.SOAPMessage";
46     public static final String JavaDoc ENTERPRISE_BEAN = "javax.ejb.EnterpriseBean";
47     public static final String JavaDoc EJB_ARGUMENTS = "javax.ejb.arguments";
48     public static final String JavaDoc SUBJECT = "javax.security.auth.Subject.container";
49     public static final String JavaDoc REUSE = "java.security.Policy.supportsReuse";
50
51     private static PolicyContextHandlerImpl pchimpl = null;
52
53     private ThreadLocal JavaDoc thisHandlerData = new ThreadLocal JavaDoc();
54
55     private PolicyContextHandlerImpl() {
56     }
57
58     public static PolicyContextHandler JavaDoc getInstance() {
59         SecurityManager JavaDoc sm = System.getSecurityManager();
60         if (sm != null) {
61             sm.checkPermission(new SecurityPermission JavaDoc("setPolicy"));
62         }
63
64     if (pchimpl == null) {
65         pchimpl = new PolicyContextHandlerImpl();
66         }
67     return pchimpl;
68     }
69
70     public boolean supports(String JavaDoc key) {
71     String JavaDoc[] s = getKeys();
72     for (int i = 0; i<s.length; i++) {
73         if (s[i].equalsIgnoreCase(key)) {
74         return true;
75             }
76     }
77         return false;
78     }
79     
80     public String JavaDoc[] getKeys(){
81     String JavaDoc[] s = {
82         HTTP_SERVLET_REQUEST,
83         SOAP_MESSAGE,
84         ENTERPRISE_BEAN,
85         SUBJECT,
86         EJB_ARGUMENTS,
87             REUSE
88     };
89     return s;
90     }
91     
92     public Object JavaDoc getContext(String JavaDoc key, Object JavaDoc data) {
93         // ignore data Object
94
return getHandlerData().get(key);
95     }
96
97     public HandlerData getHandlerData() {
98         HandlerData handlerData = (HandlerData)thisHandlerData.get();
99         if (handlerData == null) {
100             handlerData = HandlerData.getInstance();
101             thisHandlerData.set(handlerData);
102         }
103         return handlerData;
104     }
105 }
106
Popular Tags