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

org.infinispan.server.security.PasswordCredentialSource Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev05
Show newest version
package org.infinispan.server.security;

import java.io.IOException;
import java.security.spec.AlgorithmParameterSpec;
import java.util.function.Supplier;

import org.wildfly.security.auth.SupportLevel;
import org.wildfly.security.credential.Credential;
import org.wildfly.security.credential.PasswordCredential;
import org.wildfly.security.credential.source.CredentialSource;
import org.wildfly.security.password.interfaces.ClearPassword;

/**
 * @since 14.0
 */
public class PasswordCredentialSource implements CredentialSource, Supplier {
   private final PasswordCredential credential;

   public PasswordCredentialSource(char[] password) {
      this(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password)));
   }

   public PasswordCredentialSource(PasswordCredential credential) {
      this.credential = credential;
   }

   @Override
   public SupportLevel getCredentialAcquireSupport(Class credentialType, String s, AlgorithmParameterSpec algorithmParameterSpec) {
      return credentialType == PasswordCredential.class ? SupportLevel.SUPPORTED : SupportLevel.UNSUPPORTED;
   }

   @Override
   public  C getCredential(Class credentialType, String s, AlgorithmParameterSpec algorithmParameterSpec) throws IOException {
      return credentialType.cast(credential.clone());
   }

   @Override
   public CredentialSource get() {
      return this;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy