Tutorial de Segurança do Java SE - Etapa 3

O restante do tutorial demonstra como ativar a autenticação de cliente antes de se conectar a um servidor do eXtreme Scale. Para se preparar para a próxima etapa deste tutorial, é necessário empacotar o programa SecureSimpleApp.java em um JAR e criar um conjunto de arquivos de configuração, que inclui um arquivo security.xml e dois arquivos de configuração JAAS. O arquivo security.xml permite que você grave a autenticação no ambiente e os arquivos de configuração JAAS fornecem o mecanismo de autenticação durante a conexão com o servidor.

Procedimento

  1. Em uma janela de linha de comandos, acesse o diretório wxs_home/applib criado em Tutorial de Segurança do Java SE - Etapa 1.
  2. Crie e compile a classe SecureSimpleApp.java a seguir:
    SecureSimpleApp.java
    package com.ibm.websphere.objectgrid.security.sample.guide;
    
    import com.ibm.websphere.objectgrid.ClientClusterContext;
    import com.ibm.websphere.objectgrid.ObjectGrid;
    import com.ibm.websphere.objectgrid.ObjectGridManager;
    import com.ibm.websphere.objectgrid.ObjectGridManagerFactory;
    import com.ibm.websphere.objectgrid.security.config.ClientSecurityConfiguration;
    import com.ibm.websphere.objectgrid.security.config.ClientSecurityConfigurationFactory;
    import com.ibm.websphere.objectgrid.security.plugins.CredentialGenerator;
    import com.ibm.websphere.objectgrid.security.plugins.builtins.UserPasswordCredentialGenerator;
    
    public class SecureSimpleApp extends SimpleApp {
    
        public static void main(String[] args) throws Exception  {
    
            SecureSimpleApp app = new SecureSimpleApp();
            app.run(args);
        }
    
        /**
         * Get the ObjectGrid
         * @return an ObjectGrid instance
         * @throws Exception
         */
        protected ObjectGrid getObjectGrid(String[] args) throws Exception {
            ObjectGridManager ogManager = ObjectGridManagerFactory.getObjectGridManager();
            ogManager.setTraceFileName("logs/client.log");
            ogManager.setTraceSpecification("ObjectGrid*=all=enabled:ORBRas=all=enabled");
    
            // Creates a ClientSecurityConfiguration object using the specified file
            ClientSecurityConfiguration clientSC = ClientSecurityConfigurationFactory
                    .getClientSecurityConfiguration(args[0]);
            
            // Creates a CredentialGenerator using the passed-in user and password.
            CredentialGenerator credGen = new UserPasswordCredentialGenerator(args[1], args[2]);
            clientSC.setCredentialGenerator(credGen);
            
            // Create an ObjectGrid by connecting to the catalog server 
            ClientClusterContext ccContext = ogManager.connect("localhost:2809", clientSC, null);
            ObjectGrid og = ogManager.getObjectGrid(ccContext, "accounting");
    
            return og;
    
        }
    
    }
  3. Compile o pacote com estes arquivos e o nome de JAR sec_sample.jar.
  4. Altere para o diretório wxs_home.
  5. Crie um diretório chamado security.
  6. Crie um arquivo de configuração chamado security.xml. As propriedades de segurança do servidor são especificadas neste arquivo. Essas propriedades são comuns para os servidores de catálogos e os servidores de contêiner.
    security.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <securityConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://ibm.com/ws/objectgrid/config/security ../objectGridSecurity.xsd"
    	xmlns="http://ibm.com/ws/objectgrid/config/security">
    
    	<security securityEnabled="true" loginSessionExpirationTime="300" >
            
            <authenticator className ="com.ibm.websphere.
    objectgrid.security.plugins.builtins.KeyStoreLoginAuthenticator"> </authenticator> </security> </securityConfig>