This project has retired. For details please refer to its Attic page.
TokenTest xref
View Javadoc
1   /*
2    * Copyright 2013 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  package org.apache.juddi.api.impl;
17  
18  import java.rmi.RemoteException;
19  import org.apache.commons.configuration.ConfigurationException;
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.juddi.Registry;
23  import org.apache.juddi.auth.MockWebServiceContext;
24  import org.apache.juddi.v3.error.AuthTokenRequiredException;
25  import org.apache.juddi.v3.tck.TckBusiness;
26  import org.apache.juddi.v3.tck.TckFindEntity;
27  import org.apache.juddi.v3.tck.TckPublisher;
28  import org.apache.juddi.v3.tck.TckPublisherAssertion;
29  import org.apache.juddi.v3.tck.TckSecurity;
30  import org.apache.juddi.v3.tck.TckTModel;
31  import org.junit.AfterClass;
32  import org.junit.Assert;
33  import org.junit.BeforeClass;
34  import org.junit.Test;
35  import org.uddi.v3_service.UDDISecurityPortType;
36  
37  /**
38   * This was created to test the features added for JIRA JUDDI-686 which implies
39   * that auth tokens can only be used from the IP address that it was issued to
40   *
41   * @author Alex O'Ree
42   */
43  public class TokenTest {
44  
45      private static Log logger = LogFactory.getLog(TokenTest.class);
46      private static API_010_PublisherTest api010 = new API_010_PublisherTest();
47      private static TckTModel tckTModel = new TckTModel(new UDDIPublicationImpl(), new UDDIInquiryImpl());
48      private static TckBusiness tckBusiness = new TckBusiness(new UDDIPublicationImpl(), new UDDIInquiryImpl());
49      private static TckPublisherAssertion tckAssertion = new TckPublisherAssertion(new UDDIPublicationImpl());
50      private static TckFindEntity tckFindEntity = new TckFindEntity(new UDDIInquiryImpl());
51      private static String authInfoJoe = null;
52      private static String authInfoSam = null;
53      private static String authInfoMary = null;
54  
55      @BeforeClass
56      public static void startRegistry() throws ConfigurationException {
57          Registry.start();
58          logger.debug("Getting auth token..");
59          try {
60              api010.saveJoePublisher();
61              api010.saveSamSyndicator();
62              UDDISecurityPortType security = new UDDISecurityImpl();
63              authInfoJoe = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
64              authInfoSam = TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(), TckPublisher.getSamPassword());
65              authInfoMary = TckSecurity.getAuthToken(security, TckPublisher.getMaryPublisherId(), TckPublisher.getMaryPassword());
66          } catch (RemoteException e) {
67              logger.error(e.getMessage(), e);
68              Assert.fail("Could not obtain authInfo token.");
69          }
70      }
71  
72      @AfterClass
73      public static void stopRegistry() throws ConfigurationException {
74          Registry.stop();
75      }
76  
77      @Test
78      public void TestMatchingIPAddress() throws Exception {
79          MockWebServiceContext mwsc = new MockWebServiceContext("192.168.12.42");
80          UDDIPublicationImpl pub = new UDDIPublicationImplExt(mwsc);
81          UDDISecurityImpl security = new UDDISecurityImpl(mwsc);
82          String authToken1 = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
83          pub.getPublisherAssertions(authToken1);
84      }
85  
86      @Test(expected = AuthTokenRequiredException.class)
87      public void TestMisMatchingIPAddress() throws Exception {
88          MockWebServiceContext mwsc = new MockWebServiceContext("192.168.12.42");
89          MockWebServiceContext mwsc2 = new MockWebServiceContext("10.1.1.1");
90          UDDIPublicationImpl pub = new UDDIPublicationImplExt(mwsc2);
91          UDDISecurityImpl security = new UDDISecurityImpl(mwsc);
92          String authToken1 = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
93          pub.getPublisherAssertions(authToken1);
94      }
95  
96      @Test
97      public void TestNullIPAddress() throws Exception {
98          MockWebServiceContext mwsc = new MockWebServiceContext("192.168.12.42");
99          UDDIPublicationImpl pub = new UDDIPublicationImplExt(null);
100         UDDISecurityImpl security = new UDDISecurityImpl(mwsc);
101         String authToken1 = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
102         pub.getPublisherAssertions(authToken1);
103     }
104 
105     @Test
106     public void TestNullIPAddress2() throws Exception {
107         MockWebServiceContext mwsc = new MockWebServiceContext("192.168.12.42");
108         UDDIPublicationImpl pub = new UDDIPublicationImplExt(mwsc);
109         UDDISecurityImpl security = new UDDISecurityImpl(null);
110         String authToken1 = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
111         pub.getPublisherAssertions(authToken1);
112     }
113 
114     @Test
115     public void TestNullIPAddress3() throws Exception {
116         UDDIPublicationImpl pub = new UDDIPublicationImplExt(null);
117         UDDISecurityImpl security = new UDDISecurityImpl(null);
118         String authToken1 = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
119         pub.getPublisherAssertions(authToken1);
120     }
121 }