Class TokenManager
- java.lang.Object
-
- org.apache.archiva.redback.authentication.TokenManager
-
@Service("tokenManager#jce") public class TokenManager extends Object
Class that manages tokens that are encrypted with a dynamic key. The tokens are converted into BASE64 strings. Each token contains information about username, Created by Martin Stockhammer on 03.02.17.
-
-
Constructor Summary
Constructors Constructor Description TokenManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected TokenData
decrypt(byte[] token)
TokenData
decryptToken(String token)
protected byte[]
doDecrypt(byte[] encryptedData)
protected byte[]
doEncrypt(byte[] data, long nonce)
protected byte[]
encrypt(TokenData info)
String
encryptToken(String user, long lifetime)
String
encryptToken(TokenData tokenData)
String
getAlgorithm()
int
getKeySize()
void
initialize()
void
setAlgorithm(String algorithm)
Sets the encryption algorithm and resets the key size.void
setKeySize(int keySize)
Sets the key size for the encryption.
-
-
-
Constructor Detail
-
TokenManager
public TokenManager()
-
-
Method Detail
-
initialize
@PostConstruct public void initialize() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, EncryptionFailedException, InvalidAlgorithmParameterException
-
encryptToken
public String encryptToken(String user, long lifetime) throws EncryptionFailedException
- Throws:
EncryptionFailedException
-
encryptToken
public String encryptToken(TokenData tokenData) throws EncryptionFailedException
- Throws:
EncryptionFailedException
-
decryptToken
public TokenData decryptToken(String token) throws InvalidTokenException
- Throws:
InvalidTokenException
-
encrypt
protected byte[] encrypt(TokenData info) throws IOException, BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException
-
doEncrypt
protected byte[] doEncrypt(byte[] data, long nonce) throws BadPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
-
decrypt
protected TokenData decrypt(byte[] token) throws BadPaddingException, IllegalBlockSizeException, IOException, ClassNotFoundException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException
-
doDecrypt
protected byte[] doDecrypt(byte[] encryptedData) throws BadPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException
-
getAlgorithm
public String getAlgorithm()
-
setAlgorithm
public void setAlgorithm(String algorithm)
Sets the encryption algorithm and resets the key size. You may change the key size after calling this method. Additionally run the initialize() method after setting algorithm and keysize.- Parameters:
algorithm
- The encryption algorithm to use.
-
getKeySize
public int getKeySize()
-
setKeySize
public void setKeySize(int keySize)
Sets the key size for the encryption. This method must be called after setting the algorithm. The keysize will be reset by callingsetAlgorithm()
The key size must be valid for the given algorithm.- Parameters:
keySize
- The size of the encryption key
-
-