Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into...

24
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2008 SAP AG 1 Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0 Applies to: Please find the prerequisites, below, for the project; x SAP Exchange Infrastructure 3.0 SP21 x SAP NetWeaver Developer Studio Version: 7.0.11 Summary Java proxy provides accessing diverse resources by using SAP Exchange Infrastructure. The article explains, step by step how to access Active Directory attributes, by using “Java Proxy” object. You may prefer to develop an XI adapter by using adapter framework or accessing attributes by using LDAP function group on ABAP stack, but using “Java Proxy” objects on “SAP Exchange Infrastructure” is the most suitable way to read the data on AD. Of course, the way that you prefer may change regarding your specific needs. We implemented the scenario, in order to keep user master data updated on the SAP systems. I preferred SAP XI to develop this project, because XI is well designed and flexible integration tool in SAP product family. In the article, you will also find some case specific solutions that I faced during the implementation. Author: Orkun Gedik Company: ASTRON Created on: 21 January 2007 Author Bio I am Orkun Gedik and working at ASTRON as Senior SAP R/3 Development and Basis Consultant, since 1996. I have 10 years ABAP development and 6 years basis experience on SAP field.

Transcript of Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into...

Page 1: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 1

Accessing Active Directorythrough Java Proxy on SAPExchange Infrastructure 3.0

Applies to:Please find the prerequisites, below, for the project;

SAP Exchange Infrastructure 3.0 SP21

SAP NetWeaver Developer Studio Version: 7.0.11

SummaryJava proxy provides accessing diverse resources by using SAP Exchange Infrastructure. The articleexplains, step by step how to access Active Directory attributes, by using “Java Proxy” object.

You may prefer to develop an XI adapter by using adapter framework or accessing attributes by using LDAPfunction group on ABAP stack, but using “Java Proxy” objects on “SAP Exchange Infrastructure” is themost suitable way to read the data on AD. Of course, the way that you prefer may change regarding yourspecific needs.

We implemented the scenario, in order to keep user master data updated on the SAP systems. I preferredSAP XI to develop this project, because XI is well designed and flexible integration tool in SAP productfamily.

In the article, you will also find some case specific solutions that I faced during the implementation.

Author: Orkun Gedik

Company: ASTRON

Created on: 21 January 2007

Author BioI am Orkun Gedik and working at ASTRON as Senior SAP R/3 Development and BasisConsultant, since 1996. I have 10 years ABAP development and 6 years basis experience onSAP field.

Page 2: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 2

Table of Contents

Applies to:.....................................................................................................................................................1

Summary ......................................................................................................................................................1

Author Bio.....................................................................................................................................................1

Prerequisites.................................................................................................................................................3

Process model ..............................................................................................................................................5

Development and configuration.....................................................................................................................5Modeling the process on XI .......................................................................................................................5

Java Proxy Development ............................................................................................................................14

Related Content ..........................................................................................................................................23

Copyright ....................................................................................................................................................24

Page 3: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 3

Prerequisites

We need to check some configurations on ABAP stack and Java stack. Also, collect the required files, beforestarting the implementation.

Before we begin to implement the scenario, I would like to emphasize that “SAP strongly recommends “javaproxy objects should be deployed into separated adapter framework”, because of the performance reasons.This is because, java proxy object requires more hardware resources; consequently you may encounter withsome performance problems on your on going processes. In the article, I preferred deploy the proxy objectinto the adapter framework where XI is already running on, for the development purposes. But, I neverrecommend that you do this on your productive environments. Deploy those objects into a “SeparatedAdapter Framework”.

First prerequisite is collecting couple of libraries before the development. Those libraries provide developingjava proxy objects, under “Netweaver Developer Studio”. You can collect all of those files, on the XI system;

guidgenerator.jar: C:\usr\sap\<SID>\JC00\j2ee\cluster\server0\bin\ext\com.sap.guid

aii_proxy_xirt.jar: C:\usr\sap\<SID>\JC00\j2ee\cluster\server0\bin\ext\com.sap.aii.proxy.xiruntime

aii_utilxi_misc.jar: C:\usr\sap\<SID>\JC00\j2ee\cluster\server0\bin\ext\com.sap.xi.util.misc

