Author: mir
Date: Tue Feb 9 17:35:59 2010
New Revision: 908125
URL: http://svn.apache.org/viewvc?rev=908125&view=rev
Log:
CLEREZZA-107: implemented methods to return user as resource
Modified:
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/pom.xml
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManager.java
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManagerImpl.java
Modified:
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/pom.xml?rev=908125&r1=908124&r2=908125&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/pom.xml
(original)
+++
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/pom.xml
Tue Feb 9 17:35:59 2010
@@ -24,7 +24,7 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
@@ -41,6 +41,10 @@
<groupId>org.apache.clerezza</groupId>
<artifactId>org.apache.clerezza.platform.config</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+
<artifactId>org.apache.clerezza.platform.graphprovider.content</artifactId>
+ </dependency>
</dependencies>
<build>
<plugins>
Modified:
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManager.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManager.java?rev=908125&r1=908124&r2=908125&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManager.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManager.java
Tue Feb 9 17:35:59 2010
@@ -25,14 +25,14 @@
import org.apache.clerezza.rdf.utils.GraphNode;
/**
- * An implementation of this interface provides methods to manage data about
+ * An implementation of this interface provides methods to manage data about
* users and their roles.
* Data managed are needed for authentication and for setting permissions.
- * Those data include user names, email addresses, passwords, roles,
permissions,
+ * Those data include user names, email addresses, passwords, roles,
permissions,
* etc.
* A user is uniquely identified by a user name.
* Each user has an email address and an email address can only belong to a
user.
- *
+ *
* @author hasan, tio
*/
public interface UserManager {
@@ -54,29 +54,29 @@
public boolean roleExists(String title);
/**
- *
+ *
* @param title
* @return NonLiteral which is either a BNode or a UriRef
*/
public NonLiteral getRoleByTitle(String title);
/**
- *
+ *
* @return Iterator defining all roles
*/
public Iterator<NonLiteral> getRoles();
-
+
/**
- *
- * @param user
+ *
+ * @param user
* the user is either a BNode or a UriRef
- *
+ *
* @return Iterator defining all the Roles the specified user owns
*/
public Iterator<NonLiteral> getRolesOfUser(NonLiteral user);
/**
- *
+ *
* @param title
* the title of the role to be deleted, may not be null
*/
@@ -171,9 +171,45 @@
* @param name specifies the username of the user
* @return NonLiteral which is either a BNode or a UriRef
*/
+ @Deprecated
public NonLiteral getUserByName(String name);
/**
+ * Returns the user with the specified name in an (editable) MGraph
+ * (i.e. a SimpleGraph but this is implementation specific) with the
context
+ * of the user node, editing the graphnode('s Mgaph) doesn't cause any
+ * changes elsewhere. Returns null if the user does not exist.
+ * The caller of this method needs the permission to read the system
graph,
+ * otherwise a AccessControlException will be thrown.
+ *
+ * @param name The name of the user
+ * @return
+ */
+ public GraphNode getUserGraphNodeCopy(String name);
+
+ /**
+ * Returns the <code>GraphNode</code> pointing to the user with the
+ * specified name in the system graph. Returns null if the user does not
+ * exist.
+ *
+ * @param name The name of the user
+ * @return
+ */
+ public GraphNode getUserInSystemGraph(String name);
+
+ /**
+ * Returns the <code>GraphNode</code> pointing to the user with the
+ * specified name in the content graph. If the user does not exist in
the
+ * content graph, but in the system graph, then the it is created with
the
+ * PLATFORM.userName property copied from the system graph. Returns
null if
+ * the user does not exist.
+ *
+ * @param name The name of the user
+ * @return
+ */
+ public GraphNode getUserInContentGraph(String name);
+
+ /**
* Returns all users.
*
* @return Iterator defining all users.
Modified:
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManagerImpl.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManagerImpl.java?rev=908125&r1=908124&r2=908125&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManagerImpl.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-107/org.apache.clerezza.platform.usermanager/src/main/java/org/apache/clerezza/platform/usermanager/UserManagerImpl.java
Tue Feb 9 17:35:59 2010
@@ -32,6 +32,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.clerezza.platform.config.SystemConfig;
+import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
import org.apache.clerezza.rdf.core.BNode;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.NonLiteral;
@@ -62,6 +63,9 @@
@Reference(target=SystemConfig.SYSTEM_GRAPH_FILTER)
private MGraph systemGraph;
+ @Reference
+ private ContentGraphProvider cgProvider;
+
private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
@@ -555,4 +559,57 @@
});
}
+ @Override
+ public GraphNode getUserInSystemGraph(final String name) {
+ return AccessController.doPrivileged(new
PrivilegedAction<GraphNode>() {
+
+ @Override
+ public GraphNode run() {
+ NonLiteral user = getUserByName(name);
+ if (user != null) {
+ return new GraphNode(user, systemGraph);
+ } else {
+ return null;
+ }
+ }
+ });
+ }
+
+ @Override
+ public GraphNode getUserInContentGraph(final String name) {
+ final MGraph contentGraph = cgProvider.getContentGraph();
+ Iterator<Triple> triples = contentGraph.filter(null,
PLATFORM.userName,
+ new PlainLiteralImpl(name));
+ GraphNode resultNode = null;
+ if (triples.hasNext()) {
+ resultNode = new GraphNode(triples.next().getSubject(),
contentGraph);
+ } else {
+ NonLiteral user = AccessController.doPrivileged(
+ new PrivilegedAction<NonLiteral>() {
+
+ @Override
+ public NonLiteral run() {
+ return
getUserByName(name);
+ }
+ });
+ if (user != null) {
+ resultNode = new GraphNode(new BNode(),
contentGraph);
+ resultNode.addProperty(PLATFORM.userName,
+ new PlainLiteralImpl(name));
+ }
+ }
+ return resultNode;
+ }
+
+ @Override
+ public GraphNode getUserGraphNodeCopy(String name) {
+ GraphNode userNodeInSystemGraph = new
GraphNode(getUserByName(name), systemGraph);
+ if (userNodeInSystemGraph == null) {
+ return null;
+ }
+ MGraph copiedUserContext = new
SimpleMGraph(userNodeInSystemGraph.
+ getNodeContext());
+ return new GraphNode(userNodeInSystemGraph.getNode(),
copiedUserContext);
+ }
+
}