credentialmanager

A simple credential manager.

License

License

MIT
GroupId

GroupId

com.github.philippheuer.credentialmanager
ArtifactId

ArtifactId

credentialmanager
Last Version

Last Version

0.1.2
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

credentialmanager
A simple credential manager.
Project URL

Project URL

https://github.com/PhilippHeuer/credential-manager
Source Code Management

Source Code Management

https://github.com/PhilippHeuer/credential-manager

Download credentialmanager

Dependencies

runtime (4)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.30
org.apache.commons : commons-lang3 jar 3.10
com.squareup.okhttp3 : okhttp jar 4.6.0
com.fasterxml.jackson.core : jackson-databind jar 2.12.2

Project Modules

There are no modules declared in this project.

CredentialManager

Description

A simple OAuth Client & CredentialManager Library, that supports multiple storage backends.

Import

Maven:

Add the repository to your pom.xml with:

<repositories>
    <repository>
      <id>jcenter</id>
      <url>https://jcenter.bintray.com/</url>
    </repository>
</repositories>

and the dependency: (latest, you should use the actual version here)

<dependency>
    <groupId>com.github.philippheuer.credentialmanager</groupId>
    <artifactId>credentialmanager</artifactId>
    <version>0.0.6</version>
    <type>pom</type>
</dependency>

Gradle:

Add the repository to your build.gradle with:

repositories {
	jcenter()
}

and the dependency:

compile 'com.github.philippheuer.credentialmanager:credentialmanager:0.0.5'

Initialization

Credential Manager

CredentialManager credentialManager = CredentialManagerBuilder.builder()
    .withStorageBackend(new TemporaryStorageBackend())
    .build();

Custom Storage Backends

This is a in-memory storage backend as example, you can use your own as supplied in the builder to store/load the credentials from whereever you want.

public class TemporaryStorageBackend implements IStorageBackend {

    /**
     * Holds the Credentials
     */
    private List<Credential> credentialStorage = new ArrayList<>();

    /**
     * Load the Credentials
     *
     * @return List Credential
     */
    public List<Credential> loadCredentials() {
        return this.credentialStorage;
    }

    /**
     * Save the Credentials
     *
     * @param credentials List Credential
     */
    public void saveCredentials(List<Credential> credentials) {
        this.credentialStorage = credentials;
    }
    
    /**
     * Gets a credential by user id
     *
     * @param userId User Id
     * @return Credential
     */
    public Optional<Credential> getCredentialByUserId(String userId) {
        for(Credential cred : credentialStorage) {
            if (cred.getUserId().equalsIgnoreCase(userId)) {
                return Optional.ofNullable(cred);
            }
        }

        return Optional.empty();
    }

}

License

Released under the MIT License.

Versions

Version
0.1.2