Monday, April 28, 2014

OIM 11g : Service Provisioning Markup Language (SPML) Sample Code

package com.dubey.deepak.oim.spml.provisioning;

/**
 * Please modify this class to meet your needs
 *
 */

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;

import oracle.iam.wsschema.model.common.pso.Identity;
import oracle.iam.wsschema.model.common.pso.LocalizedMultiValuedString;
import oracle.iam.wsschema.model.common.pso.LocalizedStrings;
import oracle.iam.wsschema.model.common.pso.MultiValuedString;
import oracle.iam.wsschema.model.spmlv2.core.AddRequestType;
import oracle.iam.wsschema.model.spmlv2.core.ServiceHeaderType;
import oracle.iam.wsschema.model.spmlv2custom.username.ValidateUsernameRequestType;
import oracle.iam.wsschema.model.spmlv2custom.username.ValidateUsernameResponseType;

/**
 * This class was generated by Apache CXF 2.6.1 2012-08-06T16:55:38.561+05:30
 * Generated source version: 2.6.1
 *
 */
public final class SPMLRequestPortType_SPMLServiceProviderSoap_Client {

    private static final QName SERVICE_NAME = new QName(
            "http://xmlns.oracle.com/idm/identity/webservice/SPMLService",
            "SPMLService");

    private SPMLRequestPortType_SPMLServiceProviderSoap_Client() {
    }

