01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.systest.aegis;
19:
20: import java.util.List;
21: import java.util.logging.Logger;
22:
23: import org.apache.cxf.aegis.databinding.AegisDatabinding;
24: import org.apache.cxf.authservice.AuthService;
25: import org.apache.cxf.authservice.Authenticate;
26: import org.apache.cxf.frontend.ClientProxyFactoryBean;
27: import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
28: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
29: import org.junit.BeforeClass;
30: import org.junit.Test;
31:
32: public class AegisClientServerTest extends
33: AbstractBusClientServerTestBase {
34: static final Logger LOG = Logger
35: .getLogger(AegisClientServerTest.class.getName());
36:
37: @BeforeClass
38: public static void startServers() throws Exception {
39: assertTrue("server did not launch correctly",
40: launchServer(AegisServer.class));
41: }
42:
43: @Test
44: public void testAegisClient() throws Exception {
45: AegisDatabinding aegisBinding = new AegisDatabinding();
46: ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
47: proxyFactory.setDataBinding(aegisBinding);
48: proxyFactory.setServiceClass(AuthService.class);
49: proxyFactory.setAddress("http://localhost:9002/service");
50: AuthService service = (AuthService) proxyFactory.create();
51: assertTrue(service.authenticate("Joe", "Joe", "123"));
52: assertFalse(service.authenticate("Joe1", "Joe", "fang"));
53: List<String> list = service.getRoles("Joe");
54: assertEquals(1, list.size());
55: assertEquals("Joe", list.get(0));
56: assertEquals("get Joe", service.getAuthentication("Joe"));
57: Authenticate au = new Authenticate();
58: au.setSid("ffang");
59: au.setUid("ffang");
60: assertTrue(service.authenticate(au));
61: au.setUid("ffang1");
62: assertFalse(service.authenticate(au));
63: }
64:
65: @Test
66: public void testJaxWsAegisClient() throws Exception {
67: AegisDatabinding aegisBinding = new AegisDatabinding();
68: JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
69: proxyFactory.setDataBinding(aegisBinding);
70: proxyFactory.setServiceClass(AuthService.class);
71: proxyFactory.setAddress("http://localhost:9002/jaxwsAndAegis");
72: AuthService service = (AuthService) proxyFactory.create();
73: assertTrue(service.authenticate("Joe", "Joe", "123"));
74: assertFalse(service.authenticate("Joe1", "Joe", "fang"));
75: List<String> list = service.getRoles("Joe");
76: assertEquals(1, list.size());
77: assertEquals("Joe", list.get(0));
78: assertEquals("get Joe", service.getAuthentication("Joe"));
79: Authenticate au = new Authenticate();
80: au.setSid("ffang");
81: au.setUid("ffang");
82: assertTrue(service.authenticate(au));
83: au.setUid("ffang1");
84: assertFalse(service.authenticate(au));
85: }
86: }
|