/*
Copyright (c) 2003-2008 ITerative Consulting Pty Ltd. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package LDAP;
import java.io.Serializable;
import java.util.Iterator;
import org.ietf.ldap.LDAPAttributeSet;
import org.ietf.ldap.LDAPConnection;
import org.ietf.ldap.LDAPException;
import org.ietf.ldap.LDAPSearchConstraints;
import org.ietf.ldap.LDAPSearchResults;
import Framework.Array_Of_TextData;
import Framework.ParameterHolder;
import Framework.RemoteAccessException;
import Framework.TextData;
/**
* LDAPSession
* <p>
* <p>
* <b>This class was generated from the library LDAP and needs to be replaced by
* the proper source code from the library. It has been generated only to remove
* compile-time errors and is non-functional. </b>
* <p>
*
* @since 02-Aug-2006 15:55:44
*/
@SuppressWarnings({"serial", "unused"})
public class LDAPSession extends LDAPASN implements Serializable {
// ----------
// Attributes
// ----------
private LDAPConnection connection;
private TextData address;
private int port;
private int addressType;
private boolean open = false;
// ------------
// Constructors
// ------------
public LDAPSession() {
// Explicitly call the superclass constructor to prevent the implicit
// call
super();
this.connection = new LDAPConnection();
}
// ----------------------
// Accessors and Mutators
// ----------------------
// -------
// Methods
// -------
public TextData open(TextData pAddress, int pPort, int pAddressType) {
try {
this.connection.connect(pAddress.toString(), pPort);
this.address = pAddress;
this.port = pPort;
this.addressType = pAddressType;
this.open = true;
} catch (LDAPException e) {
throw new RemoteAccessException(
"Failed to to connect on this object"); // As thrown by UDS
}
return new TextData("open"); // As returned by UDS
}
public TextData open(TextData pAddress, int pAddressType) {
return this.open(pAddress, LDAPConnection.DEFAULT_PORT, pAddressType); // Default
// port
// is
// 389
}
public void close() {
try {
if (this.open) {
this.connection.disconnect();
this.open = false;
}
} catch (LDAPException e) {
e.printStackTrace();
}
}
public TextData bind(int pMessageID, TextData pName, TextData pPassword,int pVersion) {
return this.bind(pMessageID,pName,pPassword);
}
public TextData bind(int pMessageID, TextData pName, TextData pPassword) {
TextData returnString = new TextData("success"); // As returned by
// UDS
try {
this.connection.bind(com.novell.ldap.LDAPConnection.LDAP_V3, pName
.toString(), pPassword.toString().getBytes());
} catch (LDAPException e) {
if (e.getResultCode() == LDAPException.INVALID_CREDENTIALS) {
returnString = new TextData("invalidCredentials"); // As
// returned
// by UDS
}
}
return returnString;
}
public TextData unbind(int pMessageID) {
this.close();
return new TextData("Connection closed"); // As returned by UDS
}
public TextData search(int pMessageID, TextData pBase, int pScope,
int pDerefAliases, int pSizeLimit, int pTimeLimit,
boolean pTypesOnly, LDAPFilter pFilter,
Array_Of_TextData<TextData> pAttributes, ParameterHolder pResults) {
LDAPSearchResults results = null;
try {
results = this.ldapSearch(pBase, pScope, pDerefAliases,
pSizeLimit, pTimeLimit, pTypesOnly, pFilter, pAttributes);
pResults.setObject(results);
} catch (LDAPException e) {
e.printStackTrace();
}
return new TextData("success"); // As returned by UDS
}
@SuppressWarnings("unchecked")
public TextData search(int pMessageID, TextData pBase, int pScope,
int pDerefAliases, int pSizeLimit, int pTimeLimit,
boolean pTypesOnly, LDAPFilter pFilter,
Array_Of_TextData<TextData> pAttributes, ParameterHolder_LDAPEntry_Array pResults) {
TextData returnString = new TextData("success"); // As returned by
// UDS
LDAPSearchResults results;
try {
results = this.ldapSearch(pBase, pScope, pDerefAliases,
pSizeLimit, pTimeLimit, pTypesOnly, pFilter, pAttributes);
org.ietf.ldap.LDAPEntry entry;
org.ietf.ldap.LDAPAttribute attribute;
LDAPAttributeSet attrSet;
LDAP.LDAPEntry fEntry;
LDAP.LDAPAttribute fAttribute;
Iterator<org.ietf.ldap.LDAPAttribute> setItr;
Array_Of_TextData<TextData> listOfTextDataValues;
String[] listOfStringValues;
Array_Of_LDAPAttribute<LDAPAttribute> listOfAttributes;
while (results.hasMore()) {
entry = (org.ietf.ldap.LDAPEntry)(results.next());
fEntry = new LDAP.LDAPEntry();
fEntry.setDN(entry.getDN());
listOfAttributes = new Array_Of_LDAPAttribute<LDAPAttribute>();
attrSet = entry.getAttributeSet();
setItr = attrSet.iterator();
while (setItr.hasNext()) {
attribute = (org.ietf.ldap.LDAPAttribute)setItr.next();
fAttribute = new LDAP.LDAPAttribute();
fAttribute.setAttName(new TextData(attribute.getName()));
listOfStringValues = attribute.getStringValueArray();
listOfTextDataValues = new Array_Of_TextData<TextData>();
for (int j=0, jSize = listOfStringValues.length; j<jSize; j++ ) {
listOfTextDataValues.add(new TextData(listOfStringValues[j]));
}
fAttribute.setAttValueList(listOfTextDataValues);
listOfAttributes.add(fAttribute);
}
fEntry.setAttList(listOfAttributes);
((Array_Of_LDAPEntry<LDAPEntry>)pResults.getObject()).add(fEntry);
}
} catch (LDAPException e) {
if (pSizeLimit >0) {
returnString = new TextData("sizeLimitExceeded"); // As return by UDS
} else {
returnString = new TextData("failed");
}
}
return returnString;
}
private LDAPSearchResults ldapSearch(TextData pBase, int pScope,
int pDerefAliases, int pSizeLimit, int pTimeLimit,
boolean pTypesOnly, LDAPFilter pFilter,
Array_Of_TextData<TextData> pAttributes) throws LDAPException {
int scope;
if (pScope == LDAP.Constants.LDAP_SCOPE_BASE) {
scope = LDAPConnection.SCOPE_BASE;
} else if (pScope == Constants.LDAP_SCOPE_SINGLE) {
scope = LDAPConnection.SCOPE_ONE;
} else {
scope = LDAPConnection.SCOPE_SUB;
}
int timelimit;
if (pTimeLimit == 0) {
timelimit = 32767;
} else {
timelimit = pTimeLimit;
}
LDAPSearchConstraints constraints = new LDAPSearchConstraints();
constraints.setMaxResults(pSizeLimit);
constraints.setServerTimeLimit(timelimit);
constraints.setDereference(0); // UDS does not support Dereference of Aliases set to no
StringBuilder filter = new StringBuilder();
filter.append(pFilter.getAttributeValueDesc());
filter.append("=");
if (pFilter.getType() == LDAP.Constants.LDAP_FILTER_PRESENT) {
filter.append("*");
} else {
filter.append(pFilter.getAssertionValue());
}
String[] attributes = new String[pAttributes.size()];
for (int i=0, size=pAttributes.size(); i<size; i++) {
attributes[i] = ((TextData)pAttributes.get(i)).toString();
}
LDAPSearchResults results = null;
try {
results = this.connection.search(pBase.toString(),scope,filter.toString(),attributes,pTypesOnly,constraints);
} catch (LDAPException e) {
throw e;
}
return results;
}
} // end class LDAPSession
// c Pass 2 Conversion Time: 125 milliseconds