KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > security > jacc > JPolicyContextHandlerData


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: JPolicyContextHandlerData.java,v 1.4 2004/07/01 09:52:36 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.security.jacc;
28
29 import javax.ejb.EnterpriseBean JavaDoc;
30 import javax.security.auth.Subject JavaDoc;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32
33 import org.objectweb.jonas.security.auth.JPrincipal;
34
35 import org.objectweb.security.context.SecurityContext;
36 import org.objectweb.security.context.SecurityCurrent;
37
38 /**
39  * This class is given to PolicyContext. This allow to associate thread-scoped
40  * object with the PolicyContext
41  * @see javax.security.jacc.PolicyContext
42  * @author Florent Benoit
43  */

44 public class JPolicyContextHandlerData {
45
46     /**
47      * HttpServletRequest object
48      * @see jacc 4.6.1.3
49      */

50     private HttpServletRequest JavaDoc httpServletRequest = null;
51
52     /**
53      * EJB arguments object
54      * @see jacc 4.6.1.5
55      */

56     private Object JavaDoc[] ejbArguments = null;
57
58     /**
59      * Current Enterprise Bean
60      * @see jacc 4.6.1.4
61      */

62     private EnterpriseBean JavaDoc processingBean = null;
63
64     /**
65      * Default private constructor
66      */

67     public JPolicyContextHandlerData() {
68         super();
69     }
70
71     /**
72      * @return Returns the httpServletRequest.
73      */

74     public HttpServletRequest JavaDoc getHttpServletRequest() {
75         return httpServletRequest;
76     }
77
78     /**
79      * @param httpServletRequest The httpServletRequest to set.
80      */

81     public void setHttpServletRequest(HttpServletRequest JavaDoc httpServletRequest) {
82         this.httpServletRequest = httpServletRequest;
83     }
84
85     /**
86      * @return the ejb Arguments.
87      */

88     public Object JavaDoc[] getEjbArguments() {
89         return ejbArguments;
90     }
91
92     /**
93      * Set the EJB arguments which can be used by policy provider
94      * @param ejbArguments The ejb Arguments to set.
95      */

96     public void setEjbArguments(Object JavaDoc[] ejbArguments) {
97         this.ejbArguments = ejbArguments;
98     }
99
100     /**
101      * Gets the current subject (if no user is authenticated, return null)
102      * @return the container's subject
103      */

104     public Subject JavaDoc getContainerSubject() {
105         Subject JavaDoc subject = null;
106
107         SecurityCurrent current = SecurityCurrent.getCurrent();
108         if (current != null) {
109             SecurityContext ctx = current.getSecurityContext();
110             if (ctx != null) {
111                 subject = new Subject JavaDoc();
112                 String JavaDoc runAsRole = ctx.peekRunAsRole();
113                 if (runAsRole != null) {
114                     subject.getPrincipals().add(new JPrincipal(runAsRole));
115                 } else {
116                     subject.getPrincipals().add(ctx.getCallerPrincipal(false));
117                 }
118                 return subject;
119             }
120         }
121         return subject;
122     }
123
124     /**
125      * @return the processingBean.
126      */

127     public EnterpriseBean JavaDoc getProcessingBean() {
128         return processingBean;
129     }
130
131     /**
132      * @param processingBean The bean being processed
133      */

134     public void setProcessingBean(EnterpriseBean JavaDoc processingBean) {
135         this.processingBean = processingBean;
136     }
137 }
Popular Tags