    public static void main(String args[]) throws java.lang.Exception {
        // URL wsdlURL = SPMLService.WSDL_LOCATION;

        // if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
        // File wsdlFile = new File(args[0]);
        // try {
        // if (wsdlFile.exists()) {
        // wsdlURL = wsdlFile.toURI().toURL();
        // } else {
        // wsdlURL = new URL(args[0]);
        // }
        // } catch (MalformedURLException e) {
        // e.printStackTrace();
        // }
        // }

        // SPMLService ss = new SPMLService(wsdlURL, SERVICE_NAME);
        URL wsdlURL = new URL(
                "http://192.168.1.254:14000/spml-xsd/SPMLService?WSDL");
        SPMLService ss = new SPMLService(wsdlURL);
        SPMLRequestPortType port = ss.getSPMLServiceProviderSoap();

        Map ctx = ((BindingProvider) port).getRequestContext();
        ctx.put("ws-security.username", "xelsysadm");
        ctx.put("ws-security.password", "Abcd1234");

        // adding logging
        Client client = ClientProxy.getClient(port);
        client.getInInterceptors().add(new LoggingInInterceptor());
        client.getOutInterceptors().add(new LoggingOutInterceptor());

        ServiceHeaderType serviceHeader = new ServiceHeaderType();

        ValidateUsernameRequestType validateUser = new ValidateUsernameRequestType();
        validateUser.setUsername("DDUBEY");
        ValidateUsernameResponseType retValUser = port
                .spmlValidateUsernameRequest(validateUser);
        System.out.println("spml validate user =" + retValUser.isValid());

        System.out.println("Invoking spmlAddRequest...");
        oracle.iam.wsschema.model.spmlv2.core.AddRequestType _spmlAddRequest_body = new AddRequestType();
      
      
        java.util.List modCapData = new java.util.ArrayList();

          oracle.iam.wsschema.model.spmlv2.core.CapabilityDataType modCap = new oracle.iam.wsschema.model.spmlv2.core.CapabilityDataType();
          java.util.List modCapAny = new java.util.ArrayList();
          modCap.getAny().addAll(modCapAny);
          modCap.setMustUnderstand(Boolean.TRUE);
          modCap.setCapabilityURI("urn:oasis:names:tc:SPML:2:0:reference");
          modCapData.add(modCap);
        
          _spmlAddRequest_body.getCapabilityData().addAll(modCapData);
          _spmlAddRequest_body.setRequestID("RequestID-763892610");
        
          oracle.iam.wsschema.model.spmlv2.core.ExecutionModeType async = oracle.iam.wsschema.model.spmlv2.core.ExecutionModeType.ASYNCHRONOUS;
          _spmlAddRequest_body.setExecutionMode(async);
          _spmlAddRequest_body.setLocale("en");

        Identity identity = new Identity();

        LocalizedMultiValuedString value = new LocalizedMultiValuedString();
        LocalizedStrings lastName = new LocalizedStrings();
        lastName.getValue().add("Dubey");
        value.getValues().add(lastName);
        identity.setSurname(value);

        MultiValuedString userId = new MultiValuedString();
        userId.getValue().add("DDUBEY");
        identity.setUsername(userId);

        LocalizedMultiValuedString etype = new LocalizedMultiValuedString();
        LocalizedStrings estr = new LocalizedStrings();
        estr.getValue().add("Temp");
        etype.getValues().add(estr);
        identity.setEmployeeType(etype);

        MultiValuedString gname = new MultiValuedString();
        gname.getValue().add("Deepak");
        identity.setGivenName(gname);

        MultiValuedString mail = new MultiValuedString();
        mail.getValue().add("deepak.dubey@mydomain.com");
        identity.setMail(mail);

        LocalizedMultiValuedString org = new LocalizedMultiValuedString();
        LocalizedStrings orgstr = new LocalizedStrings();
        orgstr.getValue().add("1");
        org.getValues().add(orgstr);
        identity.setOrganization(org);

      
        oracle.iam.wsschema.model.common.pso.ProvisioningObjectType modsData = new oracle.iam.wsschema.model.common.pso.ProvisioningObjectType();
      
        modsData.setIdentity(identity);
      
        _spmlAddRequest_body.setData(modsData);

        oracle.iam.wsschema.model.spmlv2.core.AddResponseType _spmlAddRequest__return = port
                .spmlAddRequest(_spmlAddRequest_body);
        System.out.println("spmlAddRequest.result=" + _spmlAddRequest__return);

         {
         System.out.println("Invoking spmlValidatePasswordRequest...");
         oracle.iam.wsschema.model.spmlv2.password.ValidatePasswordRequestType
         _spmlValidatePasswordRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.password.ValidatePasswordResponseType
         _spmlValidatePasswordRequest__return =
         port.spmlValidatePasswordRequest(_spmlValidatePasswordRequest_body);
         System.out.println("spmlValidatePasswordRequest.result=" +
         _spmlValidatePasswordRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlSuggestUsernameRequest...");
         oracle.iam.wsschema.model.spmlv2custom.username.SuggestUsernameRequestType
         _spmlSuggestUsernameRequest_body = null;
         oracle.iam.wsschema.model.spmlv2custom.username.SuggestUsernameResponseType
         _spmlSuggestUsernameRequest__return =
         port.spmlSuggestUsernameRequest(_spmlSuggestUsernameRequest_body);
         System.out.println("spmlSuggestUsernameRequest.result=" +
         _spmlSuggestUsernameRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlResumeRequest...");
         oracle.iam.wsschema.model.spmlv2.suspend.ResumeRequestType
         _spmlResumeRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.ResponseType
         _spmlResumeRequest__return =
         port.spmlResumeRequest(_spmlResumeRequest_body);
         System.out.println("spmlResumeRequest.result=" +
         _spmlResumeRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlLookupRequest...");
         oracle.iam.wsschema.model.spmlv2.core.LookupRequestType
         _spmlLookupRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.LookupResponseType
         _spmlLookupRequest__return =
         port.spmlLookupRequest(_spmlLookupRequest_body);
         System.out.println("spmlLookupRequest.result=" +
         _spmlLookupRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlAddRequest...");
         oracle.iam.wsschema.model.spmlv2.core.AddRequestType
         _spmlAddRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.AddResponseType
         _spmlAddRequest__return = port.spmlAddRequest(_spmlAddRequest_body);
         System.out.println("spmlAddRequest.result=" +
         _spmlAddRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlResetPasswordRequest...");
         oracle.iam.wsschema.model.spmlv2.password.ResetPasswordRequestType
         _spmlResetPasswordRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.password.ResetPasswordResponseType
         _spmlResetPasswordRequest__return =
         port.spmlResetPasswordRequest(_spmlResetPasswordRequest_body);
         System.out.println("spmlResetPasswordRequest.result=" +
         _spmlResetPasswordRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlStatusRequest...");
         oracle.iam.wsschema.model.spmlv2.async.StatusRequestType
         _spmlStatusRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.async.StatusResponseType
         _spmlStatusRequest__return =
         port.spmlStatusRequest(_spmlStatusRequest_body);
         System.out.println("spmlStatusRequest.result=" +
         _spmlStatusRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlExpirePasswordRequest...");
         oracle.iam.wsschema.model.spmlv2.password.ExpirePasswordRequestType
         _spmlExpirePasswordRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.ResponseType
         _spmlExpirePasswordRequest__return =
         port.spmlExpirePasswordRequest(_spmlExpirePasswordRequest_body);
         System.out.println("spmlExpirePasswordRequest.result=" +
         _spmlExpirePasswordRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlModifyRequest...");
         oracle.iam.wsschema.model.spmlv2.core.ModifyRequestType
         _spmlModifyRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.ModifyResponseType
         _spmlModifyRequest__return =
         port.spmlModifyRequest(_spmlModifyRequest_body);
         System.out.println("spmlModifyRequest.result=" +
         _spmlModifyRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlLookupUsernamePolicyRequest...");
         oracle.iam.wsschema.model.spmlv2custom.username.LookupUsernamePolicyRequestType
         _spmlLookupUsernamePolicyRequest_body = null;
         oracle.iam.wsschema.model.spmlv2custom.username.LookupUsernamePolicyResponseType
         _spmlLookupUsernamePolicyRequest__return =
         port.spmlLookupUsernamePolicyRequest(_spmlLookupUsernamePolicyRequest_body);
         System.out.println("spmlLookupUsernamePolicyRequest.result=" +
         _spmlLookupUsernamePolicyRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlListTargetsRequest...");
         oracle.iam.wsschema.model.spmlv2.core.ListTargetsRequestType
         _spmlListTargetsRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.ListTargetsResponseType
         _spmlListTargetsRequest__return =
         port.spmlListTargetsRequest(_spmlListTargetsRequest_body);
         System.out.println("spmlListTargetsRequest.result=" +
         _spmlListTargetsRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlCancelRequest...");
         oracle.iam.wsschema.model.spmlv2.async.CancelRequestType
         _spmlCancelRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.async.CancelResponseType
         _spmlCancelRequest__return =
         port.spmlCancelRequest(_spmlCancelRequest_body);
         System.out.println("spmlCancelRequest.result=" +
         _spmlCancelRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlValidateUsernameRequest...");
         oracle.iam.wsschema.model.spmlv2custom.username.ValidateUsernameRequestType
         _spmlValidateUsernameRequest_body = null;
         oracle.iam.wsschema.model.spmlv2custom.username.ValidateUsernameResponseType
         _spmlValidateUsernameRequest__return =
         port.spmlValidateUsernameRequest(_spmlValidateUsernameRequest_body);
         System.out.println("spmlValidateUsernameRequest.result=" +
         _spmlValidateUsernameRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlDeleteRequest...");
         oracle.iam.wsschema.model.spmlv2.core.DeleteRequestType
         _spmlDeleteRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.ResponseType
         _spmlDeleteRequest__return =
         port.spmlDeleteRequest(_spmlDeleteRequest_body);
         System.out.println("spmlDeleteRequest.result=" +
         _spmlDeleteRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlSuspendRequest...");
         oracle.iam.wsschema.model.spmlv2.suspend.SuspendRequestType
         _spmlSuspendRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.ResponseType
         _spmlSuspendRequest__return =
         port.spmlSuspendRequest(_spmlSuspendRequest_body);
         System.out.println("spmlSuspendRequest.result=" +
         _spmlSuspendRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlActiveRequest...");
         oracle.iam.wsschema.model.spmlv2.suspend.ActiveRequestType
         _spmlActiveRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.suspend.ActiveResponseType
         _spmlActiveRequest__return =
         port.spmlActiveRequest(_spmlActiveRequest_body);
         System.out.println("spmlActiveRequest.result=" +
         _spmlActiveRequest__return);
       
       
         }
         {
         System.out.println("Invoking spmlSetPasswordRequest...");
         oracle.iam.wsschema.model.spmlv2.password.SetPasswordRequestType
         _spmlSetPasswordRequest_body = null;
         oracle.iam.wsschema.model.spmlv2.core.ResponseType
         _spmlSetPasswordRequest__return =
         port.spmlSetPasswordRequest(_spmlSetPasswordRequest_body);
         System.out.println("spmlSetPasswordRequest.result=" +
         _spmlSetPasswordRequest__return);
       
       
         }

        System.exit(0);
    }

}