Package nexj.core.util.cipher

Examples of nexj.core.util.cipher.CharacterStreamCipherDispatcher$SameSchemeCharacterStreamCipher


               return;
            }
         }

         // Configure decryption (system properties as defaults, then ant properties)
         CharacterStreamCipherDispatcher dispatcher = new CharacterStreamCipherDispatcher();
         Properties props = new Properties(SysUtil.getConfigProperties());

         props.putAll(getProject().getProperties());
         dispatcher.init(props);

         // Process file
         try
         {
            if (m_keystoreFile != null)
            {
               boolean bHasKeyStore = false;
               Param param = null;

               if (m_paramList != null)
               {
                  for (Iterator paramItr = m_paramList.iterator(); paramItr.hasNext();)
                  {
                     param = (Param)paramItr.next();

                     if (param.getName().equals("clusterKeyStore") && param.shouldUse())
                     {
                        bHasKeyStore = true;

                        break;
                     }
                  }
               }
              
               if (!bHasKeyStore)
               {
                  param = new Param();
                  fis = new BufferedInputStream(new FileInputStream(m_keystoreFile));

                  ByteArrayOutputStream dataStream = new ByteArrayOutputStream();

                  IOUtil.copy(dataStream, fis);
                  param.setName("clusterKeyStore");
                  param.setExpression(Base64Util.encode(dataStream.toByteArray()));
                  addConfiguredParam(param);

                  IOUtil.close(fis);
               }
            }

            fis = new BufferedInputStream(new FileInputStream(m_propFile));
            encReader = new InputStreamReader(fis, "UTF-8");

            Object cipher = dispatcher.create(encReader);
            Reader decReader = null;

            if (cipher instanceof CharacterStreamCipher)
            {
               decReader = ((CharacterStreamCipher)cipher).createDecryptedReader(encReader);
            }
            else
            {
               IOUtil.close(encReader);
               IOUtil.close(fis);
               fis = null;

               encReader = new StringReader((String)cipher);
               decReader = encReader;
               cipher = dispatcher;

               // The file was not encrypted at all
               props.setProperty("cipher.scheme",
                  props.getProperty("cipher.scheme", CharacterStreamCipherDispatcher.SCHEME_TEXT));
               dispatcher.init(props);
            }

            // Read from disk, applying XSLT transformation if necessary
            Document doc;

            if (m_styleFile != null)
            {
               TransformerFactory factory = (TransformerFactory)Class.forName(
               "org.apache.xalan.processor.TransformerFactoryImpl").newInstance();

               FileInputStream styleStream = new FileInputStream(m_styleFile);
               Transformer transformer = factory.newTransformer(new StreamSource(styleStream));

               // Read and set the transformation parameters
               if (m_paramList != null)
               {
                  for (int i = 0; i < m_paramList.size(); i++)
                  {
                     XSLTProcess.Param param = (XSLTProcess.Param)m_paramList.get(i);

                     if (param.shouldUse())
                     {
                        transformer.setParameter(param.getName(), param.getExpression());
                     }
                  }
               }

               Source source = new StreamSource(decReader);
               DOMResult result = new DOMResult();

               transformer.transform(source, result);
               doc = (Document)result.getNode();
            }
            else
            {
               doc = XMLUtil.parse(decReader);
            }

            Element root = XMLUtil.findFirstElement(doc.getFirstChild());
            String sRootName = root.getNodeName();
            NamedNodeMap attributes = root.getAttributes();

            if (m_outFile == null)
            {
               String sPrefix = (m_sPrefix != null) ? m_sPrefix : (sRootName + '.');

               // Read properties
               for (int i = 0; i < attributes.getLength(); i++)
               {
                  Node attribute = attributes.item(i);
                  StringBuilder nameBuilder = new StringBuilder();

                  nameBuilder.append(sPrefix);
                  nameBuilder.append(attribute.getNodeName());

                  getProject().setProperty(nameBuilder.toString(), dispatcher.decrypt(attribute.getNodeValue()));
               }
            }
            else
            {
               fos = new FileOutputStream(m_outFile);
View Full Code Here


    */
   protected void execute(String sCommand) throws Exception
   {
      Properties configProperties = SysUtil.getConfigProperties();
      MetadataEnabledProperties metadataEnabledProperties = new MetadataEnabledProperties(configProperties);
      CharacterStreamCipherDispatcher dispatcher = new CharacterStreamCipherDispatcher();

      dispatcher.init(metadataEnabledProperties);

      if (m_installer == null)
      {
         String sConfig = URLUtil.toURL(getRequiredProperty("cfg.url"));
         InputStream istream = null;
         InputStreamReader encReader = null;
         Reader decReader = null;
         Element root;

         try
         {
            istream = new BufferedInputStream(URLUtil.openStream(new URL(sConfig)));
            encReader = new InputStreamReader(istream, "UTF-8");
            decReader = dispatcher.createDecryptedReader(encReader);
            root = XMLUtil.parse(decReader, XMLMetadataHelper.DEFAULT_SCHEMA_URL_DEQUE).getDocumentElement();
         }
         finally
         {
            IOUtil.close(decReader);
            IOUtil.close(encReader);
            IOUtil.close(istream);
         }

         String sPlatform = XMLUtil.getReqStringAttr(root, "type");
         String sLocation = XMLUtil.getReqStringAttr(root, "location");
         String sUser = XMLUtil.getStringAttr(root, "user");
         String sPassword = XMLUtil.getStringAttr(root, "password");

         m_installer = (Installer)Class.forName(SysUtil.PACKAGE + ".core.admin.platform." +
            sPlatform.toLowerCase(Locale.ENGLISH) + "." + sPlatform + "Installer").newInstance();

         if (getProperty("base.url") != null)
         {
            configProperties.setProperty(XMLMetadataLoader.BASE_URL_PROPERTY, URLUtil.toURL(getProperty("base.url")));
         }

         if (getProperty("con.url") != null)
         {
            configProperties.setProperty(XMLMetadataLoader.CONNECTIONS_URL_PROPERTY, URLUtil.toURL(getProperty("con.url")));
         }

         configProperties.setProperty(SysUtil.CONFIG_PROPERTY, sConfig);

         MetadataLoaderDispatcher loaderDispatcher = new MetadataLoaderDispatcher();
        
         Metadata metadata = loaderDispatcher.load(
            URLUtil.toURL(getRequiredProperty("root.url")),
            configProperties, MetadataLoader.ENVIRONMENT_ONLY, null);

         metadataEnabledProperties.setMetadataLoaderProperties(metadata.getProperties());
         m_installer.setMetadata(metadata);

         for (int i = 0; i != CUSTOM_PROPERTIES.length; ++i)
         {
            String sName = CUSTOM_PROPERTIES[i];
            String sValue = getProperty(sName);
           
            if (sValue != null)
            {
               metadataEnabledProperties.setProperty(sName, sValue);
            }
         }

         // Decrypt the password
         sPassword = dispatcher.decrypt(sPassword);

         // Prepare for encryption
         if (metadataEnabledProperties.getProperty("cipher.scheme") == null)
         {
            metadataEnabledProperties.setProperty("cipher.scheme", metadata.getEncryptionScheme());
         }

         dispatcher.init(metadataEnabledProperties);

         m_installer.setProperties(metadataEnabledProperties);
         m_installer.setLocation(sLocation, sUser, sPassword);
      }

View Full Code Here

    * Set the key store's password.
    * @param sPassword The key store's password.
    */
   public void setPassword(String sPassword)
   {
      CharacterStreamCipherDispatcher dec = new CharacterStreamCipherDispatcher();

      dec.init(SysUtil.getConfigProperties());
      m_sPassword = dec.decrypt(sPassword);
   }
View Full Code Here

    * Sets the password.
    * @param sPassword The password to set.
    */
   public void setPassword(String sPassword)
   {
      CharacterStreamCipherDispatcher dec = new CharacterStreamCipherDispatcher();

      dec.init(SysUtil.getConfigProperties());
      m_sPassword = dec.decrypt(sPassword);
   }
View Full Code Here

               }
            }
         }
      }, m_properties);

      m_decryptionDispatcher = new CharacterStreamCipherDispatcher();
      m_decryptionDispatcher.init(m_properties);
      m_helper.setEncryptionSchemeSet(new HashHolder(4));

      loadServer(m_properties);
