com.atlassian.crowd.embedded.core
Class FilteredCrowdServiceImpl

java.lang.Object
  extended by com.atlassian.crowd.embedded.core.FilteredCrowdServiceImpl
All Implemented Interfaces:
CrowdService

public class FilteredCrowdServiceImpl
extends Object

A layer on top of CrowdService which performs group filtering. The filtered groups are treated as if they do not exist. That is, get or search operations will never return them. The only exception being addGroup(com.atlassian.crowd.embedded.api.Group) which throws an OperationNotPermittedException} when a filtered group is added. Note that this implementation assumes there is no children groups under the filtered groups.


Field Summary
protected  CrowdService crowdService
           
 
Constructor Summary
FilteredCrowdServiceImpl(CrowdService crowdService, FilteredGroupsProvider groupProvider)
           
 
Method Summary
 Group addGroup(Group group)
          Adds a group to the directory store.
 void addGroupToGroup(Group childGroup, Group parentGroup)
          Adds a group as a member of a parent group.
 User addUser(User user, String credential)
          Adds a user to the directory store.
 void addUserToGroup(User user, Group group)
          Adds a user as a member of a group.
 User authenticate(String name, String credential)
          Authenticates a user with the given credential.
 Group getGroup(String name)
          Finds the group that matches the supplied name.
 GroupWithAttributes getGroupWithAttributes(String name)
          Finds the group that matches the supplied name.
 User getUser(String name)
          Returns the user that matches the supplied name.
 UserWithAttributes getUserWithAttributes(String name)
          Returns the user that matches the supplied name.
 boolean isGroupDirectGroupMember(Group childGroup, Group parentGroup)
          Determines if a group is a direct member of another group.
 boolean isGroupMemberOfGroup(Group childGroup, Group parentGroup)
          Returns true if the childGroup is a direct or indirect (nested) member of the parentGroup.
 boolean isGroupMemberOfGroup(String childGroupName, String parentGroupName)
          Returns true if childGroupName is a direct or indirect (nested) member of parentGroupName.
 boolean isUserDirectGroupMember(User user, Group group)
          Determines if a user is a direct member of a group.
 boolean isUserMemberOfGroup(String userName, String groupName)
          Returns true if the user is a direct or indirect (nested) member of the group.
 boolean isUserMemberOfGroup(User user, Group group)
          Returns true if the user is a direct or indirect (nested) member of the group.
 void removeAllGroupAttributes(Group group)
          Removes all group attributes.
 void removeAllUserAttributes(User user)
          Remove all attributes for a user.
 boolean removeGroup(Group group)
          Removes the group that matches the supplied name.
 void removeGroupAttribute(Group group, String attributeName)
          Removes all the values for a single attribute key for a group.
 boolean removeGroupFromGroup(Group childGroup, Group parentGroup)
          Removes a group as a member of a parent group.
 boolean removeUser(User user)
          Removes the user that matches the supplied name.
 void removeUserAttribute(User user, String attributeName)
          Removes all the values for a single attribute key for a user.
 boolean removeUserFromGroup(User user, Group group)
          Removes a user as a member of a group.
