Class ExternalIdFactory


  • @Singleton
    public class ExternalIdFactory
    extends Object
    • Method Detail

      • create

        public ExternalId create​(String scheme,
                                 String id,
                                 Account.Id accountId)
        Creates an external ID.
        Parameters:
        scheme - the scheme name, must not contain colons (':'). E.g. ExternalId.SCHEME_USERNAME.
        id - the external ID, must not contain colons (':')
        accountId - the ID of the account to which the external ID belongs
        Returns:
        the created external ID
      • create

        public ExternalId create​(String scheme,
                                 String id,
                                 Account.Id accountId,
                                 String email,
                                 String hashedPassword)
        Creates an external ID.
        Parameters:
        scheme - the scheme name, must not contain colons (':'). E.g. ExternalId.SCHEME_USERNAME.
        id - the external ID, must not contain colons (':')
        accountId - the ID of the account to which the external ID belongs
        email - the email of the external ID, may be null
        hashedPassword - the hashed password of the external ID, may be null
        Returns:
        the created external ID
      • create

        public ExternalId create​(ExternalId.Key key,
                                 Account.Id accountId)
        Creates an external ID.
        Parameters:
        key - the external Id key
        accountId - the ID of the account to which the external ID belongs
        Returns:
        the created external ID
      • create

        public ExternalId create​(ExternalId.Key key,
                                 Account.Id accountId,
                                 String email,
                                 String hashedPassword)
        Creates an external ID.
        Parameters:
        key - the external Id key
        accountId - the ID of the account to which the external ID belongs
        email - the email of the external ID, may be null
        hashedPassword - the hashed password of the external ID, may be null
        Returns:
        the created external ID
      • createWithPassword

        public ExternalId createWithPassword​(ExternalId.Key key,
                                             Account.Id accountId,
                                             String email,
                                             String plainPassword)
        Creates an external ID adding a hashed password computed from a plain password.
        Parameters:
        key - the external Id key
        accountId - the ID of the account to which the external ID belongs
        email - the email of the external ID, may be null
        plainPassword - the plain HTTP password, may be null
        Returns:
        the created external ID
      • createUsername

        public ExternalId createUsername​(String id,
                                         Account.Id accountId,
                                         String plainPassword)
        Create a external ID for a username (scheme "username").
        Parameters:
        id - the external ID, must not contain colons (':')
        accountId - the ID of the account to which the external ID belongs
        plainPassword - the plain HTTP password, may be null
        Returns:
        the created external ID
      • createWithEmail

        public ExternalId createWithEmail​(String scheme,
                                          String id,
                                          Account.Id accountId,
                                          String email)
        Creates an external ID with an email.
        Parameters:
        scheme - the scheme name, must not contain colons (':'). E.g. ExternalId.SCHEME_USERNAME.
        id - the external ID, must not contain colons (':')
        accountId - the ID of the account to which the external ID belongs
        email - the email of the external ID, may be null
        Returns:
        the created external ID
      • createWithEmail

        public ExternalId createWithEmail​(ExternalId.Key key,
                                          Account.Id accountId,
                                          String email)
        Creates an external ID with an email.
        Parameters:
        key - the external Id key
        accountId - the ID of the account to which the external ID belongs
        email - the email of the external ID, may be null
        Returns:
        the created external ID
      • createEmail

        public ExternalId createEmail​(Account.Id accountId,
                                      String email)
        Creates an external ID using the `mailto`-scheme.
        Parameters:
        accountId - the ID of the account to which the external ID belongs
        email - the email of the external ID, may be null
        Returns:
        the created external ID
      • create

        public ExternalId create​(ExternalId.Key key,
                                 Account.Id accountId,
                                 String email,
                                 String hashedPassword,
                                 org.eclipse.jgit.lib.ObjectId blobId)
        Creates an external ID.
        Parameters:
        key - the external Id key
        accountId - the ID of the account to which the external ID belongs
        email - the email of the external ID, may be null
        hashedPassword - the hashed password of the external ID, may be null
        blobId - the ID of the note blob in the external IDs branch that stores this external ID. null if the external ID was created in code and is not yet stored in Git.
        Returns:
        the created external ID
      • parse

        public ExternalId parse​(String noteId,
                                byte[] raw,
                                org.eclipse.jgit.lib.ObjectId blobId)
                         throws org.eclipse.jgit.errors.ConfigInvalidException
        Parses an external ID from a byte array that contains the external ID as a Git config file text.

        The Git config must have exactly one externalId subsection with an accountId and optionally email and password:

         [externalId "username:jdoe"]
           accountId = 1003407
           email = [email protected]
           password = bcrypt:4:LCbmSBDivK/hhGVQMfkDpA==:XcWn0pKYSVU/UJgOvhidkEtmqCp6oKB7
         
        Parameters:
        noteId - the SHA-1 sum of the external ID used as the note's ID
        raw - a byte array that contains the external ID as a Git config file text.
        blobId - the ID of the note blob in the external IDs branch that stores this external ID. null if the external ID was created in code and is not yet stored in Git.
        Returns:
        the parsed external ID
        Throws:
        org.eclipse.jgit.errors.ConfigInvalidException