dev.galasa.framework.spi.creds.CredentialsUsernamePassword Maven / Gradle / Ivy
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package dev.galasa.framework.spi.creds;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import javax.crypto.spec.SecretKeySpec;
import dev.galasa.ICredentialsUsernamePassword;
public class CredentialsUsernamePassword extends AbstractCredentials implements ICredentialsUsernamePassword {
private String username;
private String password;
public CredentialsUsernamePassword(String plainTextUsername, String plainTextPassword) {
this.username = plainTextUsername;
this.password = plainTextPassword;
}
public CredentialsUsernamePassword(SecretKeySpec key, String username, String password)
throws CredentialsException {
super(key);
this.username = decryptToString(username);
this.password = decryptToString(password);
if (this.username == null) {
this.username = new String(decode(username), StandardCharsets.UTF_8);
}
if (this.password == null) {
this.password = new String(decode(password), StandardCharsets.UTF_8);
}
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
@Override
public Properties toProperties(String credentialsId) {
Properties credsProperties = new Properties();
credsProperties.setProperty(CREDS_PROPERTY_PREFIX + credentialsId + ".username" , this.username);
credsProperties.setProperty(CREDS_PROPERTY_PREFIX + credentialsId + ".password" , this.password);
return credsProperties;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy