Package org.silverpeas.core.web.token
Class SilverpeasWebTokenService
- java.lang.Object
-
- org.silverpeas.core.web.token.SilverpeasWebTokenService
-
@Technical @Bean @Singleton public class SilverpeasWebTokenService extends Object
This service allows generating several WEB tokens per identifier.An identifier represents any kind of resource (Service, entity, etc.).
This allows a service to identify use token to identify resources without using the real identifiers.
Generated tokens MUST be cleared by the service which creating them.
- Author:
- silveryocha
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SilverpeasWebTokenService.WebToken
-
Field Summary
Fields Modifier and Type Field Description protected static int
MAX_TOKENS_PER_ID
-
Constructor Summary
Constructors Constructor Description SilverpeasWebTokenService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<String>
consumeIdentifierBy(String tokenValue)
Gets the identifier behind the given token value.SilverpeasWebTokenService.WebToken
generateFor(String identifier)
Generates a new token linked to an identifier.static SilverpeasWebTokenService
get()
void
revokeById(String id)
Removes all generated token for an identifier.
-
-
-
Field Detail
-
MAX_TOKENS_PER_ID
protected static final int MAX_TOKENS_PER_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
get
public static SilverpeasWebTokenService get()
-
generateFor
public SilverpeasWebTokenService.WebToken generateFor(String identifier)
Generates a new token linked to an identifier.The token is put into cache.
To retrieve the identifier, please use
consumeIdentifierBy(String)
.At most
MAX_TOKENS_PER_ID
tokens CAN be generated per identifier. When this limit is reached, the next takes previous token space.- Parameters:
identifier
- any identifier as string managed by any service.- Returns:
- a new instance of
SilverpeasWebTokenService.WebToken
.
-
consumeIdentifierBy
public Optional<String> consumeIdentifierBy(String tokenValue)
Gets the identifier behind the given token value.- Parameters:
tokenValue
- a token value.- Returns:
- an optional string representing the identifier behind the token.
-
revokeById
public void revokeById(String id)
Removes all generated token for an identifier.- Parameters:
id
- any identifier.
-
-