Search in sources :

Example 1 with InferredAuthException

use of com.google.cloud.tools.jib.plugins.common.InferredAuthException in project jib by google.

the class MavenSettingsServerCredentials method inferAuth.

/**
 * Retrieves credentials for {@code registry} from Maven settings.
 *
 * @param registry the registry
 * @return the auth info for the registry, or {@link Optional#empty} if none could be retrieved
 */
@Override
public Optional<AuthProperty> inferAuth(String registry) throws InferredAuthException {
    Server server = getServerFromMavenSettings(registry);
    if (server == null) {
        return Optional.empty();
    }
    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult result = decrypter.decrypt(request);
    // If there are any ERROR or FATAL problems reported, then decryption failed.
    for (SettingsProblem problem : result.getProblems()) {
        if (problem.getSeverity() == SettingsProblem.Severity.ERROR || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
            throw new InferredAuthException("Unable to decrypt server(" + registry + ") info from settings.xml: " + problem);
        }
    }
    Server resultServer = result.getServer();
    String username = resultServer.getUsername();
    String password = resultServer.getPassword();
    return Optional.of(new AuthProperty() {

        @Override
        public String getUsername() {
            return username;
        }

        @Override
        public String getPassword() {
            return password;
        }

        @Override
        public String getAuthDescriptor() {
            return CREDENTIAL_SOURCE;
        }

        @Override
        public String getUsernameDescriptor() {
            return CREDENTIAL_SOURCE;
        }

        @Override
        public String getPasswordDescriptor() {
            return CREDENTIAL_SOURCE;
        }
    });
}
Also used : InferredAuthException(com.google.cloud.tools.jib.plugins.common.InferredAuthException) AuthProperty(com.google.cloud.tools.jib.plugins.common.AuthProperty) Server(org.apache.maven.settings.Server) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 2 with InferredAuthException

use of com.google.cloud.tools.jib.plugins.common.InferredAuthException in project jib by GoogleContainerTools.

the class MavenSettingsServerCredentials method inferAuth.

/**
 * Retrieves credentials for {@code registry} from Maven settings.
 *
 * @param registry the registry
 * @return the auth info for the registry, or {@link Optional#empty} if none could be retrieved
 */
@Override
public Optional<AuthProperty> inferAuth(String registry) throws InferredAuthException {
    Server server = getServerFromMavenSettings(registry);
    if (server == null) {
        return Optional.empty();
    }
    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult result = decrypter.decrypt(request);
    // If there are any ERROR or FATAL problems reported, then decryption failed.
    for (SettingsProblem problem : result.getProblems()) {
        if (problem.getSeverity() == SettingsProblem.Severity.ERROR || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
            throw new InferredAuthException("Unable to decrypt server(" + registry + ") info from settings.xml: " + problem);
        }
    }
    Server resultServer = result.getServer();
    String username = resultServer.getUsername();
    String password = resultServer.getPassword();
    return Optional.of(new AuthProperty() {

        @Override
        public String getUsername() {
            return username;
        }

        @Override
        public String getPassword() {
            return password;
        }

        @Override
        public String getAuthDescriptor() {
            return CREDENTIAL_SOURCE;
        }

        @Override
        public String getUsernameDescriptor() {
            return CREDENTIAL_SOURCE;
        }

        @Override
        public String getPasswordDescriptor() {
            return CREDENTIAL_SOURCE;
        }
    });
}
Also used : InferredAuthException(com.google.cloud.tools.jib.plugins.common.InferredAuthException) AuthProperty(com.google.cloud.tools.jib.plugins.common.AuthProperty) Server(org.apache.maven.settings.Server) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Aggregations

AuthProperty (com.google.cloud.tools.jib.plugins.common.AuthProperty)2 InferredAuthException (com.google.cloud.tools.jib.plugins.common.InferredAuthException)2 Server (org.apache.maven.settings.Server)2 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)2 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)2 SettingsDecryptionRequest (org.apache.maven.settings.crypto.SettingsDecryptionRequest)2 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)2