directNonInteractiveAuthentication Java/Axis Example

In this example the Moria2-enabled service initiates a direct non-interactive authentication session. "Non-interactive" means that this authentication method does not require any input from the user; the service must retrieve the user's credentials and forward them to Moria2. This also eliminates any need for HTTP redirects during authentication. The service requests the user attribute eduPersonAffiliation, and authenticates the user with username username@my.org and password password.

The SOAP implementation used in this example is Axis.

import javax.xml.namespace.QName;
import no.feide.moria.webservices.v2_0.Attribute;
import org.apache.axis.client.Call;
import org.apache.axis.encoding.ser.VectorDeserializerFactory;
import org.apache.axis.encoding.ser.VectorSerializerFactory;

...

Call call = new Call("http://localhost:8080/moria/v2_1/Authentication?WSDL"));
call.setUsername("service_username");
call.setPassword("service_password");
final QName attributeQName = new QName("https://login.feide.no/moria/v2_1/Authentication", 
                                       "Attribute");
call.setReturnType(attributeQName);
VectorSerializerFactory serializer = new VectorSerializerFactory(Attribute.class, 
                                                                 attributeQName);
VectorDeserializerFactory deserializer = new VectorDeserializerFactory(Attribute.class, 
                                                                       attributeQName);
call.registerTypeMapping(Attribute.class,
                         attributeQName, 
                         serializer, 
                         deserializer);
final Object[] parameters = { ["eduPersonAffiliation"], 
                              "username@my.org",  
                              "password" };
final Object returnedAttributes = call.invoke(new QName("directNonInteractiveAuthentication"), 
                                              parameters);
final Attribute convertedAttributes = (Attribute[]) returnedAttributes;

The above code assumes that Moria2 is deployed locally.