Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D736110194 for ; Wed, 8 Jan 2014 14:19:27 +0000 (UTC) Received: (qmail 75199 invoked by uid 500); 8 Jan 2014 14:02:11 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 75127 invoked by uid 500); 8 Jan 2014 14:02:00 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 74862 invoked by uid 99); 8 Jan 2014 14:01:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Jan 2014 14:01:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Jan 2014 14:01:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D044F2388B42; Wed, 8 Jan 2014 14:01:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1556535 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate: AuthorizableDelegator.java GroupDelegator.java ImpersonationDelegator.java UserDelegator.java UserManagerDelegator.java Date: Wed, 08 Jan 2014 14:01:09 -0000 To: oak-commits@jackrabbit.apache.org From: angela@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140108140109.D044F2388B42@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: angela Date: Wed Jan 8 14:01:09 2014 New Revision: 1556535 URL: http://svn.apache.org/r1556535 Log: OAK-1124 : OAK-938 incomplete: session refresh must also be reflected on derived interfaces Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java (with props) jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java (with props) jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java (with props) jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java (with props) Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java?rev=1556535&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java (added) +++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java Wed Jan 8 14:01:09 2014 @@ -0,0 +1,255 @@ +/* + * 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.oak.jcr.delegate; + +import java.security.Principal; +import java.util.Iterator; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.jcr.RepositoryException; +import javax.jcr.UnsupportedRepositoryOperationException; +import javax.jcr.Value; + +import com.google.common.base.Function; +import com.google.common.collect.Iterators; +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.oak.jcr.session.operation.SessionOperation; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * Base class for {@link GroupDelegator} and {@link UserDelegator}. + */ +abstract class AuthorizableDelegator implements Authorizable { + + final SessionDelegate sessionDelegate; + final Authorizable delegate; + + AuthorizableDelegator(@Nonnull SessionDelegate sessionDelegate, @Nonnull Authorizable delegate) { + checkArgument(!(delegate instanceof AuthorizableDelegator)); + this.sessionDelegate = sessionDelegate; + this.delegate = delegate; + } + + static Authorizable wrap(@Nonnull SessionDelegate sessionDelegate, @Nullable Authorizable authorizable) { + if (authorizable == null) { + return null; + } + if (authorizable.isGroup()) { + return GroupDelegator.wrap(sessionDelegate, (Group) authorizable); + } else { + return UserDelegator.wrap(sessionDelegate, (User) authorizable); + } + } + + static Authorizable unwrap(@Nonnull Authorizable authorizable) { + if (authorizable.isGroup()) { + return GroupDelegator.unwrap((Group) authorizable); + } else { + return UserDelegator.unwrap((User) authorizable); + } + } + + //-------------------------------------------------------< Authorizable >--- + @Override + public boolean isGroup() { + return sessionDelegate.safePerform(new SessionOperation() { + @Override + public Boolean perform() { + return delegate.isGroup(); + } + }); + } + + @Override + public String getID() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public String perform() throws RepositoryException { + return delegate.getID(); + } + }); + } + + + + @Override + public Principal getPrincipal() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Principal perform() throws RepositoryException { + return delegate.getPrincipal(); + } + }); + } + + @Override + public Iterator declaredMemberOf() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation>() { + @Override + public Iterator perform() throws RepositoryException { + Iterator groups = delegate.declaredMemberOf(); + return Iterators.transform(groups, new Function() { + @Nullable + @Override + public Group apply(@Nullable Group group) { + return GroupDelegator.wrap(sessionDelegate, group); + } + }); + } + }); + } + + @Override + public Iterator memberOf() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation>() { + @Override + public Iterator perform() throws RepositoryException { + Iterator groups = delegate.memberOf(); + return Iterators.transform(groups, new Function() { + @Nullable + @Override + public Group apply(@Nullable Group group) { + return GroupDelegator.wrap(sessionDelegate, group); + } + }); + } + }); + } + + @Override + public void remove() throws RepositoryException { + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform() throws RepositoryException { + delegate.remove(); + return null; + } + }); + } + + @Override + public Iterator getPropertyNames() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation>() { + @Override + public Iterator perform() throws RepositoryException { + return delegate.getPropertyNames(); + } + }); + } + + @Override + public Iterator getPropertyNames(final String relPath) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation>() { + @Override + public Iterator perform() throws RepositoryException { + return delegate.getPropertyNames(relPath); + } + }); + } + + @Override + public boolean hasProperty(final String relPath) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return delegate.hasProperty(relPath); + } + }); + } + + @Override + public void setProperty(final String relPath, final Value value) throws RepositoryException { + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform() throws RepositoryException { + delegate.setProperty(relPath, value); + return null; + } + }); + } + + @Override + public void setProperty(final String relPath, final Value[] value) throws RepositoryException { + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform() throws RepositoryException { + delegate.setProperty(relPath, value); + return null; + } + }); + } + + @Override + public Value[] getProperty(final String relPath) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Value[] perform() throws RepositoryException { + return delegate.getProperty(relPath); + } + }); + } + + @Override + public boolean removeProperty(final String relPath) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return delegate.removeProperty(relPath); + } + }); + } + + @Override + public String getPath() throws UnsupportedRepositoryOperationException, RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public String perform() throws RepositoryException { + return delegate.getPath(); + } + }); + } + + //-------------------------------------------------------------< Object >--- + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (other instanceof AuthorizableDelegator) { + AuthorizableDelegator ad = (AuthorizableDelegator) other; + return delegate.equals(ad.delegate); + } + return false; + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + + + @Override + public String toString() { + return delegate.toString(); + } +} Propchange: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java?rev=1556535&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java (added) +++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java Wed Jan 8 14:01:09 2014 @@ -0,0 +1,145 @@ +/* + * 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.oak.jcr.delegate; + +import java.security.Principal; +import java.util.Iterator; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.jcr.RepositoryException; +import javax.jcr.UnsupportedRepositoryOperationException; +import javax.jcr.Value; + +import com.google.common.base.Function; +import com.google.common.collect.Iterators; +import org.apache.jackrabbit.api.security.user.Authorizable; +import org.apache.jackrabbit.api.security.user.Group; +import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * This implementation of {@code Group} delegates back to a + * delegatee wrapping each call into a {@link SessionOperation} closure. + * + * @see SessionDelegate#perform(SessionOperation) + */ +final class GroupDelegator extends AuthorizableDelegator implements Group { + + private GroupDelegator(SessionDelegate sessionDelegate, Group groupDelegate) { + super(sessionDelegate, groupDelegate); + } + + static Group wrap(@Nonnull SessionDelegate sessionDelegate, Group group) { + if (group == null) { + return null; + } else { + return new GroupDelegator(sessionDelegate, group); + } + } + + @Nonnull + static Group unwrap(@Nonnull Group group) { + if (group instanceof GroupDelegator) { + return ((GroupDelegator) group).getDelegate(); + } else { + return group; + } + } + + private Group getDelegate() { + return (Group) delegate; + } + + //--------------------------------------------------------------< Group >--- + @Override + public Iterator getDeclaredMembers() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation>() { + @Override + public Iterator perform() throws RepositoryException { + Iterator authorizables = getDelegate().getDeclaredMembers(); + return Iterators.transform(authorizables, new Function() { + @Nullable + @Override + public Authorizable apply(@Nullable Authorizable authorizable) { + return wrap(sessionDelegate, authorizable); + } + }); + } + }); + } + + @Override + public Iterator getMembers() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation>() { + @Override + public Iterator perform() throws RepositoryException { + Iterator authorizables = getDelegate().getMembers(); + return Iterators.transform(authorizables, new Function() { + @Nullable + @Override + public Authorizable apply(@Nullable Authorizable authorizable) { + return wrap(sessionDelegate, authorizable); + } + }); + } + }); + } + + @Override + public boolean isDeclaredMember(final Authorizable authorizable) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return getDelegate().isDeclaredMember(unwrap(authorizable)); + } + }); + } + + @Override + public boolean isMember(final Authorizable authorizable) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return getDelegate().isMember(unwrap(authorizable)); + } + }); + } + + @Override + public boolean addMember(final Authorizable authorizable) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return getDelegate().addMember(unwrap(authorizable)); + } + }); + } + + @Override + public boolean removeMember(final Authorizable authorizable) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return getDelegate().removeMember(unwrap(authorizable)); + } + }); + } +} Propchange: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java?rev=1556535&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java (added) +++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java Wed Jan 8 14:01:09 2014 @@ -0,0 +1,96 @@ +/* + * 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.oak.jcr.delegate; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.security.Principal; + +import javax.jcr.RepositoryException; +import javax.security.auth.Subject; + +import org.apache.jackrabbit.api.security.principal.PrincipalIterator; +import org.apache.jackrabbit.api.security.user.Impersonation; +import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation; + +/** + * This implementation of {@code Impersonation} delegates back to a + * delegatee wrapping each call into a {@link SessionOperation} closure. + * + * @see SessionDelegate#perform(SessionOperation) + */ +class ImpersonationDelegator implements Impersonation { + private final SessionDelegate sessionDelegate; + private final Impersonation impersonationDelegate; + + private ImpersonationDelegator(SessionDelegate sessionDelegate, Impersonation impersonationDelegate) { + checkArgument(!(impersonationDelegate instanceof ImpersonationDelegator)); + this.sessionDelegate = sessionDelegate; + this.impersonationDelegate = impersonationDelegate; + } + + static Impersonation wrap(SessionDelegate sessionDelegate, Impersonation impersonation) { + if (impersonation == null) { + return null; + } else { + return new ImpersonationDelegator(sessionDelegate, impersonation); + } + } + + @Override + public PrincipalIterator getImpersonators() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public PrincipalIterator perform() throws RepositoryException { + return impersonationDelegate.getImpersonators(); + } + }); + } + + @Override + public boolean grantImpersonation(final Principal principal) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return impersonationDelegate.grantImpersonation(principal); + } + }); + } + + @Override + public boolean revokeImpersonation(final Principal principal) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return impersonationDelegate.revokeImpersonation(principal); + } + }); + } + + @Override + public boolean allows(final Subject subject) throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return impersonationDelegate.allows(subject); + } + }); + } +} Propchange: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java?rev=1556535&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java (added) +++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java Wed Jan 8 14:01:09 2014 @@ -0,0 +1,147 @@ +/* + * 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.oak.jcr.delegate; + +import javax.annotation.Nonnull; +import javax.jcr.Credentials; +import javax.jcr.RepositoryException; + +import org.apache.jackrabbit.api.security.user.Impersonation; +import org.apache.jackrabbit.api.security.user.User; +import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation; + +/** + * This implementation of {@code User} delegates back to a + * delegatee wrapping each call into a {@link SessionOperation} closure. + * + * @see SessionDelegate#perform(SessionOperation) + */ +final class UserDelegator extends AuthorizableDelegator implements User { + + private UserDelegator(SessionDelegate sessionDelegate, User userDelegate) { + super(sessionDelegate, userDelegate); + } + + static User wrap(SessionDelegate sessionDelegate, User user) { + if (user == null) { + return null; + } else { + return new UserDelegator(sessionDelegate, user); + } + } + + @Nonnull + static User unwrap(@Nonnull User user) { + if (user instanceof UserDelegator) { + return ((UserDelegator) user).getDelegate(); + } else { + return user; + } + } + + private User getDelegate() { + return (User) delegate; + } + + //---------------------------------------------------------------< User >--- + @Override + public boolean isAdmin() { + return sessionDelegate.safePerform(new SessionOperation() { + @Override + public Boolean perform() { + return getDelegate().isAdmin(); + } + }); + } + + @Override + public Credentials getCredentials() { + return sessionDelegate.safePerform(new SessionOperation() { + @Override + public Credentials perform() throws RepositoryException { + return getDelegate().getCredentials(); + } + }); + } + + @Override + public Impersonation getImpersonation() { + return sessionDelegate.safePerform(new SessionOperation() { + @Override + public Impersonation perform() throws RepositoryException { + Impersonation impersonation = getDelegate().getImpersonation(); + return ImpersonationDelegator.wrap(sessionDelegate, impersonation); + } + }); + } + + @Override + public void changePassword(final String password) throws RepositoryException { + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform() throws RepositoryException { + getDelegate().changePassword(password); + return null; + } + }); + } + + @Override + public void changePassword(final String password, final String oldPassword) throws RepositoryException { + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform() throws RepositoryException { + getDelegate().changePassword(password, oldPassword); + return null; + } + }); + } + + @Override + public void disable(final String reason) throws RepositoryException { + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform() throws RepositoryException { + getDelegate().disable(reason); + return null; + } + }); + } + + @Override + public boolean isDisabled() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform() throws RepositoryException { + return getDelegate().isDisabled(); + } + }); + } + + @Override + public String getDisabledReason() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public String perform() throws RepositoryException { + return getDelegate().getDisabledReason(); + } + }); + } +} Propchange: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java?rev=1556535&r1=1556534&r2=1556535&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java (original) +++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java Wed Jan 8 14:01:09 2014 @@ -21,10 +21,12 @@ package org.apache.jackrabbit.oak.jcr.de import java.security.Principal; import java.util.Iterator; - +import javax.annotation.Nullable; import javax.jcr.RepositoryException; import javax.jcr.UnsupportedRepositoryOperationException; +import com.google.common.base.Function; +import com.google.common.collect.Iterators; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.AuthorizableExistsException; import org.apache.jackrabbit.api.security.user.Group; @@ -33,6 +35,8 @@ import org.apache.jackrabbit.api.securit import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.oak.jcr.session.operation.UserManagerOperation; +import static com.google.common.base.Preconditions.checkState; + /** * This implementation of {@code UserManager} delegates back to a * delegatee wrapping each call into a {@link UserManager} closure. @@ -40,12 +44,14 @@ import org.apache.jackrabbit.oak.jcr.ses * @see SessionDelegate#perform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation) */ public class UserManagerDelegator implements UserManager { - private final UserManager userManagerDelegate; + private final SessionDelegate sessionDelegate; + private final UserManager userManagerDelegate; public UserManagerDelegator(final SessionDelegate sessionDelegate, UserManager userManagerDelegate) { - this.userManagerDelegate = userManagerDelegate; + checkState(!(userManagerDelegate instanceof UserManagerDelegator)); this.sessionDelegate = sessionDelegate; + this.userManagerDelegate = userManagerDelegate; } @Override @@ -53,7 +59,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public Authorizable perform() throws RepositoryException { - return userManagerDelegate.getAuthorizable(id); + Authorizable authorizable = userManagerDelegate.getAuthorizable(id); + return AuthorizableDelegator.wrap(sessionDelegate, authorizable); } }); } @@ -63,7 +70,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public Authorizable perform() throws RepositoryException { - return userManagerDelegate.getAuthorizable(principal); + Authorizable authorizable = userManagerDelegate.getAuthorizable(principal); + return AuthorizableDelegator.wrap(sessionDelegate, authorizable); } }); } @@ -73,7 +81,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public Authorizable perform() throws RepositoryException { - return userManagerDelegate.getAuthorizableByPath(path); + Authorizable authorizable = userManagerDelegate.getAuthorizableByPath(path); + return AuthorizableDelegator.wrap(sessionDelegate, authorizable); } }); } @@ -83,7 +92,14 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation>(sessionDelegate) { @Override public Iterator perform() throws RepositoryException { - return userManagerDelegate.findAuthorizables(relPath, value); + Iterator authorizables = userManagerDelegate.findAuthorizables(relPath, value); + return Iterators.transform(authorizables, new Function() { + @Nullable + @Override + public Authorizable apply(Authorizable authorizable) { + return AuthorizableDelegator.wrap(sessionDelegate, authorizable); + } + }); } }); } @@ -93,7 +109,14 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation>(sessionDelegate) { @Override public Iterator perform() throws RepositoryException { - return userManagerDelegate.findAuthorizables(relPath, value, searchType); + Iterator authorizables = userManagerDelegate.findAuthorizables(relPath, value, searchType); + return Iterators.transform(authorizables, new Function() { + @Nullable + @Override + public Authorizable apply(Authorizable authorizable) { + return AuthorizableDelegator.wrap(sessionDelegate, authorizable); + } + }); } }); } @@ -103,7 +126,14 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation>(sessionDelegate) { @Override public Iterator perform() throws RepositoryException { - return userManagerDelegate.findAuthorizables(query); + Iterator authorizables = userManagerDelegate.findAuthorizables(query); + return Iterators.transform(authorizables, new Function() { + @Nullable + @Override + public Authorizable apply(Authorizable authorizable) { + return AuthorizableDelegator.wrap(sessionDelegate, authorizable); + } + }); } }); } @@ -113,7 +143,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public User perform() throws RepositoryException { - return userManagerDelegate.createUser(userID, password); + User user = userManagerDelegate.createUser(userID, password); + return UserDelegator.wrap(sessionDelegate, user); } }); } @@ -123,7 +154,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public User perform() throws RepositoryException { - return userManagerDelegate.createUser(userID, password, principal, intermediatePath); + User user = userManagerDelegate.createUser(userID, password, principal, intermediatePath); + return UserDelegator.wrap(sessionDelegate, user); } }); } @@ -133,7 +165,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public Group perform() throws RepositoryException { - return userManagerDelegate.createGroup(groupID); + Group group = userManagerDelegate.createGroup(groupID); + return GroupDelegator.wrap(sessionDelegate, group); } }); } @@ -143,7 +176,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public Group perform() throws RepositoryException { - return userManagerDelegate.createGroup(principal); + Group group = userManagerDelegate.createGroup(principal); + return GroupDelegator.wrap(sessionDelegate, group); } }); } @@ -153,7 +187,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public Group perform() throws RepositoryException { - return userManagerDelegate.createGroup(principal, intermediatePath); + Group group = userManagerDelegate.createGroup(principal, intermediatePath); + return GroupDelegator.wrap(sessionDelegate, group); } }); } @@ -163,7 +198,8 @@ public class UserManagerDelegator implem return sessionDelegate.perform(new UserManagerOperation(sessionDelegate) { @Override public Group perform() throws RepositoryException { - return userManagerDelegate.createGroup(groupID, principal, intermediatePath); + Group group = userManagerDelegate.createGroup(groupID, principal, intermediatePath); + return GroupDelegator.wrap(sessionDelegate, group); } }); }