public static String createAuthorizationHeader(AuthCredentialsServiceState authState) { if (authState == null) { return null; } if (AuthCredentialsType.Bearer.toString().equals(authState.type)) { String token = EncryptionUtils.decrypt(authState.privateKey); return "Bearer " + token; } AuthCredentialsType authCredentialsType = AuthCredentialsType.valueOf(authState.type); if (AuthCredentialsType.Password == authCredentialsType) { String username = authState.userEmail; String password = EncryptionUtils.decrypt(authState.privateKey); String code = new String(Base64.getEncoder().encode( (username + ":" + password).getBytes())); return "Basic " + code; } return null; }
public static KubeConfig constructKubeConfig(String clusterAddress, AuthCredentialsServiceState credentials) { KubeConfig config = createKubeConfig(clusterAddress); KubeConfig.UserEntry userEntry = new KubeConfig.UserEntry(); userEntry.name = config.contexts.get(0).context.user; userEntry.user = new KubeConfig.AuthInfo(); config.users = Arrays.asList(userEntry); AuthCredentialsType credentialsType = AuthCredentialsType.valueOf(credentials.type); switch (credentialsType) { case Bearer: userEntry.user.token = EncryptionUtils.decrypt(credentials.privateKey); break; case PublicKey: userEntry.user.clientCertificateData = new String( Base64.getEncoder().encode(credentials.publicKey.getBytes())); userEntry.user.clientKeyData = new String(Base64.getEncoder() .encode(EncryptionUtils.decrypt(credentials.privateKey).getBytes())); break; case Password: userEntry.user.username = credentials.userEmail; userEntry.user.password = EncryptionUtils.decrypt(credentials.privateKey); break; default: throw new LocalizableValidationException("Unsupported credentials type", "adapter.unsuported.auth.credentials.type"); } return config; }
/** * Login in PKS and returns PKS context instance with token. */ private DeferredResult<PKSContext> login(Endpoint endpoint, AuthCredentialsServiceState authCredentials) { if (authCredentials == null) { return DeferredResult.completed(PKSContext.create(endpoint, null)); } AuthCredentialsType authCredentialsType = AuthCredentialsType.valueOf(authCredentials.type); if (AuthCredentialsType.Password == authCredentialsType) { String username = authCredentials.userEmail; String password = EncryptionUtils.decrypt(authCredentials.privateKey); return getClient() .login(endpoint.uaaEndpoint, username, password) .thenApply(uaaTokenResponse -> PKSContext.create(endpoint, uaaTokenResponse)); } throw new IllegalArgumentException("Credential type " + authCredentialsType.name() + " is not supported"); }
if (registryState.authCredentials != null) { AuthCredentialsServiceState authState = registryState.authCredentials; AuthCredentialsType authType = AuthCredentialsType.valueOf(authState.type); if (AuthCredentialsType.Password == authType) {