@Requirement(reqId="DOI_AUTH_020", reqName="Authentification par token") public final class TokenSecurity extends Object
Modifier and Type | Class and Description |
---|---|
static class |
TokenSecurity.TimeUnit
Time unit.
|
private static class |
TokenSecurity.TokenSecurityHolder
Class to handle the instance
|
Modifier and Type | Field and Description |
---|---|
static String |
DATE_FORMAT
Default date format for the token "EEE MMM dd HH:mm:ss z yyyy"
|
static String |
DEFAULT_TOKEN_KEY
Default token key.
|
private static org.apache.logging.log4j.Logger |
LOG
Logger.
|
static String |
PROJECT_ID
Project ID name in token.
|
static String |
PROJECT_NAME
Project name in token.
|
private static AbstractTokenDBHelper |
TOKEN_DB
Plugin for token database.
|
private String |
tokenKey
token key.
|
Modifier | Constructor and Description |
---|---|
private |
TokenSecurity()
Private constructor.
|
Modifier and Type | Method and Description |
---|---|
private Date |
computeExpirationDate(Date now,
int calendarTime,
int amount)
Computes the expiration date.
|
static String |
createKeySignatureHS256()
Creates a key for token signature encoded with the algorithm HS256
|
String |
generate(String userID,
int projectID,
TokenSecurity.TimeUnit timeUnit,
int amount)
Creates a token.
|
String |
generate(String userID,
TokenSecurity.TimeUnit timeUnit,
int amount)
Creates a token.
|
static TokenSecurity |
getInstance()
Access to unique INSTANCE of Settings
|
AbstractTokenDBHelper |
getTokenDB()
Returns the token DB.
|
io.jsonwebtoken.Jws<io.jsonwebtoken.Claims> |
getTokenInformation(String jwtToken)
Returns the token information.
|
String |
getTokenKey()
Returns the token key computed by the algorithm HS256.
|
private void |
init()
Init.
|
boolean |
isExpired(String token)
Returns true when the token is expired otherwise false.
|
void |
setTokenKey(String tokenKey)
Sets a custom token key.
|
private String tokenKey
public static final String PROJECT_ID
public static final String PROJECT_NAME
public static final String DEFAULT_TOKEN_KEY
public static final String DATE_FORMAT
private static final AbstractTokenDBHelper TOKEN_DB
private static final org.apache.logging.log4j.Logger LOG
public static TokenSecurity getInstance()
public static String createKeySignatureHS256()
private void init()
public String generate(String userID, int projectID, TokenSecurity.TimeUnit timeUnit, int amount) throws TokenSecurityException
userID
- The user that creates the tokenprojectID
- The project IDtimeUnit
- The time unit for the date expirationamount
- the amount of timeUnit for the date expirationTokenSecurityException
- if the projectID is
not first registeredpublic String generate(String userID, TokenSecurity.TimeUnit timeUnit, int amount)
userID
- The user that creates the tokentimeUnit
- The time unit for the date expirationamount
- the amount of timeUnit for the date expirationpublic String getTokenKey()
public void setTokenKey(String tokenKey)
tokenKey
- token keypublic boolean isExpired(String token)
token
- tokenpublic io.jsonwebtoken.Jws<io.jsonwebtoken.Claims> getTokenInformation(String jwtToken) throws DoiRuntimeException
jwtToken
- token JWTDoiRuntimeException
- - if an error happens getting information
from the tokenpublic AbstractTokenDBHelper getTokenDB()
Copyright © 2017–2020 CNES. All rights reserved.