aii_msg_runtime.jar: C:\usr\sap\<SID>\JC00\j2ee\cluster\server0\bin\ext\com.sap.aii.messaging.runtime

I recommend that you copy those files on your local PC, instead of sharing the directories on SAP XI system,because of the security reasons.

Another prerequisite is having a domain user that has LDAP query access authorization on active directoryserver.

Last point to check is, JPR adapter is working properly on SAP XI. In order to check the configuration, callhttp://server:port/rwb and click on “Adapter Monitoring” button, on the upcoming screen.

Page 4: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 4

Please notice that the screens are designed for SAP XI 3.0 with SP21. Screens might show slight differencesregarding the patch level. So, you should see the green light next to the JPR adapter, as below;

The most frequently faced problem is “SLD accessing” on JPR adapter. This problem occurs when thebusiness system is not defined on SLD. In order to solve this problem, create a “business system”definition for the “Java System” on SLD. It is important that SAP XI 3.0 installation step just creates“technical system” not “business system” for the java stack.

You can also find the referred solutions on OSS note #816022 and 809420.

Page 5: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 5

Process modelThe model is running very straight-forward. Understanding this schema provides more acknowledgement ofthe topic. Regarding your business needs, you can add or remove SAP systems, in the schema, below;

Technical meaning of the picture is a function module triggers a XI process at the ABAP stack level and thenXI forks the java proxy object. Consequently, proxy object read attributes on “Active Directory” and return thevalues into the function module. By doing so, user master data is being updated via proxy object, by activedirectory attributes on each SAP system.

Development and configuration

Modeling the process on XI

At this step, in order to implement the process, we need to create a product on SLD. click on “SoftwareCatalog”, under “Home” link, then click on “New Product…” button and enter the following values;

The values may be changed upon your needs. So, click on “Create” button. Consequently, this will create aproduct, on the software catalog. Now, we need to create a component under the product. Notice that asoftware product may have one or more software components. I recommend that you collect newcomponents, under the same software product. Enter following values to create software component relatedwith newly created product.

Page 6: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 6

We completed all the required tasks on solution landscape directory. At this stage we will import newlycreated software product and component into the integration repository. In order to import the object, openan “integration repository: design” application and perform the following task.

Select your newly created product on the list. As soon as you import the product, you’ll see a new item onthe left pane, like below. Sometimes you may not see the product in the list, even though you createdproduct and the component, successfully. That can be occurred; because of the fact that SLD cache is notrefreshed, yet.

After we imported the product into the integration repository, create a new namespace. I created“http://com.sap.astron/ldap” namespace, regarding the scenario. Then see the namespace, under theproduct definition, on left pane. Now that we created software product and component on SLD importednewly created product into IR and defined the namespace respectfully, we can apply the scenario.

Now, we will create a function module on ABAP stack. We will use the function module, in order to trigger theprocess on XI and read the return values. Import parameter TCK is a unique identification number. By usingthe id, we will query active directory values and read the attributes. Those attributes will be filled up in javaproxy object and return the export parameters on ABAP stack.

Page 7: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 7

Name: Z_B01_RFC_CALL_LDAP_JAVA_PROXY

*"----------------------------------------------------------------------*"*"Local Interface:*" IMPORTING*" VALUE(TCK) TYPE CHAR50*" EXPORTING*" VALUE(GIVENNAME) TYPE CHAR100*" VALUE(SN) TYPE CHAR50*" VALUE(ST) TYPE CHAR20*" VALUE(POSTALCODE) TYPE CHAR20*" VALUE(PAGER) TYPE CHAR2*" VALUE(COMPANY) TYPE CHAR100*" VALUE(DEPARTMENT) TYPE CHAR100*" VALUE(TITLE) TYPE CHAR100*" VALUE(TELEPHONENUMBER) TYPE CHAR30*" VALUE(MAIL) TYPE CHAR100

*"----------------------------------------------------------------------

Do not forget to set “Remote-Enabled Module” and “Start Immediately” on “Attributes” screen for the functionmodule. Then, generate the function module.

In order to send the data to SAP XI system, we need to define a “TCP/IP connection”. To do so, go to SM59and create a new connection named as “XI_LDAP_CONN”. We will define a business system thatcorresponds to the TCP connection, at the further steps. Now, let’s continue to implement the process onintegration builder. We should import “Z_B01_RFC_CALL_LDAP_JAVA_PROXY” function module into SAPXI system. I recommend that you import the function module under “SAP_APPL”, under related SAP release,but you can import it into “LDAP_JAVA_PROXY” project, also. Now, enter the required values and import thefunction module, as show below;

