Am Montag, den 30.07.2007, 21:35 +0000 schrieb [EMAIL PROTECTED]:
> Author: ulhasbhole
> Date: Mon Jul 30 14:35:22 2007
> New Revision: 561135

> ==============================================================================
> --- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/headers/Header.java 
> (original)
> +++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/headers/Header.java 
> Mon Jul 30 14:35:22 2007
> @@ -23,11 +23,19 @@
>  import org.apache.cxf.databinding.DataBinding;
>  
>  public class Header {
> +    public static final int DIRECTION_IN = 0;
> +    public static final int DIRECTION_OUT = 1;
> +    public static final int DIRECTION_INOUT = 2;

Hmmm...see below...

>      public static final String HEADER_LIST = Header.class.getName() + 
> ".list";
> +   
>      
>      private DataBinding dataBinding;
>      private QName name;
>      private Object object;
> +//    private boolean inbound;
> +    private enum Direction  { DIRECTION_IN, DIRECTION_OUT, DIRECTION_INOUT } 
>  
> +    

Can we make the Direction enum above public, so it can be used
externally--that way, we would not need to define DIRECTION_IN, _OUT,
_INOUT static integers at the top?  (Or is it that the callee can not
work with enums--if so, can we just work with the static ints then?)
Having both enum constants and static integers with the same name is a
little bit confusing, if we could just work with one of the two I think
that would be better.



> +    private Direction direction = Header.Direction.DIRECTION_OUT;
>  
>      public Header(QName q, Object o) {
>          this(q, o, null);
> @@ -56,6 +64,36 @@
>      }
>      public void setObject(Object object) {
>          this.object = object;
> +    }
> +    
> +    public void setDirection(int hdrDirection) {
> +       //this.inbound = true;
> +        switch (hdrDirection) {
> +        case DIRECTION_IN:
> +            this.direction = Header.Direction.DIRECTION_IN;
> +            break;
> +        case DIRECTION_INOUT:
> +            this.direction = Header.Direction.DIRECTION_INOUT;
> +            break;
> +        default:
> +            this.direction = Header.Direction.DIRECTION_OUT;
> +        }
> +    }
> +    
> +    public int getDirection() {
> +        int retval;
> +        switch (this.direction) {
> +        case DIRECTION_IN:
> +            retval = Header.DIRECTION_IN;
> +            break;
> +        case DIRECTION_INOUT:
> +            retval = Header.DIRECTION_INOUT;
> +            break;
> +        default:
> +            retval = Header.DIRECTION_OUT;
> +        }
> +        
> +        return retval;
>      }

These two methods above can get quite simple if we can collapse the
enums and static ints into one set.



> Added: 
> incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderOutFilterInterceptor.java
> URL: 
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderOutFilterInterceptor.java?view=auto&rev=561135
> ==============================================================================
> --- 
> incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderOutFilterInterceptor.java
>  (added)
> +++ 
> incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderOutFilterInterceptor.java
>  Mon Jul 30 14:35:22 2007
> @@ -0,0 +1,48 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +
> +package org.apache.cxf.binding.soap.interceptor;
> +
> +import java.util.Iterator;
> +
> +import org.apache.cxf.binding.soap.SoapMessage;
> +import org.apache.cxf.headers.Header;
> +import org.apache.cxf.interceptor.Fault;
> +import org.apache.cxf.phase.Phase;
> +
> +public class SoapHeaderOutFilterInterceptor extends AbstractSoapInterceptor {
> +    
> +    public SoapHeaderOutFilterInterceptor()  {
> +        super(Phase.PRE_LOGICAL);
> +    }
> +
> +    public void handleMessage(SoapMessage message) throws Fault {
> +        // TODO Auto-generated method stub
> +        Iterator<Header> iter =  message.getHeaders().iterator();


(I don't know the code here.  Is there any chance the iterator above
could be null -- i.e., if there are no headers?  If so, the above line
of code will NPE.)


> +        
> +        while (iter.hasNext()) {
> +            Header hdr  = (Header) iter.next();
> +            //ubhole: Only remove inbound marked headers..
> +            if (hdr.getDirection() == Header.DIRECTION_IN) {
> +                iter.remove(); 
> +            }
> +        }
> +    }
> +
> +}
> 
> Added: 
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/security/KeystorePasswordCallback.java
> URL: 
> http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/security/KeystorePasswordCallback.java?view=auto&rev=561135
> ==============================================================================
> --- 
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/security/KeystorePasswordCallback.java
>  (added)
> +++ 
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/security/KeystorePasswordCallback.java
>  Mon Jul 30 14:35:22 2007
> @@ -0,0 +1,68 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.cxf.systest.ws.security;
> +
> +import java.io.IOException;
> +import java.util.HashMap;
> +import java.util.Map;
> +
> +import javax.security.auth.callback.Callback;
> +import javax.security.auth.callback.CallbackHandler;
> +import javax.security.auth.callback.UnsupportedCallbackException;
> +
> +import org.apache.ws.security.WSPasswordCallback;
> +
> +/**
> + */
> +
> +public class KeystorePasswordCallback implements CallbackHandler {
> +    
> +    private Map<String, String> passwords = 
> +        new HashMap<String, String>();
> +    
> +    public KeystorePasswordCallback() {
> +        passwords.put("Alice", "abcd!1234");
> +        passwords.put("alice", "abcd!1234");
> +        passwords.put("Bob", "abcd!1234");
> +        passwords.put("bob", "abcd!1234");
> +    }
> +

What is the point of adding both Alice and alice here?  Bob and bob?  If
you're trying to make user entry case-insensitive (not really necessary
IMHO), I don't think that will work, because people could still enter
"BOB", "bOB", etc., and the above would fail anyway.


> +    /**
> +     * It attempts to get the password from the private 
> +     * alias/passwords map.
> +     */
> +    public void handle(Callback[] callbacks) throws IOException, 
> UnsupportedCallbackException {
> +        for (int i = 0; i < callbacks.length; i++) {
> +            WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];
> +
> +            String pass = passwords.get(pc.getIdentifer());
> +            if (pass != null) {
> +                pc.setPassword(pass);
> +                return;
> +            }
> +        }
> +    }
> +    
> +    /**
> +     * Add an alias/password pair to the callback mechanism.
> +     */
> +    public void setAliasPassword(String alias, String password) {
> +        passwords.put(alias, password);
> +    }
> +}
> 
> Added: 
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/security/Server.java
> URL: 
> http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/security/Server.java?view=auto&rev=561135
> ==============================================================================
> --- 
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/security/Server.java
>  (added)
> +++ 
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/security/Server.java
>  Mon Jul 30 14:35:22 2007
> @@ -0,0 +1,57 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +
> +package org.apache.cxf.systest.ws.security;
> +
> +import javax.xml.ws.Endpoint;
> +
> +import org.apache.cxf.Bus;
> +import org.apache.cxf.BusFactory;
> +import org.apache.cxf.bus.spring.SpringBusFactory;
> +import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
> +
> +public class Server extends AbstractBusTestServerBase {
> +
> +    protected void run()  {
> +        SpringBusFactory factory = new SpringBusFactory();
> +        Bus bus = factory.createBus(
> +            "org/apache/cxf/systest/ws/security/server.xml"
> +        );
> +        BusFactory.setDefaultBus(bus);
> +        setBus(bus);
> +        GreeterImpl implementor = new GreeterImpl();
> +
> +        Endpoint.publish(
> +            
> "http://localhost:9000/SOAPServiceWSSecurity/TimestampSignEncrypt";, 
> +            implementor
> +        );
> +    }
> +        
> +    public static void main(String[] args) {
> +        try { 
> +            Server s = new Server(); 
> +            s.start();
> +        } catch (Exception ex) {
> +            ex.printStackTrace();
> +            System.exit(-1);
> +        } finally { 
> +            System.out.println("done!");
> +        }
> +    }

I think this needs fixing.  The purpose of the finally is "run this code
whether or not there was an exception", but that is circumvented with
the System.exit(-1) in the catch {} block.  I think either the
System.exit(-1) line has to be removed, or the finally block removed,
with its single statement placed at the end of the try{} block.

Regards,
Glen


Reply via email to