<T> Iterable<T>
search(Query<T> query)
          Searches for entities (e.g.
 Iterable<User> searchUsersAllowingDuplicateNames(Query<User> query)
          Searches for User entities that match the supplied search query.
 void setGroupAttribute(Group group, String attributeName, Set<String> attributeValues)
          Adds or updates a group's attributes with the new attributes.
 void setGroupAttribute(Group group, String attributeName, String attributeValue)
          Adds or updates a group's attributes with the new attributes.
 void setUserAttribute(User user, String attributeName, Set<String> attributeValues)
          Adds or updates a user's attribute with the new attribute values.
 void setUserAttribute(User user, String attributeName, String attributeValue)
          Adds or updates a user's attribute with the new attribute value.
 Group updateGroup(Group group)
          Updates the group.
 User updateUser(User user)
          Updates the User.
 void updateUserCredential(User user, String credential)
          Updates the password for a user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

crowdService

protected final CrowdService crowdService
Constructor Detail

FilteredCrowdServiceImpl

public FilteredCrowdServiceImpl(CrowdService crowdService,
                                FilteredGroupsProvider groupProvider)
Method Detail

getGroup

public Group getGroup(String name)
Description copied from interface: CrowdService
Finds the group that matches the supplied name.

Specified by:
getGroup in interface CrowdService
Parameters:
name - the name of the group.
Returns:
group entity, null if not found.

getGroupWithAttributes

public GroupWithAttributes getGroupWithAttributes(String name)
Description copied from interface: CrowdService
Finds the group that matches the supplied name.

Specified by:
getGroupWithAttributes in interface CrowdService
Parameters:
name - the name of the group.
Returns:
group entity with attributes, null if not found.

search

public <T> Iterable<T> search(Query<T> query)
Description copied from interface: CrowdService
Searches for entities (e.g. Group or User) of type <T> that match the supplied search query. Search return types must be either String, User or Group.

Specified by:
search in interface CrowdService
Parameters:
query - Query for a given entity (e.g. Group or User)
Returns:
entities of type T matching the search query. An Iterable containing no results will be returned if there are no matches for the query.

isUserMemberOfGroup

public boolean isUserMemberOfGroup(String userName,
                                   String groupName)
Description copied from interface: CrowdService
Returns true if the user is a direct or indirect (nested) member of the group.

Specified by:
isUserMemberOfGroup in interface CrowdService
Parameters:
userName - user to inspect.
groupName - group to inspect.
Returns:
true if and only if the user is a direct or indirect (nested) member of the group. If the user or group cannot found, then false is returned.
See Also:
CrowdService.isUserMemberOfGroup(User, Group)

isUserMemberOfGroup

public boolean isUserMemberOfGroup(User user,
                                   Group group)
Description copied from interface: CrowdService
Returns true if the user is a direct or indirect (nested) member of the group.

Specified by:
isUserMemberOfGroup in interface CrowdService
Parameters:
user - user to inspect.
group - group to inspect.
Returns:
true if and only if the user is a direct or indirect (nested) member of the group, otherwise false. If the user or group cannot found, then false is returned.
See Also:
CrowdService.isUserMemberOfGroup(String, String)

isGroupMemberOfGroup

public boolean isGroupMemberOfGroup(String childGroupName,
                                    String parentGroupName)
Description copied from interface: CrowdService
Returns true if childGroupName is a direct or indirect (nested) member of parentGroupName.

Specified by:
isGroupMemberOfGroup in interface CrowdService
Parameters:
childGroupName - name of child group to inspect.
parentGroupName - name of parent group to inspect.
Returns:
true if and only if the childGroupName is a direct or indirect (nested) member of the parentGroupName. If any of the groups cannot found, then false is returned.

isGroupMemberOfGroup

public boolean isGroupMemberOfGroup(Group childGroup,
                                    Group parentGroup)
Description copied from interface: CrowdService
Returns true if the childGroup is a direct or indirect (nested) member of the parentGroup.

Specified by:
isGroupMemberOfGroup in interface CrowdService
Parameters:
childGroup - group to inspect.
parentGroup - group to inspect.
Returns:
true if and only if the childGroup is a direct or indirect (nested) member of the parentGroup. If any of the groups cannot found, then false is returned.

addGroup

public Group addGroup(Group group)
               throws InvalidGroupException,
                      OperationNotPermittedException,
                      OperationFailedException
Description copied from interface: CrowdService
Adds a group to the directory store.

Specified by:
addGroup in interface CrowdService
Parameters:
group - template of the group to add.
Returns:
the added group retrieved from the underlying store.
Throws:
InvalidGroupException - if the group already exists in ANY associated directory or the group template does not have the required properties populated.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

updateGroup

public Group updateGroup(Group group)
                  throws GroupNotFoundException,
                         InvalidGroupException,
                         OperationNotPermittedException,
                         OperationFailedException
Description copied from interface: CrowdService
Updates the group.

Specified by:
updateGroup in interface CrowdService
Parameters:
group - The group to update.
Returns:
the updated group retrieved from the underlying store.
Throws:
GroupNotFoundException - if group with given name does not exist in ANY assigned directory.
InvalidGroupException - the supplied group is invalid.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

setGroupAttribute

public void setGroupAttribute(Group group,
                              String attributeName,
                              String attributeValue)
                       throws GroupNotFoundException,
                              OperationNotPermittedException,
                              OperationFailedException
Description copied from interface: CrowdService
Adds or updates a group's attributes with the new attributes. The attributes represents new or updated attributes and does not replace existing attributes unless the key of an attribute matches the key of an existing. This will not remove any attributes.

Specified by:
setGroupAttribute in interface CrowdService
Parameters:
group - name of group to update.
attributeName - the name up the attribute to add or update
attributeValue - the value of the attribute
Throws:
GroupNotFoundException - if the group could not be found
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

setGroupAttribute

public void setGroupAttribute(Group group,
                              String attributeName,
                              Set<String> attributeValues)
                       throws GroupNotFoundException,
                              OperationNotPermittedException,
                              OperationFailedException
Description copied from interface: CrowdService
Adds or updates a group's attributes with the new attributes. The attributes represents new or updated attributes and does not replace existing attributes unless the key of an attribute matches the key of an existing. This will not remove any attributes.

Specified by:
setGroupAttribute in interface CrowdService
Parameters:
group - name of group to update.
attributeName - the name up the attribute to add or update
attributeValues - a set of values to update
Throws:
GroupNotFoundException - if the group could not be found
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

removeGroupAttribute

public void removeGroupAttribute(Group group,
                                 String attributeName)
                          throws GroupNotFoundException,
                                 OperationNotPermittedException,
                                 OperationFailedException
Description copied from interface: CrowdService
Removes all the values for a single attribute key for a group.

Specified by:
removeGroupAttribute in interface CrowdService
Parameters:
group - to update.
attributeName - name of attribute to remove.
Throws:
GroupNotFoundException - if the group could not be found
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

removeAllGroupAttributes

public void removeAllGroupAttributes(Group group)
                              throws GroupNotFoundException,
                                     OperationNotPermittedException,
                                     OperationFailedException
Description copied from interface: CrowdService
Removes all group attributes.

Specified by:
removeAllGroupAttributes in interface CrowdService
Parameters:
group - to update.
Throws:
GroupNotFoundException - if the group could not be found
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

removeGroup

public boolean removeGroup(Group group)
                    throws OperationNotPermittedException,
                           OperationFailedException
Description copied from interface: CrowdService
Removes the group that matches the supplied name.

Specified by:
removeGroup in interface CrowdService
Parameters:
group - to remove
Returns:
true if the group was removed as a result of this call, false if the group does not exist.
Throws:
OperationNotPermittedException - if the directory does not allow removal of this group
OperationFailedException - underlying directory implementation failed to execute the operation.

addUserToGroup

public void addUserToGroup(User user,
                           Group group)
                    throws GroupNotFoundException,
                           UserNotFoundException,
                           OperationNotPermittedException,
                           OperationFailedException
Description copied from interface: CrowdService
Adds a user as a member of a group. This means that all user members of childGroup will appear as members of parentGroup to querying applications.

Specified by:
addUserToGroup in interface CrowdService
Parameters:
user - The user that will become a member of the group
group - The group that will gain a new member.
Throws:
GroupNotFoundException - if the group could not be found
UserNotFoundException - if the user could not be found
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

addGroupToGroup

public void addGroupToGroup(Group childGroup,
                            Group parentGroup)
                     throws GroupNotFoundException,
                            OperationNotPermittedException,
                            InvalidMembershipException,
                            OperationFailedException
Description copied from interface: CrowdService
Adds a group as a member of a parent group. Cyclic group membership are allowed (mainly because LDAP allows it) but not recommended. I.e. group A can have group B as its member and group B can have group A as its member at the same time.

Specified by:
addGroupToGroup in interface CrowdService
Parameters:
childGroup - The group that will become a member of parentGroup
parentGroup - The group that will gain a new member
Throws:
GroupNotFoundException - if any of the group could not be found. Use GroupNotFoundException.getGroupName() to find out which group wasn't found
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
InvalidMembershipException - If the relationship would cause a circular reference.
OperationFailedException - underlying directory implementation failed to execute the operation.

removeUserFromGroup

public boolean removeUserFromGroup(User user,
                                   Group group)
                            throws GroupNotFoundException,
                                   UserNotFoundException,
                                   OperationNotPermittedException,
                                   OperationFailedException
Description copied from interface: CrowdService
Removes a user as a member of a group.

Specified by:
removeUserFromGroup in interface CrowdService
Parameters:
user - The user that will be removed from the group
group - The group that will lose the member.
Returns:
true if the user was removed from the group as a result of this call, false if the user is not a member of the group.
Throws:
GroupNotFoundException - if the group could not be found
UserNotFoundException - if the user could not be found
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - if the operation failed for any other reason

removeGroupFromGroup

public boolean removeGroupFromGroup(Group childGroup,
                                    Group parentGroup)
                             throws GroupNotFoundException,
                                    OperationNotPermittedException,
                                    OperationFailedException
Description copied from interface: CrowdService
Removes a group as a member of a parent group.

Specified by:
removeGroupFromGroup in interface CrowdService
Parameters:
childGroup - The group that will be removed from parentGroup
parentGroup - The group that will lose the member.
Returns:
true if childGroup was removed from parentGroup as a result of this call, false if childGroup is not a member of the parentGroup.
Throws:
GroupNotFoundException - if any of the groups could not be found. Use GroupNotFoundException.getGroupName() to find out which group wasn't found
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - if the operation failed for any other reason

isUserDirectGroupMember

public boolean isUserDirectGroupMember(User user,
                                       Group group)
                                throws OperationFailedException
Description copied from interface: CrowdService
Determines if a user is a direct member of a group.

Specified by:
isUserDirectGroupMember in interface CrowdService
Parameters:
user - the user for whom to check the group membership
group - the group the user is believed to belong to
Returns:
true if the user is a direct member of the group, false otherwise (including if the user and/or group could not be found)
Throws:
OperationFailedException - underlying directory implementation failed to execute the operation.

isGroupDirectGroupMember

public boolean isGroupDirectGroupMember(Group childGroup,
                                        Group parentGroup)
                                 throws OperationFailedException
Description copied from interface: CrowdService
Determines if a group is a direct member of another group.

Specified by:
isGroupDirectGroupMember in interface CrowdService
Parameters:
childGroup - the group for which to check the parentGroup membership
parentGroup - the group the childGroup is believed to belong to
Returns:
true if the childGroup is a direct member of the parentGroup, false otherwise (including if neither group could be found)
Throws:
OperationFailedException - underlying directory implementation failed to execute the operation.

authenticate

public User authenticate(String name,
                         String credential)
                  throws FailedAuthenticationException,
                         OperationFailedException
Description copied from interface: CrowdService
Authenticates a user with the given credential.

Specified by:
authenticate in interface CrowdService
Parameters:
name - The name of the user (username).
credential - The supplied credential to authenticate with
Returns:
The populated user if the authentication is valid.
Throws:
FailedAuthenticationException - Authentication with the provided credentials failed. It may indicate that the user does not exist or the user's account is inactive or the credentials are incorrect
InactiveAccountException - The supplied user is inactive.
ExpiredCredentialException - The user's credentials have expired. The user must change their credentials in order to successfully authenticate.
AccountNotFoundException - User with the given name could not be found
OperationFailedException - underlying directory implementation failed to execute the operation.

getUser

public User getUser(String name)
Description copied from interface: CrowdService
Returns the user that matches the supplied name.

Specified by:
getUser in interface CrowdService
Parameters:
name - the name of the user (username). Does not allow null, blank or empty strings.
Returns:
user entity or null if the user is not found

getUserWithAttributes

public UserWithAttributes getUserWithAttributes(String name)
Description copied from interface: CrowdService
Returns the user that matches the supplied name.

Specified by:
getUserWithAttributes in interface CrowdService
Parameters:
name - the name of the user (username).
Returns:
user entity with attributes or null if the user is not found

addUser

public User addUser(User user,
                    String credential)
             throws InvalidUserException,
                    InvalidCredentialException,
                    OperationNotPermittedException,
                    OperationFailedException
Description copied from interface: CrowdService
Adds a user to the directory store. The user must have non-null names and email address.

Specified by:
addUser in interface CrowdService
Parameters:
user - template of the user to add.
credential - password. May not be null or blank.
Returns:
the added user retrieved from the underlying store.
Throws:
InvalidUserException - The supplied user's details are invalid and/or incomplete.
InvalidCredentialException - The supplied credential is invalid, this may be due the credential not matching required directory constraints.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - if the operation failed for any other reason

updateUser

public User updateUser(User user)
                throws UserNotFoundException,
                       InvalidUserException,
                       OperationNotPermittedException,
                       OperationFailedException
Description copied from interface: CrowdService
Updates the User. The user must have non-null names and email address.

Specified by:
updateUser in interface CrowdService
Parameters:
user - The user to update.
Returns:
the updated user retrieved from the underlying store. This might be a new object instance, depending on the underlying Directory
Throws:
UserNotFoundException - if the supplied user does not exist in the directory.
InvalidUserException - The supplied user's details are invalid and/or incomplete.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

updateUserCredential

public void updateUserCredential(User user,
                                 String credential)
                          throws UserNotFoundException,
                                 InvalidCredentialException,
                                 OperationNotPermittedException,
                                 OperationFailedException
Description copied from interface: CrowdService
Updates the password for a user.

Specified by:
updateUserCredential in interface CrowdService
Parameters:
user - The name of the user (username).
credential - The new credential (password). May not be null or blank.
Throws:
UserNotFoundException - if the supplied user does not exist in the directory.
InvalidCredentialException - The supplied credential is invalid, this may be due the credential not matching required directory constraints.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

setUserAttribute

public void setUserAttribute(User user,
                             String attributeName,
                             String attributeValue)
                      throws UserNotFoundException,
                             OperationNotPermittedException,
                             OperationFailedException
Description copied from interface: CrowdService
Adds or updates a user's attribute with the new attribute value. The attributes represents new or updated attributes and does not replace existing attributes unless the key of an attribute matches the key of an existing attribute. This will not remove any attributes.

Specified by:
setUserAttribute in interface CrowdService
Parameters:
user - user to update.
attributeName - the name of the attribute
attributeValue - the new value of the attribute; any existing values will be replaced
Throws:
UserNotFoundException - the supplied user does not exist.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

setUserAttribute

public void setUserAttribute(User user,
                             String attributeName,
                             Set<String> attributeValues)
                      throws UserNotFoundException,
                             OperationNotPermittedException,
                             OperationFailedException
Description copied from interface: CrowdService
Adds or updates a user's attribute with the new attribute values. The attributes represents new or updated attributes and does not replace existing attributes unless the key of an attribute matches the key of an existing. This will not remove any attributes.

Specified by:
setUserAttribute in interface CrowdService
Parameters:
user - user to update.
attributeName - the name of the attribute
attributeValues - the new set of values; any existing values will be replaced
Throws:
UserNotFoundException - the supplied user does not exist.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

removeUserAttribute

public void removeUserAttribute(User user,
                                String attributeName)
                         throws UserNotFoundException,
                                OperationNotPermittedException,
                                OperationFailedException
Description copied from interface: CrowdService
Removes all the values for a single attribute key for a user.

Specified by:
removeUserAttribute in interface CrowdService
Parameters:
user - user to update.
attributeName - name of attribute to remove.
Throws:
UserNotFoundException - user with supplied username does not exist.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

removeAllUserAttributes

public void removeAllUserAttributes(User user)
                             throws UserNotFoundException,
                                    OperationNotPermittedException,
                                    OperationFailedException
Description copied from interface: CrowdService
Remove all attributes for a user.

Specified by:
removeAllUserAttributes in interface CrowdService
Parameters:
user - user to update.
Throws:
UserNotFoundException - user with supplied username does not exist.
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

removeUser

public boolean removeUser(User user)
                   throws OperationNotPermittedException,
                          OperationFailedException
Description copied from interface: CrowdService
Removes the user that matches the supplied name.

Specified by:
removeUser in interface CrowdService
Parameters:
user - user to remove.
Returns:
true if the user was removed as a result of this call, false if the user does not exist.
Throws:
OperationNotPermittedException - if the directory has been configured to not allow the operation to be performed
OperationFailedException - underlying directory implementation failed to execute the operation.

searchUsersAllowingDuplicateNames

public Iterable<User> searchUsersAllowingDuplicateNames(Query<User> query)
Description copied from interface: CrowdService
Searches for User entities that match the supplied search query. Users with duplicate user names can be returned.

Specified by:
searchUsersAllowingDuplicateNames in interface CrowdService
Parameters:
query - the search query.
Returns:
User entities matching the search query. An Iterable containing no results will be returned if there are no matches for the query.


Copyright © 2012 Atlassian. All Rights Reserved.