Data types should be created automatically for the function module at the end of the respective importoperation. So, create the following data types for the proxy object, under “Interface objects -> Data types”,named as “DT_LDAP_OUT” and “DT_LDAP_IN”;

Page 8: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 8

As you can see in the picture, we should create same structures with newly created function module importand export parameters. Create following message types, named as “MT_LDAP_IN” and “MT_LDAP_OUT”.MT_LDAP_OUT message type, covers that return values of the java proxy object and MT_LDAP_IN coversthat request parameter that will be sent to the java proxy object.

Page 9: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 9

Now that we created data types and message types, we will create message interface named as“MI_LDAP_Inbound_Sync”. By doing so, we will specify what kind of behavior must be performed by thesystem. By behavior meant; that inbound or outbound and synchronous or asynchronous call.

In the message interface screen, set input message to “MT_LDAP_IN” and out message “MT_LDAP_OUT”.Then set category to “Inbound” and mode “Synchronous”. Regarding the scenario, function moduleshould be called synchronously. Please see the picture, above. We will also use this message interface, inorder to create “Java Proxy” object template.

After we created message interface respectively, we need to create mappings between RFC and java proxyobject message types, as below;

Firstly, create a “MM_JPROXY_TO_LDAP” mapping from java proxy object to LDAP request; Drag TCKunder Z_B01_RFC_CALL_LDAP_JAVA_PROXY and drop it on TCK under MT_LDAP_IN.

Then create “MM_LDAP_TO_JPROXY” mapping LDAP to java proxy response; Drag the matched fieldname and drop on the destination field, done in the previous step.

Page 10: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 10

At the last step in “Integration Builder: Designer”, we will create interface mapping, named“IM_LDAP_JPROXY”, as below;

Page 11: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 11

At the end of the respective step, we completed all the task on designer tool. Now, call the “IntegrationBuilder: Configuration” and start the configuration step. At this step, we need to create a scenario andcollect all the objects under that. It provides a well modeled development to us. Scenario should be createdas described below;

As soon as you create the scenario, you will it on the left pane, as inactivated state. From now on, we willimport “Business systems” from SLD and configure them.

Under “Business system -> Assign Business System”, select required system names from the list andclick on finish button. It is important to uncheck “Create Communication Channels Automatically” box.Otherwise, unnecessary system definitions will be created, under business system node.

Create a sender “RfcLdap” channel for function module call. Then, configure “RFC Server Parameter” and“RFC Metadata Repository Parameter” values, on the adapter settings screen.

Page 12: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 12

It is important that “Program ID” in adapter settings and “Registered Server Program” in RFCdestinations must be same. Otherwise, the systems will not be communicated successfully. In order to besure that the communication is being performed successfully, go to SM59 and test the TCP connection thatyou defined at previous step.

At the receiver configuration phase, we will create a new communication channel with XI adapter type,named as “JavaProxy”, below as shown;

It is important that you should select “Use Logon Data for Non-SAP System” and enter the username andpassword into the boxes. Java proxy object will be called through “/MessagingSystem/receive/JPR/XI”.

Now that we created all the communication channels, we need to create sender and receiver agreementswith the following parameters;

Page 13: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 13

Receiver agreement; Sender agreement;

Create a receiver determination, as shown;

If you open “YXI_JAVA” in the Configuration Overview for Receiver Determination list, you will see “notdefined” items. This is because receiver determination requires an interface determination. To solve this,create an interface determination, as described;

Page 14: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 14

When you return to receiver determination screen, you will see that the mappings and determinations arecorrected. We completed design and configuration steps on the “Integration Builder”. So, we can go on withthe Java Proxy development.

Java Proxy DevelopmentAll in all, we reached the main purpose of the article. In my opinion, this topic is the most enjoyable one,because it requires couple of java coding in it. Now, we will develop a “Java Proxy” object. To develop thatobject, as we mentioned at the beginning of the article, we need a Netweaver Developer Studio. Actually, wewill develop an EJB. Then, create a java archive file and deploy it into J2EE server, consequently. XIprovides a template source code for the proxy object, which will make this step easier. In order to createtemplate go to “Integration Builder: Designer”. Then, open “Message Interfaces”, locate cursor on“MI_LDAP_Inbound_Sync” and select “Java Proxy Generation” on the context menu.

