
com.bcgdv.jwt.providers.AsymmetricSecurityKeyProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of token-generation Show documentation
Show all versions of token-generation Show documentation
JWT token generation with encrypted payloads and CLI
package com.bcgdv.jwt.providers;
import com.bcgdv.jwt.models.AsymmetricKeyInfo;
import com.google.common.base.Preconditions;
import com.google.inject.Provider;
import javax.inject.Inject;
import static com.bcgdv.jwt.Keys.ASYMMETRIC_PRIVATE_KEY;
import static com.bcgdv.jwt.Keys.ASYMMETRIC_PUBLIC_KEY;
import static com.bcgdv.jwt.util.PropUtil.getEnvOrProperty;
/**
* Provider implementaiton for @AsymmetricKeyInfo. Does check system properties for values.
*/
public class AsymmetricSecurityKeyProvider implements Provider {
/**
* Error messages
*/
protected static final String PRIV_KEY_ERROR = "Private key should be configured as environment variable or property: " + ASYMMETRIC_PRIVATE_KEY.toString();
protected static final String PUB_KEY_ERROR = "Public key should be configured as environment variable or property: " + ASYMMETRIC_PUBLIC_KEY.toString();
/**
* Needed for Guice
*/
@Inject
public AsymmetricSecurityKeyProvider() {
}
/**
* Build @AsymmetricKeyInfo and return.
* @return as @AsymmetricKeyInfo
*/
@Override
public AsymmetricKeyInfo get() {
String privateKey = Preconditions.checkNotNull(getEnvOrProperty(ASYMMETRIC_PRIVATE_KEY.toString()), PRIV_KEY_ERROR).trim();
String publicKey = Preconditions.checkNotNull(getEnvOrProperty(ASYMMETRIC_PUBLIC_KEY.toString()), PUB_KEY_ERROR).trim();
return new AsymmetricKeyInfo(publicKey, privateKey);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy