Class ExternalId

    • Constructor Detail

      • ExternalId

        public ExternalId()
    • Method Detail

      • isValidUsername

        public static boolean isValidUsername​(String username)
      • getUserName

        public static Optional<String> getUserName​(Collection<ExternalId> extIds)
        Returns the ID of the first external ID from the provided external IDs that has the SCHEME_USERNAME scheme.
        Parameters:
        extIds - external IDs
        Returns:
        the ID of the first external ID from the provided external IDs that has the SCHEME_USERNAME scheme
      • getEmails

        public static Stream<String> getEmails​(Collection<ExternalId> extIds)
        Returns all IDs of the provided external IDs that have the SCHEME_MAILTO scheme as a distinct stream.
        Parameters:
        extIds - external IDs
        Returns:
        distinct stream of all IDs of the provided external IDs that have the SCHEME_MAILTO scheme
      • create

        public static ExternalId create​(String scheme,
                                        String id,
                                        Account.Id accountId)
        Creates an external ID.
        Parameters:
        scheme - the scheme name, must not contain colons (':')
        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 static 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 (':')
        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
      • createUsername

        public static 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 static 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 (':')
        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
      • parse

        public static 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 contain the external ID as an 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
         
        Throws:
        org.eclipse.jgit.errors.ConfigInvalidException
      • parse

        public static ExternalId parse​(String noteId,
                                       org.eclipse.jgit.lib.Config externalIdConfig,
                                       org.eclipse.jgit.lib.ObjectId blobId)
                                throws org.eclipse.jgit.errors.ConfigInvalidException
        Throws:
        org.eclipse.jgit.errors.ConfigInvalidException
      • accountId

        public abstract Account.Id accountId()
      • email

        public abstract String email()
      • password

        public abstract String password()
      • blobId

        public abstract org.eclipse.jgit.lib.ObjectId blobId()
        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.
      • checkThatBlobIdIsSet

        public void checkThatBlobIdIsSet()
      • isScheme

        public boolean isScheme​(String scheme)
      • toByteArray

        public byte[] toByteArray()
      • equals

        public final boolean equals​(Object obj)
        For checking if two external IDs are equals the blobId is excluded and external IDs that have different blob IDs but identical other fields are considered equal. This way an external ID that was loaded from Git can be equal with an external ID that was created from code.
        Overrides:
        equals in class Object
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public final String toString()
        Exports this external ID as Git config file text.

        The Git config has 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
         
        Overrides:
        toString in class Object
      • writeToConfig

        public void writeToConfig​(org.eclipse.jgit.lib.Config c)