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:
023: package org.jboss.ejb3.test.jacc;
024:
025: import javax.annotation.security.RolesAllowed;
026: import javax.annotation.security.PermitAll;
027: import javax.ejb.Remote;
028: import javax.persistence.EntityManager;
029: import javax.persistence.PersistenceContext;
030:
031: import org.hibernate.LockMode;
032: import org.hibernate.ejb.HibernateEntityManager;
033: import org.jboss.annotation.security.SecurityDomain;
034: import org.jboss.annotation.ejb.AspectDomain;
035:
036: /**
037: *
038: * @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
039: * @version $Revision: 60758 $
040: */
041: @javax.ejb.Stateless
042: @Remote(Stateless.class)
043: @SecurityDomain("other")
044: //@AspectDomain("JACC Stateless Bean")
045: public class StatelessBean implements Stateless {
046: //TODO: put this in again once we update the hibernate jars (changes already made to hibernate)
047: //@PersistenceContext(unitName="jacc-test")
048: @PersistenceContext
049: HibernateEntityManager em;
050:
051: @PermitAll
052: public int unchecked(int i) {
053: System.out.println("stateless unchecked");
054: return i;
055: }
056:
057: @RolesAllowed("allowed")
058: public int checked(int i) {
059: System.out.println("stateless checked");
060: return i;
061: }
062:
063: @PermitAll
064: public AllEntity insertAllEntity() {
065: AllEntity e = new AllEntity();
066: e.val = "x";
067: em.persist(e);
068: return e;
069: }
070:
071: @PermitAll
072: public AllEntity readAllEntity(int key) {
073: AllEntity e = em.find(AllEntity.class, key);
074: return e;
075: }
076:
077: @PermitAll
078: public void updateAllEntity(AllEntity e) {
079: em.merge(e);
080: }
081:
082: @PermitAll
083: public void deleteAllEntity(AllEntity e) {
084: e = em.merge(e);
085: em.remove(e);
086: }
087:
088: @PermitAll
089: public StarEntity insertStarEntity() {
090: StarEntity e = new StarEntity();
091: e.val = "x";
092: em.persist(e);
093: return e;
094: }
095:
096: @PermitAll
097: public StarEntity readStarEntity(int key) {
098: StarEntity e = em.find(StarEntity.class, key);
099: return e;
100: }
101:
102: @PermitAll
103: public void updateStarEntity(StarEntity e) {
104: em.merge(e);
105: }
106:
107: @PermitAll
108: public void deleteStarEntity(StarEntity e) {
109: e = em.merge(e);
110: em.remove(e);
111: }
112:
113: @PermitAll
114: public SomeEntity insertSomeEntity() {
115: SomeEntity e = new SomeEntity();
116: e.val = "x";
117: em.persist(e);
118: return e;
119: }
120:
121: @PermitAll
122: public SomeEntity readSomeEntity(int key) {
123: SomeEntity e = em.find(SomeEntity.class, key);
124: return e;
125: }
126:
127: @PermitAll
128: public void updateSomeEntity(SomeEntity e) {
129: em.merge(e);
130: }
131:
132: @PermitAll
133: public void deleteSomeEntity(SomeEntity e) {
134: // If we follow specs we need to merge first, but that requires read permission
135: //e = em.merge(e);
136: em.getSession().lock(e, LockMode.NONE);
137: em.remove(e);
138: }
139: }
|