001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.web.ejb;
023:
024: import java.security.Principal;
025: import javax.ejb.CreateException;
026: import javax.ejb.SessionBean;
027: import javax.ejb.SessionContext;
028:
029: import org.jboss.logging.Logger;
030: import org.jboss.test.web.interfaces.ReferenceTest;
031: import org.jboss.test.web.interfaces.ReturnData;
032:
033: /** A simple session bean for testing declarative security.
034:
035: @author Scott.Stark@jboss.org
036: @version $Revision: 57211 $
037: */
038: public class StatelessSessionBean implements SessionBean {
039: static Logger log = Logger.getLogger(StatelessSessionBean.class);
040:
041: private SessionContext sessionContext;
042:
043: public void ejbCreate() throws CreateException {
044: log.debug("ejbCreate() called");
045: }
046:
047: public void ejbActivate() {
048: log.debug("ejbActivate() called");
049: }
050:
051: public void ejbPassivate() {
052: log.debug("ejbPassivate() called");
053: }
054:
055: public void ejbRemove() {
056: log.debug("ejbRemove() called");
057: }
058:
059: public void setSessionContext(SessionContext context) {
060: sessionContext = context;
061: }
062:
063: public String echo(String arg) {
064: log.debug("echo, arg=" + arg);
065: Principal p = sessionContext.getCallerPrincipal();
066: log.debug("echo, callerPrincipal=" + p);
067: return p.getName();
068: }
069:
070: public String forward(String echoArg) {
071: log.debug("StatelessSessionBean2.forward, echoArg=" + echoArg);
072: return echo(echoArg);
073: }
074:
075: public void noop(ReferenceTest test, boolean optimized) {
076: log.debug("noop");
077: }
078:
079: public ReturnData getData() {
080: ReturnData data = new ReturnData();
081: data.data = "TheReturnData";
082: return data;
083: }
084:
085: /** A method deployed with no method permissions */
086: public void unchecked() {
087: log.debug("unchecked");
088: }
089:
090: /** A method deployed with method permissions such that only a run-as
091: * assignment will allow access.
092: */
093: public void checkRunAs() {
094: Principal caller = sessionContext.getCallerPrincipal();
095: log.debug("checkRunAs, caller=" + caller);
096: boolean isInternalUser = sessionContext
097: .isCallerInRole("InternalUser");
098: log.debug("Caller isInternalUser: " + isInternalUser);
099: }
100: }
|