KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.security.jacc.PolicyContextHandler JavaDoc;
28 import javax.xml.rpc.handler.MessageContext JavaDoc;
29 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
30
31 import com.sun.ejb.Invocation;
32 import com.sun.enterprise.security.PermissionCacheFactory;
33 import com.sun.enterprise.security.SecurityContext;
34
35 /**
36  * This class implements a thread scoped data used for PolicyContext.
37  * @author Harry Singh
38  * @author Jyri Virkki
39  * @author Shing Wai Chan
40  *
41  */

42 public class HandlerData {
43     
44     private HttpServletRequest JavaDoc httpReq = null;
45     private Invocation inv = null;
46
47     private HandlerData(){}
48
49
50     public static HandlerData getInstance(){
51     return new HandlerData();
52     }
53
54     public void setHttpServletRequest(HttpServletRequest JavaDoc httpReq) {
55     this.httpReq = httpReq;
56     }
57
58     public void setInvocation(Invocation inv) {
59         this.inv = inv;
60     }
61
62     public Object JavaDoc get(String JavaDoc key){
63     if (PolicyContextHandlerImpl.HTTP_SERVLET_REQUEST.equalsIgnoreCase(key)){
64         return httpReq;
65     } else if (PolicyContextHandlerImpl.SUBJECT.equalsIgnoreCase(key)){
66         return SecurityContext.getCurrent().getSubject();
67     } else if (PolicyContextHandlerImpl.REUSE.equalsIgnoreCase(key)) {
68             PermissionCacheFactory.resetCaches();
69             return new Integer JavaDoc(0);
70         }
71
72         if (inv == null) {
73             return null;
74         }
75
76     if (PolicyContextHandlerImpl.SOAP_MESSAGE.equalsIgnoreCase(key)){
77         MessageContext JavaDoc msgContext = inv.messageContext;
78         if(msgContext == null)
79         return null;
80         if(msgContext instanceof SOAPMessageContext JavaDoc){
81         SOAPMessageContext JavaDoc smc = (SOAPMessageContext JavaDoc) msgContext;
82         return smc.getMessage();
83         }
84         return null;
85     } else if (PolicyContextHandlerImpl.ENTERPRISE_BEAN.equalsIgnoreCase(key)){
86         return inv.getJaccEjb();
87     } else if (PolicyContextHandlerImpl.EJB_ARGUMENTS.equalsIgnoreCase(key)){
88             if (inv.isWebService) {
89                 return null;
90             } else {
91                 return (inv.methodParams != null) ?
92                     inv.methodParams : new Object JavaDoc[0];
93             }
94     }
95     return null;
96     }
97 }
98
Popular Tags