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:bill@jboss.org">Bill Burke</a>
38: * @version $Revision: 57186 $
39: *
40: **/
41: public class RoleBasedAuthorizationInterceptorFactory implements
42: AspectFactory {
43: public Object createPerVM() {
44: throw new RuntimeException(
45: "PER_VM not supported for this interceptor factory, only PER_CLASS");
46: }
47:
48: public Object createPerClass(Advisor advisor) {
49: AuthenticationManager manager = (AuthenticationManager) advisor
50: .getDefaultMetaData().getMetaData("security",
51: "authentication-manager");
52: RealmMapping mapping = (RealmMapping) advisor
53: .getDefaultMetaData().getMetaData("security",
54: "realm-mapping");
55: if (manager == null) {
56: SecurityDomain domain = (SecurityDomain) advisor
57: .resolveAnnotation(SecurityDomain.class);
58: if (domain == null)
59: throw new RuntimeException(
60: "Unable to determine security domain");
61: try {
62: manager = (AuthenticationManager) new InitialContext()
63: .lookup("java:/jaas/" + domain.value());
64: } catch (NamingException e) {
65: throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
66: }
67: mapping = (RealmMapping) manager;
68: }
69: if (manager == null)
70: throw new RuntimeException("Unable to find Security Domain");
71: return new RoleBasedAuthorizationInterceptor(manager, mapping);
72: }
73:
74: public Object createPerInstance(Advisor advisor,
75: InstanceAdvisor instanceAdvisor) {
76: throw new RuntimeException(
77: "PER_VM not supported for this interceptor factory, only PER_CLASS");
78: }
79:
80: public Object createPerJoinpoint(Advisor advisor, Joinpoint jp) {
81: throw new RuntimeException(
82: "PER_VM not supported for this interceptor factory, only PER_CLASS");
83: }
84:
85: public Object createPerJoinpoint(Advisor advisor,
86: InstanceAdvisor instanceAdvisor, Joinpoint jp) {
87: throw new RuntimeException(
88: "PER_VM not supported for this interceptor factory, only PER_CLASS");
89: }
90:
91: public String getName() {
92: return getClass().getName();
93: }
94: }
|