Home » rampart-dist-1.4-src » org.apache » rampart » policy » model » [javadoc | source]

    1   /*
    2    * Copyright 2004,2005 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
   10    * Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   
   17   package org.apache.rampart.policy.model;
   18   
   19   import org.apache.neethi.Assertion;
   20   import org.apache.neethi.Constants;
   21   import org.apache.neethi.PolicyComponent;
   22   
   23   import javax.xml.namespace.QName;
   24   import javax.xml.stream.XMLStreamException;
   25   import javax.xml.stream.XMLStreamWriter;
   26   
   27   import java.util.Iterator;
   28   import java.util.Properties;
   29   
   30   /**
   31    * Policy model bean to capture crypto information.
   32    * 
   33    * Example:
   34   <pre>
   35   <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
   36       <ramp:property name="keystoreType">JKS</ramp:property>
   37       <ramp:property name="keystoreFile">/path/to/file.jks</ramp:property>
   38       <ramp:property name="keystorePassword">password</ramp:property>
   39   </ramp:crypto>
   40   </pre>
   41    */
   42   public class CryptoConfig implements Assertion {
   43       
   44       public final static String CRYPTO_LN = "crypto";
   45       public final static String PROVIDER_ATTR = "provider";
   46       public final static String PROPERTY_LN = "property";
   47       public final static String PROPERTY_NAME_ATTR = "name";
   48   
   49       private String provider;
   50       private Properties prop;
   51       
   52       public Properties getProp() {
   53           return prop;
   54       }
   55       public void setProp(Properties prop) {
   56           this.prop = prop;
   57       }
   58       public String getProvider() {
   59           return provider;
   60       }
   61       public void setProvider(String provider) {
   62           this.provider = provider;
   63       }
   64       
   65       public QName getName() {
   66           return new QName(RampartConfig.NS, CRYPTO_LN);
   67       }
   68   
   69       public boolean isOptional() {
   70           // TODO TODO
   71           throw new UnsupportedOperationException("TODO");
   72       }
   73    
   74       public PolicyComponent normalize() {
   75           // TODO TODO
   76           throw new UnsupportedOperationException("TODO");
   77       }
   78   
   79       public void serialize(XMLStreamWriter writer) throws XMLStreamException {
   80           String prefix = writer.getPrefix(RampartConfig.NS);
   81           
   82           if (prefix == null) {
   83               prefix = RampartConfig.NS;
   84               writer.setPrefix(prefix, RampartConfig.NS);
   85           }
   86           
   87           writer.writeStartElement(prefix, CRYPTO_LN, RampartConfig.NS);
   88           
   89           if (getProvider() != null) {
   90               writer.writeAttribute(PROVIDER_ATTR, getProvider());
   91           }
   92           
   93           String key;
   94           String value;
   95           
   96           for (Iterator iterator = prop.keySet().iterator(); iterator.hasNext();) {
   97               key = (String) iterator.next();
   98               value = prop.getProperty(key);
   99               writer.writeStartElement(RampartConfig.NS, PROPERTY_LN);
  100   
  101               writer.writeAttribute("name", key);
  102   
  103               writer.writeCharacters(value);
  104               writer.writeEndElement();
  105           }
  106           
  107           writer.writeEndElement();
  108       }
  109       
  110       public boolean equal(PolicyComponent policyComponent) {
  111           throw new UnsupportedOperationException();
  112       }
  113   
  114       public short getType() {
  115           return Constants.TYPE_ASSERTION;
  116       }
  117       
  118   }

Home » rampart-dist-1.4-src » org.apache » rampart » policy » model » [javadoc | source]