/*
 * JBoss, the OpenSource WebOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.security.plugins;

import java.io.IOException;
import javax.management.ObjectName;
import org.jboss.system.ServiceMBean;


/** The JaasSecurityDomainMBean adds support for KeyStore management.

 @author Scott.Stark@jboss.org
 @author <a href="mailto:jasone@greenrivercomputing.com">Jason Essington</a>
 @version $Revision: 1.7 $
*/
public interface JaasSecurityDomainMBean extends ServiceMBean
{
   /** KeyStore implementation type being used.
    @return the KeyStore implementation type being used.
    */
   public String getKeyStoreType();
   /** Set the type of KeyStore implementation to use. This is
    passed to the KeyStore.getInstance() factory method.
    */
   public void setKeyStoreType(String type);
   /** Get the KeyStore database URL string.
    */
   public String getKeyStoreURL();
   /** Set the KeyStore database URL string. This is used to obtain
    an InputStream to initialize the KeyStore.
    */
   public void setKeyStoreURL(String storeURL) throws IOException;
    /** Set the credential string for the KeyStore.
    */
   public void setKeyStorePass(String password);

   /** Get the type of the trust store
    * @return the type of the trust store
    */ 
   public String getTrustStoreType();
   /** Set the type of the trust store
    * @param type - the trust store implementation type
    */ 
   public void setTrustStoreType(String type);
   /** Set the credential string for the trust store.
   */
   public void setTrustStorePass(String password);   
   /** Get the trust store database URL string.
    */
   public String getTrustStoreURL();
   /** Set the trust store database URL string. This is used to obtain
    an InputStream to initialize the trust store.
    */
   public void setTrustStoreURL(String storeURL) throws IOException;
   /**
       Reload the key- and truststore
   */
   public void reloadKeyAndTrustStore() throws Exception;
   /** The JMX object name string of the security manager service.
    @return The JMX object name string of the security manager service.
    */
   public ObjectName getManagerServiceName();
   /** Set the JMX object name string of the security manager service.
    */
   public void setManagerServiceName(ObjectName jmxName);

   /** Set the salt used with PBE based on the keystore password.
    * @param salt - an 8 char randomization string
    */ 
   public void setSalt(String salt);
   /** Set the iteration count used with PBE based on the keystore password.
    * @param count - an iteration count randomization value
    */ 
   public void setIterationCount(int count);

   /** Encode a secret using the keystore password and PBEwithMD5andDES algo
    * @param secret - the byte sequence to encrypt
    * @return the encrypted byte sequence
    * @throws Exception
    */ 
   public byte[] encode(byte[] secret)
      throws Exception;

   /** Decode a secret using the keystore password and PBEwithMD5andDES algo
    * @param secret - the byte sequence to decrypt
    * @return the decrypted byte sequence
    * @throws Exception
    */ 
   public byte[] decode(byte[] secret)
      throws Exception;

   /** Encode a secret using the keystore password and PBEwithMD5andDES algo
    * @param secret - the byte sequence to encrypt as a base64 string using
    *    the Util.tob64() function
    * @return the encrypted byte sequence
    * @throws Exception
    */    
   public String encode64(byte[] secret)
      throws Exception;

   /** Decode a secret using the keystore password and PBEwithMD5andDES algo
    * @param secret - the Util.tob64 string represention to decrypt
    * @return the decrypted byte sequence
    * @throws Exception
    */ 
   public byte[] decode64(String secret)
      throws Exception;
}