felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1399574 [2/2] - in /felix/trunk: ./ jaas/ jaas/src/ jaas/src/main/ jaas/src/main/java/ jaas/src/main/java/org/ jaas/src/main/java/org/apache/ jaas/src/main/java/org/apache/felix/ jaas/src/main/java/org/apache/felix/jaas/ jaas/src/main/java...
Date Thu, 18 Oct 2012 10:10:09 GMT
Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Util.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Util.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Util.java Thu Oct 18 10:10:08
2012
@@ -0,0 +1,210 @@
+/*
+ * 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.felix.jaas.internal;
+
+import java.util.*;
+
+
+final class Util
+{
+
+    public static Set<String> parseHeader(String header)
+    {
+        //Could have used Sling commons ManifestHeader.parse
+        //but our requirement are simple
+
+        header = trimToNull(header);
+        if (header == null)
+        {
+            return new HashSet<String>();
+        }
+
+        String[] splits = header.split(",");
+        Set<String> values = new HashSet<String>();
+        for (String s : splits)
+        {
+            s = trimToNull(s);
+            if (s != null)
+            {
+                values.add(s);
+            }
+        }
+        return values;
+    }
+
+    //Instead of adding dependency on commons StringUtil we copy the used method below
+
+    public static String trimToNull(String str)
+    {
+        String ts = trim(str);
+        return isEmpty(ts) ? null : ts;
+    }
+
+    private static String trim(String str)
+    {
+        return str == null ? null : str.trim();
+    }
+
+    public static boolean isEmpty(String str)
+    {
+        return str == null || str.length() == 0;
+    }
+
+    //----------------Methods taken from org.apache.sling.commons.osgi.PropertiesUtil
+
+    //These are required to safely access properties from ConfigurationAdmin
+
+    /**
+     * Returns the parameter as a string or the
+     * <code>defaultValue</code> if the parameter is <code>null</code>.
+     * @param propValue the property value or <code>null</code>
+     * @param defaultValue the default string value
+     */
+    public static String toString(Object propValue, String defaultValue)
+    {
+        propValue = toObject(propValue);
+        return (propValue != null) ? propValue.toString() : defaultValue;
+    }
+
+    /**
+     * Returns the parameter as an integer or the
+     * <code>defaultValue</code> if the parameter is <code>null</code>
or if
+     * the parameter is not an <code>Integer</code> and cannot be converted to
+     * an <code>Integer</code> from the parameter's string value.
+     * @param propValue the property value or <code>null</code>
+     * @param defaultValue the default integer value
+     */
+    public static int toInteger(Object propValue, int defaultValue)
+    {
+        propValue = toObject(propValue);
+        if (propValue instanceof Integer)
+        {
+            return (Integer) propValue;
+        }
+        else if (propValue != null)
+        {
+            try
+            {
+                return Integer.valueOf(String.valueOf(propValue));
+            }
+            catch (NumberFormatException nfe)
+            {
+                // don't care, fall through to default value
+            }
+        }
+
+        return defaultValue;
+    }
+
+    /**
+     * Returns the parameter as a single value. If the
+     * parameter is neither an array nor a <code>java.util.Collection</code>
the
+     * parameter is returned unmodified. If the parameter is a non-empty array,
+     * the first array element is returned. If the property is a non-empty
+     * <code>java.util.Collection</code>, the first collection element is returned.
+     * Otherwise <code>null</code> is returned.
+     * @param propValue the parameter to convert.
+     */
+    private static Object toObject(Object propValue)
+    {
+        if (propValue == null)
+        {
+            return null;
+        }
+        else if (propValue.getClass().isArray())
+        {
+            Object[] prop = (Object[]) propValue;
+            return prop.length > 0 ? prop[0] : null;
+        }
+        else if (propValue instanceof Collection<?>)
+        {
+            Collection<?> prop = (Collection<?>) propValue;
+            return prop.isEmpty() ? null : prop.iterator().next();
+        }
+        else
+        {
+            return propValue;
+        }
+    }
+
+    /**
+     * Returns the parameter as an array of Strings. If
+     * the parameter is a scalar value its string value is returned as a single
+     * element array. If the parameter is an array, the elements are converted to
+     * String objects and returned as an array. If the parameter is a collection, the
+     * collection elements are converted to String objects and returned as an array.
+     * Otherwise (if the property is <code>null</code>) a provided default value
is
+     * returned.
+     * @param propValue The object to convert.
+     * @param defaultArray The default array to return.
+     */
+    public static String[] toStringArray(Object propValue, String[] defaultArray)
+    {
+        if (propValue == null)
+        {
+            // no value at all
+            return defaultArray;
+
+        }
+        else if (propValue instanceof String)
+        {
+            // single string
+            return new String[] { (String) propValue };
+
+        }
+        else if (propValue instanceof String[])
+        {
+            // String[]
+            return (String[]) propValue;
+
+        }
+        else if (propValue.getClass().isArray())
+        {
+            // other array
+            Object[] valueArray = (Object[]) propValue;
+            List<String> values = new ArrayList<String>(valueArray.length);
+            for (Object value : valueArray)
+            {
+                if (value != null)
+                {
+                    values.add(value.toString());
+                }
+            }
+            return values.toArray(new String[values.size()]);
+
+        }
+        else if (propValue instanceof Collection<?>)
+        {
+            // collection
+            Collection<?> valueCollection = (Collection<?>) propValue;
+            List<String> valueList = new ArrayList<String>(valueCollection.size());
+            for (Object value : valueCollection)
+            {
+                if (value != null)
+                {
+                    valueList.add(value.toString());
+                }
+            }
+            return valueList.toArray(new String[valueList.size()]);
+        }
+
+        return defaultArray;
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/package-info.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/package-info.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/package-info.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/package-info.java Thu Oct 18 10:10:08
2012
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides support for performing JAAS based authentication in OSGi
+ *
+ * @version 1.0
+ */
+@Version("1.0")
+@Export(optional = "provide:=true")
+package org.apache.felix.jaas;
+
+import aQute.bnd.annotation.Version;
+import aQute.bnd.annotation.Export;

Added: felix/trunk/jaas/src/main/resources/OSGI-INF/l10n/bundle.properties
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/resources/OSGI-INF/l10n/bundle.properties?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/resources/OSGI-INF/l10n/bundle.properties (added)
+++ felix/trunk/jaas/src/main/resources/OSGI-INF/l10n/bundle.properties Thu Oct 18 10:10:08
2012
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+intro=JAAS Configuration Details

Added: felix/trunk/jaas/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ felix/trunk/jaas/src/main/resources/OSGI-INF/metatype/metatype.properties Thu Oct 18 10:10:08
2012
@@ -0,0 +1,62 @@
+#
+# 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.
+#
+# suppress inspection "UnusedProperty" for whole file
+
+jaas.name=Apache Felix JAAS Configuration Factory
+jaas.description=Captures JAAS configuration with options, control flag and classname
+
+
+jaas.classname.name=Class Name
+jaas.classname.description=Fully qualified name of the LoginModule class
+
+jaas.controlFlag.name=Control Flag
+jaas.controlFlag.description=The Flag value controls the overall behavior as authentication
proceeds down the stack
+
+jaas.flag.required=Required
+jaas.flag.requisite=Requisite
+jaas.flag.sufficient=Sufficient
+jaas.flag.optional=Optional
+
+jaas.ranking.name = Ranking
+jaas.ranking.description = The relative ranking of this configuration.
+
+jaas.options.name = Options
+jaas.options.description = Properties in the form of key value pairs that are passed on to
the LoginModule(name=value pairs)
+
+jaas.realmName.name = Realm Name
+jaas.realmName.description = Name of the application
+
+jaas.spi.name = Apache Felix JAAS Configuration SPI
+jaas.spi.description= JAAS Configuration SPI implementation which provides configuration
based on OSGi ConfigAdmin
+
+jaas.defaultRealmName.name = Default JAAS Realm
+jaas.defaultRealmName.description = Default realm name to use if no realm is explicitly defined
for LoginModule
+
+jaas.configProviderName.name=JAAS Config Provider name
+jaas.configProviderName.description=Name of the provider used to register the OSGi based
configuration provider
+
+jaas.globalConfigPolicy.name=Global Configuration Policy
+jaas.globalConfigPolicy.description=Policy to manage global configuration. (1) Default: Global
configuration is not \
+  modified. (2). Replace Global Configuration: Global configuration is replaced with OSGi
based configuration \
+  (3). Proxy Global Configuration: Global configuration would be replaced with proxy configuration.
The proxy \
+  would check with OSGi based configuration. If no config is found it would look in default
global configuration
+
+jaas.configPolicy.default=Default
+jaas.configPolicy.replace=Replace Global Configuration
+jaas.configPolicy.proxy=Proxy Global Configuration
\ No newline at end of file

Modified: felix/trunk/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/pom.xml?rev=1399574&r1=1399573&r2=1399574&view=diff
==============================================================================
--- felix/trunk/pom.xml (original)
+++ felix/trunk/pom.xml Thu Oct 18 10:10:08 2012
@@ -122,6 +122,7 @@
         <module>webconsole-plugins/event</module>
         <module>fileinstall</module>
         <module>useradmin</module>
+        <module>jaas</module>
 
 		<module>gogo</module>
 



Mime
View raw message