You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2015/04/10 12:50:47 UTC
svn commit: r1672610 - in /jackrabbit/trunk:
jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/
jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/...
Author: angela
Date: Fri Apr 10 10:50:46 2015
New Revision: 1672610
URL: http://svn.apache.org/r1672610
Log:
JCR-3836 : Allow to get an Authorizable of a given type
JCR-3837 : Add AuthorizableTypeException in user security API package
Added:
jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/AuthorizableTypeException.java
Modified:
jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java
jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/package-info.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerTest.java
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java
Added: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/AuthorizableTypeException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/AuthorizableTypeException.java?rev=1672610&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/AuthorizableTypeException.java (added)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/AuthorizableTypeException.java Fri Apr 10 10:50:46 2015
@@ -0,0 +1,29 @@
+/*
+ * 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.jackrabbit.api.security.user;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * The {@code AuthorizableTypeException} signals an {@link Authorizable} type mismatch.
+ */
+public class AuthorizableTypeException extends RepositoryException {
+
+ public AuthorizableTypeException(String msg) {
+ super(msg);
+ }
+}
Modified: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java?rev=1672610&r1=1672609&r2=1672610&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java (original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java Fri Apr 10 10:50:46 2015
@@ -23,6 +23,8 @@ import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.UnsupportedRepositoryOperationException;
+import aQute.bnd.annotation.ProviderType;
+
/**
* The <code>UserManager</code> provides access to and means to maintain
* {@link Authorizable authorizable objects} i.e. {@link User users} and
@@ -37,6 +39,7 @@ import javax.jcr.UnsupportedRepositoryOp
* {@link Session#save()} operation; callers should be prepared to repeat them
* in case this happens.
*/
+@ProviderType
public interface UserManager {
/**
@@ -68,6 +71,18 @@ public interface UserManager {
Authorizable getAuthorizable(String id) throws RepositoryException;
/**
+ * Get the Authorizable of a specific type by its id.
+ *
+ * @param id the user or group id.
+ * @param authorizableClass the class of the type of Authorizable required; must not be <code>null</code>.
+ * @param <T> the required Authorizable type.
+ * @return Authorizable or <code>null</code>, if not present.
+ * @throws AuthorizableTypeException If an authorizable exists but is not of the requested type.
+ * @throws RepositoryException If an error occurs
+ */
+ <T extends Authorizable> T getAuthorizable(String id, Class<T> authorizableClass) throws AuthorizableTypeException, RepositoryException;
+
+ /**
* Get the Authorizable by its Principal.
*
* @param principal The principal of the authorizable to retrieve.
Modified: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/package-info.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/package-info.java?rev=1672610&r1=1672609&r2=1672610&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/package-info.java (original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/package-info.java Fri Apr 10 10:50:46 2015
@@ -18,5 +18,5 @@
/**
* Jackrabbit extensions for user management.
*/
-@aQute.bnd.annotation.Version("2.3.2")
+@aQute.bnd.annotation.Version("2.4.0")
package org.apache.jackrabbit.api.security.user;
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=1672610&r1=1672609&r2=1672610&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 Fri Apr 10 10:50:46 2015
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.core.secur
import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.AuthorizableExistsException;
+import org.apache.jackrabbit.api.security.user.AuthorizableTypeException;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.Query;
import org.apache.jackrabbit.api.security.user.User;
@@ -451,6 +452,22 @@ public class UserManagerImpl extends Pro
}
/**
+ * @see UserManager#getAuthorizable(String, Class)
+ */
+ public <T extends Authorizable> T getAuthorizable(String id, Class<T> authorizableClass) throws AuthorizableTypeException, RepositoryException {
+ Authorizable authorizable = getAuthorizable(id);
+ if (authorizable == null) {
+ return null;
+ } else {
+ if (authorizableClass != null && authorizableClass.isInstance(authorizable)) {
+ return authorizableClass.cast(authorizable);
+ } else {
+ throw new AuthorizableTypeException("Invalid authorizable type for authorizable '" + id + "'");
+ }
+ }
+ }
+
+ /**
* @see UserManager#getAuthorizable(Principal)
*/
public Authorizable getAuthorizable(Principal principal) throws RepositoryException {
Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerTest.java?rev=1672610&r1=1672609&r2=1672610&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerTest.java Fri Apr 10 10:50:46 2015
@@ -70,4 +70,60 @@ public class UserManagerTest extends Abs
throw new NotExecutableException();
}
}
+
+
+ public void testGetAuthorizableByIdAndType() throws NotExecutableException, RepositoryException {
+ for (Principal principal : getPrincipalSetFromSession(superuser)) {
+ Principal p = principal;
+ Authorizable a = userMgr.getAuthorizable(p);
+ if (a != null) {
+ Authorizable authorizable = userMgr.getAuthorizable(a.getID(), a.getClass());
+ assertEquals("Equal ID expected", a.getID(), authorizable.getID());
+
+ authorizable = userMgr.getAuthorizable(a.getID(), Authorizable.class);
+ assertEquals("Equal ID expected", a.getID(), authorizable.getID());
+ }
+ }
+ }
+
+ public void testGetAuthorizableByIdAndWrongType() throws NotExecutableException, RepositoryException {
+ for (Principal principal : getPrincipalSetFromSession(superuser)) {
+ Principal p = principal;
+ Authorizable auth = userMgr.getAuthorizable(p);
+ if (auth != null) {
+ Class<? extends Authorizable> otherType = auth.isGroup() ? User.class : Group.class;
+ try {
+ userMgr.getAuthorizable(auth.getID(), otherType);
+ fail("Wrong Authorizable type is not detected.");
+ } catch (AuthorizableTypeException e) {
+ // success
+ }
+ }
+ }
+ }
+
+ public void testGetNonExistingAuthorizableByIdAndType() throws NotExecutableException, RepositoryException {
+ Authorizable auth = userMgr.getAuthorizable("nonExistingAuthorizable", User.class);
+ assertNull(auth);
+
+ auth = userMgr.getAuthorizable("nonExistingAuthorizable", Authorizable.class);
+ assertNull(auth);
+ }
+
+ public void testGetAuthorizableByNullType() throws Exception {
+ String uid = superuser.getUserID();
+ Authorizable auth = userMgr.getAuthorizable(uid);
+ if (auth != null) {
+ try {
+ userMgr.getAuthorizable(uid, null);
+ fail("Null Authorizable type is not detected.");
+ } catch (AuthorizableTypeException e) {
+ // success
+ }
+ }
+ }
+
+ public void testGetNonExistingAuthorizableByNullType() throws Exception {
+ assertNull(userMgr.getAuthorizable("nonExistingAuthorizable", null));
+ }
}
\ No newline at end of file
Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java?rev=1672610&r1=1672609&r2=1672610&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java Fri Apr 10 10:50:46 2015
@@ -1593,6 +1593,10 @@ public class UserImporterTest extends Ab
return null;
}
+ public <T extends Authorizable> T getAuthorizable(String id, Class<T> authorizableClass) throws RepositoryException {
+ return null;
+ }
+
public Authorizable getAuthorizable(Principal principal) throws RepositoryException {
return null;
}