You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2004/11/10 04:39:10 UTC

svn commit: rev 57124 - geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment

Author: djencks
Date: Tue Nov  9 19:39:09 2004
New Revision: 57124

Added:
   geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment/SecurityBuilder.java
Log:
oops, how'd I miss this??

Added: geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment/SecurityBuilder.java
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment/SecurityBuilder.java	Tue Nov  9 19:39:09 2004
@@ -0,0 +1,93 @@
+/**
+ *
+ * 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.security.deployment;
+
+import org.apache.geronimo.security.deploy.Security;
+import org.apache.geronimo.security.deploy.DefaultPrincipal;
+import org.apache.geronimo.security.deploy.Role;
+import org.apache.geronimo.security.deploy.Realm;
+import org.apache.geronimo.security.deploy.Principal;
+import org.apache.geronimo.xbeans.geronimo.security.GerSecurityType;
+import org.apache.geronimo.xbeans.geronimo.security.GerDefaultPrincipalType;
+import org.apache.geronimo.xbeans.geronimo.security.GerRoleMappingsType;
+import org.apache.geronimo.xbeans.geronimo.security.GerRoleType;
+import org.apache.geronimo.xbeans.geronimo.security.GerRealmType;
+import org.apache.geronimo.xbeans.geronimo.security.GerPrincipalType;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class SecurityBuilder {
+
+    public static Security buildSecurityConfig(GerSecurityType securityType) {
+        Security security = null;
+
+        if (securityType != null) {
+            security = new Security();
+
+            security.setDoAsCurrentCaller(securityType.getDoasCurrentCaller());
+            security.setUseContextHandler(securityType.getUseContextHandler());
+            security.setDefaultRole(securityType.getDefaultRole());
+
+            GerDefaultPrincipalType defaultPrincipalType = securityType.getDefaultPrincipal();
+            DefaultPrincipal defaultPrincipal = new DefaultPrincipal();
+
+            defaultPrincipal.setRealmName(defaultPrincipalType.getRealmName());
+            defaultPrincipal.setPrincipal(buildPrincipal(defaultPrincipalType.getPrincipal()));
+
+            security.setDefaultPrincipal(defaultPrincipal);
+
+            GerRoleMappingsType roleMappingsType = securityType.getRoleMappings();
+            if (roleMappingsType != null) {
+                for (int i = 0; i < roleMappingsType.sizeOfRoleArray(); i++) {
+                    GerRoleType roleType = roleMappingsType.getRoleArray(i);
+                    Role role = new Role();
+
+                    role.setRoleName(roleType.getRoleName());
+
+                    for (int j = 0; j < roleType.sizeOfRealmArray(); j++) {
+                        GerRealmType realmType = roleType.getRealmArray(j);
+                        Realm realm = new Realm();
+
+                        realm.setRealmName(realmType.getRealmName());
+
+                        for (int k = 0; k < realmType.sizeOfPrincipalArray(); k++) {
+                            realm.getPrincipals().add(buildPrincipal(realmType.getPrincipalArray(k)));
+                        }
+
+                        role.getRealms().add(realm);
+                    }
+
+                    security.getRoleMappings().add(role);
+                }
+            }
+        }
+
+        return security;
+    }
+
+    private static Principal buildPrincipal(GerPrincipalType principalType) {
+        Principal principal = new Principal();
+
+        principal.setClassName(principalType.getClass1());
+        principal.setPrincipalName(principalType.getName());
+        principal.setDesignatedRunAs(principalType.isSetDesignatedRunAs());
+
+        return principal;
+    }
+
+}