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.jmx.connector.invoker;
23:
24: import java.util.HashSet;
25: import java.util.Properties;
26: import java.util.StringTokenizer;
27:
28: import org.jboss.logging.Logger;
29: import org.jboss.security.SimplePrincipal;
30:
31: //$Id: ExternalizableRolesAuthorization.java 57209 2006-09-26 12:21:57Z dimitris@jboss.org $
32:
33: /**
34: * JBAS-3203: Delegate for Authorization Interceptor for RMIAdaptor should have roles configurable
35: * Authorization Delegate used by the AuthorizationInterceptor
36: * that gets its predefined roles from a properties file
37: * @see org.jboss.jmx.connector.invoker.AuthorizationInterceptor
38: * @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
39: * @since May 10, 2006
40: * @version $Revision: 57209 $
41: */
42: public class ExternalizableRolesAuthorization extends
43: RolesAuthorization {
44: private static Logger log = Logger
45: .getLogger(ExternalizableRolesAuthorization.class);
46: private boolean trace = log.isTraceEnabled();
47:
48: public ExternalizableRolesAuthorization() {
49: //Load the roles from a properties file
50: Properties props = new Properties();
51: try {
52: props.load(getTCL().getResourceAsStream(
53: "jmxinvoker-roles.properties"));
54: this .setRequiredRoles(getSetOfRoles(props
55: .getProperty("roles")));
56: } catch (Exception e) {
57: log
58: .error(
59: "Error reading roles from jmxinvoker-roles.properties:",
60: e);
61: }
62: }
63:
64: /**
65: * Get a HashSet of roles as SimplePrincipal
66: *
67: * @param assignedRoles a comma seperated list of roles
68: * @return
69: */
70: private HashSet getSetOfRoles(String assignedRoles) {
71: if (trace)
72: log.trace("AssignedRolesString=" + assignedRoles);
73: HashSet set = new HashSet();
74: StringTokenizer st = new StringTokenizer(assignedRoles, ",");
75: while (st.hasMoreTokens()) {
76: String aRole = st.nextToken();
77: set.add(new SimplePrincipal(aRole));
78: }
79: if (trace)
80: log.trace("roles set=" + set);
81: return set;
82: }
83:
84: private ClassLoader getTCL() {
85: return Thread.currentThread().getContextClassLoader();
86: }
87: }
|