Package io.meeds.tenant.metamask.service
Class MetamaskLoginService
- java.lang.Object
-
- io.meeds.tenant.metamask.service.MetamaskLoginService
-
- All Implemented Interfaces:
org.picocontainer.Startable
public class MetamaskLoginService extends Object implements org.picocontainer.Startable
-
-
Field Summary
Fields Modifier and Type Field Description static StringALLOWED_ROOT_ACCESS_WALLETS_PARAMprotected static org.exoplatform.services.log.LogLOGstatic StringLOGIN_MESSAGE_ATTRIBUTE_NAMEstatic StringMETAMASK_ALLOW_REGISTRATION_PARAMstatic StringSECURE_ROOT_ACCESS_WITH_METAMASK_PARAM
-
Constructor Summary
Constructors Constructor Description 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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgenerateLoginMessage(javax.servlet.http.HttpSession session)Generates a new Login Message to sign by current user and store it inHttpSession.StringgenerateLoginMessage(javax.servlet.http.HttpSession session, boolean renew)Generates a new Login Message to sign by current user and store it inHttpSession.StringgetLoginMessage(javax.servlet.http.HttpSession session)Retrieves Login Message to Sign with Metamask Generated and stored in HTTP SessionStringgetUserWithWalletAddress(String walletAddress)Retrieves User name with associated wallet AddressbooleanisAllowUserRegistration()booleanisAllowUserRegistration(String walletAddress)booleanisSuperUser(String walletAddress)org.exoplatform.services.organization.UserregisterUser(String username, String fullName, String email)Register new User in platform based on Username, display name and email.voidstart()voidstop()booleanvalidateSignedMessage(String walletAddress, String rawMessage, String signedMessage)Validates signed message by a wallet using Metamask
-
-
-
Field Detail
-
LOGIN_MESSAGE_ATTRIBUTE_NAME
public static final String LOGIN_MESSAGE_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
METAMASK_ALLOW_REGISTRATION_PARAM
public static final String METAMASK_ALLOW_REGISTRATION_PARAM
- See Also:
- Constant Field Values
-
SECURE_ROOT_ACCESS_WITH_METAMASK_PARAM
public static final String SECURE_ROOT_ACCESS_WITH_METAMASK_PARAM
- See Also:
- Constant Field Values
-
ALLOWED_ROOT_ACCESS_WALLETS_PARAM
public static final String ALLOWED_ROOT_ACCESS_WALLETS_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:
startin interfaceorg.picocontainer.Startable
-
stop
public void stop()
- Specified by:
stopin interfaceorg.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 messagesignedMessage- 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 inHttpSession. If renew = true, a new Token will be generated even if alread exists inHttpSession, else the token already generated will be returned- Parameters:
session-HttpSessionrenew- boolean- Returns:
- already existing token in
HttpSessionor 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 inHttpSession. 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
HttpSessionor 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-HttpSessionof 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-StringfullName-Stringemail-Stringwith already validated email format- Returns:
- created
User - Throws:
RegistrationException- when a registration error happens. The error code will be added into exception message
-
-