At the incoming “Java Proxy Generation” screen, click on the save button, then give an archive name, forexample “yxi_ldap_java_proxy_template”, and click on finish button. You could select another relatedmessage interfaces and software components on the wizard, in more complex scenarios. Since we areworking on, only one message interface in the project, we finished the process, at the first step.

We will create an “EJB Module Project”. To do so, open a Netweaver Developer Studio and perform thefollowing tasks, below;

Page 15: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 15

Create an EJB module by “File -> New -> Project” and select “EJB Module Project” under “J2EE”node, then click on Next button.

Give a project name for the EJB project. For example I used “LdapQueryJavaProxy” as name of theproject. At the same screen, you can configure the workspace, also.

Then click on “Finish” button on the screen.

By doing do, we created an empty EJB module. Now, we will import the zip file(yxi_ldap_java_proxy_template.zip) that we created previously.

Select “ejbModule” node in “J2EE Explorer”.

While the cursor located on “ejbModule”, select File -> Import on the menu and on the incomingpopup window, select “Zip file” then click on “Next”.

At this step the developer studio will ask for zip file location. To browse its location, click on browsebutton, next to the “From zip file” label then select the file from the list, then click “Ok” and “Finish”.

By doing so, we imported template code into the project.

When you open ejbModule -> com.sap.astron -> ldap node, you will see the files, below;

o DTLDAPIN_Type.javao DTLDAPOUT_Type.javao MILDAPInboundSync_PortType.javao MILDAPInboundSync_PortTypeBean.javao MILDAPInboundSync_PortTypeImpl.template

Rename MILDAPInboundSync_PortTypeImpl.template to MILDAPInboundSync_PortTypeImpl.javaand unload project and load again in the “Navigator” window.

Now, we need to include XI libraries into the project. On the EJB name, click on left button and select“Properties” on the menu.

On the upcoming screen, click on “Java Build Path” and click on “Add external JARs” button. Pleasefind the name of files to be included, below;

o aii_msg_runtime.jaro aii_proxy_xirt.jaro aii_utilxi_misc.jaro guidgenerator.jar

Select all of those files then click open and “Ok” button.

So, we included XI libraries into the project. From now on all the errors should be fixed on templatesource code. You can find the source codes, below;

MILDAPInboundSync_PortTypeImpl.java

package com.sap.astron.ldap;

import com.sap.astron.ldap.LdapReader;

public class MILDAPInboundSync_PortTypeImpl extends com.sap.aii.proxy.xiruntime.core.AbstractProxyimplements MILDAPInboundSync_PortType {

Page 16: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 16

public com.sap.astron.ldap.DTLDAPOUT_Type mILDAPInboundSync(com.sap.astron.ldap.DTLDAPIN_TypemTLDAPIN) throws com.sap.aii.proxy.xiruntime.core.SystemFaultException,com.sap.aii.proxy.xiruntime.core.ApplicationFaultException{

// import TCKString TCK = mTLDAPIN.getTCK();

// create ldap reader instanceLdapReader reader = new LdapReader();

// read attributes thorugh LDAPreader.ReadLdapAttributes(TCK);

// set response to XIDTLDAPOUT_Type response = new DTLDAPOUT_Type();

response.setCOMPANY(reader.getCompany());response.setDEPARTMENT(reader.getDepartment());response.setGIVENNAME(reader.getGivenName());response.setMAIL(reader.getMail());response.setPAGER(reader.getPager());response.setPOSTALCODE(reader.getPostalCode());response.setSN(reader.getSn());response.setST(reader.getSt());response.setTELEPHONENUMBER(reader.getTelephoneNumber());response.setTITLE(reader.getTitle());

return(response); }

}

ConfigReader.java

/* * Created on 12.Kas.2007 * * To change the template for this generated file go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */package com.sap.astron.ldap;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.xpath.XPathAPI;import org.w3c.dom.Document;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;

/*** @author orkungedik1** To change the template for this generated type comment go to* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments*/

