001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: JPolicyContextHandlerData.java 5030 2004-07-01 09:52:36Z benoitf $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.security.jacc;
026:
027: import javax.ejb.EnterpriseBean;
028: import javax.security.auth.Subject;
029: import javax.servlet.http.HttpServletRequest;
030:
031: import org.objectweb.jonas.security.auth.JPrincipal;
032:
033: import org.objectweb.security.context.SecurityContext;
034: import org.objectweb.security.context.SecurityCurrent;
035:
036: /**
037: * This class is given to PolicyContext. This allow to associate thread-scoped
038: * object with the PolicyContext
039: * @see javax.security.jacc.PolicyContext
040: * @author Florent Benoit
041: */
042: public class JPolicyContextHandlerData {
043:
044: /**
045: * HttpServletRequest object
046: * @see jacc 4.6.1.3
047: */
048: private HttpServletRequest httpServletRequest = null;
049:
050: /**
051: * EJB arguments object
052: * @see jacc 4.6.1.5
053: */
054: private Object[] ejbArguments = null;
055:
056: /**
057: * Current Enterprise Bean
058: * @see jacc 4.6.1.4
059: */
060: private EnterpriseBean processingBean = null;
061:
062: /**
063: * Default private constructor
064: */
065: public JPolicyContextHandlerData() {
066: super ();
067: }
068:
069: /**
070: * @return Returns the httpServletRequest.
071: */
072: public HttpServletRequest getHttpServletRequest() {
073: return httpServletRequest;
074: }
075:
076: /**
077: * @param httpServletRequest The httpServletRequest to set.
078: */
079: public void setHttpServletRequest(
080: HttpServletRequest httpServletRequest) {
081: this .httpServletRequest = httpServletRequest;
082: }
083:
084: /**
085: * @return the ejb Arguments.
086: */
087: public Object[] getEjbArguments() {
088: return ejbArguments;
089: }
090:
091: /**
092: * Set the EJB arguments which can be used by policy provider
093: * @param ejbArguments The ejb Arguments to set.
094: */
095: public void setEjbArguments(Object[] ejbArguments) {
096: this .ejbArguments = ejbArguments;
097: }
098:
099: /**
100: * Gets the current subject (if no user is authenticated, return null)
101: * @return the container's subject
102: */
103: public Subject getContainerSubject() {
104: Subject subject = null;
105:
106: SecurityCurrent current = SecurityCurrent.getCurrent();
107: if (current != null) {
108: SecurityContext ctx = current.getSecurityContext();
109: if (ctx != null) {
110: subject = new Subject();
111: String runAsRole = ctx.peekRunAsRole();
112: if (runAsRole != null) {
113: subject.getPrincipals().add(
114: new JPrincipal(runAsRole));
115: } else {
116: subject.getPrincipals().add(
117: ctx.getCallerPrincipal(false));
118: }
119: return subject;
120: }
121: }
122: return subject;
123: }
124:
125: /**
126: * @return the processingBean.
127: */
128: public EnterpriseBean getProcessingBean() {
129: return processingBean;
130: }
131:
132: /**
133: * @param processingBean The bean being processed
134: */
135: public void setProcessingBean(EnterpriseBean processingBean) {
136: this.processingBean = processingBean;
137: }
138: }
|