Class MetamaskLoginService

  • All Implemented Interfaces:
    org.picocontainer.Startable

    public class MetamaskLoginService
    extends Object
    implements org.picocontainer.Startable
    • Field Detail

      • SECURE_ROOT_ACCESS_WITH_METAMASK_PARAM

        public static final String SECURE_ROOT_ACCESS_WITH_METAMASK_PARAM
        See Also:
        Constant Field Values
      • LOG

        protected static final org.exoplatform.services.log.Log LOG
    • Constructor Detail

      • MetamaskLoginService

        public MetamaskLoginService​(org.exoplatform.services.organization.OrganizationService organizationService,
                                    org.exoplatform.portal.config.UserACL userACL,
                                    org.exoplatform.web.security.security.SecureRandomService secureRandomService,
                                    TenantManagerService tenantManagerService,
                                    org.exoplatform.account.setup.web.AccountSetupService accountSetupService,
                                    org.exoplatform.container.xml.InitParams params)
    • Method Detail

      • start

        public void start()
        Specified by:
        start in interface org.picocontainer.Startable
      • stop

        public void stop()
        Specified by:
        stop in interface org.picocontainer.Startable
      • isAllowUserRegistration

        public boolean isAllowUserRegistration()
        Returns:
        allowUserRegistration parameter value
      • isAllowUserRegistration

        public boolean isAllowUserRegistration​(String walletAddress)
        Parameters:
        walletAddress - wallet address that attempts to register
        Returns:
        allowUserRegistration parameter value, else, it will checks whether the Tenant Manager has been registered to the tenant or not. If not regitered, allow to display the register form, else return false.
      • isSuperUser

        public boolean isSuperUser​(String walletAddress)
        Parameters:
        walletAddress - wallet address
        Returns:
        true if secure root access is allowed and designated wallet is allowed to access using root account
      • getUserWithWalletAddress

        public String getUserWithWalletAddress​(String walletAddress)
        Retrieves User name with associated wallet Address
        Parameters:
        walletAddress - Ethereum Wallet Address
        Returns:
        username
      • validateSignedMessage

        public boolean validateSignedMessage​(String walletAddress,
                                             String rawMessage,
                                             String signedMessage)
        Validates signed message by a wallet using Metamask
        Parameters:
        walletAddress - wallet Address (wallet public key)
        rawMessage - raw signed message
        signedMessage - encrypted message
        Returns:
        true if the message has been decrypted successfully, else false
      • generateLoginMessage

        public String generateLoginMessage​(javax.servlet.http.HttpSession session,
                                           boolean renew)
        Generates a new Login Message to sign by current user and store it in HttpSession. If renew = true, a new Token will be generated even if alread exists in HttpSession, else the token already generated will be returned
        Parameters:
        session - HttpSession
        renew - boolean
        Returns:
        already existing token in HttpSession or a newly generated one
      • generateLoginMessage

        public String generateLoginMessage​(javax.servlet.http.HttpSession session)
        Generates a new Login Message to sign by current user and store it in HttpSession. If a token already exists in session, it will be returned else a newly generated token will be returned
        Parameters:
        session - HttpSession
        Returns:
        already existing token in HttpSession or a newly generated one
      • getLoginMessage

        public String getLoginMessage​(javax.servlet.http.HttpSession session)
        Retrieves Login Message to Sign with Metamask Generated and stored in HTTP Session
        Parameters:
        session - HttpSession of current user
        Returns:
        Login Message
      • registerUser

        public org.exoplatform.services.organization.User registerUser​(String username,
                                                                       String fullName,
                                                                       String email)
                                                                throws RegistrationException
        Register new User in platform based on Username, display name and email.
        Parameters:
        username - String
        fullName - String
        email - String with already validated email format
        Returns:
        created User
        Throws:
        RegistrationException - when a registration error happens. The error code will be added into exception message