public class ConfigReader {

private String itemServer; // GC serverprivate String itemBaseentry; // ldap query base entryprivate String itemUsername; // credential (username)private String itemPassword; // credential (password)private String pathServer; // GC serverprivate String pathBaseentry; // ldap query base entryprivate String pathUsername; // credential (username)private String pathPassword; // credential (password)

public boolean Init() {try

Page 17: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 17

{// initailize xml factory objectDocumentBuilderFactory docBuilderFactory =

DocumentBuilderFactory.newInstance();DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();Document doc = docBuilder.parse(new

File("c:\\ldapcfg\\ldap_proxy_config.xml"));

doc.getDocumentElement().normalize();

// read xml elementspathServer = "ldapProxy/Server";itemServer = XPathAPI.eval(doc,pathServer).toString();itemServer = itemServer.replaceAll("\t","");itemServer = itemServer.replaceAll("\n","");

pathBaseentry = "ldapProxy/Baseentry";itemBaseentry = XPathAPI.eval(doc,pathBaseentry).toString();itemBaseentry = itemBaseentry.replaceAll("\t","");itemBaseentry = itemBaseentry.replaceAll("\n","");

pathUsername = "ldapProxy/Username";itemUsername = XPathAPI.eval(doc,pathUsername).toString();itemUsername = itemUsername.replaceAll("\t","");itemUsername = itemUsername.replaceAll("\n","");

pathPassword = "ldapProxy/Password";itemPassword = XPathAPI.eval(doc,pathPassword).toString();itemPassword = itemPassword.replaceAll("\t","");itemPassword = itemPassword.replaceAll("\n","");

} catch (SAXParseException err) {System.out.println ("** Parsing error" + ", line "

+ err.getLineNumber () + ", uri " + err.getSystemId ());System.out.println(" " + err.getMessage ());

} catch (SAXException e) {Exception x = e.getException ();((x == null) ? e : x).printStackTrace ();

} catch (Throwable t) {t.printStackTrace ();

}

return(true);}/*** @return*/

public String getItemBaseentry() {return itemBaseentry;

}

/*** @return*/

public String getItemPassword() {return itemPassword;

}

/*** @return*/

public String getItemServer() {return itemServer;

}

/*** @return*/

Page 18: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 18

public String getItemUsername() {return itemUsername;

}}

LdapReader.java

/* * Created on 09.Kas.2007 * * To change the template for this generated file go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */package com.sap.astron.ldap;

import java.util.Hashtable;

import javax.naming.Context;import javax.naming.NamingEnumeration;import javax.naming.NamingException;import javax.naming.directory.Attributes;import javax.naming.directory.SearchControls;import javax.naming.directory.SearchResult;import javax.naming.ldap.InitialLdapContext;import javax.naming.ldap.LdapContext;

/*** @author orkungedik1** To change the template for this generated type comment go to* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments*/

public class LdapReader {// Ldap attributesprivate class LDAP_ATTS {

private String givenName;private String sn;private String st;private String postalCode;private String Pager;private String Company;private String Department;private String Title;private String TelephoneNumber;private String mail;

}

/*** @return*/

public String getCompany() {return att.Company;

}

/*** @return*/

public String getDepartment() {return att.Department;

}

/*** @return*/

public String getGivenName() {return att.givenName;

}

/*** @return*/

public String getMail() {

Page 19: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 19

return att.mail;}

/*** @return*/

public String getPager() {return att.Pager;

}

/*** @return*/

public String getPostalCode() {return att.postalCode;

}

/*** @return*/

public String getSn() {return att.sn;

}

/*** @return*/

public String getSt() {return att.st;

}

/*** @return*/

public String getTelephoneNumber() {return att.TelephoneNumber;

}

/*** @return*/

public String getTitle() {return att.Title;

}

private String urlGC; // LDAP serverprivate String searchBaseentry; // LDAP query base entryprivate String adminCanonicalName; // usernameprivate String adminPassword; // passwordprivate LDAP_ATTS att; // ldap attributesprivate String returnedAtts[]={"givenName",

"sn","st","postalCode","Pager","Company","Department","Title","TelephoneNumber","mail"}; // Ldap attributes

// read ldap connection parameters from XML configurationprivate boolean GetLdapConnectionParams(){

