/*
 * MIT Licence
 * Copyright (c) 2017 Simon Frankenberger
 *
 * Please see LICENCE.md for complete licence text.
 */
package eu.fraho.spring.securityJwt.service;

import eu.fraho.spring.securityJwt.dto.JwtUser;
import eu.fraho.spring.securityJwt.dto.RefreshToken;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.InitializingBean;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface RefreshTokenStore extends InitializingBean {
    void saveToken(@NotNull JwtUser user, @NotNull String token);

    <T extends JwtUser> Optional<T> useToken(@NotNull String token);

    @NotNull
    List<RefreshToken> listTokens(@NotNull JwtUser user);

    @NotNull
    Map<Long, List<RefreshToken>> listTokens();

    boolean revokeToken(@NotNull String token);

    int revokeTokens(@NotNull JwtUser user);

    int revokeTokens();

    /**
     * Ask this service if refresh token support is enabled
     * by a third-party addon.
     *
     * @return {@code true} when refresh tokens are supported
     */
    default boolean isRefreshTokenSupported() {
        return true;
    }
}

@@ -504,369 +504,1845 @@
     
-void saveToken(@NotNull JwtUser user, @NotNull String token);%0A%0A    %3CT extends JwtUser%3E Optional%3CT%3E useToken(@NotNull String token);%0A%0A    @NotNull%0A    List%3CRefreshToken%3E listTokens(@NotNull JwtUser user);%0A%0A    @NotNull%0A    Map%3CLong, List%3CRefreshToken%3E%3E listTokens();%0A%0A    boolean revokeToken(@NotNull String token);%0A%0A    int revokeTokens(@NotNull JwtUser user);%0A
+/**%0A     * Save the given token to the underlying backend.%0A     *%0A     * @param user  The token is valid for the given user%0A     * @param token The token to save%0A     */%0A    void saveToken(@NotNull JwtUser user, @NotNull String token);%0A%0A    /**%0A     * Try to use the given token and return the associated userdetails.%0A     *%0A     * @param token The token to use%0A     * @param %3CT%3E   The type of the userdetails, could be a custom implementation%0A     * @return An user instance if the token was valid, otherwise an empty Optional.%0A     */%0A    %3CT extends JwtUser%3E Optional%3CT%3E useToken(@NotNull String token);%0A%0A    /**%0A     * Lists all tokens for the specified user%0A     *%0A     * @param user The user to query for%0A     * @return A List of tokens. Maybe the tokens have not all fields set, this depends%0A     * on the used implementation. (e.g. memcache doesn't know the expiration)%0A     */%0A    @NotNull%0A    List%3CRefreshToken%3E listTokens(@NotNull JwtUser user);%0A%0A    /**%0A     * Lists all tokens stored at the implementation.%0A     *%0A     * @return A Map with all tokens, whery the Key is the userId and the values are a list of%0A     * tokens for that id.%0A     */%0A    @NotNull%0A    Map%3CLong, List%3CRefreshToken%3E%3E listTokens();%0A%0A    /**%0A     * Revoke a single token.%0A     *%0A     * @param token The token to revoke%0A     * @return %3Ccode%3Etrue%3C/code%3E if the token was found and revoked, otherweise %3Ccode%3Efalse%3C/code%3E%0A     */%0A    boolean revokeToken(@NotNull String token);%0A%0A    /**%0A     * Revoke all tokens for that given user (e.g. after password change)%0A     *%0A     * @param user The user which tokens should be revoked%0A     * @return The count of revoked tokens.%0A     */%0A    int revokeTokens(@NotNull JwtUser user);%0A%0A    /**%0A     * Revoke all tokens stored at this implementation.%0A     *%0A     * @return The number of revoked tokens in total.%0A     */
 %0A   

Add javadoc for RefreshTokenStore