APIs, SDKs, and Services > Identity Service API > Using JAX-WS Based IdentityService4J API
  

Using JAX-WS Based IdentityService4J API

The Process Server IdentityService4J API is a client based on JAX-WS (version 2.1.5). To use the client API, include the avos-identityservice4j.jar along with the dependent libraries for JAX-WS in your classpath. The JAX-WS dependent jars are:
activation.jar
Java Activation Framework
jaxb-api.jar
JAX Binding
jaxb-impl.jar
jaxws-api.jar
JAX-WS
jaxws-rt.jar
jsr173_api.jar
Streaming API for XML
jsr181-api.jar
Web Services meta data
resolver.jar
woodstox.jar
StAX-compliant (JSR-173) Open Source XML-processor
Building IdentityService4J
You can build the API using the provided ant build script. The avos-identityservice4j.jar that it creates is copied to the dist/ directory. JDK 1.5 or later is required to build this project.
IdentityService4J Samples
Samples using the IdentityService4J API can be found under the /src-examples/ source tree.

Listing Role Names Using IdentityService4J API

The following sample snippet shows how to list roles using the identity service using the IdentityService4J API. The com.activevos.examples.identityservice.FindAllRolesDemo class file has the complete example.

import com.activevos.api.identityservice.AeIdentityService;
import com.activevos.api.identityservice.IdentitySearchPortType;
import com.activevos.api.identityservice.SearchFault;
import com.activevos.api.identityservice.wsdl.EmptyElement;
import com.activevos.api.identityservice.wsdl.TRoleList;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.xml.namespace.QName;

/** Identity Service endpoint WSDL */
String ID_SERVICE_WSDL = "http://localhost:8080/active-bpel/services/AeIdentityService?wsdl";

/** Identity Service endpoint QName */
QName ID_SERVICE_QNAME = new QName("http://docs.active-endpoints/wsdl/identity/2007/03/identity.wsdl",
"AeIdentityService");
try
{
// Create service using WSDL location and service qname.
AeIdentityService idService = new AeIdentityService(
new URL(ID_SERVICE_WSDL), ID_SERVICE_QNAME);
// Get service port to invoke operations.
IdentitySearchPortType idServicePort =
idService.getAeIdentityServicePort();

// Invoke findRoles() operation.
TRoleList roleList = idServicePort.findRoles(new EmptyElement() );
List roleNames = roleList.getRole();
System.out.println("Found role count: " + roleNames.size());
for (String roleName : roleNames)
{
System.out.println("Role name: " + roleName);
}
}
catch(MalformedURLException mue)
{
// Invalid service url format
mue.printStackTrace();
}
catch(SearchFault searchFault)
{
// identity service related fault.
System.out.println("Fault Message: " + searchFault.getMessage());
if (searchFault.getFaultInfo() != null)
{
// Fault details.
System.out.println("FaultInfo Code: " +
searchFault.getFaultInfo().getCode());
System.out.println("FaultInfo Message: " +
searchFault.getFaultInfo().getMessage());
}
searchFault.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}

Listing Identities Using the IdentityService4J API

This sample snippet illustrates using the findIdentitiesByRole() operation. The com.activevos.examples.identityservice.FindIdentitiesByRoleDemo class file has the complete example.

import com.activevos.api.identityservice.AeIdentityService;
import com.activevos.api.identityservice.IdentitySearchPortType;
import com.activevos.api.identityservice.SearchFault;
import com.activevos.api.identityservice.wsdl.TIdentityList;
import com.activevos.api.identityservice.xsd.TIdentity;
import com.activevos.api.identityservice.xsd.TProperty;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.xml.namespace.QName;

/** Identity Service endpoint WSDL */
String ID_SERVICE_WSDL =
"http://localhost:8080/active-bpel/services/AeIdentityService?wsdl";

/** Identity Service endpoint QName */
QName ID_SERVICE_QNAME = new QName(
"http://docs.active-endpoints/wsdl/identity/2007/03/identity.wsdl",
"AeIdentityService");
try
{
// Create service using WSDL location and service qname.
AeIdentityService idService = new AeIdentityService(new URL(ID_SERVICE_WSDL),
ID_SERVICE_QNAME);
// Get service port to invoke operations.
IdentitySearchPortType idServicePort = idService.getAeIdentityServicePort();
// Invoke findIdentitiesByRole() operation.
// In this example, get the list of identities for role 'loanreps'.
TIdentityList idList = idServicePort.findIdentitiesByRole("loanreps");

// get list of Identities from resultset
List<TIdentity> identities = idList.getIdentity();
System.out.println("Found identities count: " + identities.size());
for (TIdentity identity : identities)
{
System.out.println("ID: " + identity.getId()); // id, such as DN of LDAP entry.
// List of roles this person belongs to.
List<String> memberRoles = identity.getRoles().getRole();
for (String role : memberRoles)
{
System.out.println("Member Of : " + role);
}
// List all attributes. E.g. firstName, lastName, email etc.
List<TProperty> properties = identity.getProperties().getProperty();
for (TProperty prop : properties)
{
System.out.println("property[" + prop.getName() + "] = " +
prop.getValue() );
}
System.out.println();
}

}
catch(MalformedURLException mue)
{
// Invalid service url format
mue.printStackTrace();
}
catch(SearchFault searchFault)
{
// identity service related fault.
System.out.println("Fault Message: " + searchFault.getMessage());
if (searchFault.getFaultInfo() != null)
{
// Fault details.
System.out.println("FaultInfo Code: " +
searchFault.getFaultInfo().getCode());
System.out.println("FaultInfo Message: " +
searchFault.getFaultInfo().getMessage());
}
searchFault.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}

Constructing an Identity Query Using the IdentityService4J API

This sample snippet shows how to construct an IdentityQuery, which is used in findIdentities(), assertPrincipalInQueryResult(), assertPrincipalInQueryResultWithResponse(), and countIdentities() operations.
The com.activevos.examples.identityservice.FindIdentitiesDemo class file has the complete example.
// imports similar to previous examples
try
{
// Create service and get service port 'idServicePort' similar to previous examples.
// ...
// ...

// Create identity query with includes and excludes:
// 1) include groups : loanreps, user: loancsr
TIdentityQueryValues includeQueryValues = new TIdentityQueryValues();
includeQueryValues.getGroup().add("loanreps"); // group
includeQueryValues.getUser().add("loancsr"); // user

// 2) exclude groups : loanmgrs
TIdentityQueryValues excludeQueryValues = new TIdentityQueryValues();
excludeQueryValues.getGroup().add("loanmgrs"); // group

// Create query with includes and excludes
TIdentityQuery query = new TIdentityQuery();
query.setInclude(includeQueryValues);
query.setExclude(excludeQueryValues);

// Invoke findIdentites() operation.
TIdentityResultSet resultSet = idServicePort.findIdentities(query);
System.out.println("Query match count : " + resultSet.getTotalRowCount());
// get list of Identities from resultset
List identities = resultSet.getIdentities().getIdentity();
System.out.println("Found identities count: " + identities.size());
for (TIdentity identity : identities)
{
// print details, similar to previous example
}
}
catch(Exception e)
{
e.printStackTrace();
}