Author: angela
Date: Tue Aug 2 10:24:04 2011
New Revision: 1153089
URL: http://svn.apache.org/viewvc?rev=1153089&view=rev
Log:
JCR-3037 : Add getPath method to Authorizable interface
Modified:
jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Authorizable.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserPerWorkspaceUserManager.java
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/AuthorizableImplTest.java
Modified: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Authorizable.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Authorizable.java?rev=1153089&r1=1153088&r2=1153089&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Authorizable.java
(original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Authorizable.java
Tue Aug 2 10:24:04 2011
@@ -20,6 +20,7 @@ import java.security.Principal;
import java.util.Iterator;
import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
/**
@@ -121,6 +122,7 @@ public interface Authorizable {
* Returns the names of properties present with <code>this</code>
* Authorizable at the specified relative path.
*
+ * @param relPath A relative path.
* @return names of properties.
* @throws RepositoryException If an error occurs.
* @see #getProperty(String)
@@ -176,4 +178,23 @@ public interface Authorizable {
* @throws RepositoryException If an error occurs.
*/
boolean removeProperty(String relPath) throws RepositoryException;
+
+ /**
+ * Returns a JCR path if this authorizable instance is associated with an
+ * item that can be accessed by the editing <code>Session</code>.<p/>
+ * Throws <code>UnsupportedRepositoryOperationException</code> if this
+ * method is not supported or if there is no item associated with this
+ * authorizable that is accessible by the editing <code>Session</code>.<p/>
+ * Throws <code>RepositoryException</code> if another error occurs while
+ * retrieving the path.
+ *
+ * @return the path of the {@link javax.jcr.Item} that corresponds to this
+ * <code>Authorizable</code>.
+ * @throws UnsupportedRepositoryOperationException If this method is not
+ * supported or if there exists no accessible item associated with this
+ * <code>Authorizable</code> instance.
+ * @throws RepositoryException If an error occurs while retrieving the
+ * <code>Item</code> path.
+ */
+ String getPath() throws UnsupportedRepositoryOperationException, RepositoryException;
}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java?rev=1153089&r1=1153088&r2=1153089&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
Tue Aug 2 10:24:04 2011
@@ -36,6 +36,7 @@ import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.PropertyDefinition;
@@ -63,7 +64,6 @@ abstract class AuthorizableImpl implemen
* @param userManager UserManager that created this Authorizable.
* @throws IllegalArgumentException if the given node isn't of node type
* {@link #NT_REP_AUTHORIZABLE}.
- * @throws RepositoryException If an error occurs.
*/
protected AuthorizableImpl(NodeImpl node, UserManagerImpl userManager) {
this.node = node;
@@ -271,6 +271,13 @@ abstract class AuthorizableImpl implemen
s.save();
}
}
+
+ /**
+ * @see Authorizable#getPath()
+ */
+ public String getPath() throws UnsupportedRepositoryOperationException, RepositoryException
{
+ return userManager.getPath(node);
+ }
//-------------------------------------------------------------< Object >---
@Override
@@ -441,9 +448,9 @@ abstract class AuthorizableImpl implemen
/**
*
- * @param relPath
- * @return
- * @throws RepositoryException
+ * @param relPath A relative path.
+ * @return The corresponding node.
+ * @throws RepositoryException If an error occurs.
*/
private Node getOrCreateTargetNode(String relPath) throws RepositoryException {
Node n;
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java?rev=1153089&r1=1153088&r2=1153089&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
Tue Aug 2 10:24:04 2011
@@ -159,7 +159,7 @@ public class UserManagerImpl extends Pro
public static final String PARAM_GROUPS_PATH = "groupsPath";
/**
- * @deprecate Use {@link #PARAM_COMPATIBLE_JR16} instead.
+ * @deprecated Use {@link #PARAM_COMPATIBLE_JR16} instead.
*/
public static final String PARAM_COMPATIBILE_JR16 = "compatibleJR16";
@@ -263,6 +263,7 @@ public class UserManagerImpl extends Pro
*
* @param session The editing/reading session.
* @param adminId The user ID of the administrator.
+ * @throws javax.jcr.RepositoryException If an error occurs.
*/
public UserManagerImpl(SessionImpl session, String adminId) throws RepositoryException
{
this(session, adminId, null, null);
@@ -274,6 +275,7 @@ public class UserManagerImpl extends Pro
* @param session The editing/reading session.
* @param adminId The user ID of the administrator.
* @param config The configuration parameters.
+ * @throws javax.jcr.RepositoryException If an error occurs.
*/
public UserManagerImpl(SessionImpl session, String adminId, Properties config) throws
RepositoryException {
this(session, adminId, config, null);
@@ -299,7 +301,7 @@ public class UserManagerImpl extends Pro
* @param adminId The user ID of the administrator.
* @param config The configuration parameters.
* @param mCache Shared membership cache.
- * @throws javax.jcr.RepositoryException
+ * @throws javax.jcr.RepositoryException If an error occurs.
*/
public UserManagerImpl(SessionImpl session, String adminId, Properties config,
MembershipCache mCache) throws RepositoryException {
@@ -372,7 +374,7 @@ public class UserManagerImpl extends Pro
* If 0 (default), {@link UserConstants#P_MEMBERS} is used to record group
* memberships.
*
- * @return
+ * @return The maximum number of group members before splitting up the structure.
*/
public int getGroupMembershipSplitSize() {
return groupMembershipSplitSize;
@@ -737,6 +739,14 @@ public class UserManagerImpl extends Pro
}
/**
+ * Always throws <code>UnsupportedRepositoryOperationException</code> since
+ * the node may reside in a different workspace than the editing <code>Session</code>.
+ */
+ String getPath(Node authorizableNode) throws UnsupportedRepositoryOperationException,
RepositoryException {
+ throw new UnsupportedRepositoryOperationException();
+ }
+
+ /**
* Test if a user or group exists that has the given principals name as ID,
* which might happen if userID != principal-name.
* In this case: generate another ID for the group to be created.
@@ -941,8 +951,8 @@ public class UserManagerImpl extends Pro
/**
* Throws <code>IllegalArgumentException</code> if the specified principal
* is <code>null</code> or if it's name is <code>null</code>
or empty string.
- * @param principal
- * @param isGroup
+ * @param principal The principal to be validated.
+ * @param isGroup Flag indicating if the principal represents a group.
*/
private static void checkValidPrincipal(Principal principal, boolean isGroup) {
if (principal == null || principal.getName() == null || "".equals(principal.getName()))
{
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserPerWorkspaceUserManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserPerWorkspaceUserManager.java?rev=1153089&r1=1153088&r2=1153089&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserPerWorkspaceUserManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserPerWorkspaceUserManager.java
Tue Aug 2 10:24:04 2011
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.core.secur
import org.apache.jackrabbit.core.SessionImpl;
+import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.UnsupportedRepositoryOperationException;
@@ -91,4 +92,16 @@ public class UserPerWorkspaceUserManager
public void autoSave(boolean enable) throws UnsupportedRepositoryOperationException,
RepositoryException {
autoSave = enable;
}
+
+ //--------------------------------------------------------------------------
+ /**
+ * Returns the path of the specified authorizableNode.
+ *
+ * @param authorizableNode Node associated with an authorizable.
+ * @return The path of the node.
+ * @throws RepositoryException If an error occurs while retrieving the path.
+ */
+ String getPath(Node authorizableNode) throws RepositoryException {
+ return authorizableNode.getPath();
+ }
}
\ No newline at end of file
Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java?rev=1153089&r1=1153088&r2=1153089&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
Tue Aug 2 10:24:04 2011
@@ -193,6 +193,10 @@ public class SimpleCredentialsAuthentica
public boolean removeProperty(String name) throws RepositoryException {
return false;
}
+
+ public String getPath() {
+ return null;
+ }
}
}
Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/AuthorizableImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/AuthorizableImplTest.java?rev=1153089&r1=1153088&r2=1153089&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/AuthorizableImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/AuthorizableImplTest.java
Tue Aug 2 10:24:04 2011
@@ -31,6 +31,7 @@ import org.apache.jackrabbit.value.Strin
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.PropertyType;
import javax.jcr.nodetype.ConstraintViolationException;
@@ -374,9 +375,23 @@ public class AuthorizableImplTest extend
public boolean removeProperty(String name) throws RepositoryException {
return user.removeProperty(name);
}
+
+ public String getPath() throws UnsupportedRepositoryOperationException, RepositoryException
{
+ return user.getPath();
+ }
};
assertFalse(user.equals(user3));
assertTrue(s.add(user3));
}
+
+ public void testGetPath() throws Exception {
+ AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
+ try {
+ assertEquals(user.getNode().getPath(), user.getPath());
+ } catch (UnsupportedRepositoryOperationException e) {
+ // ok.
+ }
+
+ }
}
|