View Full Code Here

            istream = URLUtil.openResource(SysUtil.class, sCfgFileName);
         }

         // Decrypt .server file to read properties
         encReader = new InputStreamReader(new BufferedInputStream(istream), IOUtil.ENCODING);
         CharacterStreamCipherDispatcher dispatcher = new CharacterStreamCipherDispatcher();

         dispatcher.init(properties);
         decReader = dispatcher.createDecryptedReader(encReader);

         XMLUtil.parse(decReader, new DefaultHandler()
         {
            protected boolean m_bProcessed;
View Full Code Here

    * Set the default password to use for new connections.
    * @param sPassword The default password to use for new connections.
    */
   public void setPassword(String sPassword)
   {
      CharacterStreamCipherDispatcher dispatcher = new CharacterStreamCipherDispatcher();

      dispatcher.init(SysUtil.getConfigProperties());
      m_conInfo.setPassword(dispatcher.decrypt(sPassword));
   }
View Full Code Here

      /**
       * @see nexj.core.meta.xml.XMLMetadataHelper.CharacterStreamHandler#handleCharacterStream(java.io.Reader, java.lang.String)
       */
      public void handleCharacterStream(Reader reader, String sName) throws IOException
      {
         CharacterStreamCipherDispatcher dispatcher = new CharacterStreamCipherDispatcher();

         dispatcher.init(m_properties);
         dispatcher.setEncryptionSchemeSet(m_encryptionSchemeSet);
         m_handler.handleCharacterStream(dispatcher.createDecryptedReader(reader), sName);
      }
View Full Code Here

    */
   protected void installJBossService(Resource file, String sTrustStoreFileName) throws IOException
   {
      // J2EE Descriptor password encryption
      String sEncryptedKeyStorePassword = m_metadata.getKeyStorePassword();
      CharacterStreamCipherDispatcher dispatcher = null;

      if (!m_metadata.isEncrypted() && SysUtil.ENTERPRISE)
      {
         dispatcher = new CharacterStreamCipherDispatcher();

         if (m_properties.getProperty("cipher.scheme") == null)
         {
            m_properties.setProperty("cipher.scheme", m_metadata.getEncryptionScheme());
         }

         dispatcher.init(m_properties);
         sEncryptedKeyStorePassword = dispatcher.encrypt(sEncryptedKeyStorePassword);
      }

      String sNullTagFixupRegEx = "(?s)<parameter>\\s*<null/>\\s*</parameter>";
      String sNullTagFixup = "<parameter><null/></parameter>";

View Full Code Here

    * @return The encrypted string
    */
   protected String encrypt(String sToEncrypt)
   {
      // J2EE Descriptor password encryption
      CharacterStreamCipherDispatcher dispatcher = null;

      if (!m_metadata.isEncrypted() && SysUtil.ENTERPRISE)
      {
         dispatcher = new CharacterStreamCipherDispatcher();

         if (m_properties.getProperty("cipher.scheme") == null)
         {
            m_properties.setProperty("cipher.scheme", m_metadata.getEncryptionScheme());
         }

         dispatcher.init(m_properties);
      }

      return (dispatcher != null) ? dispatcher.encrypt(sToEncrypt) : sToEncrypt;
   }
View Full Code Here

TOP

Related Classes of nexj.core.util.cipher.CharacterStreamCipherDispatcher$SameSchemeCharacterStreamCipher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.