// instantiate configuration reader object ConfigReader cfg_reader = new ConfigReader();

// initialize reader cfg_reader.Init();

// assign canonical user name and its password adminCanonicalName = cfg_reader.getItemUsername(); adminPassword = cfg_reader.getItemPassword();

Page 20: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 20

// Ldap server & port urlGC = "ldap://" + cfg_reader.getItemServer();

// Ldap query base entry searchBaseentry = cfg_reader.getItemBaseentry();

return(true);}

public boolean ReadLdapAttributes(String TCK){

// initialize attribute structure att = new LDAP_ATTS();

// read ldap configuration fileif(false!=GetLdapConnectionParams()) {

// configuration storageHashtable envGC = new Hashtable();

// initialize factory objectenvGC.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

// set security credentialsenvGC.put(Context.SECURITY_AUTHENTICATION,"simple");envGC.put(Context.SECURITY_PRINCIPAL,adminCanonicalName);envGC.put(Context.SECURITY_CREDENTIALS,adminPassword);

// connect to GCenvGC.put(Context.PROVIDER_URL,urlGC);

try {//Create the initial directory context for both DC and GCLdapContext ctxGC = new InitialLdapContext(envGC,null);

//Now perform a search against the GC//Create the search controlsSearchControls searchCtls = new SearchControls();

//Specify the attributes to returnsearchCtls.setReturningAttributes(returnedAtts);

//Specify the search scopesearchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);

//specify the LDAP search filterString searchFilter = "(&(objectcategory=user)(st=" + TCK + "))";

//Search for objects in the GC using the filterNamingEnumeration answer = ctxGC.search(searchBaseentry, searchFilter,

searchCtls);

//read the search resultsif (false!=answer.hasMoreElements()) {

SearchResult sr = (SearchResult)answer.next();

// Print out some of the attributes, catch theexception if the attributes have no values

Attributes attrs = sr.getAttributes();if (attrs != null) {

try {

// read attribute valuesatt.givenName =

attrs.get("givenName").get().toString();att.sn = attrs.get("sn").get().toString();att.st = attrs.get("st").get().toString();att.postalCode =

attrs.get("postalCode").get().toString();att.Pager =

attrs.get("Pager").get().toString();att.Company =

attrs.get("Company").get().toString();

Page 21: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 21

att.Department =attrs.get("Department").get().toString();

att.Title =attrs.get("Title").get().toString();

att.TelephoneNumber =attrs.get("TelephoneNumber").get().toString();

att.mail = attrs.get("mail").get().toString();}

catch (NullPointerException e) {System.err.println("Problem listing attributes

from Global Catalog: " + e);}

}}

} catch (NamingException e) {System.err.println("Problem occured on directory searching: " + e);

}

// everything is okreturn(true);

}else return(false);

}}

After we created all the java classes respectively, we can add “MILDAPInboundSync_PortTypeBean” under“EJB Candidates”, into ejb-jar.xml. To do that, perfom the following steps;

Select “Add To ejb-jar.xml” from context menu,

Then you will see “MILDAPInboundSync_PortTypeBean” under “ejb-jar.xml”,

Open ejb-j2ee-engine.xml by double clicking on the item and then click on “Enterprise Beans” on thetabbed controls, under the window. Open “Session beans” from plus sign,

Click on “MILDAPInboundSync_PortTypeBean”,

Write down “LdapQueryProxy”. If you do not determine the JNDI name, the name will be assignedautomatically. I recommend that you determine the name, yourself,

Build EJB Archive,

Save the file.

Now, we should create EAR file in order to deploy the EJB. To do that, perform the tasks, below;

Create an “Enterprise Application Project”,

Give “ProxyEAR” as project name,

Select “LdapQueryJavaProxy” as referenced projects,

Click on “Finish” button,

Open application-j2ee-engine.xml and click on “Source” tab, then replace its content with thefollowing content;

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE application-j2ee-engine SYSTEM 'application-j2ee-engine.dtd'><application-j2ee-engine><reference reference-type="weak"><reference-target provider-name="sap.com" target-type="library">com.sap.aii.proxy.xiruntime</reference-target></reference><reference reference-type="weak"><reference-target provider-name="sap.com" target-type="library">com.sap.aii.messaging.runtime

