geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shiv...@apache.org
Subject svn commit: r675839 - in /geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main: java/org/apache/geronimo/console/configcreator/ java/org/apache/geronimo/console/configcreator/configData/ webapp/ webapp/WEB-INF/ webapp/WEB-INF/view/co...
Date Fri, 11 Jul 2008 06:37:26 GMT
Author: shivahr
Date: Thu Jul 10 23:37:25 2008
New Revision: 675839

URL: http://svn.apache.org/viewvc?rev=675839&view=rev
Log:
GERONIMO-4146 Handle Security in EAR PlanCreator. Thanks to Shrey Banga for the patch.

Modified:
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/DisplayPlanHandler.java
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/EARHandler.java
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/JSR88_Util.java
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARConfigData.java
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARHelper.java
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EnvironmentConfigData.java
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/view/configcreator/enterpriseApp.jsp
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/web.xml
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/enterpriseApp.css
    geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/js/enterpriseApp.js

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/DisplayPlanHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/DisplayPlanHandler.java?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/DisplayPlanHandler.java (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/DisplayPlanHandler.java Thu Jul 10 23:37:25 2008
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 
-import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletException;

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/EARHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/EARHandler.java?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/EARHandler.java (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/EARHandler.java Thu Jul 10 23:37:25 2008
@@ -51,6 +51,8 @@
         request.setAttribute(DATA_PARAMETER, data);
         List<String> commonLibs = JSR77_Util.getCommonLibs(request);
         request.setAttribute(COMMON_LIBS_PARAMETER, commonLibs);
+        request.setAttribute(DEPLOYED_SECURITY_REALMS_PARAMETER, JSR77_Util.getDeployedSecurityRealms(request));
+        request.setAttribute(DEPLOYED_CREDENTIAL_STORES_PARAMETER, JSR77_Util.getDeployedCredentialStores(request));
     }
 
     public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model)

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/JSR88_Util.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/JSR88_Util.java?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/JSR88_Util.java (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/JSR88_Util.java Thu Jul 10 23:37:25 2008
@@ -21,7 +21,6 @@
 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
 import javax.enterprise.deploy.spi.DeploymentManager;
 import javax.enterprise.deploy.spi.Target;
-import javax.enterprise.deploy.spi.factories.DeploymentFactory;
 import javax.enterprise.deploy.spi.status.ProgressObject;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -29,7 +28,6 @@
 import javax.portlet.PortletRequest;
 
 import org.apache.geronimo.deployment.plugin.jmx.CommandContext;
-import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryWithKernel;
 import org.apache.geronimo.deployment.plugin.jmx.JMXDeploymentManager;
 import org.apache.geronimo.deployment.plugin.local.DistributeCommand;
 import org.apache.geronimo.j2ee.ApplicationInfo;

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARConfigData.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARConfigData.java?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARConfigData.java (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARConfigData.java Thu Jul 10 23:37:25 2008
@@ -33,6 +33,7 @@
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerModuleType;
 import org.apache.geronimo.xbeans.geronimo.web.GerWebAppDocument;
 import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
 
 /**
@@ -128,11 +129,13 @@
             GerModuleType newModule = getEnterpriseApp().addNewModule();
             newModule.addNewWeb().setStringValue(moduleName);
 
-            /*WARConfigData warConfig = webModules.get(moduleName);
+            WARConfigData warConfig = webModules.get(moduleName);
+
             warConfig.getJndiRefsConfig().storeResourceRefs(warConfig.getWebApp());
             if (warConfig.getSecurity() != null) {
                 warConfig.getWebApp().setSecurity(warConfig.getSecurity());
             }
+            
             GerWebAppDocument webAppDocument = GerWebAppDocument.Factory.newInstance();
             webAppDocument.setWebApp(warConfig.getWebApp());
 
@@ -143,7 +146,7 @@
             rootCursor.toEndToken();
             xsAnyCursor.moveXml(rootCursor);
             xsAnyCursor.dispose();
-            rootCursor.dispose();*/
+            rootCursor.dispose();
         }
         for (Enumeration<String> e = ejbModules.keys(); e.hasMoreElements();) {
             String moduleName = e.nextElement();
@@ -178,8 +181,16 @@
         return "";
     }
 
-    public void setDeploymentPlan(String deploymentPlan) {
+    public String setDeploymentPlan(String deploymentPlan) {
         this.deploymentPlan = deploymentPlan;
+        try {
+            GerApplicationDocument doc = GerApplicationDocument.Factory.parse(deploymentPlan);            
+            this.enterpriseApp = doc.getApplication();
+            this.environmentConfig = new EnvironmentConfigData(this.enterpriseApp.getEnvironment());
+        } catch(XmlException e) {
+            return e.getMessage();
+        }
+        return null;
     }
 
     public Hashtable<String, WARConfigData> getWebModules() {

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARHelper.java?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARHelper.java (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EARHelper.java Thu Jul 10 23:37:25 2008
@@ -20,6 +20,7 @@
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 
@@ -28,6 +29,15 @@
 import org.apache.geronimo.console.configcreator.AbstractHandler;
 import org.apache.geronimo.deployment.xbeans.ArtifactType;
 import org.apache.geronimo.deployment.xbeans.EnvironmentType;
+import org.apache.geronimo.deployment.xbeans.PatternType;
+import org.apache.geronimo.xbeans.geronimo.security.GerDistinguishedNameType;
+import org.apache.geronimo.xbeans.geronimo.security.GerLoginDomainPrincipalType;
+import org.apache.geronimo.xbeans.geronimo.security.GerPrincipalType;
+import org.apache.geronimo.xbeans.geronimo.security.GerRealmPrincipalType;
+import org.apache.geronimo.xbeans.geronimo.security.GerRoleMappingsType;
+import org.apache.geronimo.xbeans.geronimo.security.GerRoleType;
+import org.apache.geronimo.xbeans.geronimo.security.GerSecurityType;
+import org.apache.geronimo.xbeans.geronimo.security.GerSubjectInfoType;
 import org.directwebremoting.annotations.DataTransferObject;
 import org.directwebremoting.annotations.RemoteMethod;
 import org.directwebremoting.annotations.RemoteProxy;
@@ -38,131 +48,6 @@
 @RemoteProxy
 public class EARHelper {
     //private EARConfigData earConfig;
-
-    /**
-     * 
-     * Dojo tree expects a JSON in the below format:
-     * { label: 'name',
-     *   identifier: 'name',
-     *   items: [
-     *     { name:'Web Modules', type:'webModules',
-     *       children: [
-     *         { name:'module-name-1', type:'webModule' },
-     *         ...
-     *         { name:'module-name-n', type:'webModule' }
-     *       ]
-     *     },
-     *     { name:'EJB Modules', type: 'ejbModules',
-     *       children: [
-     *         { name:'module-name-1', type:'ejbModule' },
-     *         ...
-     *         { name:'module-name-n', type:'ejbModule' }
-     *       ]
-     *     }
-     *   ]
-     * }
-     * 
-     */
-    public static class TreeJson implements Serializable {
-        String identifier = "name";
-        String label = "name";
-        List<TreeNode> items = new ArrayList<TreeNode>();
-
-        public TreeJson() {
-        }
-
-        public String getIdentifier() {
-            return identifier;
-        }
-
-        public void setIdentifier(String identifier) {
-            this.identifier = identifier;
-        }
-
-        public String getLabel() {
-            return label;
-        }
-
-        public void setLabel(String label) {
-            this.label = label;
-        }
-
-        public List<TreeNode> getItems() {
-            return items;
-        }
-
-        public void setItems(List<TreeNode> items) {
-            this.items = items;
-        }
-    }
-
-    @DataTransferObject
-    public static class EarJsonTree extends TreeJson implements Serializable {
-
-        public EarJsonTree(EARConfigData earConfig) {
-            if (earConfig.getWebModules().size() > 0) {
-                TreeFolder webModules = new TreeFolder("Web Modules", "folder");
-                items.add(webModules);
-                for (Enumeration<String> e = earConfig.getWebModules().keys(); e.hasMoreElements();) {
-                    String moduleName = e.nextElement();
-                    webModules.getChildren().add(new TreeNode(moduleName, "webModule"));
-                }
-            }
-            if (earConfig.getEjbModules().size() > 0) {
-                TreeFolder ejbModules = new TreeFolder("EJB Modules", "folder");
-                items.add(ejbModules);
-                for (Enumeration<String> e = earConfig.getEjbModules().keys(); e.hasMoreElements();) {
-                    String moduleName = e.nextElement();
-                    ejbModules.getChildren().add(new TreeNode(moduleName, "ejbModule"));
-                }
-            }
-        }
-    }
-
-    @DataTransferObject
-    public static class TreeNode implements Serializable {
-        String name;
-        String type;
-
-        public TreeNode(String name, String type) {
-            this.name = name;
-            this.type = type;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        public String getType() {
-            return type;
-        }
-
-        public void setType(String type) {
-            this.type = type;
-        }
-    }
-
-    @DataTransferObject
-    public static class TreeFolder extends TreeNode implements Serializable {
-        List<TreeNode> children = new ArrayList<TreeNode>();
-
-        public TreeFolder(String name, String type) {
-            super(name, type);
-        }
-
-        public List<TreeNode> getChildren() {
-            return children;
-        }
-
-        public void setChildren(List<TreeNode> children) {
-            this.children = children;
-        }
-    }
-
     public EARHelper() {
         //earConfig = (EARConfigData) WebContextFactory.get().getHttpServletRequest().getSession().getAttribute(
         //        AbstractHandler.EAR_CONFIG_DATA_ID);
@@ -172,11 +57,6 @@
         return (EARConfigData) request.getSession().getAttribute(AbstractHandler.EAR_CONFIG_DATA_ID);
     }
 
-    @RemoteMethod
-    public EarJsonTree getEarTree(HttpServletRequest request) {
-        return new EarJsonTree(getEarConfigData(request));
-    }
-
     @DataTransferObject
     public static class EnvironmentJson implements Serializable {
         String groupId;
@@ -422,11 +302,585 @@
         dependenciesJsonTree.save(getEarConfigData(request).getEnvironmentConfig().getDependenciesSet());
     }
 
+    @DataTransferObject
+    public static class SecurityPrincipalJson implements Serializable {
+        private String name;
+        private String principalName;
+        private String type;
+        private String className;
+        private String domainName;
+        private String realmName;
+
+        public SecurityPrincipalJson() {
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getPrincipalName() {
+            return principalName;
+        }
+
+        public void setPrincipalName(String principalName) {
+            this.principalName = principalName;
+        }
+
+        public String getType() {
+            return type;
+        }
+
+        public void setType(String type) {
+            this.type = type;
+        }
+
+        public String getClassName() {
+            return className;
+        }
+
+        public void setClassName(String className) {
+            this.className = className;
+        }
+
+        public String getDomainName() {
+            return domainName;
+        }
+
+        public void setDomainName(String domainName) {
+            this.domainName = domainName;
+        }
+
+        public String getRealmName() {
+            return realmName;
+        }
+
+        public void setRealmName(String realmName) {
+            this.realmName = realmName;
+        }
+    }
+
+    @DataTransferObject
+    public static class SecurityRoleJson implements Serializable {
+        private String roleName;
+        private SecurityPrincipalJson[] children;
+
+        public SecurityRoleJson() {
+        }
+
+        public String getName() {
+            return "role = '" + roleName + "'";
+        }
+
+        public void setName(String name) {
+            int beg = name.indexOf('\'');
+            this.roleName = name.substring(beg, name.indexOf('\'', beg + 1));
+        }
+
+        public String getRoleName() {
+            return roleName;
+        }
+
+        public void setRoleName(String roleName) {
+            this.roleName = roleName;
+        }
+
+        public SecurityPrincipalJson[] getChildren() {
+            return children;
+        }
+
+        public void setChildren(SecurityPrincipalJson[] children) {
+            this.children = children;
+        }
+    }
+
+    @DataTransferObject
+    public static class ModuleSecurityJsonTree implements Serializable {
+        SecurityRoleJson[] items;
+
+        public String getIdentifier() {
+            return "name";
+        }
+
+        public void setIdentifier(String name) {
+        }
+
+        public String getLabel() {
+            return "name";
+        }
+
+        public void setLabel(String label) {
+        }
+
+        public SecurityRoleJson[] getItems() {
+            return items;
+        }
+
+        public void setItems(SecurityRoleJson[] items) {
+            this.items = items;
+        }
+
+        public ModuleSecurityJsonTree() {
+        }
+
+        public ModuleSecurityJsonTree(WARConfigData warConfig) {
+            GerRoleType[] roles = warConfig.getSecurity().getRoleMappings().getRoleArray();
+            items = new SecurityRoleJson[roles.length];
+
+            for (int i = 0; i < roles.length; i++) {
+                SecurityRoleJson jRole = new SecurityRoleJson();
+                GerRoleType role = roles[i];
+                String roleName = role.getRoleName();
+                jRole.setRoleName(roleName);
+
+                GerPrincipalType[] principals = role.getPrincipalArray();
+                GerLoginDomainPrincipalType[] loginDomainPrincipals = role.getLoginDomainPrincipalArray();
+                GerRealmPrincipalType[] realmPrincipals = role.getRealmPrincipalArray();
+                GerDistinguishedNameType[] distinguishedNames = role.getDistinguishedNameArray();
+
+                int jLength = principals.length + loginDomainPrincipals.length + realmPrincipals.length + distinguishedNames.length;
+
+                if (jLength > 0) {
+                    SecurityPrincipalJson[] jPrincipals = new SecurityPrincipalJson[jLength];
+                    int jIndex;
+
+                    for (int j = 0; j < principals.length; j++) {
+                        SecurityPrincipalJson jPrincipal = new SecurityPrincipalJson();
+                        jPrincipal.setPrincipalName(principals[j].getName());
+                        jPrincipal.setClassName(principals[j].getClass1());
+                        jPrincipal.setType("Principal");
+                        jPrincipal.setName(roleName + ".principal" + (1 + j));
+                        jPrincipals[j] = jPrincipal;
+                    }
+                    jIndex = principals.length;
+
+                    for (int j = 0; j < loginDomainPrincipals.length; j++) {
+                        SecurityPrincipalJson jPrincipal = new SecurityPrincipalJson();
+                        jPrincipal.setPrincipalName(loginDomainPrincipals[j].getName());
+                        jPrincipal.setClassName(loginDomainPrincipals[j].getClass1());
+                        jPrincipal.setDomainName(loginDomainPrincipals[j].getDomainName());
+                        jPrincipal.setType("LoginDomainPrincipal");
+                        jPrincipal.setName(roleName + ".principal" + (1 + j + jIndex));
+                        jPrincipals[j + jIndex] = jPrincipal;
+                    }
+                    jIndex += loginDomainPrincipals.length;
+
+                    for (int j = 0; j < realmPrincipals.length; j++) {
+                        SecurityPrincipalJson jPrincipal = new SecurityPrincipalJson();
+                        jPrincipal.setPrincipalName(realmPrincipals[j].getName());
+                        jPrincipal.setClassName(realmPrincipals[j].getClass1());
+                        jPrincipal.setDomainName(realmPrincipals[j].getDomainName());
+                        jPrincipal.setRealmName(realmPrincipals[j].getRealmName());
+                        jPrincipal.setType("RealmPrincipal");
+                        jPrincipal.setName(roleName + ".principal" + (1 + j + jIndex));
+                        jPrincipals[j + jIndex] = jPrincipal;
+                    }
+                    jIndex += realmPrincipals.length;
+
+                    for (int j = 0; j < distinguishedNames.length; j++) {
+                        SecurityPrincipalJson jPrincipal = new SecurityPrincipalJson();
+                        jPrincipal.setPrincipalName(distinguishedNames[j].getName());
+                        jPrincipal.setType("DistinguishedName");
+                        jPrincipal.setName(roleName + ".principal" + (1 + j + jIndex));
+                        jPrincipals[j + jIndex] = jPrincipal;
+                    }
+
+                    jRole.setChildren(jPrincipals);
+                }
+                items[i] = jRole;
+            }
+        }
+
+        public void save(WARConfigData warConfig, Hashtable<String, Subject> runAsSubjects) {
+            if (warConfig.getSecurity().isSetRoleMappings())
+                warConfig.getSecurity().unsetRoleMappings();
+            GerRoleMappingsType roleMappings = warConfig.getSecurity().addNewRoleMappings();
+
+            for (int i = 0; i < items.length; i++) {
+                SecurityPrincipalJson[] jPrincipals = items[i].getChildren();
+                SecurityRoleJson item = items[i];
+
+                GerRoleType role = roleMappings.addNewRole();
+                role.setRoleName(item.getRoleName());
+
+                for (int j = 0; j < jPrincipals.length; j++) {
+                    SecurityPrincipalJson jPrincipal = jPrincipals[j];
+                    String type = jPrincipal.getType();
+
+                    if (type.equals("Principal")) {
+                        GerPrincipalType principal = role.addNewPrincipal();
+                        principal.setName(jPrincipal.getPrincipalName());
+                        principal.setClass1(jPrincipal.getClassName());
+                    } else if (type.equals("LoginDomainPrincipal")) {
+                        GerLoginDomainPrincipalType principal = role.addNewLoginDomainPrincipal();
+                        principal.setName(jPrincipal.getPrincipalName());
+                        principal.setClass1(jPrincipal.getClassName());
+                        principal.setDomainName(jPrincipal.getDomainName());
+                    } else if (type.equals("RealmPrincipal")) {
+                        GerRealmPrincipalType principal = role.addNewRealmPrincipal();
+                        principal.setName(jPrincipal.getPrincipalName());
+                        principal.setClass1(jPrincipal.getClassName());
+                        principal.setDomainName(jPrincipal.getDomainName());
+                        principal.setRealmName(jPrincipal.getRealmName());
+                    } else if (type.equals("DistinguishedName")) {
+                        GerDistinguishedNameType principal = role.addNewDistinguishedName();
+                        principal.setName(jPrincipal.getPrincipalName());
+                    }
+                }
+
+                if (runAsSubjects != null
+                        && runAsSubjects.containsKey(item.getRoleName())) {
+                    GerSubjectInfoType gerRunAsSubject = role.addNewRunAsSubject();
+                    Subject runAsSubject = runAsSubjects.get(item.getRoleName());
+                    gerRunAsSubject.setId(runAsSubject.getId());
+                    gerRunAsSubject.setRealm(runAsSubject.getRealm());
+                }
+            }
+        }
+    }
+
+    @DataTransferObject
+    public static class Subject implements Serializable {
+        String realm;
+        String id;
+
+        public Subject() {
+        }
+
+        public Subject(String id, String realm) {
+            this.id = id;
+            this.realm = realm;
+        }
+
+        public String getRealm() {
+            return realm;
+        }
+
+        public void setRealm(String realm) {
+            this.realm = realm;
+        }
+
+        public String getId() {
+            return id;
+        }
+
+        public void setId(String id) {
+            this.id = id;
+        }
+    }
+
+    @DataTransferObject
+    public static class CredentialStoreRef implements Serializable {
+        String groupId;
+        String artifactId;
+        String version;
+        String type;
+        String module;
+        String name;
+
+        public String getGroupId() {
+            return groupId;
+        }
+
+        public void setGroupId(String groupId) {
+            this.groupId = groupId;
+        }
+
+        public String getArtifactId() {
+            return artifactId;
+        }
+
+        public void setArtifactId(String artifactId) {
+            this.artifactId = artifactId;
+        }
+
+        public String getVersion() {
+            return version;
+        }
+
+        public void setVersion(String version) {
+            this.version = version;
+        }
+
+        public String getType() {
+            return type;
+        }
+
+        public void setType(String type) {
+            this.type = type;
+        }
+
+        public String getModule() {
+            return module;
+        }
+
+        public void setModule(String module) {
+            this.module = module;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public CredentialStoreRef() {
+        }
+
+        public CredentialStoreRef(String groupId, String artifactId,
+                String version, String type, String module, String name) {
+            this.groupId = groupId;
+            this.artifactId = artifactId;
+            this.version = version;
+            this.type = type;
+            this.module = module;
+            this.name = name;
+        }
+
+        public CredentialStoreRef(String combined) {
+            String[] values = combined.split("/", 6);
+            groupId = values[0];
+            artifactId = values[1];
+            version = values[2];
+            type = values[3];
+            module = values[4];
+            name = values[5];
+        }
+
+        public void save(PatternType credentialStoreRef) {
+            credentialStoreRef.setGroupId(groupId);
+            credentialStoreRef.setArtifactId(artifactId);
+            credentialStoreRef.setVersion(version);
+            credentialStoreRef.setType(type);
+            credentialStoreRef.setModule(module);
+            credentialStoreRef.setName(name);
+        }
+
+        public String toString() {
+            String combined = groupId;
+            if (artifactId != null)
+                combined = combined + '/' + artifactId;
+            if (version != null)
+                combined = combined + '/' + version;
+            if (type != null)
+                combined = combined + '/' + type;
+            if (module != null)
+                combined = combined + '/' + module;
+            if (name != null)
+                combined = combined + '/' + name;
+
+            return combined;
+        }
+    }
+
+    @DataTransferObject
+    public static class ModuleSecurityConfig implements Serializable {
+        private ModuleSecurityJsonTree roleMappings;
+        private String securityRealmName;
+        private Hashtable<String, Subject> runAsSubjects;
+        private String defaultSubjectRealm, defaultSubjectId;
+        private CredentialStoreRef credentialStoreRef;
+        private boolean doasCurrentCaller;
+        private boolean useContextHandler;
+
+        public ModuleSecurityConfig() {
+        }
+
+        public ModuleSecurityConfig(WARConfigData warConfig) {
+            roleMappings = new ModuleSecurityJsonTree(warConfig);
+            setSecurityRealmName(warConfig.getWebApp().getSecurityRealmName());
+
+            GerSecurityType security = warConfig.getSecurity();
+
+            GerRoleType[] roles = security.getRoleMappings().getRoleArray();
+            runAsSubjects = new Hashtable<String, Subject>();
+            for (int i = 0; i < roles.length; i++) {
+                GerSubjectInfoType runAsSubject = roles[i].getRunAsSubject();
+                if (runAsSubject != null && runAsSubject.getId() != null && runAsSubject.getRealm() != null) {
+                    runAsSubjects.put(roles[i].getRoleName(), new Subject(runAsSubject.getId(), runAsSubject.getRealm()));
+                }
+            }
+
+            GerSubjectInfoType gerDefaultSubject = security.getDefaultSubject();
+            if (gerDefaultSubject != null && gerDefaultSubject.getId() != null && gerDefaultSubject.getRealm() != null) {
+                defaultSubjectId = gerDefaultSubject.getId();
+                defaultSubjectRealm = gerDefaultSubject.getRealm();
+            }
+
+            if (security.isSetCredentialStoreRef()) {
+                PatternType c = security.getCredentialStoreRef();
+                credentialStoreRef = new CredentialStoreRef(c.getGroupId(), c.getArtifactId(), c.getVersion(), c.getType(), c.getModule(), c.getName());
+            }
+            doasCurrentCaller = security.getDoasCurrentCaller();
+            useContextHandler = security.getUseContextHandler();
+        }
+
+        public void save(WARConfigData warConfig) {
+            roleMappings.save(warConfig, runAsSubjects);
+            warConfig.getWebApp().setSecurityRealmName(securityRealmName);
+
+            GerSecurityType security = warConfig.getSecurity();
+
+            if (security.isSetDefaultSubject())
+                security.unsetDefaultSubject();
+            if (defaultSubjectRealm != null && defaultSubjectId != null) {
+                GerSubjectInfoType gerDefaultSubject = security
+                        .addNewDefaultSubject();
+                gerDefaultSubject.setId(defaultSubjectId);
+                gerDefaultSubject.setRealm(defaultSubjectRealm);
+            }
+
+            if (security.isSetCredentialStoreRef())
+                security.unsetCredentialStoreRef();
+            if (credentialStoreRef != null)
+                credentialStoreRef.save(security.addNewCredentialStoreRef());
+
+            if (security.isSetDoasCurrentCaller())
+                security.unsetDoasCurrentCaller();
+            if (doasCurrentCaller)
+                security.setDoasCurrentCaller(doasCurrentCaller);
+
+            if (security.isSetUseContextHandler())
+                security.unsetUseContextHandler();
+            if (useContextHandler)
+                security.setUseContextHandler(useContextHandler);
+        }
+
+        public String getSecurityRealmName() {
+            return securityRealmName;
+        }
+
+        public void setSecurityRealmName(String securityRealmName) {
+            this.securityRealmName = securityRealmName;
+        }
+
+        public ModuleSecurityJsonTree getRoleMappings() {
+            return roleMappings;
+        }
+
+        public void setRoleMappings(ModuleSecurityJsonTree roleMappings) {
+            this.roleMappings = roleMappings;
+        }
+
+        public Hashtable<String, Subject> getRunAsSubjects() {
+            return runAsSubjects;
+        }
+
+        public void setRunAsSubjects(Hashtable<String, Subject> runAsSubjects) {
+            this.runAsSubjects = runAsSubjects;
+        }
+
+        public boolean isDoasCurrentCaller() {
+            return doasCurrentCaller;
+        }
+
+        public void setDoasCurrentCaller(boolean doasCurrentCaller) {
+            this.doasCurrentCaller = doasCurrentCaller;
+        }
+
+        public boolean isUseContextHandler() {
+            return useContextHandler;
+        }
+
+        public void setUseContextHandler(boolean useContextHandler) {
+            this.useContextHandler = useContextHandler;
+        }
+
+        public String getCredentialStoreRef() {
+            if (credentialStoreRef != null)
+                return credentialStoreRef.toString();
+            return "";
+        }
+
+        public void setCredentialStoreRef(String credentialStoreRef) {
+            if (credentialStoreRef.trim().length() == 0) {
+                this.credentialStoreRef = null;
+            } else {
+                this.credentialStoreRef = new CredentialStoreRef(credentialStoreRef);
+            }
+        }
+
+        public String getDefaultSubjectRealm() {
+            return defaultSubjectRealm;
+        }
+
+        public void setDefaultSubjectRealm(String defaultSubjectRealm) {
+            this.defaultSubjectRealm = defaultSubjectRealm;
+        }
+
+        public String getDefaultSubjectId() {
+            return defaultSubjectId;
+        }
+
+        public void setDefaultSubjectId(String defaultSubjectId) {
+            this.defaultSubjectId = defaultSubjectId;
+        }
+    }
+
+    @DataTransferObject
+    public static class SecurityJson implements Serializable {
+        private Hashtable<String, ModuleSecurityConfig> webModules = new Hashtable<String, ModuleSecurityConfig>();
+
+        // TODO EJB Modules
+        // private Hashtable<String, ModuleSecurityConfig> ejbModules = new
+        // Hashtable<String, ModuleSecurityConfig>();
+        public SecurityJson() {
+        }
+
+        public SecurityJson(EARConfigData earConfig) {
+            Hashtable<String, WARConfigData> webConfigs = earConfig.getWebModules();
+
+            Enumeration keys = webConfigs.keys();
+            while (keys.hasMoreElements()) {
+                String key = (String) keys.nextElement();
+                webModules.put(key, new ModuleSecurityConfig(webConfigs.get(key)));
+            }
+        }
+
+        public Hashtable<String, ModuleSecurityConfig> getWebModules() {
+            return webModules;
+        }
+
+        public void setWebModules(Hashtable<String, ModuleSecurityConfig> webModules) {
+            this.webModules = webModules;
+        }
+
+        public void save(EARConfigData earConfig) {
+            Hashtable<String, WARConfigData> webConfigs = earConfig
+                    .getWebModules();
+
+            Enumeration keys = webConfigs.keys();
+            while (keys.hasMoreElements()) {
+                String key = (String) keys.nextElement();
+                webModules.get(key).save(webConfigs.get(key));
+            }
+        }
+    }
+
+    @RemoteMethod
+    public SecurityJson getSecurityJson(HttpServletRequest request) {
+        return new SecurityJson(getEarConfigData(request));
+    }
+
+    @RemoteMethod
+    public void saveSecurityJson(HttpServletRequest request, SecurityJson securityData) {
+        securityData.save(getEarConfigData(request));
+    }
+
     @RemoteMethod
     public String getGeneratedPlan(HttpServletRequest request) {
         return getEarConfigData(request).getDeploymentPlan();
     }
 
+    @RemoteMethod
+    public String saveGeneratedPlan(HttpServletRequest request, String plan) {
+        return getEarConfigData(request).setDeploymentPlan(plan);
+    }
     /*@RemoteMethod
     public String[] getWebModules() {
         return null;

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EnvironmentConfigData.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EnvironmentConfigData.java?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EnvironmentConfigData.java (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/java/org/apache/geronimo/console/configcreator/configData/EnvironmentConfigData.java Thu Jul 10 23:37:25 2008
@@ -28,7 +28,6 @@
 import org.apache.geronimo.deployment.xbeans.DependencyType;
 import org.apache.geronimo.deployment.xbeans.EnvironmentType;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.repository.Dependency;
 import org.apache.geronimo.kernel.repository.Environment;
 
 /**
@@ -42,6 +41,15 @@
 
     public EnvironmentConfigData(EnvironmentType environment) {
         this.environment = environment;
+        DependenciesType dependencies = environment.getDependencies();
+        if(dependencies != null) {
+            DependencyType[] depArray = dependencies.getDependencyArray();
+            for(int i = 0; i < depArray.length; i++) {
+                DependencyType d = depArray[i];
+                Artifact artifact = new Artifact(d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getType());
+                dependenciesSet.add(artifact.toString());
+            }
+        }
     }
 
     public void parseEnvironment(Environment env) {

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/view/configcreator/enterpriseApp.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/view/configcreator/enterpriseApp.jsp?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/view/configcreator/enterpriseApp.jsp (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/view/configcreator/enterpriseApp.jsp Thu Jul 10 23:37:25 2008
@@ -38,6 +38,7 @@
   dojo.require("dijit.layout.TabContainer");
   dojo.require("dijit.layout.ContentPane");
   dojo.require("dijit.layout.SplitContainer");
+  dojo.require("dijit.layout.AccordionContainer");
   dojo.require("dojo.data.ItemFileReadStore");
   dojo.require("dojo.data.ItemFileWriteStore");
   dojo.require("dijit.Tree");
@@ -60,8 +61,14 @@
 
 <script type='text/javascript' src='<%=request.getContextPath()%>/js/enterpriseApp.js'></script>
 
-<body class="tundra"> 
-<div id="mainTabContainer" dojoType="dijit.layout.TabContainer" style="width:750px; height:800px">
+<body class="tundra">
+<table width="750px">
+    <tr>
+        <td align="left" width="100px"><button dojoType="dijit.form.Button" onClick="doPrevious()">&lt; Previous</button></td>
+        <td align="left"><button dojoType="dijit.form.Button" onClick="doNext()">Next &gt;</button></td>
+    </tr>
+</table>
+<div id="mainTabContainer" dojoType="dijit.layout.TabContainer" style="width:750px; height: 700px">
   <div id="environment" dojoType="dijit.layout.ContentPane" title="Environment">
     <form dojoType="dijit.form.Form" id="environmentForm" 
       execute="saveEnvironment(arguments[0]); saveDependencies()"
@@ -218,12 +225,6 @@
         </tr>
       </table>
     </div>
-      <CENTER>
-        <!-- Save button -->
-        <button dojoType="dijit.form.Button" iconClass="dijitEditorIcon dijitEditorIconSave" type="submit">
-          Save
-        </button>
-      </CENTER>
     </form>
   </div>
   <div id="references" dojoType="dijit.layout.ContentPane" title="References">
@@ -237,20 +238,101 @@
       </div>
     </div>
   </div>
+  <!-- Security -->
   <div id="security" dojoType="dijit.layout.ContentPane" title="Security">
-    <div dojoType="dijit.layout.SplitContainer" orientation="horizontal" sizerWidth="7"
-        activeSizing="true" style="border: 1px solid #bfbfbf;">
-      <div dojoType="dijit.layout.ContentPane" sizeMin="100" sizeShare="20">
-        <div id="securityTreeHolder">EAR tree goes here</div>
-      </div>
-      <div dojoType="dijit.layout.ContentPane" sizeMin="200" sizeShare="80">
-        Editors for security go here
-      </div>
+    <div dojoType="dijit.layout.AccordionContainer" id="securityAccordionContainer" duration="200">
+        <c:forEach var="webModule" items="${data.webModules}"> 
+            <c:set var="moduleName" value="${webModule.key}"/>                       
+                <div dojoType="dijit.layout.AccordionPane" selected="true" title="${webModule.key}" id="${webModule.key}">
+                    <form dojoType="dijit.form.Form" id="${moduleName}.form" 
+                    execute="saveSecurity(arguments[0]);" onsubmit="return false;">
+                        <table width="720px" cellspacing="15px">
+                            <tr>
+                                <td colspan="2">Realm-name:
+                                    <select dojoType="dijit.form.FilteringSelect" name="securityRealmName" id="${moduleName}.form.txtSecurityRealmName" value="">
+                                        <c:forEach var="securityRealm" items="${deployedSecurityRealms}"><option value="${securityRealm.realmName}">${securityRealm.realmName}</option></c:forEach>
+                                    </select>
+                                </td>                    
+                            </tr>
+                        </table>
+                        <div dojoType="dijit.TitlePane" title="Role Mappings" open="true" style="margin:0px 10px; padding:0;">
+                            <table width="700px">
+                                <tr>
+                                    <td valign="top">
+                                        <div id="${moduleName}.form.securityTree">Security roles tree</div>
+                                    </td>
+                                    <td align="right" valign="top">
+                                        <button dojoType="dijit.form.Button" id="${moduleName}.form.btnAdd" onclick="doAddOrEditRoleMapping('${moduleName}.form.securityTree',true)" disabled="true">
+                                          <div style="width:58px">Add</div>
+                                        </button><br/>
+                                        <button dojoType="dijit.form.Button" id="${moduleName}.form.btnEdit" onclick="doAddOrEditRoleMapping('${moduleName}.form.securityTree',false)" disabled="true">
+                                          <div style="width:58px">Edit</div>
+                                        </button><br/>
+                                        <button dojoType="dijit.form.Button" id="${moduleName}.form.btnDelete" onclick="doDeleteRoleMapping('${moduleName}.form.securityTree')" disabled="true">
+                                          <div style="width:58px">Delete</div>
+                                        </button><br/>
+                                    </td>
+                                </tr>
+                            </table>
+                        </div>
+                        <div dojoType="dijit.TitlePane" title="Advanced Settings" open="false" style="margin:0px 10px; padding:0;">
+                            <table width="700px" cellspacing="10px">
+                                <tr>
+                                    <td><b>Credential Store:</b></td>
+                                    <td>
+                                        <select name="credentialStoreRef" dojoType="dijit.form.FilteringSelect" id="${moduleName}.form.selCredentialStore" style="width:520px" value="">
+                                        <option value=""></option>
+                                        <c:forEach var="credentialStore" items="${deployedCredentialStores}"><option value="${credentialStore.patternName}">${credentialStore.displayName}</option></c:forEach>
+                                        </select>
+                                     </td>
+                                </tr>
+                                <tr><td colspan="2" align="left"><b>Default Subject:</b></td></tr>
+                                <tr>
+                                    <td align="right" width="120px">Realm:</td>
+                                    <td><input name="defaultSubjectRealm" dojotype="dijit.form.TextBox" type="text" size="25"/></td>
+                                </tr>
+                                <tr>
+                                    <td align="right">Id:</td>
+                                    <td><input name="defaultSubjectId" dojotype="dijit.form.TextBox" type="text" size="25"/></td>
+                                </tr>
+                            </table>
+                            <table cellspacing="10px">
+                                <tr>
+                                    <td align="right"><input name="doasCurrentCaller" dojotype="dijit.form.CheckBox" type="checkbox" value="true"/></td>                                    
+                                    <td>Do as current caller</td>
+                                </tr>
+                                <tr>
+                                    <td align="right"><input name="useContextHandler" dojotype="dijit.form.CheckBox" type="checkbox" value="true"/></td>                                    
+                                    <td>Use context handler</td>
+                                </tr>
+                            </table>
+                            <table width="700px">
+                                <tr>
+                                    <td valign="top">
+                                        <div id="${moduleName}.form.runAsSubjectsTree">Run-as-subjects tree</div>
+                                    </td>
+                                    <td align="right" valign="top">
+                                        <button dojoType="dijit.form.Button" id="${moduleName}.form.btnAddRunAsSubject" onclick="doAddOrEditRunAsSubject('${moduleName}.form.runAsSubjectsTree',true)" disabled="true">
+                                          <div style="width:58px">Add</div>
+                                        </button><br/>
+                                        <button dojoType="dijit.form.Button" id="${moduleName}.form.btnEditRunAsSubject" onclick="doAddOrEditRunAsSubject('${moduleName}.form.runAsSubjectsTree',false)" disabled="true">
+                                          <div style="width:58px">Edit</div>
+                                        </button><br/>
+                                        <button dojoType="dijit.form.Button" id="${moduleName}.form.btnDeleteRunAsSubject" onclick="doDeleteRunAsSubject('${moduleName}.form.runAsSubjectsTree')" disabled="true">
+                                          <div style="width:58px">Delete</div>
+                                        </button><br/>
+                                    </td>
+                                </tr>
+                            </table>
+                        </div>
+                    </form>
+                </div>
+            <c:remove var="moduleName"/>
+        </c:forEach>
     </div>
   </div>
   <div id="generatedPlan" dojoType="dijit.layout.ContentPane" title="Generated Plan">
-    <textarea rows="30" cols="85" id="generatedPlanDisplayer" name="deploymentPlan">${data.deploymentPlan}</textarea>
-    <!--<textarea id="generatedPlanDisplayer" dojoType="dijit.form.Textarea" style="width:600px">${data.deploymentPlan}</textarea>-->
+    <pre id="generatedPlanDisplayer" class="dijitTextarea" contentEditable="true" style="padding:0px; width:744px; height: 668px; font-family: monospace">${data.deploymentPlan}</pre>
   </div>
 </div>
 <div id="dependenciesDialog" dojotype="dijit.Dialog"
@@ -260,7 +342,8 @@
       <c:forEach var="commonLib" items="${commonLibs}" varStatus="vs">
         <tr>
           <td>
-            <input dojotype="dijit.form.CheckBox" id="depChkBox_${vs.index}" name="dependencies" value="${commonLib}" type="checkbox"/>
+            <input dojotype="dijit.form.CheckBox" id="depChkBox_${vs.index}" 
+            name="dependencies" value="${commonLib}" type="checkbox"/>
           </td>
           <td valign="middle" align="left">
             <label for="dependencies">${commonLib}</label>
@@ -271,6 +354,9 @@
   </div>
   <center><button dojoType="dijit.form.Button" type="submit">OK</button></center>
 </div>
+<!-- 
+    Dependency Dialog 
+-->
 <div id="editDependencyDialog" dojotype="dijit.Dialog" 
     title="Edit dependency" execute="editDependencyTo(arguments[0])" extractContent="false">
   <input type="hidden" name="prevName" id="depEditPrevName" value="none"/>
@@ -304,4 +390,87 @@
   </table>
   <center><button dojoType="dijit.form.Button" type="submit" id="btnDepEditOK">OK</button></center>
 </div>
+<!-- 
+    Role Mapping Dialog 
+-->
+<div id="roleMappingDialog" dojotype="dijit.Dialog" 
+    title="Role Mapping" execute="addOrEditRoleMapping(arguments[0])" extractContent="false">
+  <table cellspacing="15">
+    <tr>
+      <td width="100px">Type:</td>
+      <td>
+        <select dojoType="dijit.form.FilteringSelect" name="type" id="selRoleMappingType" 
+        onchange="modifyRoleMappingForm(this.getValue())" style="width:200px">
+            <option value="Principal">Principal</option>
+            <option value="LoginDomainPrincipal">Login Domain Principal</option>
+            <option value="RealmPrincipal">Realm Principal</option>
+            <option value="DistinguishedName">Distinguished Name</option>
+        </select>
+      </td>
+    </tr>
+    <tr>
+      <td>Name:</td>
+      <td>
+        <input type="text" dojoType="dijit.form.ValidationTextBox" name="principalName" required="true" style="width:200px"
+        id="txtRoleMappingName" trim="true" validator="validatePrincipalName" onBlur="checkRoleMappingFields"
+        invalidMessage="Please enter a unique principal name for this role"/>
+      </td>
+    </tr>
+    <tr>
+      <td>Class:</td>
+      <td>
+        <select dojoType="dijit.form.FilteringSelect" name="className" id="selRoleMappingClass" style="width:200px"
+         onBlur="checkRoleMappingFields">
+            <option value="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal">Group Principal</option>
+            <option value="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal">User Principal</option>
+        </select>
+      </td>
+    </tr>
+    <tr style="display:none">
+      <td>Domain Name:</td>
+      <td>
+        <input type="text" dojoType="dijit.form.ValidationTextBox" name="domainName" style="width:200px" disabled="true"
+        id="txtRoleMappingDomainName" trim="true" required="true" onBlur="checkRoleMappingFields"
+        invalidMessage="Please enter a domain name for this role"/>
+      </td>
+    </tr>
+    <tr style="display:none">
+      <td>Realm Name:</td>
+      <td>
+        <select dojoType="dijit.form.FilteringSelect" name="realmName" style="width:200px" id="selRoleMappingRealmName" disabled="true">
+            <c:forEach var="securityRealm" items="${deployedSecurityRealms}"><option value="${securityRealm.realmName}">${securityRealm.realmName}</option></c:forEach>
+        </select>
+      </td>
+    </tr>
+  </table>
+  <center><button dojoType="dijit.form.Button" type="submit" id="btnRoleMappingOK">OK</button></center>
+</div>
+<!-- 
+    Run-as-subject Dialog 
+-->
+<div id="runAsSubjectDialog" dojotype="dijit.Dialog" 
+    title="Run-as-subject" execute="addOrEditRunAsSubject(arguments[0])" extractContent="false">
+  <table cellspacing="15">
+    <tr id="selRunAsSubjectRoleRow">
+      <td align="right">Role:</td>
+      <td>
+        <select dojoType="dijit.form.FilteringSelect" name="name" id="selRunAsSubjectRole" onBlur="checkRunAsSubjectFields">
+        </select>
+      </td>
+    </tr>
+    <tr>
+      <td align="right">Realm:</td>
+      <td>
+        <input type="text" dojoType="dijit.form.ValidationTextBox" name="realm" required="true" style="width:200px" trim="true" onBlur="checkRunAsSubjectFields"/>
+      </td>
+    </tr>
+    <tr>
+      <td align="right">Id:</td>
+      <td>
+        <input type="text" dojoType="dijit.form.ValidationTextBox" name="id" required="true" style="width:200px" trim="true" onBlur="checkRunAsSubjectFields"/>
+      </td>
+    </tr>
+  </table>
+  <center><button dojoType="dijit.form.Button" type="submit" id="btnRunAsSubjectOK" disabled="true">OK</button></center>
+</div>
 </body>

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/web.xml?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/web.xml (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/WEB-INF/web.xml Thu Jul 10 23:37:25 2008
@@ -31,24 +31,28 @@
     </servlet>
 
     <servlet>
-      <servlet-name>dwr-invoker</servlet-name>
-      <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
-      <init-param>
-        <param-name>classes</param-name>
-        <param-value>
-            org.apache.geronimo.console.configcreator.configData.EARHelper,
-            org.apache.geronimo.console.configcreator.configData.EARHelper$EarJsonTree,
-            org.apache.geronimo.console.configcreator.configData.EARHelper$TreeNode,
-            org.apache.geronimo.console.configcreator.configData.EARHelper$TreeFolder,
-            org.apache.geronimo.console.configcreator.configData.EARHelper$EnvironmentJson,
-            org.apache.geronimo.console.configcreator.configData.EARHelper$DependencyItem,
-            org.apache.geronimo.console.configcreator.configData.EARHelper$DependenciesJsonTree
-        </param-value>
-      </init-param>
-      <init-param>
-          <param-name>activeReverseAjaxEnabled</param-name>
-          <param-value>true</param-value>
-      </init-param>
+        <servlet-name>dwr-invoker</servlet-name>
+        <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
+        <init-param>
+            <param-name>classes</param-name>
+            <param-value>
+                org.apache.geronimo.console.configcreator.configData.EARHelper,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$EnvironmentJson,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$DependencyItem,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$DependenciesJsonTree,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$SecurityJson,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$SecurityRoleJson,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$SecurityPrincipalJson,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$Subject,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$CredentialStoreRef,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$ModuleSecurityConfig,
+                org.apache.geronimo.console.configcreator.configData.EARHelper$ModuleSecurityJsonTree
+            </param-value>
+        </init-param>
+        <init-param>
+            <param-name>activeReverseAjaxEnabled</param-name>
+            <param-value>true</param-value>
+        </init-param>
     </servlet>
 
     <servlet>

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/enterpriseApp.css
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/enterpriseApp.css?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/enterpriseApp.css (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/enterpriseApp.css Thu Jul 10 23:37:25 2008
@@ -33,3 +33,25 @@
     width: 16px;
     height: 16px;
 }
+.tundra .dijitPrincipalIcon {
+    background: transparent url('images/principalIcon.gif') no-repeat scroll 0% 0%;
+}
+.tundra .dijitLoginDomainPrincipalIcon {
+    background: transparent url('images/loginDomainPrincipalIcon.gif') no-repeat scroll 0% 0%;
+}
+.tundra .dijitRealmPrincipalIcon {
+    background: transparent url('images/realmPrincipalIcon.gif') no-repeat scroll 0% 0%;
+}
+.tundra .dijitDistinguishedNameIcon {
+    background: transparent url('images/distinguishedNameIcon.gif') no-repeat scroll 0% 0%;
+}
+pre .tag {
+    color: purple;
+}
+pre .value {
+    font-weight: bold;
+    color: #49C;
+}
+pre .string {
+    color: #B84;
+}

Modified: geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/js/enterpriseApp.js
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/js/enterpriseApp.js?rev=675839&r1=675838&r2=675839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/js/enterpriseApp.js (original)
+++ geronimo/server/trunk/plugins/plancreator/plancreator-portlets/src/main/webapp/js/enterpriseApp.js Thu Jul 10 23:37:25 2008
@@ -17,17 +17,46 @@
 
 // $Rev$ $Date$
 
-function updateEarTree(earTree) {
-    var earTreeStore = new dojo.data.ItemFileReadStore({data: earTree});
-    new dijit.Tree({id: 'referencesTree', store: earTreeStore, label: 'EAR'}, dojo.byId("referencesTreeHolder"));
-    new dijit.Tree({id: 'securityTree', store: earTreeStore, label: 'EAR'}, dojo.byId("securityTreeHolder"));
+function populateEnvironment(envJson) {
+    var envForm = dijit.byId("environmentForm");
+    envForm.setValues(envJson);
 }
 
+function saveEnvironment() {
+    EARHelper.saveEnvironmentJson(dijit.byId("environmentForm").getValues());
+    
+    var treeItems = [];
+    dijit.byId("dependenciesTree").store.fetch({
+        query: {name: "*"},
+        scope: this,
+        onItem: function(item) {treeItems.push({name: item.name[0]})},
+        onComplete: function() {
+            var depJson = new Object();
+            depJson.identifier = 'name';
+            depJson.label = 'name';
+            depJson.items = treeItems;
+            EARHelper.saveDependenciesJsonTree(depJson);
+        }
+    });
+}
+
+function refreshGeneratedPlan() {
+    EARHelper.getGeneratedPlan(function(plan) {
+        var elem = dojo.byId('generatedPlanDisplayer');
+        if(elem.textContent) {
+            elem.textContent = plan;
+        } else {
+            elem.innerText = plan;
+        }
+    });
+}
+
+// Dependencies related methods:
 function updateDependenciesTree(dependenciesJson) {
     var dependenciesStore = new dojo.data.ItemFileWriteStore({data: dependenciesJson});
     new dijit.Tree(
-  	    {
-            id: 'dependenciesTree', 
+        {
+            id: 'dependenciesTree',
             store: dependenciesStore,
             label: 'Dependencies'
         }, dojo.byId("dependenciesTree"));
@@ -45,45 +74,14 @@
     }
 }
 
-function populateEnvironment(envJson) {
-    var envForm = dijit.byId("environmentForm");
-    envForm.setValues(envJson);
-}
-
-function saveEnvironment(envJson) {
-    EARHelper.saveEnvironmentJson(envJson);
-}
-
-function refreshGeneratedPlan() {
-    EARHelper.getGeneratedPlan(function(plan) {
-        dojo.byId("generatedPlanDisplayer").value = plan;
-    });
-}
-  
-function saveDependencies() {
-    var treeItems = [];
-    dijit.byId("dependenciesTree").store.fetch({
-        query: {name: "*"},
-        scope: this,
-        onItem: function(item) { treeItems.push({name: item.name[0]}) },
-        onComplete: function() {
-            var depJson = new Object();
-            depJson.identifier = 'name';
-            depJson.label = 'name';
-            depJson.items = treeItems;
-            EARHelper.saveDependenciesJsonTree(depJson);
-        }
-    });
-}
-
 function addDependencyCallback(items, request) {
     value = request.query.name;
     
     if(items == null || items.length == 0) {
         var depTree = dijit.byId("dependenciesTree");
         
-		depTree.store.save({scope: {'value': value, 'depTree': depTree}, onComplete: function() {
-                depTree.store.newItem({name: value, attribute:'name'});
+        depTree.store.save({scope: {'value': value, 'depTree': depTree}, onComplete: function() {
+                depTree.store.newItem({name: value});
                 depTree._expandNode(depTree.rootNode);
             }
         });
@@ -102,8 +100,8 @@
         addNewDependency(deps[i]);
     }
     var checkedElements = dojo.query("input","dependenciesDialog").filter(
-        function(elem) { 
-            return elem.checked; 
+        function(elem) {
+            return elem.checked;
         }).forEach(
             function(item) {
                 dijit.byId(item.id).setAttribute("disabled", true);
@@ -128,12 +126,12 @@
         chkBoxWidget.setChecked(false);
         chkBoxWidget.setAttribute("disabled", false);
 
-		var depTree = dijit.byId("dependenciesTree");
+        var depTree = dijit.byId("dependenciesTree");
 
-		depTree.store.save({
-		    scope: item,
-		    onComplete: function() { dijit.byId("dependenciesTree").store.deleteItem(this) }
-		});
+        depTree.store.save({
+            scope: item,
+            onComplete: function() { dijit.byId("dependenciesTree").store.deleteItem(this) }
+        });
     }
 }
   
@@ -147,7 +145,7 @@
         }
         depTree.store.fetchItemByIdentity({
             identity: depTree.lastFocused.label,
-            onItem: deleteDependencyCallback 
+            onItem: deleteDependencyCallback
         });
     }
 }
@@ -173,12 +171,12 @@
         chkBoxLabel.innerHTML = newName;
         var depTree = dijit.byId("dependenciesTree");
         depTree.store.fetchItemByIdentity({
-            identity: name, 
+            identity: name,
             onItem: function(item) { 
                 dijit.byId("dependenciesTree").store.deleteItem(item)
             }
         });
-        depTree.store.newItem({name: newName, attribute: 'name'});
+        depTree.store.newItem({name: newName});
     }
 }
 
@@ -215,21 +213,466 @@
     }
 }
 
+/*
+**
+** Security related data and methods:
+**
+*/
+function updateSecurity(securityJson) {
+    var webModules = securityJson.webModules;
+
+    for(module in webModules) {
+        var moduleConfig = webModules[module];
+        var treeJson = moduleConfig.roleMappings;
+
+        var runAsSubjectsData = {identifier: 'name', label: 'name', items:[]};
+        for(i = 0; i < treeJson.items.length; i++) {
+            var item = treeJson.items[i];
+            var runAsSubject = moduleConfig.runAsSubjects[item.roleName];
+            if(runAsSubject) {
+                runAsSubjectsData.items.push({name: item.roleName, realm: runAsSubject.realm, id: runAsSubject.id});
+            }
+
+            if(item.children == null) delete item.children;
+        }
+
+        var securityStore = new dojo.data.ItemFileWriteStore({data: treeJson});
+        new dijit.Tree(
+            {   id: module+'.form.securityTree',
+                store: securityStore,
+                label: 'Role Mappings',
+                onClick: checkSecurityTreeFocusedNode,
+                getLabel: getSecurityTreeLabels,
+                getIconClass: getSecurityTreeIcons
+            }, dojo.byId(module+'.form.securityTree'));
+
+
+        var runAsSubjectsStore = new dojo.data.ItemFileWriteStore({data: runAsSubjectsData});
+        var treeId = module+'.form.runAsSubjectsTree';
+        new dijit.Tree(
+            {   id: treeId,
+                store: runAsSubjectsStore,
+                label: 'Run-as-subjects',
+                onClick: checkRunAsSubjectsTreeFocusedNode,
+                getLabel: getRunAsSubjectsTreeLabels
+            }, dojo.byId(treeId));
+
+        var rolesJson = {identifier: 'name', label: 'name', items: []};
+        for(i = 0; i < treeJson.items.length; i++) {
+            var item = treeJson.items[i];
+            if(!moduleConfig.runAsSubjects[item.roleName])
+                rolesJson.items.push({name: item.roleName.toString()});
+        }
+
+        dijit.byId(treeId).rolesJson = rolesJson;
+
+        if(moduleConfig.doasCurrentCaller) moduleConfig.doasCurrentCaller = ["true"];
+        if(moduleConfig.useContextHandler) moduleConfig.useContextHandler = ["true"];
+
+        for(p in moduleConfig)
+            if(moduleConfig[p] == null) delete moduleConfig[p];
+
+        var form = dijit.byId(module+'.form');
+        form.reset();
+        if(!moduleConfig.securityRealmName) {
+            moduleConfig.securityRealmName = dijit.byId(module+'.form.txtSecurityRealmName').getDisplayedValue();
+        }
+        if(!moduleConfig.credentialStoreRef) {
+            moduleConfig.credentialStoreRef = '';
+        }
+        form.setValues(moduleConfig);
+    }
+}
+
+function _constructModuleJson(moduleName, securityTree, runAsSubjectsTree) {
+    if(dijit.byId(moduleName + ".form").isValid()) {        
+        var module = dijit.byId(moduleName + ".form").getValues();
+        module.doasCurrentCaller = (dojo.indexOf(module.doasCurrentCaller, "true") != -1);
+        module.useContextHandler = (dojo.indexOf(module.useContextHandler, "true") != -1);
+        for(val in module)
+            if(module[val] == "") delete module[val];
+
+        module.roleMappings = {identifier: 'name', label: 'name', items: []};
+        module.runAsSubjects = null;
+
+        var roles = securityTree.rootNode.item.children;
+        for(i = 0; i < roles.length; i++) {
+            var role = {roleName: roles[i].roleName.toString(), children: []};
+            var mappings = roles[i].children;
+            if(mappings) {
+                for(j = 0; j < mappings.length; j++) {
+                    var mapping = {};
+                    for(p in mappings[j])
+                        if(p[0]!='_') mapping[p] = mappings[j][p].toString();
+                    role.children.push(mapping);
+                }
+            }
+            module.roleMappings.items.push(role);
+        }
+
+        var runAsSubjects = runAsSubjectsTree.rootNode.item.children;
+        for(i = 0; i < runAsSubjects.length; i++) {
+            var item = runAsSubjects[i];
+            if(item.realm && item.id) {
+                module.runAsSubjects = (module.runAsSubjects) ? module.runAsSubjects : {};
+                module.runAsSubjects[item.name] = {'realm': item.realm.toString(), 'id': item.id.toString()};
+            }
+        }
+        return module;
+    }
+    return null;
+}
+
+function saveSecurity() {
+    var webModules = null;
+
+    for(i = 0; i < dojo.global._moduleNames.length; i++) {
+        var moduleName = dojo.global._moduleNames[i];
+        var securityTree = dijit.byId(module + ".form.securityTree");
+        var runAsSubjectsTree = dijit.byId(module + ".form.runAsSubjectsTree");
+        var moduleJson = _constructModuleJson(moduleName, securityTree, runAsSubjectsTree);
+        if(moduleJson) {
+            webModules = webModules ? webModules : {}; 
+            webModules[module] = moduleJson;
+        }
+    }
+
+    if(webModules)
+        EARHelper.saveSecurityJson({'webModules': webModules});
+}
+
+function checkRunAsSubjectsTreeFocusedNode(item, node) {
+    var currentModule = dijit.byId("securityAccordionContainer").selectedChildWidget.id;
+    var btnAdd = dijit.byId(currentModule+".form.btnAddRunAsSubject");
+    btnAdd.setAttribute('disabled', true);
+    if(node == node.tree.rootNode) {
+        if(dijit.byId(currentModule+".form.runAsSubjectsTree").rolesJson.items.length != 0)
+            btnAdd.setAttribute('disabled', false);
+        dijit.byId(currentModule+".form.btnEditRunAsSubject").setAttribute('disabled', true);
+        dijit.byId(currentModule+".form.btnDeleteRunAsSubject").setAttribute('disabled', true);
+    } else {
+        dijit.byId(currentModule+".form.btnEditRunAsSubject").setAttribute('disabled', false);
+        dijit.byId(currentModule+".form.btnDeleteRunAsSubject").setAttribute('disabled', false);
+    }
+}
+
+function getRunAsSubjectsTreeLabels(item) {
+    var name = item.name;
+    if(item.realm && item.id)
+        name = name + ': realm="' + item.realm + '", id="' + item.id + '"';
+    return name;
+}
+
+function doAddOrEditRunAsSubject(treeId, isAdding) {
+    var dialog = dijit.byId('runAsSubjectDialog');
+    dialog.runAsSubjectsTree = dijit.byId(treeId);
+    dialog.isAdding = isAdding;
+
+    var select = dijit.byId('selRunAsSubjectRole');
+    dialog.reset();
+    if(isAdding) {
+        dojo.byId('selRunAsSubjectRoleRow').style.display = "";
+        select.store = new dojo.data.ItemFileReadStore({data: dialog.runAsSubjectsTree.rolesJson});
+        select.setDisplayedValue(dialog.runAsSubjectsTree.rolesJson.items[0].name.toString());
+    } else {
+        var item = dialog.runAsSubjectsTree.lastFocused.item;
+        dialog.setValues({name: item.name.toString(), realm: item.realm.toString(), id: item.id.toString()});
+        select.setDisplayedValue(item.name.toString());
+        dojo.byId('selRunAsSubjectRoleRow').style.display = 'none';
+    }
+    dialog.show();
+}
+
+function doDeleteRunAsSubject(treeId) {
+    var runAsSubjectsTree = dijit.byId(treeId);
+    var item = runAsSubjectsTree.lastFocused.item;
+    runAsSubjectsTree.store.save({scope: this, onComplete: function() {
+            runAsSubjectsTree.rolesJson.items.push({name: item.name.toString()});
+            runAsSubjectsTree.store.deleteItem(item);
+        }
+    });
+}
+
+function addOrEditRunAsSubject(runAsSubject) {
+    var runAsSubjectDialog = dijit.byId("runAsSubjectDialog");
+    var runAsSubjectsTree = runAsSubjectDialog.runAsSubjectsTree;
+    var runAsSubject = runAsSubject;
+    if(runAsSubjectDialog.isAdding) {
+        runAsSubjectsTree.store.save({scope: this, onComplete: function() {
+                runAsSubjectsTree.store.newItem(runAsSubject);
+                var items = runAsSubjectsTree.rolesJson.items;
+                var newItems = [];
+                for(var i = 0; i < items.length; i++)
+                    if(items[i].name.toString() != runAsSubject.name)
+                        newItems.push(items[i]);
+                runAsSubjectsTree.rolesJson.items = newItems;
+            }
+        });
+    } else {
+        var item = runAsSubjectsTree.lastFocused.item;
+        runAsSubjectsTree.store.setValue(item, 'realm', runAsSubject.realm);
+        runAsSubjectsTree.store.setValue(item, 'id', runAsSubject.id);
+    }
+}
+function checkRunAsSubjectFields() {
+    var dialog = dijit.byId("runAsSubjectDialog");
+    var values = dialog.getValues();
+    var valid = (values.realm != "") && (values.id != "");
+    if(dialog.isAdding) valid = valid && (dijit.byId("selRunAsSubjectRole").isValid());
+    dijit.byId("btnRunAsSubjectOK").setAttribute('disabled', !valid);
+}
+
+function getSecurityTreeLabels(item) {
+    if(item.roleName) return item.roleName;
+
+    var label = "Name: " + item.principalName[0];
+
+    if(item.className && item.className[0]) {
+        var className = item.className[0];
+        className = className.substring(className.lastIndexOf('.')+1, className.length);
+        label = label + ", Class: " + className;
+        if(item.domainName && item.domainName[0]) {
+            label = label + ", Domain: " + item.domainName[0];
+            if(item.realmName && item.realmName[0]) {
+                label = label + ", Realm: " + item.realmName[0];
+            }
+        }
+    }
+    return label;
+}
+
+function getSecurityTreeIcons(item, opened) {
+    if(!item || item.root || item.roleName) {
+        return (opened ? "dijitFolderOpened" : "dijitFolderClosed")
+    } else {
+        return "dijit" + item.type[0] + "Icon";
+    }
+}
+
+function checkSecurityTreeFocusedNode(item, node) {
+    var currentModule = dijit.byId("securityAccordionContainer").selectedChildWidget.id;
+    dijit.byId(currentModule+".form.btnAdd").setAttribute('disabled', (item.roleName==null));
+    var disable = (item.roleName!=null) || (node == node.tree.rootNode);
+    dijit.byId(currentModule+".form.btnEdit").setAttribute('disabled', disable);
+    dijit.byId(currentModule+".form.btnDelete").setAttribute('disabled', disable);
+}
+
+function validatePrincipalName(value) {
+        var valid = false;
+        if(value != "") {
+            valid = true;
+
+            var dialog = dijit.byId("roleMappingDialog");
+            if(dialog.roleMappingTree) {
+                if(dialog.isAdding) {
+                    var existingPrincipals = dialog.roleMappingTree.lastFocused.item.children;
+                    if(existingPrincipals) {
+                        for(i = 0; i < existingPrincipals.length; i++)
+                            if(existingPrincipals[i].principalName == value) {
+                                valid = false;
+                                break;
+                            }
+                    }
+                } else {
+                    var selectedNode = dialog.roleMappingTree.lastFocused;
+                    var existingPrincipals = selectedNode.getParent().item.children;
+                    if(existingPrincipals) {
+                        for(i = 0; i < existingPrincipals.length; i++)
+                            if((existingPrincipals[i] != selectedNode.item) && (existingPrincipals[i].principalName == value)) {
+                                valid = false;
+                                break;
+                            }
+                    }
+                }
+            }
+        }
+        if(!valid) {
+            var btnOk = dijit.byId("btnRoleMappingOK");
+            if(btnOk)
+                btnOk.setAttribute("disabled", true);
+        }
+        return valid;
+}
+function addRoleMappingCallback(item) {
+    if(!item) {
+        var securityTree = this.securityTree;
+        var principal = this.principal;
+        switch(principal.type) {
+            case "Distinguished Name":
+                delete principal.className;
+            case "Principal":
+                delete principal.domainName;
+            case "Login Domain Principal":
+                delete principal.realmName;
+                break;
+        }
+        securityTree.store.save({scope: this, onComplete: function() {
+                securityTree.store.newItem(principal, {parent: securityTree.lastFocused.item, attribute: 'children'});
+            }
+        });
+    }
+}
+
+function editRoleMappingCallback(item) {
+    var store = this.store;
+    var principal = this.principal;
+
+    switch(this.principal.type) {
+        case "Distinguished Name":
+            delete principal.className;
+        case "Principal":
+            delete principal.domainName;
+        case "Login Domain Principal":
+            delete principal.realmName;
+            break;
+    }
+
+    store.unsetAttribute(item, "className");
+    store.unsetAttribute(item, "domainName");
+    store.unsetAttribute(item, "realmName");
+
+    for(p in principal) {
+        store.setValue(item, p, principal[p]);
+    }
+    store.save();
+}
+
+function addOrEditRoleMapping(principal) {   
+    this.securityTree = dijit.byId("roleMappingDialog").roleMappingTree;
+    this.store = this.securityTree.store;
+    this.principal = principal;  
+
+    if(dijit.byId("roleMappingDialog").isAdding) {
+        var roleNode = securityTree.lastFocused;
+        roleNode.pCount = (roleNode.pCount) ? (roleNode.pCount+1) : 1;
+        principal.name = roleNode.item.roleName + ".principal" + roleNode.pCount;
+        this.store.fetchItemByIdentity({identity: principal.name, scope: this, onItem: addRoleMappingCallback});
+    } else {
+        this.store.fetchItemByIdentity({identity: this.securityTree.lastFocused.item.name, scope: this, onItem: editRoleMappingCallback});
+    }
+}
+
+function doAddOrEditRoleMapping(treeId, isAdding) {
+    checkRoleMappingFields();
+    var dialog = dijit.byId("roleMappingDialog");
+    dialog.roleMappingTree = dijit.byId(treeId); 
+    dialog.isAdding = isAdding;
+
+    if(!isAdding) {
+        var principal = dialog.roleMappingTree.lastFocused.item;
+        var values = {};
+
+        for(p in principal) {
+            if(p[0] != "_") {        
+                var value = principal[p].toString();
+                if(value != "")
+                    values[p] = value;
+            }
+        }
+        dialog.setValues(values);
+    }
+    checkRoleMappingFields();
+    dialog.validate();
+    dialog.show();
+}
+
+function deleteRoleMappingCallback(item) {
+    if(!item) return;
+    this.securityTree.store.save({
+        scope: {'securityTree': this.securityTree, 'item': item},
+        onComplete: function() { this.securityTree.store.deleteItem(this.item) }
+    });
+}
+
+function doDeleteRoleMapping(treeId) {
+    var securityTree = dijit.byId(treeId);
+    if(securityTree.lastFocused != null) {
+        securityTree.store.fetchItemByIdentity({
+            identity: securityTree.lastFocused.item.name,
+            onItem: deleteRoleMappingCallback,
+            scope: {'securityTree': securityTree}
+        });
+    }
+}
+
+function _setRoleMappingFieldVisibility(fieldName, hide) {
+    var field = dijit.byId(fieldName);
+    field.setAttribute("disabled", hide);
+    field.domNode.parentNode.parentNode.style.display = (hide ? "none" : "");
+}
+
+function modifyRoleMappingForm(mappingType) {
+    var isPrincipal = (mappingType == "Principal");
+    var isLoginDomain = (mappingType == "LoginDomainPrincipal");
+    var isRealm = (mappingType == "RealmPrincipal");
+    var isDistinguished = (mappingType == "DistinguishedName");
+
+    _setRoleMappingFieldVisibility("selRoleMappingClass", isDistinguished);
+    _setRoleMappingFieldVisibility("txtRoleMappingDomainName", isPrincipal || isDistinguished);
+    _setRoleMappingFieldVisibility("selRoleMappingRealmName", isPrincipal || isDistinguished || isLoginDomain);
+
+    checkRoleMappingFields();
+}
+
+function checkRoleMappingFields() {
+    var domainNameField = dijit.byId("txtRoleMappingDomainName");
+    if(!dijit.byId("txtRoleMappingName").isValid() || (!domainNameField.disabled && !domainNameField.isValid()))
+        dijit.byId("btnRoleMappingOK").setAttribute("disabled", true);
+    else
+        dijit.byId("btnRoleMappingOK").setAttribute("disabled", false);
+}
+
+function doPrevious() {
+    var tabContainer = dijit.byId("mainTabContainer");
+    if(tabContainer.selectedChildWidget.title != "Environment") 
+        tabContainer.back();
+}
+
+function doNext() {
+    var tabContainer = dijit.byId("mainTabContainer");
+    if(tabContainer.selectedChildWidget.title != "Generated Plan")
+        tabContainer.forward();
+}
+
+function saveGeneratedPlan() {
+    var elem = dojo.byId('generatedPlanDisplayer');
+    var plan = (elem.textContent ? elem.textContent : elem.innerText);
+    EARHelper.saveGeneratedPlan(plan);
+}
+
+function onTabSwitch(page) {
+    switch(this.currentTab) {
+        case 'environment': saveEnvironment(); break;
+        case 'references': /* saveReferences() */; break;
+        case 'security': saveSecurity(); break;
+        case 'generatedPlan': saveGeneratedPlan(); break;
+    }
+    this.currentTab = page.id;
+    switch(this.currentTab) {
+        case 'generatedPlan': refreshGeneratedPlan(); break;
+    }
+}
+
 dojo.addOnLoad(function(){
     EARHelper.getEnvironmentJson(populateEnvironment);
     EARHelper.getDependenciesJsonTree(updateDependenciesTree);
-    EARHelper.getEarTree(updateEarTree);
+    EARHelper.getSecurityJson(updateSecurity);
 
     var dlgDep = dijit.byId("dependenciesDialog");
     dlgDep._getFocusItems = function(node) {}
     dlgDep._firstFocusItem = dojo.byId("depChkBox_1");
     dlgDep._lastFocusItem = dojo.byId("btnAdd");
-    
+
     var nodeCount = 0;
     dojo.query("tr", "dependenciesDialog").filter(
         function(row) {
             return (nodeCount++) % 2 == 0;
         }).style("backgroundColor","rgb(240,250,255)");
 
-    dojo.connect(dijit.byId('generatedPlan').controlButton, 'onClick', refreshGeneratedPlan);
+    dojo.subscribe('mainTabContainer-selectChild', {currentTab: 'environment'}, onTabSwitch);
+
+    var moduleWidgets = dijit.byId('securityAccordionContainer').getChildren();
+    dojo.global._moduleNames = [];
+    for(i = 0; i < moduleWidgets.length; i++)
+        dojo.global._moduleNames.push(moduleWidgets[i].id);
 });



Mime
View raw message