Abstract group systems into GroupBackend interface.
Currently, every NameKey and UUID for a group is expected to be backed by an entry in the AccountGroup table. In the future, the group backend will be swapable by allowing implementations to scope AccountGroup.UUIDs e.g. "ldap:<ldap identifier>". This change adds a GroupBackend interface that abstracts the implementation details of a group system with respect to looking up groups (editing and creating are not supported), which should be used instead of GroupCache when looking up by AccountGroup.UUID or name. GroupBackends scope which AccountGroup.UUIDs they handle by implementing the handles() method for a particular prefix. The UniversalGroupBackend is a GroupBackend that delegates methods to the GroupBackend that handles() the UUID, using DynamicSets. The InternalGroupBackend and LdapGroupBackend are the first GroupBackend implementation. It should be possible to bind many GroupBackends concurrently, unfortunately, the current implementation of LdapGroupBackend.handles() overlaps with the InternalGroupBackend.handles() (since they are both stored in the database), so only one those implementations may be bound at once. Change-Id: Ieda21916247084ebc2dffc9dd82d3e1230b9ab64
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed 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 com.google.gerrit.common.data;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
|
||||
/**
|
||||
* Group methods exposed by the GroupBackend.
|
||||
*/
|
||||
public class GroupDescription {
|
||||
/**
|
||||
* The Basic information required to be exposed by any Group.
|
||||
*/
|
||||
public interface Basic {
|
||||
/** @return the non-null UUID of the group. */
|
||||
AccountGroup.UUID getGroupUUID();
|
||||
|
||||
/** @return the non-null name of the group. */
|
||||
String getName();
|
||||
|
||||
/** @return whether the group is visible to all accounts. */
|
||||
boolean isVisibleToAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* The extended information exposed by internal groups backed by an
|
||||
* AccountGroup.
|
||||
*/
|
||||
public interface Internal extends Basic {
|
||||
/** @return the backing AccountGroup. */
|
||||
AccountGroup getAccountGroup();
|
||||
}
|
||||
|
||||
private GroupDescription() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed 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 com.google.gerrit.common.data;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Utility class for building GroupDescription objects.
|
||||
*/
|
||||
public class GroupDescriptions {
|
||||
|
||||
@Nullable
|
||||
public static AccountGroup toAccountGroup(GroupDescription.Basic group) {
|
||||
if (group instanceof GroupDescription.Internal) {
|
||||
return ((GroupDescription.Internal) group).getAccountGroup();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GroupDescription.Internal forAccountGroup(final AccountGroup group) {
|
||||
return new GroupDescription.Internal() {
|
||||
@Override
|
||||
public AccountGroup.UUID getGroupUUID() {
|
||||
return group.getGroupUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return group.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisibleToAll() {
|
||||
return group.isVisibleToAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountGroup getAccountGroup() {
|
||||
return group;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private GroupDescriptions() {
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,10 @@ public class GroupReference implements Comparable<GroupReference> {
|
||||
return new GroupReference(group.getGroupUUID(), group.getName());
|
||||
}
|
||||
|
||||
public static GroupReference forGroup(GroupDescription.Basic group) {
|
||||
return new GroupReference(group.getGroupUUID(), group.getName());
|
||||
}
|
||||
|
||||
protected String uuid;
|
||||
protected String name;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user