Search in sources :

Example 1 with TokenList

use of org.graylog2.rest.models.users.responses.TokenList in project graylog2-server by Graylog2.

the class UsersResource method listTokens.

@GET
@Path("{username}/tokens")
@RequiresPermissions(RestPermissions.USERS_TOKENLIST)
@ApiOperation("Retrieves the list of access tokens for a user")
public TokenList listTokens(@ApiParam(name = "username", required = true) @PathParam("username") String username) {
    final User user = _tokensCheckAndLoadUser(username);
    final ImmutableList.Builder<Token> tokenList = ImmutableList.builder();
    for (AccessToken token : accessTokenService.loadAll(user.getName())) {
        tokenList.add(Token.create(token.getName(), token.getToken(), token.getLastAccess()));
    }
    return TokenList.create(tokenList.build());
}
Also used : User(org.graylog2.plugin.database.users.User) ImmutableList(com.google.common.collect.ImmutableList) AccessToken(org.graylog2.security.AccessToken) AccessToken(org.graylog2.security.AccessToken) Token(org.graylog2.rest.models.users.responses.Token) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ApiOperation (io.swagger.annotations.ApiOperation)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 User (org.graylog2.plugin.database.users.User)1 Token (org.graylog2.rest.models.users.responses.Token)1 AccessToken (org.graylog2.security.AccessToken)1