Class DefaultSecureTokenService

  • All Implemented Interfaces:
    SecureTokenService, org.springframework.beans.factory.InitializingBean

    public class DefaultSecureTokenService
    extends java.lang.Object
    implements SecureTokenService, org.springframework.beans.factory.InitializingBean
    Default implementation of SecureTokenService
    • Constructor Detail

      • DefaultSecureTokenService

        public DefaultSecureTokenService()
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws org.apache.commons.codec.DecoderException,
                                       java.security.NoSuchAlgorithmException
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        org.apache.commons.codec.DecoderException
        java.security.NoSuchAlgorithmException
      • getRandom

        protected java.security.SecureRandom getRandom()
      • getSignatureKeyBytes

        protected byte[] getSignatureKeyBytes()
      • getEncryptionKeyBytes

        protected byte[] getEncryptionKeyBytes()
      • encryptData

        public java.lang.String encryptData​(SecureToken data)
        Description copied from interface: SecureTokenService
        Encrypt the SecureToken parameter to a String
        Specified by:
        encryptData in interface SecureTokenService
        Parameters:
        data - The unencrypted token data
        Returns:
        encrypted token
      • decryptData

        public SecureToken decryptData​(java.lang.String token)
        Description copied from interface: SecureTokenService
        Decrypt the token to a SecureToken.
        Specified by:
        decryptData in interface SecureTokenService
        Parameters:
        token - the encrypted token data
        Returns:
        decrypted SecureToken
      • decodeHexString

        protected byte[] decodeHexString​(java.lang.String text)
                                  throws org.apache.commons.codec.DecoderException
        Throws:
        org.apache.commons.codec.DecoderException
      • computePaddingLengths

        protected int[] computePaddingLengths()
      • generatePadding

        protected byte[] generatePadding​(int length)
      • generateSignature

        protected byte[] generateSignature​(byte[] data,
                                           int offset,
                                           int length,
                                           byte[] signatureKeyBytes)
                                    throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • encrypt

        protected java.lang.String encrypt​(byte[] plainText,
                                           byte[] encryptionKeyBytes)
                                    throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • convert

        protected java.lang.String convert​(byte[] data)
      • buildSecretKey

        protected javax.crypto.spec.SecretKeySpec buildSecretKey​(byte[] encryptionKeyBytes)
      • skipPadding

        protected void skipPadding​(java.io.DataInputStream dataInputStream)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • validateSignature

        protected boolean validateSignature​(byte[] dataBytes,
                                            int dataOffset,
                                            int dataLength,
                                            byte[] signatureBytes,
                                            int signatureOffset,
                                            byte[] signatureKeyBytes)
                                     throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • arrayEquals

        protected boolean arrayEquals​(byte[] array1,
                                      int offset1,
                                      byte[] array2,
                                      int offset2,
                                      int length)
      • decrypt

        protected byte[] decrypt​(java.lang.String encryptedText,
                                 byte[] encryptionKeyBytes)
                          throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • createChecksum

        protected java.lang.String createChecksum​(java.lang.String data)
                                           throws java.io.IOException,
                                                  java.security.NoSuchAlgorithmException
        Throws:
        java.io.IOException
        java.security.NoSuchAlgorithmException
      • getSignatureKeyHex

        protected java.lang.String getSignatureKeyHex()
      • setSignatureKeyHex

        public void setSignatureKeyHex​(java.lang.String signatureKeyHex)
        Parameters:
        signatureKeyHex - the signatureKeyHex to set
      • getEncryptionKeyHex

        protected java.lang.String getEncryptionKeyHex()
      • setEncryptionKeyHex

        public void setEncryptionKeyHex​(java.lang.String encryptionKeyHex)
        Parameters:
        encryptionKeyHex - the encryptionKeyHex to set