Tutorial de Segurança do Java SE - Etapa 1

Para trabalhar com o restante do tutorial, é necessário criar e fazer um pacote de um programa Java simples e dois arquivos XML. Esse conjunto de arquivos define uma configuração simples do ObjectGrid com uma instância ObjectGrid denominada accounting e um mapa customer. O arquivo SimpleDP.xml retrata uma política de implementação de um conjunto de mapas configurado com uma partição e réplicas com o mínimo de zero requeridas.

Procedimento

  1. Em uma janela de linha de comandos, acesse o diretório wxs_home.
  2. Crie um diretório chamado applib.
  3. Crie e compile a classe SimpleApp.java a seguir:
    SimpleApp.java
    // This sample program is provided AS IS and may be used, executed, copied and modified 
    // without royalty payment by customer 
    // (a) for its own instruction and study, 
    // (b) in order to develop applications designed to run with an IBM WebSphere product, 
    // either for customer's own internal use or for redistribution by customer, as part of such an 
    // application, in customer's own products.
    // Licensed Materials - Property of IBM
    // 5724-J34 (C) COPYRIGHT International Business Machines Corp. 2007-2009
    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.ObjectMap;
    import com.ibm.websphere.objectgrid.Session;
    
    public class SimpleApp {
    
        public static void main(String[] args) throws Exception  {
    
            SimpleApp app = new SimpleApp();
            app.run(args);
        }
    
        /**
         * read and write the map 
         * @throws Exception
         */
        protected void run(String[] args) throws Exception {
            ObjectGrid og = getObjectGrid(args);
    
            Session session = og.getSession();
    
            ObjectMap customerMap = session.getMap("customer");
    
            String customer = (String) customerMap.get("0001");
    
            if (customer == null) {
                customerMap.insert("0001", "fName lName");
            } else {
                customerMap.update("0001", "fName lName");
            }
            customer = (String) customerMap.get("0001");
    	// Close the session (optional in Version 
    7.1.1 and later) for improved performance
    session.close(); System.out.println("The customer name for ID 0001 is " + customer); } /** * Get the ObjectGrid * @return an ObjectGrid instance * @throws Exception */ protected ObjectGrid getObjectGrid(String[] args) throws Exception { ObjectGridManager ogManager = ObjectGridManagerFactory.getObjectGridManager(); // Create an ObjectGrid ClientClusterContext ccContext = ogManager.connect("localhost:2809", null, null); ObjectGrid og = ogManager.getObjectGrid(ccContext, "accounting"); return og; } }
  4. Compile o pacote com este arquivo e o nome de JAR sec_sample.jar.
  5. Acesse o diretório wxs_home e crie um diretório denominado xml
  6. No diretório wxs_home/xml, crie os arquivos de configuração a seguir:
    SimpleApp.xml
    
    <?xml version="1.0" encoding="UTF-8"?>
    <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd" 
    	xmlns="http://ibm.com/ws/objectgrid/config">
        <objectGrids>
            <objectGrid name="accounting">
                <backingMap name="customer" readOnly="false" copyKey="true"/>
            </objectGrid>
        </objectGrids>
    </objectGridConfig>

    O arquivo XML a seguir configura o ambiente de implementação.

    SimpleDP.xml
    
    <?xml version="1.0" encoding="UTF-8"?>
    <deploymentPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://ibm.com/ws/objectgrid/deploymentPolicy ../deploymentPolicy.xsd"
    	xmlns="http://ibm.com/ws/objectgrid/deploymentPolicy">
    
    	<objectgridDeployment objectgridName="accounting">
    		<mapSet name="mapSet1" numberOfPartitions="1" minSyncReplicas="0" 
    maxSyncReplicas="2" maxAsyncReplicas="1"> <map ref="customer"/> </mapSet> </objectgridDeployment> </deploymentPolicy>

Resultados

Esses arquivos criam uma configuração simples do ObjectGrid com um ObjectGrid e a instância accounting e um mapa customer.