[jboss-cvs] JBossAS SVN: r58037 - projects/security/trunk/src/main/org/jboss/security/mapping/providers
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 2 23:38:42 EST 2006
Author: anil.saldhana at jboss.com
Date: 2006-11-02 23:38:41 -0500 (Thu, 02 Nov 2006)
New Revision: 58037
Added:
projects/security/trunk/src/main/org/jboss/security/mapping/providers/DeploymentRolesMappingProvider.java
Log:
SECURITY-18:Deployment roles mapping provider
Added: projects/security/trunk/src/main/org/jboss/security/mapping/providers/DeploymentRolesMappingProvider.java
===================================================================
--- projects/security/trunk/src/main/org/jboss/security/mapping/providers/DeploymentRolesMappingProvider.java 2006-11-03 02:00:19 UTC (rev 58036)
+++ projects/security/trunk/src/main/org/jboss/security/mapping/providers/DeploymentRolesMappingProvider.java 2006-11-03 04:38:41 UTC (rev 58037)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.mapping.providers;
+
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.logging.Logger;
+import org.jboss.security.SecurityConstants;
+import org.jboss.security.SimpleGroup;
+import org.jboss.security.SimplePrincipal;
+import org.jboss.security.mapping.MappingProvider;
+
+//$Id$
+
+/**
+ * A Role Mapping Module that takes into consideration a principal
+ * to roles mapping that can be done in the assembly descriptor of
+ * jboss.xml, jboss-web.xml and jboss-app.xml
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @since Nov 1, 2006
+ * @version $Revision$
+ */
+public class DeploymentRolesMappingProvider implements MappingProvider
+{
+ private static Logger log = Logger.getLogger(DeploymentRolesMappingProvider.class);
+ private boolean trace = log.isTraceEnabled();
+
+ public void init(Map options)
+ {
+ }
+
+ /**
+ * Obtains the deployment roles via the context map and applies it
+ * on the mappedObject
+ * @see MappingProvider#performMapping(Map, Object)
+ */
+ public void performMapping(Map map, Object mappedObject)
+ {
+ if(map == null || map.isEmpty())
+ throw new IllegalArgumentException("Context Map is null or empty");
+ if(mappedObject instanceof Group == false)
+ throw new IllegalArgumentException("mapped Object is not an instance of java.security.acl.Group");
+
+ //Obtain the principal to roles mapping
+ Principal principal = (Principal) map.get(SecurityConstants.PRINCIPAL_IDENTIFIER);
+ Map principalRolesMap = (Map)map.get(SecurityConstants.DEPLOYMENT_PRINCIPAL_ROLES_MAP);
+ if(trace)
+ log.trace("Principal="+principal+":principalRolesMap="+principalRolesMap);
+
+ if(principal == null || principalRolesMap == null || principalRolesMap.isEmpty())
+ return; // No Mapping
+
+ Set roleset = (Set)principalRolesMap.get(principal.getName());
+ if(roleset != null)
+ {
+ Group newRoles = new SimpleGroup(SecurityConstants.ROLES_IDENTIFIER);
+ Iterator iter = roleset.iterator();
+ while(iter.hasNext())
+ {
+ String rolename = (String)iter.next();
+ newRoles.addMember(createNewPrincipal((Group) mappedObject,rolename));
+ }
+ mappedObject = MappingProviderUtil.replacePrincipals((Group) mappedObject, newRoles);
+ }
+ }
+
+ /**
+ * Need to maintain the Principal type from the original group
+ * @param grp
+ * @param name
+ * @return
+ */
+ private Principal createNewPrincipal(Group grp, String name)
+ {
+ Principal p = new SimplePrincipal(name);
+
+ //If the original group had a different principal than simpleprincipal
+ if(grp.members().hasMoreElements())
+ {
+ Principal origp = grp.members().nextElement();
+ p = MappingProviderUtil.instantiatePrincipal(origp.getClass(), name);
+ if(p == null)
+ p = new SimplePrincipal(name);
+ }
+ return p;
+ }
+}
More information about the jboss-cvs-commits
mailing list