ASTRAHow-to: Consume ASTRA Web Service from Java J2EEContents:
IntroductionThis document describes how to create a J2EE client application that consumes authorization data from the ASTRA web service. The client authenticates using X509 client certificates.Required software
Install X509 certificatesImportant: You cannot use keytool (the default tool for creating, import and exporting certificates) to generate X509 v3 certificates, which are required by the ASTRA web service. The keytool utility only creates X509 v1 certificates. To overcome this, you can use a different tool, such as OpenSSL, IBM's iKeyMan (GUI or command line), or Microsoft's Certificate Manager, to generate the keypair. Once the keypair has been generated, and the certificate has been signed, you can use Sun's new pkcs12import tool that ships with JWSDP 1.4 to import the key pair into an existing key store. The steps below describe how to do this with OpenSSL.
Click on the "PEM Method" button and enter the text generated in mycrt.req. The UWCA will process the request within about 10 minutes and will notify you by email that your certificate is ready. Generate the static proxyUse the Sun wscompile utility to generate a static proxy.
wscompile config-wsdl.xml -gen:client -d ${build} -classpath ${build}
The contents of the config-wsdl.xml file referenced above will look something like:
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<wsdl location="https://ucs.admin.washington.edu/astraws/astraws.asmx?wsdl"
packageName="AstraStatic"/>
</configuration>
Import the necessary namespacesimport javax.xml.rpc.Stub; import java.io.*; import java.util.*; import java.beans.XMLEncoder; import java.beans.XMLDecoder; Set the security credentialsSpecify the java key store and trust store to use.
// Set the security credential properties
System.setProperty("javax.net.ssl.keyStore",
keyStore);
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStorePassword",
keyStorePassword);
System.setProperty("javax.net.ssl.trustStore",
trustStore);
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStorePassword",
trustStorePassword);
Call the web service// Instantiate the proxy object Stub stub = createProxy(); // Set the web service end point URL stub._setProperty( javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, endpointAddress); // Cast it to an AuthzProvider object AuthzProviderSoap astra = (AuthzProviderSoap) stub; // Create the auth filter Auth authFilter = new Auth(); authFilter.privilege = new Privilege(); authFilter.privilege.code = privilegeCode; authFilter.party = new Party(); authFilter.party.uwNetid = uwnetid; authFilter.environment = new Environment(); authFilter.environment.code = environmentCode; // Invoke the call Authz authz = astra.getAuthz(authFilter); Cache authorization data for user session// if authz exist in session cache, deserialize the object from cache byte[] buf = cache.toByteArray(); InputStream is = new ByteArrayInputStream(buf); XMLDecoder decoder = new XMLDecoder( is ); Authz authz = (Authz)decoder.readObject(); // else call the web service, serialize the output and save it to cache // Serialize the XML output to a string ByteArrayOutputStream os = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(os); encoder.writeObject(authz); encoder.close(); // SAVE serialized object to cache ... Iterate the authorization collection returned
// Work with the authz
for (int i = 0; i < authz.authCollection.auth.length; i++)
{
Auth a = authz.authCollection.auth[i];
System.out.println(a.privilege.code);
System.out.println(a.role.code);
System.out.println(a.action.code);
for (int n = 0; n < a.spanOfControlCollection.spanOfControl.length; n++)
{
SpanOfControl s = a.spanOfControlCollection.spanOfControl[n];
System.out.println(s.code);
}
}
ReferencesWS-Security Interoperability Using WSE 2.0 and Sun JWSDP 1.4 |