KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > securitymgr > ejb > BadBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.securitymgr.ejb;
23
24 import java.security.Principal JavaDoc;
25 import javax.ejb.SessionBean JavaDoc;
26 import javax.ejb.SessionContext JavaDoc;
27 import javax.security.auth.Subject JavaDoc;
28
29 import org.jboss.logging.Logger;
30
31 import org.jboss.security.SecurityAssociation;
32 import org.jboss.security.RunAsIdentity;
33
34 /** A session bean that attempts things that should not be allowed
35 when running JBoss with a security manager.
36  
37 @author Scott.Stark@jboss.org
38 @version $Revision: 58115 $
39  */

40 public class BadBean implements SessionBean JavaDoc
41 {
42    static final Logger log = Logger.getLogger(BadBean.class);
43
44    public void ejbCreate()
45    {
46    }
47    public void ejbActivate()
48    {
49    }
50    public void ejbPassivate()
51    {
52    }
53    public void ejbRemove()
54    {
55    }
56
57    public void setSessionContext(SessionContext JavaDoc context)
58    {
59    }
60
61    /** Creates a new instance of BadBean */
62    public BadBean()
63    {
64    }
65    
66    public void accessSystemProperties()
67    {
68       System.getProperty("java.home");
69       System.setProperty("java.home","tjo");
70    }
71    
72    public Principal JavaDoc getPrincipal()
73    {
74       return SecurityAssociation.getPrincipal();
75    }
76    public Object JavaDoc getCredential()
77    {
78       return SecurityAssociation.getCredential();
79    }
80    public void setPrincipal(Principal JavaDoc user)
81    {
82       SecurityAssociation.setPrincipal(user);
83    }
84    public void setCredential(char[] password)
85    {
86       SecurityAssociation.setCredential(password);
87    }
88    public void getSubject()
89    {
90       // This should be allowed
91
Subject JavaDoc s = SecurityAssociation.getSubject();
92    }
93    public void getSubjectCredentials()
94    {
95       // This should be allowed
96
Subject JavaDoc s = SecurityAssociation.getSubject();
97       // This should fail
98
s.getPrivateCredentials();
99    }
100    public void setSubject()
101    {
102       Subject JavaDoc s = new Subject JavaDoc();
103       SecurityAssociation.pushSubjectContext(s, null, null);
104    }
105    public void popRunAsRole()
106    {
107       SecurityAssociation.popRunAsIdentity();
108    }
109    public void pushRunAsRole()
110    {
111       RunAsIdentity runAs = new RunAsIdentity("SuperUser", "admin");
112       SecurityAssociation.pushRunAsIdentity(runAs);
113    }
114
115 }
116
Popular Tags