01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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.aspects.security;
23:
24: import org.jboss.aop.Advisor;
25: import org.jboss.aop.InstanceAdvisor;
26: import org.jboss.aop.advice.AspectFactory;
27: import org.jboss.aop.joinpoint.Joinpoint;
28: import org.jboss.security.AuthenticationManager;
29: import org.jboss.security.RealmMapping;
30:
31: import javax.naming.InitialContext;
32: import javax.naming.NamingException;
33:
34: /**
35: * Comment
36: *
37: * @author <a href="mailto:bdecoste@jboss.com">William DeCoste</a>
38: * @version $Revision: 57186 $
39: *
40: **/
41: public class RunAsSecurityInterceptorFactory implements AspectFactory {
42: public Object createPerVM() {
43: throw new RuntimeException(
44: "PER_VM not supported for this interceptor factory, only PER_CLASS");
45: }
46:
47: public Object createPerClass(Advisor advisor) {
48: AuthenticationManager manager = (AuthenticationManager) advisor
49: .getDefaultMetaData().getMetaData("security",
50: "authentication-manager");
51: RealmMapping mapping = (RealmMapping) advisor
52: .getDefaultMetaData().getMetaData("security",
53: "realm-mapping");
54: if (manager == null) {
55: SecurityDomain domain = (SecurityDomain) advisor
56: .resolveAnnotation(SecurityDomain.class);
57: if (domain == null)
58: throw new RuntimeException(
59: "Unable to determine security domain");
60: try {
61: manager = (AuthenticationManager) new InitialContext()
62: .lookup("java:/jaas/" + domain.value());
63: } catch (NamingException e) {
64: throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
65: }
66: mapping = (RealmMapping) manager;
67: }
68: if (manager == null)
69: throw new RuntimeException("Unable to find Security Domain");
70: return new RunAsSecurityInterceptor(manager, mapping);
71: }
72:
73: public Object createPerInstance(Advisor advisor,
74: InstanceAdvisor instanceAdvisor) {
75: throw new RuntimeException(
76: "PER_VM not supported for this interceptor factory, only PER_CLASS");
77: }
78:
79: public Object createPerJoinpoint(Advisor advisor, Joinpoint jp) {
80: throw new RuntimeException(
81: "PER_VM not supported for this interceptor factory, only PER_CLASS");
82: }
83:
84: public Object createPerJoinpoint(Advisor advisor,
85: InstanceAdvisor instanceAdvisor, Joinpoint jp) {
86: throw new RuntimeException(
87: "PER_VM not supported for this interceptor factory, only PER_CLASS");
88: }
89:
90: public String getName() {
91: return getClass().getName();
92: }
93: }
|