This commit is contained in:
miodrag%netscape.com 1999-06-05 00:53:02 +00:00
Родитель 6e340ba483
Коммит 5f14e72099
20 изменённых файлов: 496 добавлений и 213 удалений

Просмотреть файл

@ -0,0 +1,4 @@
Name: netscape/ldap/beans/DisplayString.class
Java-Bean: True
Name: netscape/ldap/beans/DisplayStringBeanInfo.class

Просмотреть файл

@ -221,7 +221,7 @@ public class LDAPBasePropertySupport implements Serializable {
* @param listener a client to be notified of changes
*/
public void addPropertyChangeListener( PropertyChangeListener listener ) {
System.out.println( "Adding listener " + listener );
printDebug( "Adding listener " + listener );
m_propSupport.addPropertyChangeListener( listener );
}
@ -304,6 +304,9 @@ public class LDAPBasePropertySupport implements Serializable {
args[0] = new String( "UniversalConnect" );
m[i].invoke( null, args );
printDebug( "UniversalConnect enabled" );
args[0] = new String( "UniversalPropertyRead" );
m[i].invoke( null, args );
printDebug( "UniversalPropertyRead enabled" );
} catch ( Exception e ) {
printDebug( "Exception on invoking " +
"enablePrivilege: " +
@ -320,11 +323,54 @@ public class LDAPBasePropertySupport implements Serializable {
}
conn.connect( host, port );
setDefaultReferralCredentials( conn );
}
protected void setDefaultReferralCredentials(
LDAPConnection conn ) {
final LDAPConnection m_conn = conn;
LDAPRebind rebind = new LDAPRebind() {
public LDAPRebindAuth getRebindAuthentication(
String host,
int port ) {
return new LDAPRebindAuth(
m_conn.getAuthenticationDN(),
m_conn.getAuthenticationPassword() );
}
};
LDAPSearchConstraints cons = conn.getSearchConstraints();
cons.setReferrals( true );
cons.setRebindProc( rebind );
}
/**
* Utility method to convert an array of Strings to a single String
* with line feeds between elements.
* @param aResult The array of Strings to convert
* @return A String with the elements separated by line feeds
*/
public String convertToString( String[] aResult ) {
String sResult = "";
if ( null != aResult ) {
for ( int i = 0; i < aResult.length; i++ ) {
sResult += aResult[i] + "\n";
}
}
return sResult;
}
/*
* Variables
*/
/* Error codes from search operations, etc */
public static final int OK = 0;
public static final int INVALID_PARAMETER = 1;
public static final int CONNECT_ERROR = 2;
public static final int AUTHENTICATION_ERROR = 3;
public static final int PROPERTY_NOT_FOUND = 4;
public static final int AMBIGUOUS_RESULTS = 5;
public static final int NO_SUCH_OBJECT = 6;
private boolean _debug = false;
private int _errCode = 0;
private String _host = new String("localhost");
@ -339,3 +385,4 @@ public class LDAPBasePropertySupport implements Serializable {
transient private PropertyChangeSupport m_propSupport =
new PropertyChangeSupport( this );
}

Просмотреть файл

@ -87,26 +87,31 @@ public class LDAPGetEntries extends LDAPBasePropertySupport implements Serializa
setScope( theScope );
}
private String convertToStrings( String[] aResult ) {
String sResult = "";
if ( null != aResult ) {
for ( int i = 0; i < aResult.length; i++ ) {
sResult += aResult[i] + "\n";
}
}
return sResult;
}
private void notifyResult( String error ) {
firePropertyChange( "error", _errorMsg, error );
_errorMsg = error;
}
private void notifyResult( String[] newResult ) {
String sNewResult = convertToStrings( newResult );
firePropertyChange( "result", result, newResult );
String sNewResult = convertToString( newResult );
firePropertyChange( "result", _result, newResult );
_sResult = sNewResult;
result = newResult;
_result = newResult;
}
/**
* Returns the name of the attribute to retrieve
* @return attribute name to retrieve
*/
public String getAttribute() {
return _attribute;
}
/**
* Sets the attribute to retrieve
*/
public void setAttribute( String attr ) {
_attribute = attr;
}
public void setResultString( String sNewValue ) {
@ -244,7 +249,7 @@ public class LDAPGetEntries extends LDAPBasePropertySupport implements Serializa
try {
printDebug("Searching " + getBase() +
" for " + getFilter() + ", scope = " + getScope());
String[] attrs = null;
String[] attrs = { _attribute };
LDAPSearchResults results = m_ldc.search( getBase(),
getScope(),
getFilter(),
@ -256,48 +261,56 @@ public class LDAPGetEntries extends LDAPBasePropertySupport implements Serializa
LDAPEntry entry = null;
while ( results.hasMoreElements() ) {
try {
entry = (LDAPEntry)results.next();
} catch (LDAPReferralException e) {
if (getDebug()) {
notifyResult("Referral URLs: ");
LDAPUrl refUrls[] = e.getURLs();
for (int i = 0; i < refUrls.length; i++)
notifyResult(refUrls[i].getUrl());
}
continue;
entry = results.next();
} catch (LDAPException e) {
if (getDebug())
notifyResult(e.toString());
continue;
}
String dn = entry.getDN();
v.addElement( dn );
printDebug( "... " + dn );
// Add the DN to the list
String value = "";
if ( _attribute.equals("dn") ) {
value = entry.getDN();
} else {
LDAPAttribute attr = entry.getAttribute( _attribute );
if ( attr != null ) {
Enumeration vals = attr.getStringValues();
if ( (vals != null) && (vals.hasMoreElements()) ) {
value = (String)vals.nextElement();
}
}
}
v.addElement( value );
printDebug( "... " + value );
}
// Pull out the DNs and create a string array
if ( v.size() > 0 ) {
res = new String[v.size()];
for( int i = 0; i < v.size(); i++ )
res[i] = (String)v.elementAt( i );
v.copyInto( res );
v.removeAllElements();
setErrorCode( OK );
} else {
printDebug( "No entries found for " + getFilter() );
setErrorCode( PROPERTY_NOT_FOUND );
}
} catch (Exception e) {
printDebug( "Failed to search for " + getFilter() + ": " +
e.toString() );
if (getDebug()) {
printDebug( "Failed to search for " + getFilter() + ": " +
e.toString() );
}
setErrorCode( PROPERTY_NOT_FOUND );
}
} catch (Exception e) {
}
// Disconnect
try {
if ( (m_ldc != null) && m_ldc.isConnected() )
m_ldc.disconnect();
} catch ( Exception e ) {
}
// Notify any clients with a PropertyChangeEvent
notifyResult( res );
return res;
}
@ -307,7 +320,16 @@ public class LDAPGetEntries extends LDAPBasePropertySupport implements Serializa
* @param args list of arguments
*/
public static void main(String args[]) {
if (args.length != 5) {
String[] scope = { "base", "one", "sub" };
int scopeIndex = -1;
for( int i = 0; (i < scope.length) && (args.length == 5); i++ ) {
if ( args[3].equalsIgnoreCase(scope[i]) ) {
scopeIndex = i;
break;
}
}
if ( scopeIndex < 0 ) {
System.out.println( "Usage: LDAPGetEntries host port base" +
" scope filter" );
System.exit(1);
@ -316,7 +338,7 @@ public class LDAPGetEntries extends LDAPBasePropertySupport implements Serializa
app.setHost( args[0] );
app.setPort( java.lang.Integer.parseInt( args[1] ) );
app.setBase( args[2] );
app.setScope( Integer.parseInt(args[3]) );
app.setScope( scopeIndex );
app.setFilter( args[4] );
String[] response = app.getEntries();
if ( response != null ) {
@ -329,13 +351,8 @@ public class LDAPGetEntries extends LDAPBasePropertySupport implements Serializa
/*
* Variables
*/
public static final int OK = 0;
public static final int INVALID_PARAMETER = 1;
public static final int CONNECT_ERROR = 2;
public static final int AUTHENTICATION_ERROR = 3;
public static final int PROPERTY_NOT_FOUND = 4;
public static final int AMBIGUOUS_RESULTS = 5;
transient private String[] result;
private String _attribute = "dn";
private String[] _result;
private String _sResult = null;
private String _errorMsg = null;
}

Просмотреть файл

@ -0,0 +1,7 @@
Name: netscape/ldap/beans/LDAPGetEntries.class
Java-Bean: True
Name: netscape/ldap/beans/LDAPBasePropertySupport.class
Name: netscape/ldap/beans/LDAPGetEntriesBeanInfo.class

Просмотреть файл

@ -74,37 +74,26 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
* @return attribute name to retrieve
*/
public String getAttribute() {
return attribute;
return _attribute;
}
/**
* Sets the attribute to retrieve
*/
public void setAttribute( String attr ) {
attribute = attr;
}
private String convertToStrings( String[] aResult ) {
String sResult = "";
if ( null != aResult ) {
for ( int i = 0; i < aResult.length; i++ ) {
sResult += aResult[i] + "\n";
}
}
return sResult;
_attribute = attr;
}
private void notifyResult( String[] newResult ) {
String sNewResult = convertToStrings( newResult );
firePropertyChange( "result", result, newResult );
// firePropertyChange( "resultString", _sResult, sNewResult );
String sNewResult = convertToString( newResult );
firePropertyChange( "result", _result, newResult );
_sResult = sNewResult;
result = newResult;
_result = newResult;
}
private void notifyResult( Vector newResult ) {
firePropertyChange( "result", resultV, newResult );
resultV = (Vector)newResult.clone();
firePropertyChange( "result", _resultV, newResult );
_resultV = (Vector)newResult.clone();
}
private void notifyResult( String error ) {
@ -154,7 +143,7 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
* @return Array of values for the property
*/
public String[] getProperty() {
if ( (attribute.length() < 1) || (getFilter().length() < 1) ) {
if ( (_attribute.length() < 1) || (getFilter().length() < 1) ) {
printDebug( "Invalid attribute name or filter" );
setErrorCode( INVALID_PARAMETER );
notifyResult( (String[])null );
@ -210,7 +199,7 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
// Search
try {
String[] attrs = new String[1];
attrs[0] = attribute;
attrs[0] = _attribute;
LDAPSearchResults results = m_ldc.search(getBase(),
getScope(),
getFilter(),
@ -230,14 +219,6 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
setErrorCode( AMBIGUOUS_RESULTS );
break;
}
} catch (LDAPReferralException e) {
if (getDebug()) {
notifyResult("Referral URLs: ");
LDAPUrl refUrls[] = e.getURLs();
for (int i = 0; i < refUrls.length; i++)
notifyResult(refUrls[i].getUrl());
}
continue;
} catch (LDAPException e) {
if (getDebug())
notifyResult(e.toString());
@ -248,7 +229,7 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
printDebug( "... " + entry.getDN() );
// Good - exactly one entry found; get the attribute
// Treat DN as a special case
if ( attribute.equalsIgnoreCase( "dn" ) ) {
if ( _attribute.equalsIgnoreCase( "dn" ) ) {
res = new String[1];
res[0] = entry.getDN();
setErrorCode( OK );
@ -270,8 +251,7 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
printDebug( "\t\t" + val );
}
res = new String[v.size()];
for( int i = 0; i < v.size(); i++ )
res[i] = (String)v.elementAt( i );
v.copyInto( res );
setErrorCode( OK );
} else {
Enumeration byteEnum = attr.getByteValues();
@ -287,14 +267,16 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
}
} else {
printDebug( "No properties found for " +
attribute );
_attribute );
setErrorCode( PROPERTY_NOT_FOUND );
}
}
}
} catch (Exception e) {
printDebug( "Failed to search for " + getFilter() + ": "
+ e.toString() );
if (getDebug()) {
printDebug( "Failed to search for " + getFilter() + ": "
+ e.toString() );
}
setErrorCode( PROPERTY_NOT_FOUND );
}
@ -303,6 +285,7 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
setErrorCode( PROPERTY_NOT_FOUND );
}
// Disconnect
try {
if ( (m_ldc != null) && m_ldc.isConnected() )
m_ldc.disconnect();
@ -340,16 +323,10 @@ public class LDAPGetProperty extends LDAPBasePropertySupport implements
/*
* Variables
*/
public static final int OK = 0;
public static final int INVALID_PARAMETER = 1;
public static final int CONNECT_ERROR = 2;
public static final int AUTHENTICATION_ERROR = 3;
public static final int PROPERTY_NOT_FOUND = 4;
public static final int AMBIGUOUS_RESULTS = 5;
private String[] _dns = null;
private String attribute = new String("cn");
transient private String[] result;
private Vector resultV = null;
private String _attribute = new String("cn");
transient private String[] _result;
private Vector _resultV = null;
private String _sResult = null;
private String _errorMsg = null;
}

Просмотреть файл

@ -0,0 +1,6 @@
Name: netscape/ldap/beans/LDAPGetProperty.class
Java-Bean: True
Name: netscape/ldap/beans/LDAPBasePropertySupport.class
Name: netscape/ldap/beans/LDAPGetPropertyBeanInfo.class

Просмотреть файл

@ -18,6 +18,7 @@
package netscape.ldap.beans;
import netscape.ldap.*;
import netscape.ldap.util.*;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.io.Serializable;
@ -28,6 +29,11 @@ import java.awt.event.*;
* authentication name and password, and DN of a group and another DN
* which might be a member of the group, and returns true or
* false, depending on whether the second DN is a member of the first.
* <BR>
* Also handles the case of dynamic groups by derefencing the URL
* and searching for membership based on the url search.
* <BR>
* It doesn't handle nested groups.
* <BR><BR>
* A false result means the member could not be identified as
* belonging to the group. The exact reason is
@ -43,7 +49,8 @@ import java.awt.event.*;
* NO_SUCH_OBJECT
*</PRE>
*/
public class LDAPIsMember extends LDAPBasePropertySupport implements Serializable {
public class LDAPIsMember extends LDAPBasePropertySupport
implements Serializable {
/**
* Constructor with no parameters
@ -147,14 +154,16 @@ public class LDAPIsMember extends LDAPBasePropertySupport implements Serializabl
int numDataEntries = 0;
// Search
try {
String[] attrs = new String[3];
String[] attrs = new String[4];
attrs[0] = "member";
attrs[1] = "uniqueMember";
attrs[2] = "memberOfGroup";
LDAPSearchResults results = m_ldc.search( group,
LDAPConnection.SCOPE_BASE,
"objectclass=*",
attrs, false);
attrs[3] = "memberurl";
LDAPSearchResults results =
m_ldc.search( group,
LDAPConnection.SCOPE_BASE,
"objectclass=*",
attrs, false);
// Should be only one result, at most
LDAPEntry entry = null;
@ -194,22 +203,37 @@ public class LDAPIsMember extends LDAPBasePropertySupport implements Serializabl
LDAPAttribute attr =
(LDAPAttribute)attrsenum.nextElement();
printDebug( attr.getName() + " = " );
// Get the values as strings
boolean urlHandler =
attr.getName().equalsIgnoreCase("memberurl");
/* Get the values as strings.
The following code also handles dynamic
groups by calling URLMatch to see if an entry
DN is found via a URL search.
This is transparent to the caller of the bean.
*/
Enumeration valuesenum = attr.getStringValues();
if (valuesenum != null) {
while (valuesenum.hasMoreElements()) {
String val = (String)valuesenum.nextElement();
if (urlHandler) {
if ( URLMatch(m_ldc, val, normMember) ) {
isMember = true;
setErrorCode( OK );
break;
}
}
printDebug( "\t\t" + val );
String normFound = normalizeDN( val );
if ( normMember.equalsIgnoreCase( normFound ) ) {
if ( normMember.equals( normFound ) ) {
isMember = true;
setErrorCode( OK );
break;
setErrorCode( OK );
break;
}
}
} else {
setErrorCode(PROPERTY_NOT_FOUND);
printDebug("Failed to do string conversion for "+ attr.getName());
printDebug("Failed to do string conversion for "+
attr.getName());
}
}
if ( !isMember )
@ -307,16 +331,69 @@ public class LDAPIsMember extends LDAPBasePropertySupport implements Serializabl
}
private String normalizeDN( String dn ) {
StringTokenizer st = new StringTokenizer( dn, "," );
String norm = "";
if( st.hasMoreTokens() ) {
norm = st.nextToken();
while( st.hasMoreTokens() )
norm = norm + "," + st.nextToken().trim();
}
return norm;
return new DN( dn ).toRFCString().toUpperCase();
}
/**
* Return true if normMember is result of url search.
* Urls from dynamic groups do not typically contain
* the host and port so we need to fix them before
* constructing an LDAP URL.
* current ldap:///.... make ldap://host:port/...
**/
private boolean URLMatch(LDAPConnection ld, String URL,
String normMemberDN) {
String cURL = URL;
boolean isMember = false;
int loc = URL.indexOf(":///");
if ( loc > 0) {
cURL = URL.substring(0,loc) + "://" + ld.getHost() +
":" + ld.getPort() + URL.substring(loc+3);
}
printDebug("URLMatch: url = " + cURL +
", member DN = " + normMemberDN);
LDAPUrl ldapurl;
try {
ldapurl = new LDAPUrl(cURL);
printDebug("URL ->"+ldapurl.getUrl());
} catch (java.net.MalformedURLException murl) {
printDebug("bad URL");
return isMember;
}
try {
LDAPSearchResults results = ld.search(ldapurl);
String entry = "";
while ( results.hasMoreElements() && !isMember ) {
try {
entry = ((LDAPEntry)results.next()).getDN();
String normEntry = normalizeDN( entry );
if (normEntry.equals(normMemberDN)) {
isMember = true;
break;
}
} catch (LDAPReferralException e) {
if (getDebug()) {
notifyResult("Referral URLs: ");
LDAPUrl refUrls[] = e.getURLs();
for (int i = 0; i < refUrls.length; i++)
notifyResult(refUrls[i].getUrl());
}
continue;
} catch (LDAPException e) {
if (getDebug())
notifyResult(e.toString());
continue;
}
}
} catch (LDAPException lde) {
printDebug("Failed search for url " + ldapurl.getUrl());
setErrorCode(NO_SUCH_OBJECT);
}
return isMember;
}
/**
* The main body if we run it as application instead of applet.
* @param args list of arguments

Просмотреть файл

@ -0,0 +1,6 @@
Name: netscape/ldap/beans/LDAPIsMember.class
Java-Bean: True
Name: netscape/ldap/beans/LDAPBasePropertySupport.class
Name: netscape/ldap/beans/LDAPIsMemberBeanInfo.class

Просмотреть файл

@ -0,0 +1,6 @@
Name: netscape/ldap/beans/LDAPSimpleAuth.class
Java-Bean: True
Name: netscape/ldap/beans/LDAPBasePropertySupport.class
Name: netscape/ldap/beans/LDAPSimpleAuthBeanInfo.class

Просмотреть файл

@ -12,12 +12,13 @@
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package netscape.ldap;
import java.util.*;
import java.text.*;
import netscape.ldap.client.*;
/**
@ -38,6 +39,8 @@ public class LDAPCompareAttrNames implements LDAPEntryComparator {
String m_attrs[];
boolean m_ascending[];
Locale m_locale = null;
Collator m_collator = null;
/**
* Constructs a comparator that compares the string values of
@ -134,7 +137,9 @@ public class LDAPCompareAttrNames implements LDAPEntryComparator {
* <P>
*
* @param attribute Array of the attribute names to use for comparisons.
* @param ascendingFlags Array of boolean values specifying ascending or descending order to use for each attribute name. If <CODE>true</CODE>, sort the attributes in ascending order.
* @param ascendingFlags Array of boolean values specifying ascending
* or descending order to use for each attribute name. If
* <CODE>true</CODE>, sort the attributes in ascending order.
*/
public LDAPCompareAttrNames (String[] attributes,
boolean[] ascendingFlags) {
@ -147,6 +152,31 @@ public class LDAPCompareAttrNames implements LDAPEntryComparator {
}
}
/**
* Get the locale used for collation, if any. If it is null,
* an ordinary string comparison will be used for sorting.
*
* @return The locale used for collation, or null.
*/
public Locale getLocale() {
return m_locale;
}
/**
* Set the locale used for collation, if any. If it is null,
* an ordinary string comparison will be used for sorting.
*
* @param locale The locale used for collation, or null.
*/
public void setLocale( Locale locale ) {
m_locale = locale;
if ( m_locale == null ) {
m_collator = null;
} else {
m_collator = Collator.getInstance( m_locale );
}
}
/**
* If the value of the attribute in the first entry is greater
* than the attribute in the second entry, returns <CODE>true</CODE>.
@ -231,10 +261,17 @@ public class LDAPCompareAttrNames implements LDAPEntryComparator {
else
return attrGreater (greater, less, attrPos+1);
if( ascending )
return (greaterValue.compareTo (lessValue) > 0);
else
return (greaterValue.compareTo (lessValue) < 0);
if ( m_collator != null ) {
if ( ascending )
return ( m_collator.compare( greaterValue, lessValue ) > 0 );
else
return ( m_collator.compare( greaterValue, lessValue ) < 0 );
} else {
if ( ascending )
return (greaterValue.compareTo (lessValue) > 0);
else
return (greaterValue.compareTo (lessValue) < 0);
}
}
}

Просмотреть файл

@ -209,11 +209,11 @@ public class LDAPConnection implements LDAPv3, Cloneable {
/**
* Properties
*/
private final static Float SdkVersion = new Float(3.1f);
private final static Float SdkVersion = new Float(3.2f);
private final static Float ProtocolVersion = new Float(3.0f);
private final static String SecurityVersion = new String("none,simple,sasl");
private final static Float MajorVersion = new Float(3.0f);
private final static Float MinorVersion = new Float(0.1f);
private final static Float MinorVersion = new Float(0.2f);
private final static String DELIM = "#";
private final static String PersistSearchPackageName =
"netscape.ldap.controls.LDAPPersistSearchControl";
@ -2031,7 +2031,7 @@ public class LDAPConnection implements LDAPv3, Cloneable {
int deref = cons.getDereference();
JDAPSearchRequest request = new JDAPSearchRequest (base,
scope, deref, cons.getMaxResults(), cons.getTimeLimit(),
scope, deref, cons.getMaxResults(), cons.getServerTimeLimit(),
attrsOnly, filter, attrs);
synchronized(myListener) {
@ -2986,7 +2986,7 @@ public class LDAPConnection implements LDAPv3, Cloneable {
case LDAPv2.SIZELIMIT:
return new Integer (cons.getMaxResults());
case LDAPv2.TIMELIMIT:
return new Integer (cons.getTimeLimit());
return new Integer (cons.getServerTimeLimit());
case LDAPv2.REFERRALS:
return new Boolean (cons.getReferrals());
case LDAPv2.REFERRALS_REBIND_PROC:
@ -3175,7 +3175,7 @@ public class LDAPConnection implements LDAPv3, Cloneable {
cons.setMaxResults(((Integer)value).intValue());
return;
case LDAPv2.TIMELIMIT:
cons.setTimeLimit(((Integer)value).intValue());
cons.setServerTimeLimit(((Integer)value).intValue());
return;
case LDAPv2.REFERRALS:
cons.setReferrals(((Boolean)value).booleanValue());

Просмотреть файл

@ -151,11 +151,11 @@ public class LDAPException extends java.lang.Exception {
* (3) The search operation could not be completed within
* the maximum time limit. You can specify the maximum time
* limit by calling the <CODE>LDAPConnection.setOption</CODE>
* method or the <CODE>LDAPSearchConstraints.setTimeLimit</CODE>
* method or the <CODE>LDAPSearchConstraints.setServerTimeLimit</CODE>
* method.<P>
*
* @see netscape.ldap.LDAPConnection@setOption
* @see netscape.ldap.LDAPSearchConstraints@setTimeLimit
* @see netscape.ldap.LDAPSearchConstraints@setServerTimeLimit
*/
public final static int TIME_LIMIT_EXCEEDED = 3;

Просмотреть файл

@ -114,4 +114,22 @@ public class LDAPModificationSet {
}
}
}
/**
* Retrieves the string representation of the
* modification set.
*
* @return String representation of the modification set.
*/
public String toString() {
String s = "LDAPModificationSet: {";
for( int i = 0; i < modifications.size(); i++ ) {
s += (LDAPModification)modifications.elementAt(i);
if ( i < modifications.size()-1 ) {
s += ", ";
}
}
s += "}";
return s;
}
}

Просмотреть файл

@ -173,6 +173,27 @@ public abstract class LDAPSchemaElement {
update( ld, LDAPModification.ADD, attrName );
}
/**
* Replace a single value of the object class, attribute type,
* or matching rule definition in the schema. Typically, most servers
* will require you to authenticate before allowing you to
* edit the schema.
* @param ld The <CODE>LDAPConnection</CODE> object representing
* a connection to an LDAP server.
* @param newValue The new value
* @exception LDAPException The specified definition cannot be
* modified.
*/
public void modify( LDAPConnection ld, LDAPSchemaElement newValue )
throws LDAPException {
LDAPModificationSet mods = new LDAPModificationSet();
mods.add( LDAPModification.DELETE,
new LDAPAttribute( attrName, getValue() ) );
mods.add( LDAPModification.ADD,
new LDAPAttribute( attrName, newValue.getValue() ) );
ld.modify( "cn=schema", mods );
}
/**
* Removes the current object class, attribute type, or matching rule
* definition from the schema. Typically, most servers

Просмотреть файл

@ -30,6 +30,7 @@ package netscape.ldap;
public class LDAPSearchConstraints implements Cloneable {
private int timeLimit;
private int serverTimeLimit;
private int deref;
private int maxRes;
private boolean referrals;
@ -46,6 +47,7 @@ public class LDAPSearchConstraints implements Cloneable {
*/
public LDAPSearchConstraints() {
timeLimit = 0;
serverTimeLimit = 0;
deref = 0;
maxRes = 1000;
referrals = false;
@ -102,6 +104,58 @@ public class LDAPSearchConstraints implements Cloneable {
m_serverControls = null;
}
/**
* Constructs a new <CODE>LDAPSearchConstraints</CODE> object and allows you
* to specify the search constraints in that object.
* <P>
* @param msLimit Maximum time in milliseconds to wait for results (0
* by default, which means that there is no maximum time limit)
* @param timeLimit Maximum time in seconds for the server to spend
* processing a search request (0 by default for no limit)
* @param dereference Either <CODE>LDAPv2.DEREF_NEVER</CODE>,
* <CODE>LDAPv2.DEREF_FINDING</CODE>,
* <CODE>LDAPv2.DEREF_SEARCHING</CODE>, or
* <CODE>LDAPv2.DEREF_ALWAYS</CODE> (see LDAPConnection.setOption).
* <CODE>LDAPv2.DEREF_NEVER</CODE> is the default.
* @param maxResults Maximum number of search results to return
* (1000 by default)
* @param doReferrals Specify <CODE>true</CODE> to follow referrals
* automatically, or <CODE>False</CODE> to throw an
* <CODE>LDAPReferralException</CODE> error if the server sends back
* a referral (<CODE>False</CODE> by default)
* @param batchSize Specify the number of results to return at a time
* (1 by default)
* @param rebind_proc Specifies the object of the class that
* implements the <CODE>LDAPRebind</CODE> interface (you need to
* define this class). The object will be using when the client
* follows referrals automatically. The object provides the client
* with a method for getting the distinguished name and password
* used to authenticate to another LDAP server during a referral.
* (This field is <CODE>null</CODE> by default.)
* @param hop_limit Maximum number of referrals to follow in a
* sequence when attempting to resolve a request.
* @see netscape.ldap.LDAPConnection#setOption(int, java.lang.Object)
* @see netscape.ldap.LDAPConnection#search(netscape.ldap.LDAPUrl, netscape.ldap.LDAPSearchConstraints)
* @see netscape.ldap.LDAPConnection#search(java.lang.String, int, java.lang.String, java.lang.String[], boolean, netscape.ldap.LDAPSearchConstraints)
*/
public LDAPSearchConstraints( int msLimit, int timeLimit,
int dereference,
int maxResults, boolean doReferrals,
int batchSize,
LDAPRebind rebind_proc,
int hop_limit) {
timeLimit = msLimit;
serverTimeLimit = timeLimit;
deref = dereference;
maxRes = maxResults;
referrals = doReferrals;
batch = batchSize;
m_rebind_proc = rebind_proc;
m_hop_limit = hop_limit;
m_clientControls = null;
m_serverControls = null;
}
/**
* Returns the maximum number of milliseconds to wait for any operation
* under these search constraints. If 0, there is no maximum time limit
@ -109,7 +163,16 @@ public class LDAPSearchConstraints implements Cloneable {
* @return Maximum number of milliseconds to wait for operation results.
*/
public int getTimeLimit() {
return timeLimit*1000;
return timeLimit;
}
/**
* Returns the maximum number of seconds to wait for the server to
* spend on a search operation.If 0, there is no time limit.
* @return Maximum number of seconds for the server to spend.
*/
public int getServerTimeLimit() {
return serverTimeLimit;
}
/**
@ -207,12 +270,22 @@ public class LDAPSearchConstraints implements Cloneable {
* Sets the maximum number of milliseconds to wait for any operation
* under these search constraints. If 0, there is no maximum time limit
* on waiting for the operation results.
* @param msLimit Maximum number of milliseconds to wait for operation results.
* @param msLimit Maximum number of milliseconds to wait for operation
* results.
* (0 by default, which means that there is no maximum time limit.)
*/
public void setTimeLimit( int msLimit ) {
if (msLimit != 0)
timeLimit = Math.max( 1, (msLimit + 500) / 1000 );
timeLimit = msLimit;
}
/**
* Sets the maximum number of seconds for the server to spend
* returning search results. If 0, there is no time limit.
* @param limit Maximum number of seconds for the server to spend.
* (0 by default, which means that there is no maximum time limit.)
*/
public void setServerTimeLimit( int limit ) {
serverTimeLimit = limit;
}
/**
@ -355,6 +428,7 @@ public class LDAPSearchConstraints implements Cloneable {
LDAPSearchConstraints o = new LDAPSearchConstraints();
o.timeLimit = this.timeLimit;
o.serverTimeLimit = this.serverTimeLimit;
o.deref = this.deref;
o.maxRes = this.maxRes;
o.referrals = this.referrals;

Просмотреть файл

@ -57,7 +57,12 @@ public class JDAPBindResponse extends JDAPResult implements JDAPProtocolOp {
return;
BERElement e = s.elementAt(3);
if (e.getType() == BERElement.TAG) {
BEROctetString str = (BEROctetString)((BERTag)e).getValue();
BERElement el = ((BERTag)e).getValue();
if (el instanceof BERSequence)
{
el = ((BERSequence)el).elementAt(0);
}
BEROctetString str = (BEROctetString)el;
try{
m_credentials = new String(str.getValue(),"UTF8");
} catch(Throwable x)

Просмотреть файл

@ -1,19 +1,8 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
/* ======================================================================
* Copyright (c) 1997 Netscape Communications Corporation
* This file contains proprietary information of Netscape Communications.
* Copying or reproduction without prior written approval is prohibited.
* ======================================================================
*/
import java.io.*;
@ -116,6 +105,7 @@ public class LDAPDelete extends LDAPTool { /* LDAPDelete */
System.err.println(" -M manage references (treat them "+
"as regular entries)");
System.err.println(" -y proxy-DN DN to use for access control");
}
/**
@ -179,10 +169,18 @@ public class LDAPDelete extends LDAPTool { /* LDAPDelete */
int msgid = 0;
LDAPSearchConstraints cons =
(LDAPSearchConstraints)m_client.getSearchConstraints().clone();
Vector controlVector = new Vector();
if (m_proxyControl != null)
controlVector.addElement(m_proxyControl);
if (m_ordinary) {
LDAPControl control = new LDAPControl(
LDAPControl.MANAGEDSAIT, true, null);
cons.setServerControls(control);
controlVector.addElement( new LDAPControl(
LDAPControl.MANAGEDSAIT, true, null) );
}
if (controlVector.size() > 0) {
LDAPControl[] controls = new LDAPControl[controlVector.size()];
controlVector.copyInto(controls);
cons.setServerControls(controls);
}
cons.setReferrals( m_referrals );
if ( m_referrals ) {

Просмотреть файл

@ -1,19 +1,8 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
/* ======================================================================
* Copyright (c) 1997 Netscape Communications Corporation
* This file contains proprietary information of Netscape Communications.
* Copying or reproduction without prior written approval is prohibited.
* ======================================================================
*/
/*
* @(#) LDAPModify.java
@ -150,6 +139,7 @@ public class LDAPModify extends LDAPTool { /* LDAPModify */
"default");
System.err.println(" -e rejectfile save rejected entries in " +
"\'rejfile\'");
System.err.println(" -y proxy-DN DN to use for access control");
}
/**
@ -197,19 +187,26 @@ public class LDAPModify extends LDAPTool { /* LDAPModify */
} /* extract parameters */
/**
* This class-method is used to call the JDAP Modify Operation with the
* Call the LDAPConnection modify operation with the
* specified options, and/or parameters.
*/
private static void doModify() throws IOException { /* doModify */
DataOutputStream reject = null;
PrintWriter reject = null;
LDAPSearchConstraints cons = null;
if (!m_justShow) {
cons =
(LDAPSearchConstraints)m_client.getSearchConstraints().clone();
Vector controlVector = new Vector();
if (m_proxyControl != null)
controlVector.addElement(m_proxyControl);
if (m_ordinary) {
LDAPControl control = new LDAPControl(
LDAPControl.MANAGEDSAIT, true, null);
cons.setServerControls(control);
controlVector.addElement( new LDAPControl(
LDAPControl.MANAGEDSAIT, true, null) );
}
if (controlVector.size() > 0) {
LDAPControl[] controls = new LDAPControl[controlVector.size()];
controlVector.copyInto(controls);
cons.setServerControls(controls);
}
cons.setReferrals( m_referrals );
if ( m_referrals ) {
@ -360,33 +357,27 @@ public class LDAPModify extends LDAPTool { /* LDAPModify */
if ( skip && (m_rejectsFile != null) ) {
try {
if ( reject == null ) {
reject = new DataOutputStream(
reject = new PrintWriter(
new FileOutputStream( m_rejectsFile ) );
}
} catch ( Exception e ) {
}
if ( reject != null ) {
try {
reject.writeUTF( "dn: "+rec.getDN()+ " # Error: " + errCode + '\n' );
if ( mods != null ) {
for( int m = 0; m < mods.length; m++ ) {
reject.writeUTF( mods[m].toString() +
'\n' );
}
} else if ( newEntry != null ) {
reject.writeUTF( "Add " + newEntry.toString()
+ '\n' );
} else if ( doDelete ) {
reject.writeUTF( "Delete " + rec.getDN()
+ '\n' );
} else if (doModDN) {
reject.writeUTF( "ModDN "+
((LDIFModDNContent)content).toString()+'\n');
reject.println( "dn: "+rec.getDN()+ " # Error: " +
errCode );
if ( mods != null ) {
for( int m = 0; m < mods.length; m++ ) {
reject.println( mods[m].toString() );
}
} catch ( IOException ex ) {
System.err.println( ex.toString() );
System.exit( 1 );
} else if ( newEntry != null ) {
reject.println( "Add " + newEntry.toString() );
} else if ( doDelete ) {
reject.println( "Delete " + rec.getDN() );
} else if (doModDN) {
reject.println( "ModDN "+
((LDIFModDNContent)content).toString() );
}
reject.flush();
}
}
}

Просмотреть файл

@ -1,19 +1,8 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
/* ======================================================================
* Copyright (c) 1997 Netscape Communications Corporation
* This file contains proprietary information of Netscape Communications.
* Copying or reproduction without prior written approval is prohibited.
* ======================================================================
*/
import java.io.*;
@ -137,6 +126,7 @@ public class LDAPSearch extends LDAPTool {
"where 'before' and 'after' are the number of "+
"entries surrounding 'index'. 'count' is the "+
"content count, 'value' is the search value.");
System.err.println(" -y proxy-DN DN to use for access control");
}
/**
@ -372,6 +362,9 @@ public class LDAPSearch extends LDAPTool {
if (vControl != null)
cons.addElement(vControl);
if (m_proxyControl != null)
cons.addElement(m_proxyControl);
if (m_ordinary) {
LDAPControl manageDSAITControl = new LDAPControl(
LDAPControl.MANAGEDSAIT, true, null);
@ -444,6 +437,9 @@ public class LDAPSearch extends LDAPTool {
for (int i=0; i<urls.length; i++)
System.err.println("\t"+urls[i].getUrl().toString());
continue;
} catch (Exception e) {
System.err.println( e.toString() );
continue;
}
String dn = findEntry.getDN();

Просмотреть файл

@ -1,23 +1,13 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
/* ======================================================================
* Copyright (c) 1997 Netscape Communications Corporation
* This file contains proprietary information of Netscape Communications.
* Copying or reproduction without prior written approval is prohibited.
* ======================================================================
*/
import netscape.ldap.*;
import netscape.ldap.util.*;
import netscape.ldap.controls.*;
/**
* LDAPTool
@ -35,7 +25,7 @@ class LDAPTool {
*/
protected static GetOpt extractParameters(String privateOpts, String args[]) {
GetOpt options = new GetOpt("vnRMD:h:O:p:w:d:V:" + privateOpts, args);
GetOpt options = new GetOpt("vnRMD:h:O:p:w:d:V:y:" + privateOpts, args);
if (options.hasOption('n'))
m_justShow = true;
@ -94,6 +84,11 @@ class LDAPTool {
if (options.hasOption('w'))
m_passwd = options.getOptionParam('w');
/* -y proxy DN */
if (options.hasOption('y'))
m_proxyControl = new LDAPProxiedAuthControl(
options.getOptionParam('y'), true );
/* -M treat ref attribute as ordinary entry */
if (options.hasOption('M'))
m_ordinary = true;
@ -127,4 +122,5 @@ class LDAPTool {
protected static boolean m_justShow = false;
protected static boolean m_verbose = false;
protected static boolean m_ordinary = false;
protected static LDAPControl m_proxyControl = null;
}