geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r772462 - in /geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security: jaspi/AuthConfigFactoryGBean.java util/ConfigurationUtil.java
Date Wed, 06 May 2009 22:57:59 GMT
Author: djencks
Date: Wed May  6 22:57:58 2009
New Revision: 772462

URL: http://svn.apache.org/viewvc?rev=772462&view=rev
Log:
enhance principal construction for jacc, move missing class from jetty7 integration

Added:
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jaspi/AuthConfigFactoryGBean.java
  (with props)
Modified:
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/util/ConfigurationUtil.java

Added: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jaspi/AuthConfigFactoryGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jaspi/AuthConfigFactoryGBean.java?rev=772462&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jaspi/AuthConfigFactoryGBean.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jaspi/AuthConfigFactoryGBean.java
Wed May  6 22:57:58 2009
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.jaspi;
+
+import javax.security.auth.message.config.AuthConfigFactory;
+
+import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.annotation.ParamSpecial;
+import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
+
+/**
+ * Installs the specified AuthConfigFactory
+ *
+ * @version $Rev$ $Date$
+ */
+public class AuthConfigFactoryGBean {
+
+    public AuthConfigFactoryGBean(@ParamAttribute(name = "authConfigFactoryClassName") final
String authConfigFactoryClassName,
+                                  @ParamSpecial(type = SpecialAttributeType.classLoader)
ClassLoader classLoader) {
+
+        Thread currentThread = Thread.currentThread();
+        ClassLoader oldClassLoader = currentThread.getContextClassLoader();
+        currentThread.setContextClassLoader(classLoader);
+        try {
+            java.security.AccessController.doPrivileged(new java.security.PrivilegedAction()
{
+                        public Object run() {
+                            java.security.Security.setProperty(AuthConfigFactory.DEFAULT_FACTORY_SECURITY_PROPERTY,
authConfigFactoryClassName);
+                            return null;
+                        }
+                    });
+
+            AuthConfigFactory.getFactory();
+
+        } finally {
+            currentThread.setContextClassLoader(oldClassLoader);
+        }
+
+    }
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jaspi/AuthConfigFactoryGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jaspi/AuthConfigFactoryGBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jaspi/AuthConfigFactoryGBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/util/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/util/ConfigurationUtil.java?rev=772462&r1=772461&r2=772462&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/util/ConfigurationUtil.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/util/ConfigurationUtil.java
Wed May  6 22:57:58 2009
@@ -18,9 +18,12 @@
 package org.apache.geronimo.security.util;
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.security.Principal;
 
 import javax.security.auth.x500.X500Principal;
 import javax.security.jacc.PolicyContext;
@@ -34,6 +37,8 @@
 import org.apache.geronimo.security.PrimaryRealmPrincipal;
 import org.apache.geronimo.security.RealmPrincipal;
 import org.apache.geronimo.security.deploy.PrincipalInfo;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
 
 
 /**
@@ -45,6 +50,7 @@
  * @see "JSR 115" Java Authorization Contract for Containers
  */
 public class ConfigurationUtil {
+    private static final Logger log = LoggerFactory.getLogger(ConfigurationUtil.class);
 
     /**
      * Create an X500Principal from a deployment description.
@@ -63,23 +69,44 @@
      * @param classLoader
      * @return a RealmPrincipal from a deployment description
      */
-    public static java.security.Principal generatePrincipal(final PrincipalInfo principalInfo,
ClassLoader classLoader) {
+    public static Principal generatePrincipal(final PrincipalInfo principalInfo, ClassLoader
classLoader) {
         return generatePrincipal(principalInfo.getClassName(), principalInfo.getPrincipalName(),
classLoader);
     }
 
-    public static java.security.Principal generatePrincipal(final String className, final
String principalName, final ClassLoader classLoader) {
+    public static Principal generatePrincipal(final String className, final String principalName,
final ClassLoader classLoader) {
         try {
-            return (java.security.Principal) AccessController.doPrivileged(new PrivilegedExceptionAction()
{
-                public Object run() throws Exception {
-                    Class clazz = classLoader.loadClass(className);
-                    Constructor constructor = clazz.getDeclaredConstructor(new Class[]{String.class});
-                    return (java.security.Principal) constructor.newInstance(new Object[]{principalName});
+            return AccessController.doPrivileged(new PrivilegedExceptionAction<Principal>()
{
+                public Principal run() throws Exception {
+                    Class<Principal> clazz = (Class<Principal>) classLoader.loadClass(className);
+                    try {
+                        Constructor<Principal> constructor = clazz.getDeclaredConstructor(new
Class[]{String.class});
+                        return constructor.newInstance(new Object[]{principalName});
+                    } catch (NoSuchMethodException e) {
+                        Constructor<Principal>[] constructors = (Constructor<Principal>[])clazz.getDeclaredConstructors();
+                        for (Constructor<Principal> constructor: constructors) {
+                            Class<?>[] paramTypes = constructor.getParameterTypes();
+                            if (paramTypes.length == 0) {
+                                Principal p = constructor.newInstance();
+                                Method m = clazz.getMethod("setName", String.class);
+                                m.invoke(p, principalName);
+                                return p;
+                            }
+                            if (paramTypes[0] == String.class) {
+                                Object[] params = new Object[paramTypes.length];
+                                params[0] = principalName;
+                                return constructor.newInstance(params);
+                            }
+                        }
+                        throw new RuntimeException("Could not construct principal of class:
" + className);
+                    }
                 }
             });
         } catch (PrivilegedActionException e) {
             e.printStackTrace();
             if (e.getException() != null) {
-                e.getException().printStackTrace();
+                log.info("PrivilegedActionException containing", e.getException());
+            } else {
+                log.info("PrivilegedActionException", e);
             }
             return null;
         }
@@ -134,10 +161,10 @@
         try {
             return (PrimaryRealmPrincipal) AccessController.doPrivileged(new PrivilegedExceptionAction()
{
                 public Object run() throws Exception {
-                    java.security.Principal p = null;
+                    Principal p = null;
                     Class clazz = classLoader.loadClass(className);
                     Constructor constructor = clazz.getDeclaredConstructor(new Class[]{String.class});
-                    p = (java.security.Principal) constructor.newInstance(new Object[]{principalName});
+                    p = (Principal) constructor.newInstance(new Object[]{principalName});
 
                     return new PrimaryRealmPrincipal(realm, domain, p);
                 }
@@ -164,10 +191,10 @@
         try {
             return (PrimaryDomainPrincipal) AccessController.doPrivileged(new PrivilegedExceptionAction()
{
                 public Object run() throws Exception {
-                    java.security.Principal p = null;
+                    Principal p = null;
                     Class clazz = classLoader.loadClass(className);
                     Constructor constructor = clazz.getDeclaredConstructor(new Class[]{String.class});
-                    p = (java.security.Principal) constructor.newInstance(new Object[]{principalName});
+                    p = (Principal) constructor.newInstance(new Object[]{principalName});
 
                     return new PrimaryDomainPrincipal(domain, p);
                 }
@@ -192,10 +219,10 @@
         try {
             return (PrimaryPrincipal) AccessController.doPrivileged(new PrivilegedExceptionAction()
{
                 public Object run() throws Exception {
-                    java.security.Principal p = null;
+                    Principal p = null;
                     Class clazz = classLoader.loadClass(className);
                     Constructor constructor = clazz.getDeclaredConstructor(new Class[]{String.class});
-                    p = (java.security.Principal) constructor.newInstance(new Object[]{principalName});
+                    p = (Principal) constructor.newInstance(new Object[]{principalName});
 
                     return new PrimaryPrincipal(p);
                 }



Mime
View raw message