This project has retired. For details please refer to its Attic page.
UDDISecurityService xref
View Javadoc
1   /*
2    * Copyright 2001-2010 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.juddi.v3.client.transport.wrapper;
18  
19  import java.util.HashMap;
20  
21  import org.apache.juddi.v3.client.ClassUtil;
22  import org.apache.juddi.v3.client.config.UDDIClient;
23  import org.apache.juddi.v3.client.config.UDDIClientContainer;
24  import org.apache.juddi.v3.client.transport.Transport;
25  import org.uddi.api_v3.DiscardAuthToken;
26  import org.uddi.api_v3.GetAuthToken;
27  import org.uddi.v3_service.UDDISecurityPortType;
28  import org.w3c.dom.Element;
29  import org.w3c.dom.Node;
30  
31  /**
32   * @author Tom Cunningham (tcunning@apache.org)
33   * @author Kurt Stam (kurt.stam@redhat.com)
34   */
35  public class UDDISecurityService {
36  
37  	private final static String DEFAULT_NODE_NAME = "default";
38  
39  	private String clientName = null;
40  	private String nodeName = null;
41  	// collection of valid operations
42  	private HashMap<String, Handler> operations = null;
43  
44  	public UDDISecurityService() {
45  		super();
46  		clientName = System.getProperty("org.apache.juddi.v3.client.name"); 
47  		nodeName    = System.getProperty("org.apache.juddi.v3.client.node.name",DEFAULT_NODE_NAME);
48  		operations = new HashMap<String, Handler>();
49  		operations.put("get_authToken", new Handler("getAuthToken", GetAuthToken.class));
50  		operations.put("discard_authToken", new Handler("discardAuthToken", DiscardAuthToken.class));
51  	}
52  
53  	//Verify that the appropriate endpoint was targeted for
54  	// this service request.  The validateRequest method will
55  	// throw an UnsupportedOperationException if anything's amiss.
56  	public void validateRequest(String operation)
57  			throws UnsupportedOperationException
58  	{
59  	    if ((operation == null) || (operation.trim().length() == 0))
60  	    	throw new UnsupportedOperationException("operation " + operation + " not supported");
61  	  }
62  	
63  	public Node secure(Element uddiReq) throws Exception {
64  	    return secure(uddiReq, nodeName, clientName);
65  	}
66  
67  	public Node secure(Element uddiReq, String nodeName, String clientName) throws Exception
68  	{
69  	    UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
70  	    String clazz = client.getClientConfig().getUDDINode(nodeName).getProxyTransport();
71              Class<?> transportClass = ClassUtil.forName(clazz, this.getClass());
72              Transport transport = (Transport) transportClass.getConstructor(String.class, String.class).newInstance(clientName, nodeName);
73  	    UDDISecurityPortType security = transport.getUDDISecurityService();
74  
75  	    //new RequestHandler on it's own thread
76  	    RequestHandler requestHandler = new RequestHandler();
77  	    requestHandler.setPortType(security);
78  
79  	    String operation = requestHandler.getOperation(uddiReq);
80  	    Handler opHandler = operations.get(operation);
81  	    if (opHandler == null) {
82  	        throw new IllegalArgumentException("Operation not found: " + operation);
83  	    }
84  
85  	    requestHandler.setMethodName(opHandler.getMethodName());
86  	    requestHandler.setOperationClass(opHandler.getParameter());
87  
88  	    @SuppressWarnings("unused")
89  	    String version   = requestHandler.getVersion(uddiReq, operation);
90  	    validateRequest(operation);
91  	    return requestHandler.invoke(uddiReq);
92  	}
93  }