Page 22: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 22

</reference-target></reference><reference reference-type="weak"><reference-target provider-name="sap.com" target-type="library">com.sap.xi.util.misc</reference-target></reference><reference reference-type="weak"><reference-target provider-name="sap.com" target-type="library">com.sap.guid</reference-target></reference><provider-name>sap.com</provider-name><fail-over-enable mode="disable"/>

</application-j2ee-engine>

Build application archive,

Save the file.

Now, we can deploy the EJB into J2EE server. There are many ways to do that. The easiest way isdeploying EJB through Developer Studio. To do that, open context menu on “ProxyEAR.ear” file under“ProxyEAR” project and click on “Deploy to J2EE Engine”. Of course, in order to deploy the archive filethrough developer studio, it needs to be configured for the J2EE server that we are working on. You can useSDM to deploy the file also.

In order to execute EJB, we need to register it, on the J2EE server. Call the URL below;

http://[hostname]:[port]/ProxyServer/register?ns=http://com.sap.astron/ldap&interface=MI_LDAP_Inbound_Sync&bean=LdapQueryProxy&method=mILDAPInboundSync

At the last step, we need to create a directory and put the following xml file, as shown;

C:\ldapcfg

ldap_proxy_config.xml<ldapProxy>

<Server>sample.domain.com:389</Server><Baseentry>dc=sample</Baseentry><Username>CN=Generic, OU=MyOU,DC=MyDC</Username><Password>xxxxxx</Password>

</ldapProxy>

Congratulations!!! You completed the tutorial successfully. For the testing purposes, you can execute theABAP program, below;

*&---------------------------------------------------------------------**& Report Z_LDAP_SAMPLE*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*

REPORT Z_LDAP_SAMPLE.

Page 23: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 23

DATA: GIVENNAME(100), SN(50), ST(20), POSTALCODE(20), PAGER(2), COMPANY(100), DEPARTMENT(100), TITLE(100), TELEPHONENUMBER(30), MAIL(100).

CALL FUNCTION 'Z_B01_RFC_CALL_LDAP_JAVA_PROXY' DESTINATION 'LDAP_SAMPLE' EXPORTING TCK = '11111111111' IMPORTING GIVENNAME = GIVENNAME SN = SN ST = ST POSTALCODE = POSTALCODE PAGER = PAGER COMPANY = COMPANY DEPARTMENT = DEPARTMENT TITLE = TITLE TELEPHONENUMBER = TELEPHONENUMBER MAIL = MAIL.

WRITE: / GIVENNAME.WRITE: / SN.WRITE: / ST.WRITE: / POSTALCODE.WRITE: / PAGER.WRITE: / COMPANY.WRITE: / DEPARTMENT.WRITE: / TITLE.WRITE: / TELEPHONENUMBER.WRITE: / MAIL.

Related ContentHow To… Work with XI 3.0 Java Proxies

Page 24: Accessing Active Directory through Java Proxy on SAP ......proxy objects should be deployed into separated adapter framework”, because of the performance reasons. This is because,

Accessing Active Directory through Java Proxy on SAP Exchange Infrastructure 3.0

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com© 2008 SAP AG 24

Copyright© 2008 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries,zSeries, System i, System i5, System p, System p5, System x, System z, System z9, z/OS, AFP, Intelligent Miner, WebSphere,Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, POWER5+, OpenPower and PowerPC are trademarks or registered trademarks ofIBM Corporation.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe SystemsIncorporated in the United States and/or other countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks ofCitrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, MassachusettsInstitute of Technology.

Java is a registered trademark of Sun Microsystems, Inc.

JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented byNetscape.

MaxDB is a trademark of MySQL AB, Sweden.

SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as theirrespective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. Allother product and service names mentioned are the trademarks of their respective companies. Data contained in this document servesinformational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAPGroup") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors oromissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in theexpress warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting anadditional warranty.

These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the impliedwarranties of merchantability, fitness for a particular purpose, or non-infringement.

SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that mayresult from the use of these materials.

SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within thesematerials. SAP has no control over the information that you may access through the use of hot links contained in these materials anddoes not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages.

Any software coding and/or code lines/strings (“Code”) included in this documentation are only examples and are not intended to beused in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules ofcertain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errorsor damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.