OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | easybeans-commits List | May 2008 Index

<--  Date Index  --> <--  Thread Index  -->

[easybeans-commits] [3361] trunk/util: Share some common classes to manage the security.


Title: [3361] trunk/util: Share some common classes to manage the security.
Revision
3361
Author
loris
Date
2008-05-30 15:20:39 +0200 (Fri, 30 May 2008)

Log Message

Share some common classes to manage the security.

Modified Paths

Added Paths

Diff

Modified: trunk/util/.classpath (3360 => 3361)


--- trunk/util/.classpath	2008-05-30 12:09:25 UTC (rev 3360)
+++ trunk/util/.classpath	2008-05-30 13:20:39 UTC (rev 3361)
@@ -61,7 +61,9 @@
 		</attributes>
 	</classpathentry>
 	<classpathentry kind="src" output="target-eclipse/classes" path="modules/scan/api/src/main/java"/>
-	<classpathentry kind="src" output="target-eclipse/classes" path="modules/scan/impl/src/main/java"/>
+	<classpathentry kind="src" output="target-eclipse/classes" path="modules/scan/impl/src/main/java"/>
+    <classpathentry kind="src" output="target-eclipse/classes" path="modules/security/api/src/main/java"/>
+    <classpathentry kind="src" output="target-eclipse/classes" path="modules/security/impl/src/main/java"/>
 	<classpathentry kind="src" output="target-eclipse/classes" path="modules/url/src/main/java"/>
 	<classpathentry kind="src" output="target-eclipse/classes" path="modules/xml/src/main/java"/>
 	<classpathentry kind="src" output="target-eclipse/classes" path="modules/xmlconfig/src/main/java"/>

Modified: trunk/util/modules/pom.xml (3360 => 3361)


--- trunk/util/modules/pom.xml	2008-05-30 12:09:25 UTC (rev 3360)
+++ trunk/util/modules/pom.xml	2008-05-30 13:20:39 UTC (rev 3361)
@@ -27,7 +27,8 @@
     <module>execution</module>
     <module>maven</module>
     <module>pool</module>
-    <module>xmlconfig</module>
+    <module>xmlconfig</module>
+    <module>security</module>
   </modules>
 
-</project>
\ No newline at end of file
+</project>

Property changes: trunk/util/modules/security/api


Name: svn:ignore
   + target

Added: trunk/util/modules/security/api/pom.xml (0 => 3361)


--- trunk/util/modules/security/api/pom.xml	                        (rev 0)
+++ trunk/util/modules/security/api/pom.xml	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+  - OW2 Util
+  - Copyright (C) 2008 Bull S.A.S.
+  - Contact: easybeans@xxxxxxx
+  -
+  - This library 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 library 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 library; if not, write to the Free Software
+  - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+  -
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+  - $Id$
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.ow2.util</groupId>
+    <artifactId>util-security</artifactId>
+    <version>1.0.8-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.ow2.util</groupId>
+  <artifactId>util-security-api</artifactId>
+  <packaging>jar</packaging>
+  <name>OW2 Util :: Security :: API</name>
+  <description>
+    API for security.
+  </description>
+</project>
Property changes on: trunk/util/modules/security/api/pom.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/ISecurityContext.java (0 => 3361)


--- trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/ISecurityContext.java	                        (rev 0)
+++ trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/ISecurityContext.java	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,67 @@
+/**
+ * EasyBeans
+ * Copyright (C) 2006 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.security.api;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+/**
+ * Interface used to describe operations on a security context.
+ * @author Florent Benoit
+ */
+public interface ISecurityContext {
+
+    /**
+     * Gets the caller's principal.
+     * @param runAsBean if true, the bean is a run-as bean.
+     * @return principal of the caller.
+     */
+    Principal getCallerPrincipal(final boolean runAsBean);
+
+    /**
+     * Enters in run-as mode with the given subject.<br>
+     * The previous subject is stored and will be restored when run-as mode will
+     * be ended.
+     * @param runAsSubject the subject to used in run-as mode.
+     * @return the previous subject.
+     */
+    Subject enterRunAs(final Subject runAsSubject);
+
+    /**
+     * Ends the run-as mode and then restore the context stored by container.
+     * @param oldSubject subject kept by container and restored.
+     */
+    void endsRunAs(final Subject oldSubject);
+
+    /**
+     * Gets the caller's roles.
+     * @param runAsBean if true, the bean is a run-as bean.
+     * @return array of roles of the caller.
+     */
+    Principal[] getCallerRoles(final boolean runAsBean);
+
+}
Property changes on: trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/ISecurityContext.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/ISecurityCurrent.java (0 => 3361)


--- trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/ISecurityCurrent.java	                        (rev 0)
+++ trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/ISecurityCurrent.java	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,55 @@
+/**
+ * EasyBeans
+ * Copyright (C) 2006 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.security.api;
+
+
+/**
+ * Interface that describes what a security current should provide, ie : a security context.
+ * @author Florent Benoit
+ */
+public interface ISecurityCurrent {
+
+    /**
+     * Gets the current context.
+     * @return SecurityContext return the Security context associated to the
+     *         current thread or the JVM
+     */
+    ISecurityContext getSecurityContext();
+
+    /**
+     * Associates the given security context to the current thread.
+     * @param securityContext Security context to associate to the current thread.
+     */
+    void setSecurityContext(final ISecurityContext securityContext);
+
+    /**
+     * Associates the given security context to all threads (JVM).
+     * @param securityContext Security context to associate to the JVM
+     */
+    void setGlobalSecurityContext(final ISecurityContext securityContext);
+
+
+}
Property changes on: trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/ISecurityCurrent.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/package.html (0 => 3361)


--- trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/package.html	                        (rev 0)
+++ trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/package.html	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+                      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<!--
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ - EasyBeans
+ - Copyright (C) 2006 Bull S.A.S.
+ - Contact: easybeans@xxxxxxx
+ -
+ - This library 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 any later version.
+ -
+ - This library 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 library; if not, write to the Free Software
+ - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ - USA
+ -
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ - $Id: package.html 2557 2008-03-04 18:12:05Z benoitf $
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ -->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+   <title>EJB 3.0 API</title>
+</head>
+<body>
+<p>Implementation of EJB 3.0 container API</p>
+</body>
+</html>
Property changes on: trunk/util/modules/security/api/src/main/java/org/ow2/util/security/api/package.html
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Property changes: trunk/util/modules/security/impl


Name: svn:ignore
   + target

Added: trunk/util/modules/security/impl/pom.xml (0 => 3361)


--- trunk/util/modules/security/impl/pom.xml	                        (rev 0)
+++ trunk/util/modules/security/impl/pom.xml	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+  - OW2 Util
+  - Copyright (C) 2008 Bull S.A.S.
+  - Contact: easybeans@xxxxxxx
+  -
+  - This library 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 library 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 library; if not, write to the Free Software
+  - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+  -
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+  - $Id$
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.ow2.util</groupId>
+    <artifactId>util-security</artifactId>
+    <version>1.0.8-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.ow2.util</groupId>
+  <artifactId>util-security-impl</artifactId>
+  <packaging>jar</packaging>
+  <name>OW2 Util :: Security :: IMPL</name>
+  <description>
+    Implementation of security.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.ow2.util</groupId>
+      <artifactId>util-security-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.ow2.util</groupId>
+      <artifactId>util-log</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+  </dependencies>
+</project>
Property changes on: trunk/util/modules/security/impl/pom.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/SecurityContext.java (0 => 3361)


--- trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/SecurityContext.java	                        (rev 0)
+++ trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/SecurityContext.java	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,255 @@
+/**
+ * EasyBeans
+ * Copyright (C) 2006 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.security.propagation.context;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.security.auth.Subject;
+
+import org.ow2.util.log.Log;
+import org.ow2.util.log.LogFactory;
+import org.ow2.util.security.api.ISecurityContext;
+import org.ow2.util.security.struct.JGroup;
+import org.ow2.util.security.struct.JPrincipal;
+
+/**
+ * Security Context that is exchanged and propagated from clients to beans.<br>
+ * This is also why it is a serializable object (as it has to be exchanged).<br>
+ * The security contains allow to get the current principal and the roles
+ * associated to this principal.<br>
+ * RunAs mode is managed by keeping the previous security context.
+ * @author Florent Benoit
+ */
+public final class SecurityContext implements ISecurityContext, Serializable {
+
+    /**
+     * UID for serialization.
+     */
+    private static final long serialVersionUID = 6612085599241360430L;
+
+    /**
+     * Logger.
+     */
+    private static Log logger = LogFactory.getLog(SecurityContext.class);
+
+    /**
+     * Anonymous user name.
+     */
+    private static final String ANONYMOUS_USER = "OW2/Anonymous";
+
+    /**
+     * Anonymous role.
+     */
+    private static final String ANONYMOUS_ROLE = "anonymous";
+
+    /**
+     * Anonymous subject (not authenticated).
+     */
+    public static final Subject ANONYMOUS_SUBJECT = buildAnonymousSubject();
+
+    /**
+     * Current subject (subject that has been authenticated).<br>
+     * By default, it is the anonymous subject.
+     */
+    private Subject subject = ANONYMOUS_SUBJECT;
+
+    /**
+     * caller subject in run-as mode<br>
+     * In run-as case, the run-as subject is set as the current subject, and the
+     * previous one is kept.<br>
+     * This previous subject is used to get the caller on the run-as bean.
+     */
+    private Subject callerInRunAsModeSubject = null;
+
+    /**
+     * Default private constructor.
+     */
+    public SecurityContext() {
+
+    }
+
+    /**
+     * Build a security context with the given subject.
+     * @param subject the given subject.
+     */
+    public SecurityContext(final Subject subject) {
+        this.subject = subject;
+    }
+
+    /**
+     * Enters in run-as mode with the given subject.<br>
+     * The previous subject is stored and will be restored when run-as mode will
+     * be ended.
+     * @param runAsSubject the subject to used in run-as mode.
+     * @return the previous subject.
+     */
+    public Subject enterRunAs(final Subject runAsSubject) {
+        // keep previous
+        callerInRunAsModeSubject = subject;
+
+        // update the new one
+        subject = runAsSubject;
+
+        // return previous.
+        return callerInRunAsModeSubject;
+    }
+
+    /**
+     * Ends the run-as mode and then restore the context stored by container.
+     * @param oldSubject subject kept by container and restored.
+     */
+    public void endsRunAs(final Subject oldSubject) {
+        subject = oldSubject;
+
+        // cancel caller of run-as subject (run-as mode has ended)
+        callerInRunAsModeSubject = null;
+    }
+
+    /**
+     * Gets the caller's principal.
+     * @param runAsBean if true, the bean is a run-as bean.
+     * @return principal of the caller.
+     */
+    public Principal getCallerPrincipal(final boolean runAsBean) {
+        Subject subject = null;
+
+        // in run-as mode, needs to return callerInRunAsModeSubject's principal.
+        if (runAsBean && callerInRunAsModeSubject != null) {
+            subject = callerInRunAsModeSubject;
+        } else {
+            subject = this.subject;
+        }
+
+        // Then, takes the first principal found. (which is not a role)
+        for (Principal principal : subject.getPrincipals(Principal.class)) {
+            if (!(principal instanceof Group)) {
+                return principal;
+            }
+        }
+
+        // Principal was not found, severe problem as it should be there. Maybe
+        // the subject was not built correctly.
+        logger.error("No principal found in the current subject. Authentication should have failed when populating subject");
+        throw new IllegalStateException(
+                "No principal found in the current subject. Authentication should have failed when populating subject");
+    }
+
+    /**
+     * Gets the caller's roles.
+     * @param runAsBean if true, the bean is a run-as bean.
+     * @return list of roles of the caller.
+     */
+    public List<? extends Principal> getCallerRolesList(final boolean runAsBean) {
+        Subject subject = null;
+
+        // in run-as mode, needs to return callerInRunAsModeSubject's principal.
+        if (runAsBean && callerInRunAsModeSubject != null) {
+            subject = callerInRunAsModeSubject;
+        } else {
+            subject = this.subject;
+        }
+
+        // Then, takes all the roles found in this principal.
+        for (Principal principal : subject.getPrincipals(Principal.class)) {
+            if (principal instanceof Group) {
+                return Collections.list(((Group) principal).members());
+            }
+        }
+
+        // Principal was not found, severe problem as it should be there. Maybe
+        // the subject was not built correctly.
+        logger.error("No role found in the current subject. Authentication should have failed when populating subject");
+        throw new IllegalStateException(
+                "No role found in the current subject. Authentication should have failed when populating subject");
+    }
+
+    /**
+     * Gets the caller's roles.
+     * @param runAsBean if true, the bean is a run-as bean.
+     * @return array of roles of the caller.
+     */
+    public Principal[] getCallerRoles(final boolean runAsBean) {
+        List<? extends Principal> callerRoles = getCallerRolesList(runAsBean);
+        return callerRoles.toArray(new Principal[callerRoles.size()]);
+    }
+
+    /**
+     * Build an anonymous subject when no user is authenticated.<br>
+     * This is required as getCallerPrincipal() should never return null.
+     * @return anonymous subject.
+     */
+    private static Subject buildAnonymousSubject() {
+        return buildSubject(ANONYMOUS_USER, new String[] {ANONYMOUS_ROLE});
+    }
+
+
+    /**
+     * Build a subject with the given user name and the list of roles.<br>
+     * @param userName given username
+     * @param roleArray given array of roles.
+     * @return built subject.
+     */
+    public static Subject buildSubject(final String userName, final String[] roleArray) {
+        List<String> roles = new ArrayList<String>();
+        if (roleArray != null) {
+            for (String role : roleArray) {
+                roles.add(role);
+            }
+        }
+        return buildSubject(userName, roles);
+    }
+
+    /**
+     * Build a subject with the given user name and the list of roles.<br>
+     * @param userName given username
+     * @param roleList given list of roles.
+     * @return built subject.
+     */
+    public static Subject buildSubject(final String userName, final List<String> roleList) {
+        Subject subject = new Subject();
+
+        // Add principal name
+        Principal principalName = new JPrincipal(userName);
+        subject.getPrincipals().add(principalName);
+
+        // Add roles for this principal
+        Group roles = new JGroup("roles");
+        if (roleList != null) {
+            for (String role : roleList) {
+                roles.addMember(new JPrincipal(role));
+            }
+        }
+        subject.getPrincipals().add(roles);
+
+        return subject;
+    }
+
+}
Property changes on: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/SecurityContext.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/SecurityCurrent.java (0 => 3361)


--- trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/SecurityCurrent.java	                        (rev 0)
+++ trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/SecurityCurrent.java	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,124 @@
+/**
+ * EasyBeans
+ * Copyright (C) 2006 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.security.propagation.context;
+
+import org.ow2.util.security.api.ISecurityContext;
+import org.ow2.util.security.api.ISecurityCurrent;
+
+/**
+ * Manages the current security context associated to the current thread.
+ * @author Florent Benoit
+ */
+public class SecurityCurrent implements ISecurityCurrent {
+
+    /**
+     * Inherited Local thread used to keep the security context.
+     */
+    private static InheritableThreadLocal<ISecurityContext> threadLocal;
+
+    /**
+     * Static Security Context that is applied on all threads (used for heavy
+     * client).
+     */
+    private static ISecurityContext globalContext = null;
+
+    /**
+     * Default security context.
+     */
+    private static final ISecurityContext DEFAULT_CTX = new SecurityContext();
+
+    /**
+     * Init the thread
+     */
+    static {
+        threadLocal = new InheritableThreadLocal<ISecurityContext>();
+        threadLocal.set(new SecurityContext());
+    }
+
+    /**
+     * Unique instance of this current object.
+     */
+    private static ISecurityCurrent unique = null;
+
+    /**
+     * Return the unique instance of this object.
+     * @return SecurityCurrent return the current
+     */
+    public static ISecurityCurrent getCurrent() {
+        if (unique == null) {
+            // Build a default implementation
+            unique = new SecurityCurrent();
+        }
+        return unique;
+    }
+
+    /**
+     * Associates the given security context to the current thread.
+     * @param securityContext Security context to associate to the current
+     *        thread.
+     */
+    public void setSecurityContext(final ISecurityContext securityContext) {
+        threadLocal.set(securityContext);
+    }
+
+    /**
+     * Associates the given security context to all threads (JVM).
+     * @param securityContext Security context to associate to the JVM
+     */
+    public void setGlobalSecurityContext(final ISecurityContext securityContext) {
+        globalContext = securityContext;
+    }
+
+    /**
+     * Gets the current context.
+     * @return SecurityContext return the Security context associated to the
+     *         current thread or the JVM
+     */
+    public ISecurityContext getSecurityContext() {
+        if (globalContext != null) {
+            return globalContext;
+        }
+        if (threadLocal.get() != null) {
+            return threadLocal.get();
+        }
+
+        // else, never null context.
+        return DEFAULT_CTX;
+    }
+
+
+    /**
+     * Sets the security current instance to use.
+     * @param current the given instance.
+     */
+    public static void setSecurityCurrent(final ISecurityCurrent current) {
+        if (unique != null) {
+            throw new IllegalStateException("Unable to set the unique instance. It is already set");
+        }
+        unique = current;
+    }
+
+}
Property changes on: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/SecurityCurrent.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/package.html (0 => 3361)


--- trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/package.html	                        (rev 0)
+++ trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/package.html	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+                      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<!--
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ - EasyBeans
+ - Copyright (C) 2006 Bull S.A.S.
+ - Contact: easybeans@xxxxxxx
+ -
+ - This library 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 any later version.
+ -
+ - This library 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 library; if not, write to the Free Software
+ - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ - USA
+ -
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ - $Id: package.html 2557 2008-03-04 18:12:05Z benoitf $
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ -->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+   <title>EJB 3.0</title>
+</head>
+<body>
+<p>Implementation of EJB 3.0 container</p>
+</body>
+</html>
Property changes on: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/propagation/context/package.html
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JGroup.java (0 => 3361)


--- trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JGroup.java	                        (rev 0)
+++ trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JGroup.java	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,159 @@
+/**
+ * EasyBeans
+ * Copyright (C) 2006 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.security.struct;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * This class represents all the roles of a principal (group of principals).
+ * These roles are added to the Subject
+ * @author Florent Benoit
+ */
+public class JGroup implements Group, Serializable {
+
+    /**
+     * UID for serialization.
+     */
+    private static final long serialVersionUID = 7035827226889396034L;
+
+    /**
+     * Name of this group.
+     */
+    private String groupName = null;
+
+    /**
+     * Members of this group.
+     */
+    private Vector<Principal> members = null;
+
+    /**
+     * Build a new group with the following name.
+     * @param groupName name of the group
+     */
+    public JGroup(final String groupName) {
+        this.groupName = groupName;
+        this.members = new Vector<Principal>();
+    }
+
+    /**
+     * Compares this principal to the specified object. Returns true if the
+     * object passed in matches the principal represented by the implementation
+     * of this interface.
+     * @param another principal to compare with.
+     * @return true if the principal passed in is the same as that encapsulated
+     *         by this principal, and false otherwise.
+     */
+    @Override
+    public boolean equals(final Object another) {
+        if (!(another instanceof Group)) {
+            return false;
+        }
+        // else
+        return groupName.equals(((Group) another).getName());
+    }
+
+    /**
+     * Returns a string representation of this principal.
+     * @return a string representation of this principal.
+     */
+    @Override
+    public String toString() {
+        return "Principal[" + groupName + "]";
+    }
+
+    /**
+     * Returns a hashcode for this principal.
+     * @return a hashcode for this principal.
+     */
+    @Override
+    public int hashCode() {
+        return groupName.hashCode();
+    }
+
+    /**
+     * Returns the name of this principal.
+     * @return the name of this principal.
+     */
+    public String getName() {
+        return groupName;
+    }
+
+    /**
+     * Adds the specified member to the group.
+     * @param user the principal to add to this group.
+     * @return true if the member was successfully added, false if the principal
+     *         was already a member.
+     */
+    public boolean addMember(final Principal user) {
+        if (isMember(user)) {
+            return false;
+        }
+        // else
+        members.add(user);
+        return true;
+    }
+
+    /**
+     * Removes the specified member from the group.
+     * @param user the principal to remove from this group.
+     * @return true if the principal was removed, or false if the principal was
+     *         not a member.
+     */
+    public boolean removeMember(final Principal user) {
+        if (!isMember(user)) {
+            return false;
+        }
+        // else
+        members.remove(user);
+        return true;
+    }
+
+    /**
+     * Returns true if the passed principal is a member of the group. This
+     * method does a recursive search, so if a principal belongs to a group
+     * which is a member of this group, true is returned.
+     * @param member the principal whose membership is to be checked.
+     * @return true if the principal is a member of this group, false otherwise.
+     */
+    public boolean isMember(final Principal member) {
+        return members.contains(member);
+    }
+
+    /**
+     * Returns an enumeration of the members in the group. The returned objects
+     * can be instances of either Principal or Group (which is a subclass of
+     * Principal).
+     * @return an enumeration of the group members.
+     */
+    public Enumeration<? extends Principal> members() {
+        return members.elements();
+    }
+
+}
Property changes on: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JGroup.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JPrincipal.java (0 => 3361)


--- trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JPrincipal.java	                        (rev 0)
+++ trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JPrincipal.java	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,98 @@
+/**
+ * EasyBeans
+ * Copyright (C) 2006 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.security.struct;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+/**
+ * Implementation of Principal class.
+ * @author Florent Benoit
+ */
+public class JPrincipal implements Principal, Serializable {
+
+    /**
+     * UID for serialization.
+     */
+    private static final long serialVersionUID = 5864848835776239991L;
+
+    /**
+     * Name of this principal.
+     */
+    private String name = null;
+
+    /**
+     * Constructor.
+     * @param name the name of this principal
+     */
+    public JPrincipal(final String name) {
+        this.name = name;
+    }
+
+    /**
+     * Compares this principal to the specified object. Returns true if the
+     * object passed in matches the principal represented by the implementation
+     * of this interface.
+     * @param another principal to compare with.
+     * @return true if the principal passed in is the same as that encapsulated
+     *         by this principal, and false otherwise.
+     */
+    @Override
+    public boolean equals(final Object another) {
+        if (!(another instanceof Principal)) {
+            return false;
+        }
+        // else
+        return name.equals(((Principal) another).getName());
+    }
+
+    /**
+     * Returns a string representation of this principal.
+     * @return a string representation of this principal.
+     */
+    @Override
+    public String toString() {
+        return "Principal[" + name + "]";
+    }
+
+    /**
+     * Returns a hashcode for this principal.
+     * @return a hashcode for this principal.
+     */
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    /**
+     * Returns the name of this principal.
+     * @return the name of this principal.
+     */
+    public String getName() {
+        return name;
+    }
+
+}
Property changes on: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JPrincipal.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JRole.java (0 => 3361)


--- trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JRole.java	                        (rev 0)
+++ trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JRole.java	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,49 @@
+/**
+ * EasyBeans
+ * Copyright (C) 2006 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.security.struct;
+
+/**
+ * This class defines a Role.
+ * It use the Principal class in order to add roles to
+ * the java.security.acl.Group class
+ * @author Florent Benoit
+ */
+public class JRole extends JPrincipal {
+
+    /**
+     * UID for serialization.
+     */
+    private static final long serialVersionUID = 7698441696763650989L;
+
+    /**
+     * Constructor (use the super constructor).
+     * @param roleName the name of this role
+     */
+    public JRole(final String roleName) {
+        super(roleName);
+    }
+
+}
Property changes on: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/JRole.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Added: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/package.html (0 => 3361)


--- trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/package.html	                        (rev 0)
+++ trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/package.html	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+                      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<!--
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ - EasyBeans
+ - Copyright (C) 2006 Bull S.A.S.
+ - Contact: easybeans@xxxxxxx
+ -
+ - This library 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 any later version.
+ -
+ - This library 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 library; if not, write to the Free Software
+ - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ - USA
+ -
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ - $Id: package.html 2557 2008-03-04 18:12:05Z benoitf $
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ -->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+   <title>EJB 3.0</title>
+</head>
+<body>
+<p>Implementation of EJB 3.0 container</p>
+</body>
+</html>
Property changes on: trunk/util/modules/security/impl/src/main/java/org/ow2/util/security/struct/package.html
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/util/modules/security/pom.xml (0 => 3361)


--- trunk/util/modules/security/pom.xml	                        (rev 0)
+++ trunk/util/modules/security/pom.xml	2008-05-30 13:20:39 UTC (rev 3361)
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+  - OW2 Util
+  - Copyright (C) 2008 Bull S.A.S.
+  - Contact: easybeans@xxxxxxx
+  -
+  - This library 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 library 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 library; if not, write to the Free Software
+  - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+  -
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+  - $Id$
+  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.ow2.util</groupId>
+    <artifactId>util-modules</artifactId>
+    <version>1.0.8-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.ow2.util</groupId>
+  <artifactId>util-security</artifactId>
+  <packaging>pom</packaging>
+  <name>OW2 Util :: Security</name>
+  <description>Security</description>
+
+  <modules>
+    <module>api</module>
+    <module>impl</module>
+  </modules>
+
+ </project>
Property changes on: trunk/util/modules/security/pom.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id


<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.