Commit 38a80acd authored by Nachiappan Palaniappan's avatar Nachiappan Palaniappan
Browse files

Addition of a new extension 'getEffectivePrivilegesList'. This LDAP extension...

Addition of a new extension 'getEffectivePrivilegesList'. This LDAP extension is specific to eDirectory. It retrieves the effective rights list from an GetEffectivePrivilegesListResponse object. The GetEffectivePrivilegesListRequest.java processes the extended request and the GetEffectivePrivilegesListResponse.java processes the extended response.
parent 9b90e67e
/* **************************************************************************
* $OpenLDAP$
*
* Copyright (C) 1999, 2000, 2001 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
* TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
* TO VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS
* AVAILABLE AT HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE"
* IN THE TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION
* OF THIS WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP
* PUBLIC LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT
* THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
******************************************************************************/
package com.novell.ldap.extensions;
import com.novell.ldap.*;
import com.novell.ldap.asn1.*;
import com.novell.ldap.resources.*;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
/**
*
* Returns the effective rights of one object to a string of attributes of another object.
*
* <p>To use this class, you must instantiate an object of this class and then
* call the extendedOperation method with this object as the required
* LDAPExtendedOperation parameter.</p>
*
* <p>The returned LDAPExtendedResponse object can then be converted to
* a GetEffectivePrivilegesListResponse object with the ExtendedResponseFactory class.
* The GetEffectivePrivilegesListResponse class contains methods for
* retrieving the effective rights.</p>
*
* <p>The getEffectivePrivilegesListRequest extension uses the following OID:<br>
* &nbsp;&nbsp;&nbsp;2.16.840.1.113719.1.27.100.103</p>
*
* <p>The requestValue has the following format:<br>
*
* requestValue ::=<br>
* &nbsp;&nbsp;&nbsp;&nbsp; dn &nbsp;&nbsp;&nbsp; LDAPDN<br>
* &nbsp;&nbsp;&nbsp;&nbsp; trusteeDN&nbsp;&nbsp;&nbsp; LDAPDN<br>
* &nbsp;&nbsp;&nbsp;&nbsp; sequence of {"attr1","attr2",...,null} &nbsp;&nbsp;&nbsp; LDAPDN </p>
*/
public class GetEffectivePrivilegesListRequest extends LDAPExtendedOperation {
static
{
/*
* Register the extendedresponse class which is returned by the
* server in response to a GetEffectivePrivilegesListRequest
*/
try {
LDAPExtendedResponse.register(
ReplicationConstants.GET_EFFECTIVE_LIST_PRIVILEGES_RES,
Class.forName("com.novell.ldap.extensions.GetEffectivePrivilegesListResponse"));
}catch (ClassNotFoundException e) {
System.err.println("Could not register Extended Response -" +
" Class not found");
}catch(Exception e){
e.printStackTrace();
}
}
/**
* Constructs an extended operation object for checking effective rights.
*
* @param dn The distinguished name of the entry whose attribute is
* being checked.
*<br><br>
* @param trusteeDN The distinguished name of the entry whose trustee rights
* are being returned
*<br><br>
* @param sequence of {"attr1","attr2",...,null} The list of LDAP attribute names.
*
* @exception LDAPException A general exception which includes an error
* message and an LDAP error code.
*/
public GetEffectivePrivilegesListRequest(String dn, String trusteeDN, String[] attrName)
throws LDAPException
{
super(ReplicationConstants.GET_EFFECTIVE_LIST_PRIVILEGES_REQ, null);
try {
if ( (dn == null) )
throw new IllegalArgumentException(ExceptionMessages.PARAM_ERROR);
ByteArrayOutputStream encodedData = new ByteArrayOutputStream();
LBEREncoder encoder = new LBEREncoder();
ASN1OctetString asn1_trusteeDN = new ASN1OctetString(trusteeDN);
ASN1OctetString asn1_dn = new ASN1OctetString(dn);
asn1_trusteeDN.encode(encoder, encodedData);
asn1_dn.encode(encoder, encodedData);
ASN1Sequence asn1_seqattr = new ASN1Sequence();
for (int i = 0;attrName[i]!= null ; i++)
{
ASN1OctetString asn1_attrName = new ASN1OctetString(attrName[i]);
asn1_seqattr.add(asn1_attrName);
}
asn1_seqattr.encode(encoder, encodedData);
setValue(encodedData.toByteArray());
}
catch(IOException ioe) {
throw new LDAPException(ExceptionMessages.ENCODING_ERROR,LDAPException.ENCODING_ERROR,(String)null);
}
}
}
/* **************************************************************************
* $OpenLDAP$
*
* Copyright (C) 1999, 2000, 2001 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
* TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
* TO VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS
* AVAILABLE AT HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE"
* IN THE TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION
* OF THIS WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP
* PUBLIC LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT
* THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
******************************************************************************/
package com.novell.ldap.extensions;
import com.novell.ldap.*;
import com.novell.ldap.asn1.*;
import com.novell.ldap.rfc2251.*;
import java.io.IOException;
/**
* Retrieves the effective rights from an GetEffectivePrivilegesListResponse object.
*
* <p>An object in this class is generated from an ExtendedResponse object
* using the ExtendedResponseFactory class.</p>
*
* <p>The getEffectivePrivilegesListResponse extension uses the following OID:<br>
* &nbsp;&nbsp;&nbsp;2.16.840.1.113719.1.27.100.104</p>
*
*/
public class GetEffectivePrivilegesListResponse extends LDAPExtendedResponse{
//Identity returned by the server
private int[] privileges= {0};
private int no_privileges;
/**
* Constructs an object from the responseValue which contains the effective
* privileges.
*
* <p>The constructor parses the responseValue which has the following
* format:<br>
* responseValue ::=<br>
* &nbsp;&nbsp;&nbsp;&nbsp; sequence of number of privileges&nbsp;&nbsp;&nbsp; INTEGER</p>
* &nbsp;&nbsp;&nbsp;&nbsp; set of sequence of privileges &nbsp;&nbsp;&nbsp; INTEGER</p>
*
* @exception IOException The responseValue could not be decoded.
*/
public GetEffectivePrivilegesListResponse (RfcLDAPMessage rfcMessage) throws IOException
{
super(rfcMessage);
if (getResultCode() == LDAPException.SUCCESS)
{
// parse the contents of the reply
byte [] returnedValue = this.getValue();
if (returnedValue == null)
throw new IOException("No returned value");
//Create a decoder object
LBERDecoder decoder = new LBERDecoder();
if (decoder == null)
throw new IOException("Decoding error");
ASN1Sequence asn1_seq1 = (ASN1Sequence)decoder.decode(returnedValue);
if (asn1_seq1 == null)
throw new IOException("Decoding error");
ASN1Sequence asn1_seq2 = (ASN1Sequence)asn1_seq1.get(0);
no_privileges = ((ASN1Integer)asn1_seq2.get(0)).intValue();
/*
* Chunks returned from server is encoded as shown below::
* SET of [
* SEQUENCE of {privileges INTEGER}]
* }
*/
ASN1Set set_privileg_response = null;
ASN1Integer[] asn1_privileges = null;
set_privileg_response = ((ASN1Set)asn1_seq1.get(1));
ASN1Sequence seq2 = null;
privileges = new int[no_privileges];
for(int index=0; index < no_privileges; index++)
{
seq2 = (ASN1Sequence)set_privileg_response.get(index);
privileges[index]=((ASN1Integer)seq2.get(0)).intValue();
}
}
}
public int[] getPrivileges()
{
return privileges;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment