001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.security.wss4j;
019:
020: import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
021: import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
022: import org.apache.cxf.endpoint.Client;
023: import org.apache.cxf.endpoint.Server;
024: import org.apache.cxf.frontend.ClientProxy;
025: import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
026: import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
027: import org.apache.cxf.service.Service;
028: import org.apache.cxf.transport.local.LocalTransportFactory;
029: import org.apache.ws.security.handler.WSHandlerConstants;
030:
031: import org.junit.Before;
032: import org.junit.Ignore;
033: import org.junit.Test;
034:
035: public class RoundTripTest extends AbstractSecurityTest {
036: private WSS4JInInterceptor wsIn;
037: private WSS4JOutInterceptor wsOut;
038: private Echo echo;
039: private Client client;
040:
041: @Before
042: public void setUpService() throws Exception {
043: JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
044: factory.setServiceBean(new EchoImpl());
045: factory.setAddress("local://Echo");
046: factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
047: Server server = factory.create();
048: Service service = server.getEndpoint().getService();
049:
050: service.getInInterceptors().add(new SAAJInInterceptor());
051: service.getOutInterceptors().add(new SAAJOutInterceptor());
052:
053: wsIn = new WSS4JInInterceptor();
054: wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE,
055: "META-INF/cxf/insecurity.properties");
056: wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE,
057: "META-INF/cxf/insecurity.properties");
058: wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
059: TestPwdCallback.class.getName());
060:
061: service.getInInterceptors().add(wsIn);
062:
063: wsOut = new WSS4JOutInterceptor();
064: wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE,
065: "META-INF/cxf/outsecurity.properties");
066: wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE,
067: "META-INF/cxf/outsecurity.properties");
068: wsOut.setProperty(WSHandlerConstants.USER, "myalias");
069: wsOut.setProperty("password", "myAliasPassword");
070: wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
071: TestPwdCallback.class.getName());
072: service.getOutInterceptors().add(wsOut);
073:
074: // Create the client
075: JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
076: proxyFac.setServiceClass(Echo.class);
077: proxyFac.setAddress("local://Echo");
078: proxyFac.getClientFactoryBean().setTransportId(
079: LocalTransportFactory.TRANSPORT_ID);
080:
081: echo = (Echo) proxyFac.create();
082:
083: client = ClientProxy.getClient(echo);
084: client.getInInterceptors().add(wsIn);
085: client.getInInterceptors().add(new SAAJInInterceptor());
086: client.getOutInterceptors().add(wsOut);
087: client.getOutInterceptors().add(new SAAJOutInterceptor());
088: }
089:
090: @Test
091: public void testSignature() throws Exception {
092: wsIn.setProperty(WSHandlerConstants.ACTION,
093: WSHandlerConstants.SIGNATURE);
094: wsOut.setProperty(WSHandlerConstants.ACTION,
095: WSHandlerConstants.SIGNATURE);
096:
097: assertEquals("test", echo.echo("test"));
098: }
099:
100: @Test
101: @Ignore("Seems to randomly hang on Linux")
102: public void testEncryptionPlusSig() throws Exception {
103: wsIn.setProperty(WSHandlerConstants.ACTION,
104: WSHandlerConstants.ENCRYPT + " "
105: + WSHandlerConstants.SIGNATURE);
106: wsOut.setProperty(WSHandlerConstants.ACTION,
107: WSHandlerConstants.ENCRYPT + " "
108: + WSHandlerConstants.SIGNATURE);
109:
110: assertEquals("test", echo.echo("test"));
111: }
112:
113: @Test
114: public void testUsernameToken() throws Exception {
115: String actions = WSHandlerConstants.ENCRYPT + " "
116: + WSHandlerConstants.SIGNATURE + " "
117: + WSHandlerConstants.TIMESTAMP + " "
118: + WSHandlerConstants.USERNAME_TOKEN;
119:
120: wsIn.setProperty(WSHandlerConstants.ACTION, actions);
121: wsOut.setProperty(WSHandlerConstants.ACTION, actions);
122:
123: assertEquals("test", echo.echo("test"));
124: }
125: }
|