geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlaskow...@apache.org
Subject svn commit: r393787 [2/22] - in /geronimo/trunk/applications: ./ console/ console/console-core/ console/console-core/src/ console/console-core/src/java/ console/console-core/src/java/org/ console/console-core/src/java/org/apache/ console/console-core/s...
Date Thu, 13 Apr 2006 11:36:26 GMT
Added: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesFileLoginModuleNoCache.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesFileLoginModuleNoCache.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesFileLoginModuleNoCache.java (added)
+++ geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesFileLoginModuleNoCache.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,224 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.core.security;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.common.GeronimoSecurityException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
+import org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal;
+import org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
+
+public class PropertiesFileLoginModuleNoCache implements LoginModule {
+
+    Kernel kernel;
+
+    ServerInfo serverInfo;
+
+    URI usersURI;
+
+    URI groupsURI;
+
+    public final static String USERS_URI = "usersURI";
+
+    public final static String GROUPS_URI = "groupsURI";
+
+    private static Log log = LogFactory
+            .getLog(PropertiesFileLoginModuleNoCache.class);
+
+    final Properties users = new Properties();
+
+    final Map groups = new HashMap();
+
+    Subject subject;
+
+    CallbackHandler handler;
+
+    String username;
+
+    String password;
+
+    public void initialize(Subject subject, CallbackHandler callbackHandler,
+            Map sharedState, Map options) {
+        this.subject = subject;
+        this.handler = callbackHandler;
+        try {
+            kernel = KernelRegistry.getKernel((String) options
+                    .get(JaasLoginModuleUse.KERNEL_NAME_LM_OPTION));
+            serverInfo = (ServerInfo) options
+                    .get(JaasLoginModuleUse.SERVERINFO_LM_OPTION);
+            usersURI = new URI((String) options.get(USERS_URI));
+            groupsURI = new URI((String) options.get(GROUPS_URI));
+        } catch (Exception e) {
+            log.error(e);
+            throw new IllegalArgumentException(
+                    "Unable to configure properties file login module: " + e);
+        }
+    }
+
+    public void loadProperties(Kernel kernel, ServerInfo serverInfo,
+            URI userURI, URI groupURI) throws GeronimoSecurityException {
+        try {
+            URI userFile = serverInfo.resolve(userURI);
+            URI groupFile = serverInfo.resolve(groupURI);
+            InputStream stream = userFile.toURL().openStream();
+            // always get a fresh group of users.
+            users.clear();
+            users.load(stream);
+            stream.close();
+
+            Properties temp = new Properties();
+            stream = groupFile.toURL().openStream();
+            temp.load(stream);
+            stream.close();
+            // refresh groups.
+            groups.clear();
+            Enumeration e = temp.keys();
+            while (e.hasMoreElements()) {
+                String groupName = (String) e.nextElement();
+                String[] userList = ((String) temp.get(groupName)).split(",");
+
+                Set userset = (Set) groups.get(groupName);
+                if (userset == null) {
+                    userset = new HashSet();
+                    groups.put(groupName, userset);
+                }
+
+                for (int i = 0; i < userList.length; i++) {
+                    userset.add(userList[i]);
+                }
+            }
+
+        } catch (Exception e) {
+            log.error("Properties File Login Module - data load failed", e);
+            throw new GeronimoSecurityException(e);
+        }
+    }
+
+    public boolean login() throws LoginException {
+        // This is the fundamental modification to the parent class. load
+        // properties before login.
+        loadProperties(kernel, serverInfo, usersURI, groupsURI);
+
+        Callback[] callbacks = new Callback[2];
+
+        callbacks[0] = new NameCallback("User name");
+        callbacks[1] = new PasswordCallback("Password", false);
+        try {
+            handler.handle(callbacks);
+        } catch (IOException ioe) {
+            throw (LoginException) new LoginException().initCause(ioe);
+        } catch (UnsupportedCallbackException uce) {
+            throw (LoginException) new LoginException().initCause(uce);
+        }
+        assert callbacks.length == 2;
+        username = ((NameCallback) callbacks[0]).getName();
+        if (username == null || username.equals("")) {
+            return false;
+        }
+        password = users.getProperty(username);
+
+        return new String(((PasswordCallback) callbacks[1]).getPassword())
+                .equals(password);
+    }
+
+    public boolean commit() throws LoginException {
+        Set principals = subject.getPrincipals();
+
+        principals.add(new GeronimoUserPrincipal(username));
+
+        Iterator e = groups.keySet().iterator();
+        while (e.hasNext()) {
+            String groupName = (String) e.next();
+            Set users = (Set) groups.get(groupName);
+            Iterator iter = users.iterator();
+            while (iter.hasNext()) {
+                String user = (String) iter.next();
+                if (username.equals(user)) {
+                    principals.add(new GeronimoGroupPrincipal(groupName));
+                    break;
+                }
+            }
+        }
+
+        return true;
+    }
+
+    public boolean abort() throws LoginException {
+        username = null;
+        password = null;
+
+        return true;
+    }
+
+    public boolean logout() throws LoginException {
+        username = null;
+        password = null;
+
+        return true;
+    }
+
+    /**
+     * Gets the names of all principal classes that may be populated into a
+     * Subject.
+     */
+    public String[] getPrincipalClassNames() {
+        return new String[] { GeronimoUserPrincipal.class.getName(),
+                GeronimoGroupPrincipal.class.getName() };
+    }
+
+    /**
+     * Gets a list of all the principals of a particular type (identified by the
+     * principal class). These are available for manual role mapping.
+     */
+    public String[] getPrincipalsOfClass(String className) {
+        Set s;
+        if (className.equals(GeronimoGroupPrincipal.class.getName())) {
+            s = groups.keySet();
+        } else if (className.equals(GeronimoUserPrincipal.class.getName())) {
+            s = users.keySet();
+        } else {
+            throw new IllegalArgumentException("No such principal class "
+                    + className);
+        }
+        return (String[]) s.toArray(new String[s.size()]);
+    }
+}

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesFileLoginModuleNoCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesFileLoginModuleNoCache.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesFileLoginModuleNoCache.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java (added)
+++ geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,293 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.core.security;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.UnknownServiceException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.geronimo.common.GeronimoSecurityException;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.security.jaas.LoginModuleGBean;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+
+public class PropertiesLoginModuleManager {
+
+    private ServerInfo serverInfo;
+
+    private LoginModuleGBean loginModule;
+
+    private Properties users = new Properties();
+
+    private Properties groups = new Properties();
+
+    private static final String usersKey = "usersURI";
+
+    private static final String groupsKey = "groupsURI";
+
+    public PropertiesLoginModuleManager(ServerInfo serverInfo,
+            LoginModuleGBean loginModule) {
+        this.serverInfo = serverInfo;
+        this.loginModule = loginModule;
+    }
+
+    private void refreshUsers() {
+        users.clear();
+        try {
+            users.load(serverInfo.resolve(getUsersURI()).toURL().openStream());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException(e);
+        }
+    }
+
+    private void refreshGroups() throws GeronimoSecurityException {
+        groups.clear();
+        try {
+            groups
+                    .load(serverInfo.resolve(getGroupsURI()).toURL()
+                            .openStream());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException(e);
+        }
+    }
+
+    public String[] getUsers() throws GeronimoSecurityException {
+        users.clear();
+        try {
+            users.load(serverInfo.resolve(getUsersURI()).toURL().openStream());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException(e);
+        }
+        return (String[]) users.keySet().toArray(new String[0]);
+    }
+
+    public String[] getGroups() throws GeronimoSecurityException {
+        groups.clear();
+        try {
+            groups
+                    .load(serverInfo.resolve(getGroupsURI()).toURL()
+                            .openStream());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException(e);
+        }
+        return (String[]) groups.keySet().toArray(new String[0]);
+    }
+
+    public void addUserPrincipal(Hashtable properties)
+            throws GeronimoSecurityException {
+        if (users.getProperty((String) properties.get("UserName")) != null) {
+            throw new GeronimoSecurityException("User principal "
+                    + (String) properties.get("UserName") + " already exists.");
+        }
+        try {
+            refreshUsers();
+            users.setProperty((String) properties.get("UserName"),
+                    (String) properties.get("Password"));
+            store(users, serverInfo.resolve(getUsersURI()).toURL());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException("Cannot add user principal: "
+                    + e.getMessage());
+        }
+    }
+
+    public void removeUserPrincipal(String userPrincipal)
+            throws GeronimoSecurityException {
+        try {
+            refreshUsers();
+            users.remove(userPrincipal);
+            store(users, serverInfo.resolve(getUsersURI()).toURL());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException("Cannot remove user principal "
+                    + userPrincipal + ": " + e.getMessage());
+        }
+    }
+
+    public void updateUserPrincipal(Hashtable properties)
+            throws GeronimoSecurityException {
+        //same as add pricipal overriding the property
+        try {
+            refreshUsers();
+            users.setProperty((String) properties.get("UserName"),
+                    (String) properties.get("Password"));
+            store(users, serverInfo.resolve(getUsersURI()).toURL());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException("Cannot add user principal: "
+                    + e.getMessage());
+        }
+    }
+
+    public void addGroupPrincipal(Hashtable properties)
+            throws GeronimoSecurityException {
+        refreshGroups();
+        if (groups.getProperty((String) properties.get("GroupName")) != null) {
+            throw new GeronimoSecurityException("Group "
+                    + (String) properties.get("GroupName") + " already exists.");
+        }
+        try {
+            groups.setProperty((String) properties.get("GroupName"),
+                    (String) properties.get("Members"));
+            store(groups, serverInfo.resolve(getGroupsURI()).toURL());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException("Cannot add group principal: "
+                    + e.getMessage());
+        }
+    }
+
+    public void removeGroupPrincipal(String groupPrincipal)
+            throws GeronimoSecurityException {
+        refreshGroups();
+        try {
+            groups.remove(groupPrincipal);
+            store(groups, serverInfo.resolve(getGroupsURI()).toURL());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException(
+                    "Cannot remove group principal: " + e.getMessage());
+        }
+    }
+
+    public void updateGroupPrincipal(Hashtable properties)
+            throws GeronimoSecurityException {
+        //same as add group principal
+        refreshGroups();
+        try {
+            groups.setProperty((String) properties.get("GroupName"),
+                    (String) properties.get("Members"));
+            store(groups, serverInfo.resolve(getGroupsURI()).toURL());
+        } catch (Exception e) {
+            throw new GeronimoSecurityException("Cannot add group principal: "
+                    + e.getMessage());
+        }
+    }
+
+    public void addToGroup(String userPrincipal, String groupPrincipal)
+            throws GeronimoSecurityException {
+        throw new GeronimoSecurityException(
+                "Not implemented for properties file security realm...");
+    }
+
+    public void removeFromGroup(String userPrincipal, String groupPrincipal)
+            throws GeronimoSecurityException {
+        throw new GeronimoSecurityException(
+                "Not implemented for properties file security realm...");
+    }
+
+    public String getPassword(String userPrincipal)
+            throws GeronimoSecurityException {
+        refreshUsers();
+        return users.getProperty(userPrincipal);
+    }
+
+    public Set getGroupMembers(String groupPrincipal)
+            throws GeronimoSecurityException {
+        Set memberSet = new HashSet();
+        groups.clear();
+        refreshGroups();
+        if (groups.getProperty(groupPrincipal) == null) {
+            return memberSet;
+        }
+        String[] members = ((String) groups.getProperty(groupPrincipal))
+                .split(",");
+
+        memberSet.addAll(Arrays.asList(members));
+        return memberSet;
+    }
+
+    private String getUsersURI() {
+        return loginModule.getOptions().getProperty(usersKey);
+    }
+
+    private String getGroupsURI() {
+        return loginModule.getOptions().getProperty(groupsKey);
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("PropertiesLoginModuleManager", PropertiesLoginModuleManager.class);
+
+        infoFactory.addOperation("addUserPrincipal",
+                new Class[] { Hashtable.class });
+        infoFactory.addOperation("removeUserPrincipal",
+                new Class[] { String.class });
+        infoFactory.addOperation("updateUserPrincipal",
+                new Class[] { Hashtable.class });
+        infoFactory.addOperation("getGroups");
+        infoFactory.addOperation("getUsers");
+
+        infoFactory.addOperation("updateUserPrincipal",
+                new Class[] { Hashtable.class });
+
+        infoFactory.addOperation("getPassword", new Class[] { String.class });
+        infoFactory.addOperation("getGroupMembers",
+                new Class[] { String.class });
+        infoFactory.addOperation("addGroupPrincipal",
+                new Class[] { Hashtable.class });
+        infoFactory.addOperation("removeGroupPrincipal",
+                new Class[] { String.class });
+        infoFactory.addOperation("updateGroupPrincipal",
+                new Class[] { Hashtable.class });
+        infoFactory.addOperation("addToGroup", new Class[] { String.class,
+                String.class });
+        infoFactory.addOperation("removeFromGroup", new Class[] { String.class,
+                String.class });
+
+        infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE);
+        infoFactory.addReference("LoginModule", LoginModuleGBean.class, NameFactory.LOGIN_MODULE);
+
+        infoFactory
+                .setConstructor(new String[] { "ServerInfo", "LoginModule" });
+
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+
+    private void store(Properties props, URL url) throws Exception{
+        OutputStream out = null;
+        try {
+            URLConnection con = url.openConnection();
+            con.setDoOutput(true);
+            out = con.getOutputStream();
+        } catch(Exception e){
+            if("file".equalsIgnoreCase(url.getProtocol()) && e instanceof UnknownServiceException) {
+                out = new FileOutputStream(new File(url.getFile()));
+            } else {
+                throw e;
+            }
+        }
+        props.store(out, null);
+        try {
+            out.close();
+        } catch(IOException ie) {
+            // Ignore
+        }
+    }
+}

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/SEServerInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/SEServerInfo.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/SEServerInfo.java (added)
+++ geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/SEServerInfo.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,78 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.core.system.serverinfo;
+
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+
+public class SEServerInfo {
+    private static final String PLATFORM_ARCH = "os.arch";
+
+    public String getVersion() {
+        return ServerConstants.getVersion();
+    }
+
+    public String getBuildDate() {
+        return ServerConstants.getBuildDate();
+    }
+
+    public String getBuildTime() {
+        return ServerConstants.getBuildTime();
+    }
+
+    public String getCopyright() {
+        return ServerConstants.getCopyright();
+    }
+
+    public String getGeronimoBuildVersion() {
+        return ServerConstants.getGeronimoBuildVersion();
+    }
+
+    public String getGeronimoSpecVersion() {
+        return ServerConstants.getGeronimoSpecVersion();
+    }
+
+    public String getPortalCoreVersion() {
+        return ServerConstants.getPortalCoreVersion();
+    }
+
+    public String getPlatformArch() {
+        return System.getProperty(PLATFORM_ARCH);
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(SEServerInfo.class);
+
+        infoFactory.addAttribute("version", String.class, false);
+        infoFactory.addAttribute("buildDate", String.class, false);
+        infoFactory.addAttribute("buildTime", String.class, false);
+        infoFactory.addAttribute("copyright", String.class, false);
+        infoFactory.addAttribute("geronimoBuildVersion", String.class, false);
+        infoFactory.addAttribute("geronimoSpecVersion", String.class, false);
+        infoFactory.addAttribute("portalCoreVersion", String.class, false);
+        infoFactory.addAttribute("platformArch", String.class, false);
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+
+}

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/SEServerInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/SEServerInfo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/SEServerInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java (added)
+++ geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,143 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.core.system.serverinfo;
+
+import java.util.Properties;
+
+public class ServerConstants {
+
+    private static final String PROPERTIES_FILE = "org/apache/geronimo/console/core/system/serverinfo/geronimo-version.properties";
+
+    private static final String VERSION;
+
+    private static final String BUILD_DATE;
+
+    private static final String BUILD_TIME;
+
+    private static final String COPYRIGHT;
+
+    private static final String GERONIMO_BUILD_VERSION;
+
+    private static final String GERONIMO_SPEC_VERSION;
+
+    private static final String PORTAL_CORE_VERSION;
+
+    /**
+     * Gets the server version
+     *
+     * @return version of the server
+     */
+    public static String getVersion() {
+        return VERSION;
+    }
+
+    public static String getGeronimoBuildVersion() {
+        return GERONIMO_BUILD_VERSION;
+    }
+
+    public static String getGeronimoSpecVersion() {
+        return GERONIMO_SPEC_VERSION;
+    }
+
+    public static String getPortalCoreVersion() {
+        return PORTAL_CORE_VERSION;
+    }
+
+    /**
+     * Gets the date the server was built
+     *
+     * @return date of the server build
+     */
+    public static String getBuildDate() {
+        return BUILD_DATE;
+    }
+
+    /**
+     * Gets the time the server was built
+     *
+     * @return time of the server build
+     */
+    public static String getBuildTime() {
+        return BUILD_TIME;
+    }
+
+    /**
+     * Gets the copyright message for the server
+     *
+     * @return
+     */
+    public static String getCopyright() {
+        return COPYRIGHT;
+    }
+
+    /**
+     * load all of the properties from the geronimo-version.properties file,
+     * which is generated during the build
+     */
+    static {
+        Properties versionInfo = new Properties();
+        try {
+            versionInfo.load(ServerConstants.class.getClassLoader()
+                    .getResourceAsStream(PROPERTIES_FILE));
+        } catch (java.io.IOException e) {
+            throw new ExceptionInInitializerError(new Exception(
+                    "Could not load geronimo-version.properties", e));
+        }
+        VERSION = versionInfo.getProperty("version");
+        if (VERSION == null || VERSION.length() == 0) {
+            throw new ExceptionInInitializerError(
+                    "geronimo-version.properties does not contain a 'version' property");
+        }
+
+        BUILD_DATE = versionInfo.getProperty("build.date");
+        if (BUILD_DATE == null || BUILD_DATE.length() == 0) {
+            throw new ExceptionInInitializerError(
+                    "geronimo-version.properties does not contain a 'build.date' property");
+        }
+
+        BUILD_TIME = versionInfo.getProperty("build.time");
+        if (BUILD_TIME == null || BUILD_TIME.length() == 0) {
+            throw new ExceptionInInitializerError(
+                    "geronimo-version.properties does not contain a 'build.time' property");
+        }
+
+        COPYRIGHT = versionInfo.getProperty("copyright");
+        if (COPYRIGHT == null || COPYRIGHT.length() == 0) {
+            throw new ExceptionInInitializerError(
+                    "geronimo-version.properties does not contain a 'copyright' property");
+        }
+        GERONIMO_BUILD_VERSION = versionInfo
+                .getProperty("geronimo.build.version");
+        if (GERONIMO_BUILD_VERSION == null || COPYRIGHT.length() == 0) {
+            throw new ExceptionInInitializerError(
+                    "geronimo-version.properties does not contain a 'copyright' property");
+        }
+        GERONIMO_SPEC_VERSION = versionInfo
+                .getProperty("geronimo.spec.version");
+        if (GERONIMO_SPEC_VERSION == null || COPYRIGHT.length() == 0) {
+            throw new ExceptionInInitializerError(
+                    "geronimo-version.properties does not contain a 'copyright' property");
+        }
+        PORTAL_CORE_VERSION = versionInfo.getProperty("portal.core.version");
+        if (PORTAL_CORE_VERSION == null || COPYRIGHT.length() == 0) {
+            throw new ExceptionInInitializerError(
+                    "geronimo-version.properties does not contain a 'copyright' property");
+        }
+
+    }
+}

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java (added)
+++ geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,1142 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.console.util;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.GBeanQuery;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.j2ee.management.impl.Util;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.proxy.ProxyManager;
+import org.apache.geronimo.kernel.repository.Repository;
+import org.apache.geronimo.management.AppClientModule;
+import org.apache.geronimo.management.EJB;
+import org.apache.geronimo.management.EJBModule;
+import org.apache.geronimo.management.J2EEDeployedObject;
+import org.apache.geronimo.management.J2EEDomain;
+import org.apache.geronimo.management.J2EEModule;
+import org.apache.geronimo.management.J2EEResource;
+import org.apache.geronimo.management.JCAConnectionFactory;
+import org.apache.geronimo.management.JDBCDataSource;
+import org.apache.geronimo.management.JDBCDriver;
+import org.apache.geronimo.management.JDBCResource;
+import org.apache.geronimo.management.JMSResource;
+import org.apache.geronimo.management.ResourceAdapter;
+import org.apache.geronimo.management.Servlet;
+import org.apache.geronimo.management.WebModule;
+import org.apache.geronimo.management.geronimo.EJBConnector;
+import org.apache.geronimo.management.geronimo.EJBManager;
+import org.apache.geronimo.management.geronimo.J2EEApplication;
+import org.apache.geronimo.management.geronimo.J2EEServer;
+import org.apache.geronimo.management.geronimo.JCAAdminObject;
+import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
+import org.apache.geronimo.management.geronimo.JCAResource;
+import org.apache.geronimo.management.geronimo.JMSBroker;
+import org.apache.geronimo.management.geronimo.JMSConnector;
+import org.apache.geronimo.management.geronimo.JMSManager;
+import org.apache.geronimo.management.geronimo.JVM;
+import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
+import org.apache.geronimo.management.geronimo.WebAccessLog;
+import org.apache.geronimo.management.geronimo.WebConnector;
+import org.apache.geronimo.management.geronimo.WebContainer;
+import org.apache.geronimo.management.geronimo.WebManager;
+import org.apache.geronimo.pool.GeronimoExecutor;
+import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
+import org.apache.geronimo.security.jaas.server.JaasLoginServiceMBean;
+import org.apache.geronimo.security.realm.SecurityRealm;
+import org.apache.geronimo.system.logging.SystemLog;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
+
+/**
+ * An implementation of the ManagementHelper interface that uses a Geronimo
+ * kernel. That may be an in-VM kernel or a remote kernel, we don't really
+ * care.
+ *
+ * @version $Rev$ $Date$
+ */
+public class KernelManagementHelper implements ManagementHelper {
+    private final static Log log = LogFactory.getLog(KernelManagementHelper.class);
+    private Kernel kernel;
+    private ProxyManager pm;
+
+    public KernelManagementHelper(Kernel kernel) {
+        this.kernel = kernel;
+        pm = kernel.getProxyManager();
+    }
+
+    public J2EEDomain[] getDomains() {
+        String[] names = Util.getObjectNames(kernel, "*:", new String[]{"J2EEDomain"});
+        J2EEDomain[] domains = new J2EEDomain[names.length];
+        for (int i = 0; i < domains.length; i++) {
+            try {
+                domains[i] = (J2EEDomain)kernel.getProxyManager().createProxy(ObjectName.getInstance(names[i]), J2EEDomain.class);
+            } catch (MalformedObjectNameException e) {
+                log.error("Unable to look up related GBean", e);
+            }
+        }
+        return domains;
+    }
+
+    public J2EEServer[] getServers(J2EEDomain domain) {
+        J2EEServer[] servers = new J2EEServer[0];
+        try {
+            String[] names = domain.getServers();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            servers = new J2EEServer[temp.length];
+            System.arraycopy(temp, 0, servers, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return servers;
+    }
+
+    public J2EEDeployedObject[] getDeployedObjects(J2EEServer server) {
+        J2EEDeployedObject[] result = new J2EEDeployedObject[0];
+        try {
+            String[] names = server.getDeployedObjects();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new J2EEDeployedObject[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public J2EEApplication[] getApplications(J2EEServer server) {
+        List list = new ArrayList();
+        try {
+            String[] names = server.getDeployedObjects();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.J2EE_APPLICATION)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (J2EEApplication[]) list.toArray(new J2EEApplication[list.size()]);
+    }
+
+    public AppClientModule[] getAppClients(J2EEServer server) {
+        List list = new ArrayList();
+        try {
+            String[] names = server.getDeployedObjects();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.APP_CLIENT_MODULE)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (AppClientModule[]) list.toArray(new AppClientModule[list.size()]);
+    }
+
+    public WebModule[] getWebModules(J2EEServer server) {
+        List list = new ArrayList();
+        try {
+            String[] names = server.getDeployedObjects();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.WEB_MODULE)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (WebModule[]) list.toArray(new WebModule[list.size()]);
+    }
+
+    public EJBModule[] getEJBModules(J2EEServer server) {
+        List list = new ArrayList();
+        try {
+            String[] names = server.getDeployedObjects();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.EJB_MODULE)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (EJBModule[]) list.toArray(new EJBModule[list.size()]);
+    }
+
+    public ResourceAdapterModule[] getRAModules(J2EEServer server) {
+        List list = new ArrayList();
+        try {
+            String[] names = server.getDeployedObjects();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.RESOURCE_ADAPTER_MODULE)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (ResourceAdapterModule[]) list.toArray(new ResourceAdapterModule[list.size()]);
+    }
+
+    public JCAManagedConnectionFactory[] getOutboundFactories(J2EEServer server, String connectionFactoryInterface) {
+        List list = new ArrayList();
+        try {
+            String[] names = server.getDeployedObjects();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.RESOURCE_ADAPTER_MODULE)) {
+                    ResourceAdapterModule module = (ResourceAdapterModule) pm.createProxy(name, KernelManagementHelper.class.getClassLoader());
+                    ResourceAdapter[] adapters = getResourceAdapters(module);
+                    for (int j = 0; j < adapters.length; j++) {
+                        ResourceAdapter adapter = adapters[j];
+                        JCAResource[] resources = getRAResources(adapter);
+                        for (int k = 0; k < resources.length; k++) {
+                            JCAResource resource = resources[k];
+                            JCAConnectionFactory[] factories = getConnectionFactories(resource);
+                            for (int l = 0; l < factories.length; l++) {
+                                JCAConnectionFactory factory = factories[l];
+                                JCAManagedConnectionFactory mcf = getManagedConnectionFactory(factory);
+                                if(mcf.getConnectionFactoryInterface().equals(connectionFactoryInterface)) {
+                                    list.add(mcf);
+                                    continue;
+                                }
+                                for (int m = 0; m < mcf.getImplementedInterfaces().length; m++) {
+                                    String iface = mcf.getImplementedInterfaces()[m];
+                                    if(iface.equals(connectionFactoryInterface)) {
+                                        list.add(mcf);
+                                        break;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (JCAManagedConnectionFactory[]) list.toArray(new JCAManagedConnectionFactory[list.size()]);
+    }
+
+    public ResourceAdapterModule[] getOutboundRAModules(J2EEServer server, String connectionFactoryInterface) {
+        return getOutboundRAModules(server, new String[]{connectionFactoryInterface});
+    }
+
+    public ResourceAdapterModule[] getOutboundRAModules(J2EEServer server, String[] connectionFactoryInterfaces) {
+        Set targets = new HashSet(Arrays.asList(connectionFactoryInterfaces));
+        List list = new ArrayList();
+        try {
+            String[] names = server.getDeployedObjects();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.RESOURCE_ADAPTER_MODULE)) {
+                    ResourceAdapterModule module = (ResourceAdapterModule) pm.createProxy(name, KernelManagementHelper.class.getClassLoader());
+                    ResourceAdapter[] adapters = getResourceAdapters(module);
+                    outer:
+                    for (int j = 0; j < adapters.length; j++) {
+                        ResourceAdapter adapter = adapters[j];
+                        JCAResource[] resources = getRAResources(adapter);
+                        for (int k = 0; k < resources.length; k++) {
+                            JCAResource resource = resources[k];
+                            JCAConnectionFactory[] factories = getConnectionFactories(resource);
+                            for (int l = 0; l < factories.length; l++) {
+                                JCAConnectionFactory factory = factories[l];
+                                JCAManagedConnectionFactory mcf = getManagedConnectionFactory(factory);
+                                if(targets.contains(mcf.getConnectionFactoryInterface())) {
+                                    list.add(module);
+                                    break outer;
+                                }
+                                for (int m = 0; m < mcf.getImplementedInterfaces().length; m++) {
+                                    String iface = mcf.getImplementedInterfaces()[m];
+                                    if(targets.contains(iface)) {
+                                        list.add(module);
+                                        break outer;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (ResourceAdapterModule[]) list.toArray(new ResourceAdapterModule[list.size()]);
+    }
+
+    public ResourceAdapterModule[] getAdminObjectModules(J2EEServer server, String[] adminObjectInterfaces) {
+        List list = new ArrayList();
+        try {
+            String[] names = server.getDeployedObjects();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.RESOURCE_ADAPTER_MODULE)) {
+                    ResourceAdapterModule module = (ResourceAdapterModule) pm.createProxy(name, KernelManagementHelper.class.getClassLoader());
+                    ResourceAdapter[] adapters = getResourceAdapters(module);
+                    outer:
+                    for (int j = 0; j < adapters.length; j++) {
+                        ResourceAdapter adapter = adapters[j];
+                        JCAResource[] resources = getRAResources(adapter);
+                        for (int k = 0; k < resources.length; k++) {
+                            JCAResource resource = resources[k];
+                            JCAAdminObject[] admins = getAdminObjects(resource);
+                            for (int l = 0; l < admins.length; l++) {
+                                JCAAdminObject admin = admins[l];
+                                String adminIface = admin.getAdminObjectInterface();
+                                for (int m = 0; m < adminObjectInterfaces.length; m++) {
+                                    if(adminIface.equals(adminObjectInterfaces[m])) {
+                                        list.add(module);
+                                        break outer;
+                                    }
+
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (ResourceAdapterModule[]) list.toArray(new ResourceAdapterModule[list.size()]);
+    }
+
+    public JCAManagedConnectionFactory[] getOutboundFactories(ResourceAdapterModule module) {
+        List list = new ArrayList();
+        try {
+            ResourceAdapter[] adapters = getResourceAdapters(module);
+            for (int j = 0; j < adapters.length; j++) {
+                ResourceAdapter adapter = adapters[j];
+                JCAResource[] resources = getRAResources(adapter);
+                for (int k = 0; k < resources.length; k++) {
+                    JCAResource resource = resources[k];
+                    JCAConnectionFactory[] factories = getConnectionFactories(resource);
+                    for (int l = 0; l < factories.length; l++) {
+                        JCAConnectionFactory factory = factories[l];
+                        JCAManagedConnectionFactory mcf = getManagedConnectionFactory(factory);
+                        list.add(mcf);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (JCAManagedConnectionFactory[]) list.toArray(new JCAManagedConnectionFactory[list.size()]);
+    }
+
+    public JCAManagedConnectionFactory[] getOutboundFactories(ResourceAdapterModule module, String connectionFactoryInterface) {
+        return getOutboundFactories(module, new String[]{connectionFactoryInterface});
+    }
+    public JCAManagedConnectionFactory[] getOutboundFactories(ResourceAdapterModule module, String[] connectionFactoryInterfaces) {
+        Set targets = new HashSet(Arrays.asList(connectionFactoryInterfaces));
+        List list = new ArrayList();
+        try {
+            ResourceAdapter[] adapters = getResourceAdapters(module);
+            for (int j = 0; j < adapters.length; j++) {
+                ResourceAdapter adapter = adapters[j];
+                JCAResource[] resources = getRAResources(adapter);
+                for (int k = 0; k < resources.length; k++) {
+                    JCAResource resource = resources[k];
+                    JCAConnectionFactory[] factories = getConnectionFactories(resource);
+                    for (int l = 0; l < factories.length; l++) {
+                        JCAConnectionFactory factory = factories[l];
+                        JCAManagedConnectionFactory mcf = getManagedConnectionFactory(factory);
+                        if(targets.contains(mcf.getConnectionFactoryInterface())) {
+                            list.add(mcf);
+                            continue;
+                        }
+                        for (int m = 0; m < mcf.getImplementedInterfaces().length; m++) {
+                            String iface = mcf.getImplementedInterfaces()[m];
+                            if(targets.contains(iface)) {
+                                list.add(mcf);
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (JCAManagedConnectionFactory[]) list.toArray(new JCAManagedConnectionFactory[list.size()]);
+    }
+
+    public JCAAdminObject[] getAdminObjects(ResourceAdapterModule module, String[] adminObjectInterfaces) {
+        List list = new ArrayList();
+        try {
+            ResourceAdapter[] adapters = getResourceAdapters(module);
+            for (int j = 0; j < adapters.length; j++) {
+                ResourceAdapter adapter = adapters[j];
+                JCAResource[] resources = getRAResources(adapter);
+                for (int k = 0; k < resources.length; k++) {
+                    JCAResource resource = resources[k];
+                    JCAAdminObject[] admins = getAdminObjects(resource);
+                    for (int l = 0; l < admins.length; l++) {
+                        JCAAdminObject admin = admins[l];
+                        String adminIface = admin.getAdminObjectInterface();
+                        for (int m = 0; m < adminObjectInterfaces.length; m++) {
+                            if(adminIface.equals(adminObjectInterfaces[m])) {
+                                list.add(admin);
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (JCAAdminObject[]) list.toArray(new JCAAdminObject[list.size()]);
+    }
+
+    public J2EEResource[] getResources(J2EEServer server) {
+        J2EEResource[] result = new J2EEResource[0];
+        try {
+            String[] names = server.getResources();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new J2EEResource[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public JCAResource[] getJCAResources(J2EEServer server) {
+        List list = new ArrayList();
+        try {
+            //todo: filter based on ObjectName or something, but what counts as a "JCAResource"?
+            J2EEResource[] all = getResources(server);
+            for (int i = 0; i < all.length; i++) {
+                if(all[i] instanceof JCAResource) {
+                    list.add(all[i]);
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (JCAResource[]) list.toArray(new JCAResource[list.size()]);
+    }
+
+    public JDBCResource[] getJDBCResources(J2EEServer server) {
+        return new JDBCResource[0]; // Geronimo uses JCA resources for this
+    }
+
+    public JMSResource[] getJMSResources(J2EEServer server) {
+        return new JMSResource[0];  // Geronimo uses JCA resources for this
+    }
+
+    public JVM[] getJavaVMs(J2EEServer server) {
+        JVM[] result = new JVM[0];
+        try {
+            String[] names = server.getJavaVMs();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JVM[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up JVMs for J2EEServer", e);
+        }
+        return result;
+    }
+
+    public Repository[] getRepositories(J2EEServer server) {
+        Repository[] result = new Repository[0];
+        try {
+            String[] names = server.getRepositories();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new Repository[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up repositories for J2EEServer", e);
+        }
+        return result;
+    }
+
+    public SecurityRealm[] getSecurityRealms(J2EEServer server) {
+        SecurityRealm[] result = new SecurityRealm[0];
+        try {
+            String[] names = server.getSecurityRealms();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new SecurityRealm[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up security realms for J2EEServer", e);
+        }
+        return result;
+    }
+
+    public ServerInfo getServerInfo(J2EEServer server) {
+        try {
+            String name = server.getServerInfo();
+            return (ServerInfo) pm.createProxy(ObjectName.getInstance(name), KernelManagementHelper.class.getClassLoader());
+        } catch (Exception e) {
+            log.error("Unable to look up ServerInfo for J2EEServer", e);
+            return null;
+        }
+    }
+
+    public JaasLoginServiceMBean getLoginService(J2EEServer server) {
+        try {
+            String name = server.getServerInfo();
+            return (JaasLoginServiceMBean) pm.createProxy(ObjectName.getInstance(name), KernelManagementHelper.class.getClassLoader());
+        } catch (Exception e) {
+            log.error("Unable to look up LoginService for J2EEServer", e);
+            return null;
+        }
+    }
+
+    public WebManager[] getWebManagers(J2EEServer server) {
+        WebManager[] result = new WebManager[0];
+        try {
+            String[] names = server.getWebManagers();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new WebManager[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up WebManagers for J2EEServer", e);
+        }
+        return result;
+    }
+
+    public WebAccessLog getWebAccessLog(WebManager manager, WebContainer container) {
+        return getWebAccessLog(manager, kernel.getObjectNameFor(container).getCanonicalName());
+    }
+
+    public WebAccessLog getWebAccessLog(WebManager manager, String container) {
+        WebAccessLog result = null;
+        try {
+            String name = manager.getAccessLog(container);
+            Object temp = pm.createProxy(ObjectName.getInstance(name), KernelManagementHelper.class.getClassLoader());
+            result = (WebAccessLog) temp;
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public WebContainer[] getWebContainers(WebManager manager) {
+        WebContainer[] result = new WebContainer[0];
+        try {
+            String[] names = manager.getContainers();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new WebContainer[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public WebConnector[] getWebConnectorsForContainer(WebManager manager, WebContainer container, String protocol) {
+        return getWebConnectorsForContainer(manager, kernel.getObjectNameFor(container).getCanonicalName(), protocol);
+    }
+
+    public WebConnector[] getWebConnectorsForContainer(WebManager manager, WebContainer container) {
+        return getWebConnectorsForContainer(manager, kernel.getObjectNameFor(container).getCanonicalName());
+    }
+
+    public WebConnector[] getWebConnectorsForContainer(WebManager manager, String containerObjectName, String protocol) {
+        WebConnector[] result = new WebConnector[0];
+        try {
+            String[] names = manager.getConnectorsForContainer(containerObjectName, protocol);
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new WebConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public WebConnector[] getWebConnectorsForContainer(WebManager manager, String containerObjectName) {
+        WebConnector[] result = new WebConnector[0];
+        try {
+            String[] names = manager.getConnectorsForContainer(containerObjectName);
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new WebConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public WebConnector[] getWebConnectors(WebManager manager, String protocol) {
+        WebConnector[] result = new WebConnector[0];
+        try {
+            String[] names = manager.getConnectors(protocol);
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new WebConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public WebConnector[] getWebConnectors(WebManager manager) {
+        WebConnector[] result = new WebConnector[0];
+        try {
+            String[] names = manager.getConnectors();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new WebConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public EJBManager[] getEJBManagers(J2EEServer server) {
+        EJBManager[] result = null;
+        try {
+            String names[] = server.getEJBManagers();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new EJBManager[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public EJBConnector[] getEJBConnectors(EJBManager container, String protocol) {
+        EJBConnector[] result = new EJBConnector[0];
+        try {
+            String[] names = container.getConnectors(protocol);
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new EJBConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public EJBConnector[] getEJBConnectors(EJBManager container) {
+        EJBConnector[] result = new EJBConnector[0];
+        try {
+            String[] names = container.getConnectors();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new EJBConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public JMSManager[] getJMSManagers(J2EEServer server) {
+        JMSManager[] result = null;
+        try {
+            String[] names = server.getJMSManagers();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JMSManager[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public JMSBroker[] getJMSBrokers(JMSManager manager) {
+        JMSBroker[] result = null;
+        try {
+            String[] names = manager.getContainers();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JMSBroker[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public JMSConnector[] getJMSConnectors(JMSManager manager, String protocol) {
+        JMSConnector[] result = null;
+        try {
+            String[] names = manager.getConnectors(protocol);
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JMSConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public JMSConnector[] getJMSConnectors(JMSManager manager) {
+        JMSConnector[] result = null;
+        try {
+            String[] names = manager.getConnectors();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JMSConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public JMSConnector[] getJMSConnectorsForContainer(JMSManager manager, JMSBroker broker, String protocol) {
+        return getJMSConnectorsForContainer(manager, kernel.getObjectNameFor(broker).getCanonicalName(), protocol);
+    }
+
+    public JMSConnector[] getJMSConnectorsForContainer(JMSManager manager, JMSBroker broker) {
+        return getJMSConnectorsForContainer(manager, kernel.getObjectNameFor(broker).getCanonicalName());
+    }
+
+    public JMSConnector[] getJMSConnectorsForContainer(JMSManager manager, String brokerObjectName, String protocol) {
+        JMSConnector[] result = null;
+        try {
+            String[] names = manager.getConnectorsForContainer(brokerObjectName, protocol);
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JMSConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public JMSConnector[] getJMSConnectorsForContainer(JMSManager manager, String brokerObjectName) {
+        JMSConnector[] result = null;
+        try {
+            String[] names = manager.getConnectorsForContainer(brokerObjectName);
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JMSConnector[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public GeronimoExecutor[] getThreadPools(J2EEServer server) {
+        GeronimoExecutor[] result = new GeronimoExecutor[0];
+        try {
+            String[] names = server.getThreadPools();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new GeronimoExecutor[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public SystemLog getSystemLog(JVM jvm) {
+        SystemLog result = null;
+        try {
+            String name = jvm.getSystemLog();
+            Object temp = pm.createProxy(ObjectName.getInstance(name), KernelManagementHelper.class.getClassLoader());
+            result = (SystemLog)temp;
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    // application properties
+    public J2EEModule[] getModules(J2EEApplication application) {
+        J2EEModule[] result = new J2EEModule[0];
+        try {
+            String[] names = application.getModules();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new J2EEModule[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public AppClientModule[] getAppClients(J2EEApplication application) {
+        List list = new ArrayList();
+        try {
+            String[] names = application.getModules();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.APP_CLIENT_MODULE)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (AppClientModule[]) list.toArray(new AppClientModule[list.size()]);
+    }
+
+    public WebModule[] getWebModules(J2EEApplication application) {
+        List list = new ArrayList();
+        try {
+            String[] names = application.getModules();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.WEB_MODULE)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (WebModule[]) list.toArray(new WebModule[list.size()]);
+    }
+
+    public EJBModule[] getEJBModules(J2EEApplication application) {
+        List list = new ArrayList();
+        try {
+            String[] names = application.getModules();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.EJB_MODULE)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (EJBModule[]) list.toArray(new EJBModule[list.size()]);
+    }
+
+    public ResourceAdapterModule[] getRAModules(J2EEApplication application) {
+        List list = new ArrayList();
+        try {
+            String[] names = application.getModules();
+            for (int i = 0; i < names.length; i++) {
+                ObjectName name = ObjectName.getInstance(names[i]);
+                String type = name.getKeyProperty(NameFactory.J2EE_TYPE);
+                if(type.equals(NameFactory.RESOURCE_ADAPTER_MODULE)) {
+                    list.add(pm.createProxy(name, KernelManagementHelper.class.getClassLoader()));
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (ResourceAdapterModule[]) list.toArray(new ResourceAdapterModule[list.size()]);
+    }
+
+
+    public J2EEResource[] getResources(J2EEApplication application) {
+        J2EEResource[] result = new J2EEResource[0];
+        try {
+            String[] names = application.getResources();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new J2EEResource[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return result;
+    }
+
+    public JCAResource[] getJCAResources(J2EEApplication application) {
+        List list = new ArrayList();
+        try {
+            //todo: filter based on ObjectName or something, but what counts as a "JCAResource"?
+            J2EEResource[] all = getResources(application);
+            for (int i = 0; i < all.length; i++) {
+                if(all[i] instanceof JCAResource) {
+                    list.add(all[i]);
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return (JCAResource[]) list.toArray(new JCAResource[list.size()]);
+    }
+
+    public JDBCResource[] getJDBCResources(J2EEApplication application) {
+        return new JDBCResource[0];  // Geronimo uses JCAResources for this
+    }
+
+    public JMSResource[] getJMSResources(J2EEApplication application) {
+        return new JMSResource[0];  // Geronimo uses JCAResources for this
+    }
+
+    // module properties
+    public EJB[] getEJBs(EJBModule module) {
+        return new EJB[0];  //todo
+    }
+
+    public Servlet[] getServlets(WebModule module) {
+        return new Servlet[0];  //todo
+    }
+
+    public ResourceAdapter[] getResourceAdapters(ResourceAdapterModule module) {
+        ResourceAdapter[] result = new ResourceAdapter[0];
+        try {
+            String[] names = module.getResourceAdapters();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new ResourceAdapter[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up resource adapters for module", e);
+        }
+        return result;
+    }
+
+    // resource adapter properties
+    public JCAResource[] getRAResources(ResourceAdapter adapter) {
+        JCAResource[] result = new JCAResource[0];
+        try {
+            String[] names = adapter.getJCAResources();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JCAResource[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up JCA resources for resource adapter", e);
+        }
+        return result;
+    }
+
+    // resource properties
+    public JDBCDataSource[] getDataSource(JDBCResource resource) {
+        return new JDBCDataSource[0];  //todo
+    }
+
+    public JDBCDriver[] getDriver(JDBCDataSource dataSource) {
+        return new JDBCDriver[0];  //todo
+    }
+
+    public JCAConnectionFactory[] getConnectionFactories(JCAResource resource) {
+        JCAConnectionFactory[] result = new JCAConnectionFactory[0];
+        try {
+            String[] names = resource.getConnectionFactories();
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JCAConnectionFactory[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (Exception e) {
+            log.error("Unable to look up connection factories for JCA resource", e);
+        }
+        return result;
+    }
+
+    public JCAAdminObject[] getAdminObjects(JCAResource resource) {
+        JCAAdminObject[] result = new JCAAdminObject[0];
+        String objectName = resource.getObjectName();
+        try {
+            String name = ObjectName.getInstance(objectName).getKeyProperty(NameFactory.J2EE_NAME);
+            String query = "*:JCAResource="+name+",j2eeType=JCAAdminObject,*";
+            Set results = kernel.listGBeans(ObjectName.getInstance(query));
+            String[] names = new String[results.size()];
+            int i = 0;
+            for (Iterator it = results.iterator(); it.hasNext();) {
+                ObjectName next = (ObjectName) it.next();
+                names[i++] = next.getCanonicalName();
+            }
+            Object[] temp = pm.createProxies(names, KernelManagementHelper.class.getClassLoader());
+            result = new JCAAdminObject[temp.length];
+            System.arraycopy(temp, 0, result, 0, temp.length);
+        } catch (MalformedObjectNameException e) {
+            log.error("Unable to look up admin objects for resource adapter", e);
+        }
+        return result;
+    }
+
+    public JCAManagedConnectionFactory getManagedConnectionFactory(JCAConnectionFactory factory) {
+        try {
+            String name = factory.getManagedConnectionFactory();
+            return (JCAManagedConnectionFactory) pm.createProxy(ObjectName.getInstance(name), KernelManagementHelper.class.getClassLoader());
+        } catch (Exception e) {
+            log.error("Unable to look up managed connection factory for connection factory", e);
+            return null;
+        }
+    }
+
+    public Object getObject(String objectName) {
+        try {
+            return kernel.getProxyManager().createProxy(ObjectName.getInstance(objectName), KernelManagementHelper.class.getClassLoader());
+        } catch (MalformedObjectNameException e) {
+            log.error("Unable to look up related GBean", e);
+            return null;
+        }
+    }
+
+    public URI getConfigurationNameFor(String objectName) {
+        try {
+            Set parents = kernel.getDependencyManager().getParents(ObjectName.getInstance(objectName));
+            if(parents.size() == 0) {
+                throw new IllegalStateException("No parents for GBean '"+objectName+"'");
+            }
+            for (Iterator it = parents.iterator(); it.hasNext();) {
+                ObjectName name = (ObjectName) it.next();
+                if(Configuration.isConfigurationObjectName(name)) {
+                    return Configuration.getConfigurationID(name);
+                }
+            }
+        } catch (Exception e) {
+            log.error("Unable to look up related GBean", e);
+        }
+        return null;
+    }
+
+    public String getGBeanDescription(String objectName) {
+        try {
+            return kernel.getGBeanInfo(ObjectName.getInstance(objectName)).getName();
+        } catch (GBeanNotFoundException e) {
+            return null;
+        } catch (MalformedObjectNameException e) {
+            return "Invalid object name";
+        }
+    }
+
+    public void testLoginModule(J2EEServer server, LoginModule module, Map options) {
+        options.put(JaasLoginModuleUse.KERNEL_NAME_LM_OPTION, kernel.getKernelName());
+        options.put(JaasLoginModuleUse.CLASSLOADER_LM_OPTION, module.getClass().getClassLoader());
+        try {
+            options.put(JaasLoginModuleUse.SERVERINFO_LM_OPTION, pm.createProxy(ObjectName.getInstance(server.getServerInfo()),module.getClass().getClassLoader()));
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalStateException("Unable to look up server info: "+e.getMessage());
+        }
+        module.initialize(null, null, new HashMap(), options);
+    }
+
+    public Subject testLoginModule(final J2EEServer server, final LoginModule module, final Map options, final String username, final String password) throws LoginException {
+        options.put(JaasLoginModuleUse.KERNEL_NAME_LM_OPTION, kernel.getKernelName());
+        options.put(JaasLoginModuleUse.CLASSLOADER_LM_OPTION, module.getClass().getClassLoader());
+        try {
+            options.put(JaasLoginModuleUse.SERVERINFO_LM_OPTION, pm.createProxy(ObjectName.getInstance(server.getServerInfo()),module.getClass().getClassLoader()));
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalStateException("Unable to look up server info: "+e.getMessage());
+        }
+        Subject sub = new Subject();
+        CallbackHandler handler = new CallbackHandler() {
+            public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
+                for (int i = 0; i < callbacks.length; i++) {
+                    Callback callback = callbacks[i];
+                    if(callback instanceof PasswordCallback) {
+                        ((PasswordCallback)callback).setPassword(password.toCharArray());
+                    } else if(callback instanceof NameCallback) {
+                        ((NameCallback)callback).setName(username);
+                    } else {
+                        throw new UnsupportedCallbackException(callback);
+                    }
+                }
+            }
+        };
+        module.initialize(sub, handler, new HashMap(), options);
+        if(module.login() && module.commit()) {
+            return sub;
+        } else {
+            module.abort();
+        }
+        return null;
+    }
+
+    public Object[] findByInterface(Class iface) {
+        Set set = kernel.listGBeans(new GBeanQuery(null, iface.getName()));
+        Object[] result = new Object[set.size()];
+        int i=0;
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            ObjectName name = (ObjectName) it.next();
+            result[i++] = kernel.getProxyManager().createProxy(name, iface.getClassLoader());
+        }
+        return result;
+    }
+
+    /**
+     * Helper method to connect to a remote kernel.
+     */
+    public static KernelManagementHelper getRemoteKernelManager(String host, String user, String password) throws java.io.IOException {
+        String uri = "jmx:rmi://"+host+"/jndi/rmi:/JMXConnector";
+        java.util.Map environment = new java.util.HashMap();
+        String[] credentials = new String[]{user, password};
+        environment.put(javax.management.remote.JMXConnector.CREDENTIALS, credentials);
+        javax.management.remote.JMXServiceURL address = new javax.management.remote.JMXServiceURL("service:" + uri);
+        javax.management.remote.JMXConnector jmxConnector = javax.management.remote.JMXConnectorFactory.connect(address, environment);
+        javax.management.MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
+        Kernel kernel = new org.apache.geronimo.kernel.jmx.KernelDelegate(mbServerConnection);
+        return new KernelManagementHelper(kernel);
+    }
+
+    /**
+     * For test purposes; start the server, deploy an app or two, and run this.
+     * Should be changed to a JUnit test with the Maven plugin to start and
+     * stop the server.
+     */
+    public static void main(String[] args) {
+        try {
+            ManagementHelper mgr = getRemoteKernelManager("localhost", "system", "manager");
+            J2EEDomain domain = mgr.getDomains()[0];
+            System.out.println("Found domain "+domain.getObjectName()+" with "+domain.getServers().length+" servers");
+            J2EEServer server = mgr.getServers(domain)[0];
+            System.out.println("Found server "+server.getObjectName()+" with "+server.getDeployedObjects().length+" deployments");
+            System.out.println("  "+mgr.getApplications(server).length+" applications");
+            System.out.println("  "+mgr.getAppClients(server).length+" app clients");
+            System.out.println("  "+mgr.getEJBModules(server).length+" EJB JARs");
+            System.out.println("  "+mgr.getWebModules(server).length+" web apps");
+            System.out.println("  "+mgr.getRAModules(server).length+" RA modules");
+            J2EEDeployedObject[] deployments = mgr.getDeployedObjects(server);
+            for (int i = 0; i < deployments.length; i++) {
+                J2EEDeployedObject deployment = deployments[i];
+                System.out.println("Deployment "+i+": "+deployment.getObjectName());
+            }
+            J2EEApplication[] applications = mgr.getApplications(server);
+            for (int i = 0; i < applications.length; i++) {
+                J2EEApplication app = applications[i];
+                System.out.println("Application "+i+": "+app.getObjectName());
+                J2EEModule[] modules = mgr.getModules(app);
+                for (int j = 0; j < modules.length; j++) {
+                    J2EEModule deployment = modules[j];
+                    System.out.println("  Module "+j+": "+deployment.getObjectName());
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message