Class AbstractPushService<T extends AbstractPushService<T>>

  • Direct Known Subclasses:
    PushAsyncService, PushService

    public abstract class AbstractPushService<T extends AbstractPushService<T>>
    extends java.lang.Object
    • Constructor Detail

      • AbstractPushService

        public AbstractPushService()
      • AbstractPushService

        public AbstractPushService​(java.lang.String gcmApiKey)
      • AbstractPushService

        public AbstractPushService​(java.security.KeyPair keyPair)
      • AbstractPushService

        public AbstractPushService​(java.security.KeyPair keyPair,
                                   java.lang.String subject)
      • AbstractPushService

        public AbstractPushService​(java.lang.String publicKey,
                                   java.lang.String privateKey)
                            throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • AbstractPushService

        public AbstractPushService​(java.lang.String publicKey,
                                   java.lang.String privateKey,
                                   java.lang.String subject)
                            throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
    • Method Detail

      • encrypt

        public static Encrypted encrypt​(byte[] payload,
                                        org.bouncycastle.jce.interfaces.ECPublicKey userPublicKey,
                                        byte[] userAuth,
                                        Encoding encoding)
                                 throws java.security.GeneralSecurityException
        Encrypt the payload. Encryption uses Elliptic curve Diffie-Hellman (ECDH) cryptography over the prime256v1 curve.
        Parameters:
        payload - Payload to encrypt.
        userPublicKey - The user agent's public key (keys.p256dh).
        userAuth - The user agent's authentication secret (keys.auth).
        encoding -
        Returns:
        An Encrypted object containing the public key, salt, and ciphertext.
        Throws:
        java.security.GeneralSecurityException
      • prepareRequest

        protected final HttpRequest prepareRequest​(Notification notification,
                                                   Encoding encoding)
                                            throws java.security.GeneralSecurityException,
                                                   java.io.IOException,
                                                   org.jose4j.lang.JoseException
        Throws:
        java.security.GeneralSecurityException
        java.io.IOException
        org.jose4j.lang.JoseException
      • setGcmApiKey

        public T setGcmApiKey​(java.lang.String gcmApiKey)
        Set the Google Cloud Messaging (GCM) API key
        Parameters:
        gcmApiKey -
        Returns:
      • getGcmApiKey

        public java.lang.String getGcmApiKey()
      • getSubject

        public java.lang.String getSubject()
      • setSubject

        public T setSubject​(java.lang.String subject)
        Set the JWT subject (for VAPID)
        Parameters:
        subject -
        Returns:
      • setKeyPair

        public T setKeyPair​(java.security.KeyPair keyPair)
        Set the public and private key (for VAPID).
        Parameters:
        keyPair -
        Returns:
      • getPublicKey

        public java.security.PublicKey getPublicKey()
      • setPublicKey

        public T setPublicKey​(java.lang.String publicKey)
                       throws java.security.NoSuchAlgorithmException,
                              java.security.NoSuchProviderException,
                              java.security.spec.InvalidKeySpecException
        Set the public key using a base64url-encoded string.
        Parameters:
        publicKey -
        Returns:
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.NoSuchProviderException
        java.security.spec.InvalidKeySpecException
      • getPrivateKey

        public java.security.PrivateKey getPrivateKey()
      • getKeyPair

        public java.security.KeyPair getKeyPair()
      • setPublicKey

        public T setPublicKey​(java.security.PublicKey publicKey)
        Set the public key (for VAPID)
        Parameters:
        publicKey -
        Returns:
      • setPrivateKey

        public T setPrivateKey​(java.lang.String privateKey)
                        throws java.security.NoSuchAlgorithmException,
                               java.security.NoSuchProviderException,
                               java.security.spec.InvalidKeySpecException
        Set the public key using a base64url-encoded string.
        Parameters:
        privateKey -
        Returns:
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.NoSuchProviderException
        java.security.spec.InvalidKeySpecException
      • setPrivateKey

        public T setPrivateKey​(java.security.PrivateKey privateKey)
        Set the private key (for VAPID)
        Parameters:
        privateKey -
        Returns:
      • vapidEnabled

        protected boolean vapidEnabled()
        Check if VAPID is enabled
        Returns: