Package io.toro.martini
Class UserGroupMethods
- java.lang.Object
-
- io.toro.martini.UserGroupMethods
-
public final class UserGroupMethods extends Object
This class provides methods for access control list management in Gloop.
-
-
Constructor Summary
Constructors Constructor Description UserGroupMethods(io.toro.martini.permissions.AccessControlService accessControlService)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addUserToGroup(String username, String groupname)
Add a user to a group by name.static void
deleteGroupByName(String groupName)
Delete a group by name.static void
deleteUser(String id)
Delete a user by ID.static void
deleteUserByUsername(String username)
Delete a user by username.static GloopModel
findAccessTokenByUserId(String userId)
Retrieves the access token of the user, whose id matches the provided string.static GloopModel
findAccessTokenByUsername(String userName)
Retrieves the access token of the user, whose username matches the provided string.static List<String>
findGroups()
Get the names of all registered groups.static GloopModel
findUser(String username)
Retrieve the user matching the provided username.static GloopModel
findUser(String username, String password)
Retrieve the user, whose credentials match the provided username and password.static GloopModel
findUserByEmail(String emailAddress)
Retrieve a user by email address.static GloopModel
findUserById(String userId)
Retrieve a user by ID.static GloopModel
findUsers(Closure predicateClosure)
Filters existing users, returning only users matching the provided predicate.static GloopModel
generateToken(String userName)
Generates an access token for the user, whose username matches the provided string.static boolean
groupExists(String name)
Checks whether or not a group with the provided name exists.static List<String>
groupsExist(List<String> groupNames)
Filters the provided list of group names, returning only the names of groups that exist.static void
removeUserFromGroup(String username, String groupname)
Remove a user from a group by name.static void
saveGroup(String groupName)
Save a new group.static void
saveUser(GloopModel user)
-
-
-
Constructor Detail
-
UserGroupMethods
@Autowired UserGroupMethods(io.toro.martini.permissions.AccessControlService accessControlService)
-
-
Method Detail
-
findUser
@GloopObjectParameter("user{\n user#io.toro.martini.user.User{\n }\n}") public static GloopModel findUser(@GloopParameter(allowNull=false) String username)
Retrieve the user matching the provided username.- Returns:
- the user, whose username matches the provided string
- Since:
- 1.0
-
findUser
@GloopObjectParameter("user{\n user#io.toro.martini.user.User{\n }\n}") public static GloopModel findUser(@GloopParameter(allowNull=false) String username, @GloopParameter(allowNull=false) String password)
Retrieve the user, whose credentials match the provided username and password.- Returns:
- the user, whose credentials matched the provided username and password
- Since:
- 1.0
-
findUserById
@GloopObjectParameter("user{\n user#io.toro.martini.user.User{\n }\n}") public static GloopModel findUserById(@GloopParameter(allowNull=false) String userId)
Retrieve a user by ID.- Parameters:
userId
- the ID of the user to get- Returns:
- the user, whose ID matches the provided string
- Since:
- 1.0.2
-
findUserByEmail
@GloopObjectParameter("user{\n user#io.toro.martini.user.User{\n }\n}") public static GloopModel findUserByEmail(@GloopParameter(allowNull=false) String emailAddress)
Retrieve a user by email address.- Parameters:
emailAddress
- the email address of the user to get- Returns:
- the user, whose email address matches the provided string
- Since:
- 1.0
-
groupExists
public static boolean groupExists(@GloopParameter(allowNull=false) String name)
Checks whether or not a group with the provided name exists.- Parameters:
name
- the name of the group to look for- Returns:
- true if the provided group exists; false otherwise
- Since:
- 1.0
-
groupsExist
public static List<String> groupsExist(@GloopParameter(allowNull=false) List<String> groupNames)
Filters the provided list of group names, returning only the names of groups that exist.- Parameters:
groupNames
- the list of group names to filter- Returns:
- names of existing groups from the provided list
- Since:
- 1.0
-
saveUser
public static void saveUser(@GloopParameter(allowNull=false) @GloopObjectParameter("user#io.toro.martini.user.User{\n}") GloopModel user)
- Parameters:
user
- the user to persist- Since:
- 1.0
-
findUsers
@GloopObjectParameter("users{\n users#io.toro.martini.user.User[]{\n }\n}") public static GloopModel findUsers(Closure predicateClosure)
Filters existing users, returning only users matching the provided predicate.- Parameters:
predicateClosure
- a Groovy closure that receives one argument, calledit
that is aUser
object; and returns a boolean value indicating whether or not to include a user in the result or not- Returns:
- filtered users
- Since:
- 1.0
-
findGroups
public static List<String> findGroups()
Get the names of all registered groups.- Returns:
- group names
- Since:
- 1.0
-
saveGroup
public static void saveGroup(@GloopParameter(allowNull=false) String groupName)
Save a new group.- Parameters:
groupName
- the name of the group to persist- Since:
- 1.0
-
addUserToGroup
public static void addUserToGroup(@GloopParameter(allowNull=false) String username, @GloopParameter(allowNull=false) String groupname)
Add a user to a group by name.- Parameters:
username
- the name of the user to add to the groupgroupname
- the name of the group where to add the user to- Since:
- 1.0
-
removeUserFromGroup
public static void removeUserFromGroup(@GloopParameter(allowNull=false) String username, @GloopParameter(allowNull=false) String groupname)
Remove a user from a group by name.- Parameters:
username
- the name of the user to remove from the groupgroupname
- the name of the group where to remove the user from- Since:
- 1.0
-
deleteUser
public static void deleteUser(@GloopParameter(allowNull=false) String id)
Delete a user by ID.- Parameters:
id
- the ID of the user to delete- Since:
- 1.0
-
deleteUserByUsername
public static void deleteUserByUsername(@GloopParameter(allowNull=false) String username)
Delete a user by username.- Parameters:
username
- the username of the user to delete- Since:
- 1.0.2
-
deleteGroupByName
public static void deleteGroupByName(@GloopParameter(allowNull=false) String groupName)
Delete a group by name.- Parameters:
groupName
- the name of the group to delete- Since:
- 1.0.2
-
findAccessTokenByUserId
@GloopObjectParameter("token{\n token#io.toro.martini.user.AccessToken{\n }\n}") public static GloopModel findAccessTokenByUserId(String userId)
Retrieves the access token of the user, whose id matches the provided string.- Parameters:
userId
- the ID of the user- Returns:
- the access token, if present
- Since:
- 1.0.2
-
findAccessTokenByUsername
@GloopObjectParameter("token{\n token#io.toro.martini.user.AccessToken{\n }\n}") public static GloopModel findAccessTokenByUsername(String userName)
Retrieves the access token of the user, whose username matches the provided string.- Parameters:
userName
- the username of the user- Returns:
- the access token, if present
- Since:
- 1.0.2
-
generateToken
@GloopObjectParameter("token{\n token#io.toro.martini.user.AccessToken{\n }\n}") public static GloopModel generateToken(String userName)
Generates an access token for the user, whose username matches the provided string.- Parameters:
userName
- the username of the user- Returns:
- the generated token
-
-