| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006 Sun Microsystems, Inc. |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.protocols.ldap; |
| | | |
| | |
| | | import org.opends.server.protocols.asn1.ASN1Integer; |
| | | import org.opends.server.protocols.asn1.ASN1Sequence; |
| | | |
| | | import static org.opends.server.loggers.Debug.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugCought; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | import static org.opends.server.messages.ProtocolMessages.*; |
| | | import static org.opends.server.protocols.ldap.LDAPResultCode.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class defines the data structures and methods to use when interacting |
| | | * with an LDAP message, which is the basic envelope used to hold LDAP requests |
| | |
| | | public class LDAPMessage |
| | | implements ProtocolElement |
| | | { |
| | | /** |
| | | * The fully-qualified name of this class for debugging purposes. |
| | | */ |
| | | private static final String CLASS_NAME = |
| | | "org.opends.server.protocols.ldap.LDAPMessage"; |
| | | |
| | | |
| | | |
| | |
| | | */ |
| | | public LDAPMessage(int messageID, ProtocolOp protocolOp) |
| | | { |
| | | assert debugConstructor(CLASS_NAME, String.valueOf(messageID), |
| | | String.valueOf(protocolOp)); |
| | | |
| | | this.messageID = messageID; |
| | | this.protocolOp = protocolOp; |
| | |
| | | public LDAPMessage(int messageID, ProtocolOp protocolOp, |
| | | ArrayList<LDAPControl> controls) |
| | | { |
| | | assert debugConstructor(CLASS_NAME, String.valueOf(messageID), |
| | | String.valueOf(protocolOp), |
| | | String.valueOf(controls)); |
| | | |
| | | this.messageID = messageID; |
| | | this.protocolOp = protocolOp; |
| | |
| | | */ |
| | | public int getMessageID() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getMessageID"); |
| | | |
| | | return messageID; |
| | | } |
| | |
| | | */ |
| | | public void setMessageID(int messageID) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "setMessageID", String.valueOf(messageID)); |
| | | |
| | | this.messageID = messageID; |
| | | } |
| | |
| | | */ |
| | | public ProtocolOp getProtocolOp() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getProtocolOp"); |
| | | |
| | | return protocolOp; |
| | | } |
| | |
| | | */ |
| | | public byte getProtocolOpType() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getProtocolOpType"); |
| | | |
| | | return protocolOp.getType(); |
| | | } |
| | |
| | | */ |
| | | public String getProtocolOpName() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getProtocolOpName"); |
| | | |
| | | return protocolOp.getProtocolOpName(); |
| | | } |
| | |
| | | public AbandonRequestProtocolOp getAbandonRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getAbandonRequestProtocolOp"); |
| | | |
| | | return (AbandonRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public AddRequestProtocolOp getAddRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getAddRequestProtocolOp"); |
| | | |
| | | return (AddRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public AddResponseProtocolOp getAddResponseProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getAddResponseProtocolOp"); |
| | | |
| | | return (AddResponseProtocolOp) protocolOp; |
| | | } |
| | |
| | | public BindRequestProtocolOp getBindRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getBindRequestProtocolOp"); |
| | | |
| | | return (BindRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public BindResponseProtocolOp getBindResponseProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getBindResponseProtocolOp"); |
| | | |
| | | return (BindResponseProtocolOp) protocolOp; |
| | | } |
| | |
| | | public CompareRequestProtocolOp getCompareRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getCompareRequestProtocolOp"); |
| | | |
| | | return (CompareRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public CompareResponseProtocolOp getCompareResponseProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getCompareResponseProtocolOp"); |
| | | |
| | | return (CompareResponseProtocolOp) protocolOp; |
| | | } |
| | |
| | | public DeleteRequestProtocolOp getDeleteRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getDeleteRequestProtocolOp"); |
| | | |
| | | return (DeleteRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public DeleteResponseProtocolOp getDeleteResponseProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getDeleteResponseProtocolOp"); |
| | | |
| | | return (DeleteResponseProtocolOp) protocolOp; |
| | | } |
| | |
| | | public ExtendedRequestProtocolOp getExtendedRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getExtendedRequestProtocolOp"); |
| | | |
| | | return (ExtendedRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public ExtendedResponseProtocolOp getExtendedResponseProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getExtendedResponseProtocolOp"); |
| | | |
| | | return (ExtendedResponseProtocolOp) protocolOp; |
| | | } |
| | |
| | | public ModifyRequestProtocolOp getModifyRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getModifyRequestProtocolOp"); |
| | | |
| | | return (ModifyRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public ModifyResponseProtocolOp getModifyResponseProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getModifyResponseProtocolOp"); |
| | | |
| | | return (ModifyResponseProtocolOp) protocolOp; |
| | | } |
| | |
| | | public ModifyDNRequestProtocolOp getModifyDNRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getModifyDNRequestProtocolOp"); |
| | | |
| | | return (ModifyDNRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public ModifyDNResponseProtocolOp getModifyDNResponseProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getModifyDNResponseProtocolOp"); |
| | | |
| | | return (ModifyDNResponseProtocolOp) protocolOp; |
| | | } |
| | |
| | | public SearchRequestProtocolOp getSearchRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getSearchRequestProtocolOp"); |
| | | |
| | | return (SearchRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | public SearchResultDoneProtocolOp getSearchResultDoneProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getSearchResultDoneProtocolOp"); |
| | | |
| | | return (SearchResultDoneProtocolOp) protocolOp; |
| | | } |
| | |
| | | public SearchResultEntryProtocolOp getSearchResultEntryProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getSearchResultEntryProtocolOp"); |
| | | |
| | | return (SearchResultEntryProtocolOp) protocolOp; |
| | | } |
| | |
| | | public SearchResultReferenceProtocolOp getSearchResultReferenceProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getSearchResultReferenceProtocolOp"); |
| | | |
| | | return (SearchResultReferenceProtocolOp) protocolOp; |
| | | } |
| | |
| | | public UnbindRequestProtocolOp getUnbindRequestProtocolOp() |
| | | throws ClassCastException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getUnbindRequestProtocolOp"); |
| | | |
| | | return (UnbindRequestProtocolOp) protocolOp; |
| | | } |
| | |
| | | */ |
| | | public void setProtocolOp(ProtocolOp protocolOp) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "setProtocolOp", String.valueOf(protocolOp)); |
| | | |
| | | this.protocolOp = protocolOp; |
| | | } |
| | |
| | | */ |
| | | public ArrayList<LDAPControl> getControls() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getControls"); |
| | | |
| | | return controls; |
| | | } |
| | |
| | | */ |
| | | public ASN1Element encode() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "encode"); |
| | | |
| | | ArrayList<ASN1Element> messageElements = new ArrayList<ASN1Element>(3); |
| | | messageElements.add(new ASN1Integer(messageID)); |
| | |
| | | public static LDAPMessage decode(ASN1Sequence messageSequence) |
| | | throws LDAPException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "decode", String.valueOf(messageSequence)); |
| | | |
| | | if (messageSequence == null) |
| | | { |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "decode", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_LDAP_MESSAGE_DECODE_MESSAGE_ID; |
| | | int msgID = MSGID_LDAP_MESSAGE_DECODE_MESSAGE_ID; |
| | | String message = getMessage(msgID, String.valueOf(e)); |
| | | throw new LDAPException(PROTOCOL_ERROR, msgID, message, e); |
| | | } |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "decode", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_LDAP_MESSAGE_DECODE_PROTOCOL_OP; |
| | | int msgID = MSGID_LDAP_MESSAGE_DECODE_PROTOCOL_OP; |
| | | String message = getMessage(msgID, String.valueOf(e)); |
| | | throw new LDAPException(PROTOCOL_ERROR, msgID, message, e); |
| | | } |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "decode", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_LDAP_MESSAGE_DECODE_CONTROLS; |
| | | int msgID = MSGID_LDAP_MESSAGE_DECODE_CONTROLS; |
| | | String message = getMessage(msgID, String.valueOf(e)); |
| | | throw new LDAPException(PROTOCOL_ERROR, msgID, message, e); |
| | | } |
| | |
| | | */ |
| | | public String getProtocolElementName() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getProtocolElementName"); |
| | | |
| | | return "LDAP"; |
| | | } |
| | |
| | | */ |
| | | public String toString() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toString"); |
| | | |
| | | StringBuilder buffer = new StringBuilder(); |
| | | toString(buffer); |
| | |
| | | */ |
| | | public void toString(StringBuilder buffer) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toString", "java.lang.StringBuilder"); |
| | | |
| | | buffer.append("LDAPMessage(msgID="); |
| | | buffer.append(messageID); |
| | |
| | | */ |
| | | public void toString(StringBuilder buffer, int indent) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toString", "java.lang.StringBuilder", |
| | | String.valueOf(indent)); |
| | | |
| | | StringBuilder indentBuf = new StringBuilder(indent); |
| | | for (int i=0 ; i < indent; i++) |