You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2012/04/17 11:45:14 UTC
svn commit: r1327018 - in
/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user:
AuthorizableImpl.java GroupImpl.java ImpersonationImpl.java UserImpl.java
Author: angela
Date: Tue Apr 17 09:45:13 2012
New Revision: 1327018
URL: http://svn.apache.org/viewvc?rev=1327018&view=rev
Log:
OAK-50 - Implement User Management (WIP)
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java?rev=1327018&r1=1327017&r2=1327018&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java Tue Apr 17 09:45:13 2012
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.jcr.se
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.oak.jcr.NodeImpl;
import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
@@ -85,6 +84,9 @@ abstract class AuthorizableImpl implemen
return null;
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#remove()
+ */
@Override
public void remove() throws RepositoryException {
// don't allow for removal of the administrator even if the executing
@@ -97,11 +99,17 @@ abstract class AuthorizableImpl implemen
node.remove();
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#getPropertyNames()
+ */
@Override
public Iterator<String> getPropertyNames() throws RepositoryException {
return getPropertyNames(".");
}
+ /**
+ * @see Authorizable#getPropertyNames(String)
+ */
@Override
public Iterator<String> getPropertyNames(String relPath) throws RepositoryException {
Node n = node.getNode(relPath);
@@ -119,11 +127,17 @@ abstract class AuthorizableImpl implemen
}
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#hasProperty(String)
+ */
@Override
public boolean hasProperty(String relPath) throws RepositoryException {
return node.hasProperty(relPath) && isAuthorizableProperty(node.getProperty(relPath), true);
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#getProperty(String)
+ */
@Override
public Value[] getProperty(String relPath) throws RepositoryException {
Value[] values = null;
@@ -140,6 +154,9 @@ abstract class AuthorizableImpl implemen
return values;
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#setProperty(String, javax.jcr.Value)
+ */
@Override
public void setProperty(String relPath, Value value) throws RepositoryException {
String name = Text.getName(relPath);
@@ -158,6 +175,9 @@ abstract class AuthorizableImpl implemen
n.setProperty(name, value);
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#setProperty(String, javax.jcr.Value[])
+ */
@Override
public void setProperty(String relPath, Value[] values) throws RepositoryException {
String name = Text.getName(relPath);
@@ -176,6 +196,9 @@ abstract class AuthorizableImpl implemen
n.setProperty(name, values);
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#removeProperty(String)
+ */
@Override
public boolean removeProperty(String relPath) throws RepositoryException {
String name = Text.getName(relPath);
@@ -191,12 +214,18 @@ abstract class AuthorizableImpl implemen
return false;
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#getPath()
+ */
@Override
public String getPath() throws RepositoryException {
return node.getPath();
}
//-------------------------------------------------------------< Object >---
+ /**
+ * @see Object#hashCode()
+ */
@Override
public int hashCode() {
if (hashCode == 0) {
@@ -213,6 +242,9 @@ abstract class AuthorizableImpl implemen
return hashCode;
}
+ /**
+ * @see Object#equals(Object)
+ */
@Override
public boolean equals(Object obj) {
if (obj instanceof AuthorizableImpl) {
@@ -226,6 +258,9 @@ abstract class AuthorizableImpl implemen
return false;
}
+ /**
+ * @see Object#toString()
+ */
@Override
public String toString() {
try {
@@ -238,16 +273,23 @@ abstract class AuthorizableImpl implemen
//--------------------------------------------------------------------------
/**
- * @return node The node associated with this authorizable instance.
+ * @return The node associated with this authorizable instance.
*/
NodeImpl getNode() {
return node;
}
+ /**
+ * @return The user manager associated with this authorizable.
+ */
UserManagerImpl getUserManager() {
return userManager;
}
+ /**
+ * @return The principal name of this authorizable.
+ * @throws RepositoryException If no principal name can be retrieved.
+ */
String getPrincipalName() throws RepositoryException {
String principalName;
if (node.hasProperty(REP_PRINCIPAL_NAME)) {
@@ -293,18 +335,37 @@ abstract class AuthorizableImpl implemen
}
/**
+ * Retrieves the node at {@code relPath} relative to node associated with
+ * this authorizable. If no such node exist it and any missing intermediate
+ * nodes are created.
*
* @param relPath A relative path.
* @return The corresponding node.
- * @throws RepositoryException If an error occurs.
+ * @throws RepositoryException If an error occurs or if {@code relPath} refers
+ * to a node that is outside of the scope of this authorizable.
*/
private Node getOrCreateTargetNode(String relPath) throws RepositoryException {
Node n;
if (relPath != null) {
- n = JcrUtils.getOrCreateByPath(node, relPath, false, null, null, false);
- if (!Text.isDescendantOrEqual(node.getPath(), n.getPath())) {
- node.refresh(false);
- throw new RepositoryException("Relative path " + relPath + " outside of scope of " + this);
+ String userPath = node.getPath();
+ if (node.hasNode(relPath)) {
+ n = node.getNode(relPath);
+ if (!Text.isDescendantOrEqual(userPath, n.getPath())) {
+ throw new RepositoryException("Relative path " + relPath + " outside of scope of " + this);
+ }
+ } else {
+ n = node;
+ for (String segment : Text.explode(relPath, '/')) {
+ if (n.hasNode(segment)) {
+ n = n.getNode(segment);
+ } else {
+ if (Text.isDescendantOrEqual(userPath, n.getPath())) {
+ n = n.addNode(segment);
+ } else {
+ throw new RepositoryException("Relative path " + relPath + " outside of scope of " + this);
+ }
+ }
+ }
}
} else {
n = node;
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java?rev=1327018&r1=1327017&r2=1327018&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java Tue Apr 17 09:45:13 2012
@@ -30,7 +30,7 @@ import java.util.Iterator;
/**
* GroupImpl...
*/
-public class GroupImpl extends AuthorizableImpl implements Group {
+class GroupImpl extends AuthorizableImpl implements Group {
/**
* logger instance
@@ -42,11 +42,17 @@ public class GroupImpl extends Authoriza
}
//-------------------------------------------------------< Authorizable >---
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#isGroup()
+ */
@Override
public boolean isGroup() {
return true;
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#getPrincipal()
+ */
@Override
public Principal getPrincipal() throws RepositoryException {
return new GroupPrincipal(getPrincipalName(), getNode().getPath());
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java?rev=1327018&r1=1327017&r2=1327018&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java Tue Apr 17 09:45:13 2012
@@ -39,7 +39,7 @@ import java.util.Set;
/**
* ImpersonationImpl...
*/
-public class ImpersonationImpl implements Impersonation {
+class ImpersonationImpl implements Impersonation {
/**
* logger instance
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java?rev=1327018&r1=1327017&r2=1327018&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java Tue Apr 17 09:45:13 2012
@@ -25,12 +25,13 @@ import org.slf4j.LoggerFactory;
import javax.jcr.Credentials;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
import java.security.Principal;
/**
* UserImpl...
*/
-public class UserImpl extends AuthorizableImpl implements User {
+class UserImpl extends AuthorizableImpl implements User {
/**
* logger instance
@@ -42,11 +43,17 @@ public class UserImpl extends Authorizab
}
//-------------------------------------------------------< Authorizable >---
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#isGroup()
+ */
@Override
public boolean isGroup() {
return false;
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.Authorizable#getPrincipal()
+ */
@Override
public Principal getPrincipal() throws RepositoryException {
String principalName = getPrincipalName();
@@ -55,6 +62,9 @@ public class UserImpl extends Authorizab
}
//---------------------------------------------------------------< User >---
+ /**
+ * @see org.apache.jackrabbit.api.security.user.User#isAdmin()
+ */
@Override
public boolean isAdmin() {
try {
@@ -66,16 +76,27 @@ public class UserImpl extends Authorizab
}
}
+ /**
+ * Always throws {@code UnsupportedRepositoryOperationException}
+ *
+ * @see org.apache.jackrabbit.api.security.user.User#getCredentials()
+ */
@Override
public Credentials getCredentials() throws RepositoryException {
- throw new UnsupportedOperationException("Not implemented.");
+ throw new UnsupportedRepositoryOperationException("Not implemented.");
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.User#getImpersonation()
+ */
@Override
public Impersonation getImpersonation() throws RepositoryException {
return new ImpersonationImpl(this);
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.User#changePassword(String)
+ */
@Override
public void changePassword(String password) throws RepositoryException {
UserManagerImpl userManager = getUserManager();
@@ -83,6 +104,9 @@ public class UserImpl extends Authorizab
userManager.setPassword(getNode(), password, true);
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.User#changePassword(String, String)
+ */
@Override
public void changePassword(String password, String oldPassword) throws RepositoryException {
// make sure the old password matches.
@@ -96,6 +120,9 @@ public class UserImpl extends Authorizab
changePassword(password);
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.User#disable(String)
+ */
@Override
public void disable(String reason) throws RepositoryException {
if (isAdmin()) {
@@ -111,11 +138,17 @@ public class UserImpl extends Authorizab
}
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.User#isDisabled()
+ */
@Override
public boolean isDisabled() throws RepositoryException {
return getNode().hasProperty(REP_DISABLED);
}
+ /**
+ * @see org.apache.jackrabbit.api.security.user.User#getDisabledReason()
+ */
@Override
public String getDisabledReason() throws RepositoryException {
if (isDisabled()) {