All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.galasa.framework.spi.creds.CredentialsToken Maven / Gradle / Ivy

There is a newer version: 0.37.0
Show newest version
/*
 * Copyright contributors to the Galasa project
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package dev.galasa.framework.spi.creds;

import java.util.Properties;

import javax.crypto.spec.SecretKeySpec;

import dev.galasa.ICredentialsToken;

public class CredentialsToken extends AbstractCredentials implements ICredentialsToken {
    private final byte[] token;

    public CredentialsToken(String plainTextToken) {
        this.token = plainTextToken.getBytes();
    }

    public CredentialsToken(SecretKeySpec key, String stoken) throws CredentialsException {
        super(key);

        String decryptedToken = decryptToString(stoken);
        if (decryptedToken == null) {
            this.token = decode(stoken);
        } else {
            this.token = decryptedToken.getBytes();
        }
    }

    public byte[] getToken() {
        return token;
    }

    @Override
    public Properties toProperties(String credentialsId) {
        Properties credsProperties = new Properties();
        credsProperties.setProperty(CREDS_PROPERTY_PREFIX + credentialsId + ".token" , new String(this.token));
        return credsProperties;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy