| | |
| | | <version>${forgerockBuildToolsVersion}</version> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>slf4j-api</artifactId> |
| | | <version>1.7.5</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>slf4j-jdk14</artifactId> |
| | | <version>1.7.5</version> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | <properties> |
| | | <opendj.osgi.import> |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package com.forgerock.opendj.ldap; |
| | |
| | | import static com.forgerock.opendj.ldap.LDAPConstants.ELEMENT_READ_STATE_NEED_TYPE; |
| | | import static com.forgerock.opendj.ldap.LDAPConstants.ELEMENT_READ_STATE_NEED_VALUE_BYTES; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.asn1.ASN1Reader; |
| | | import org.forgerock.opendj.asn1.AbstractASN1Reader; |
| | |
| | | import org.glassfish.grizzly.memory.CompositeBuffer; |
| | | import org.glassfish.grizzly.memory.MemoryManager; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * Grizzly ASN1 reader implementation. |
| | | */ |
| | |
| | | public SequenceLimiter endSequence() throws IOException { |
| | | parent.checkLimit(remaining()); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE) && remaining() > 0) { |
| | | StaticUtils.DEBUG_LOG.fine(String.format( |
| | | "Ignoring %d unused trailing bytes in ASN.1 SEQUENCE", remaining())); |
| | | if (remaining() > 0) { |
| | | IO_LOG.debug("Ignoring {} unused trailing bytes in ASN.1 SEQUENCE", remaining()); |
| | | } |
| | | |
| | | for (int i = 0; i < remaining(); i++) { |
| | |
| | | readLimiter.checkLimit(peekLength); |
| | | final byte readByte = buffer.get(); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", peekType, peekLength, |
| | | String.valueOf(readByte != 0x00))); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 BOOLEAN(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, String.valueOf(readByte != 0x00)); |
| | | |
| | | state = ELEMENT_READ_STATE_NEED_TYPE; |
| | | return readByte != 0x00; |
| | |
| | | public void readEndSequence() throws IOException { |
| | | readLimiter = readLimiter.endSequence(); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("READ ASN.1 END SEQUENCE")); |
| | | } |
| | | IO_LOG.debug("READ ASN.1 END SEQUENCE"); |
| | | |
| | | // Reset the state |
| | | state = ELEMENT_READ_STATE_NEED_TYPE; |
| | |
| | | intValue = (intValue << 8) | (readByte & 0xFF); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", peekType, peekLength, |
| | | intValue)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 INTEGER(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, intValue); |
| | | |
| | | state = ELEMENT_READ_STATE_NEED_TYPE; |
| | | return intValue; |
| | |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("READ ASN.1 NULL(type=0x%x, length=%d)", |
| | | peekType, peekLength)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 NULL(type=0x{}, length={})", |
| | | byteToHex(peekType), peekLength); |
| | | |
| | | state = ELEMENT_READ_STATE_NEED_TYPE; |
| | | } |
| | |
| | | final byte[] value = new byte[peekLength]; |
| | | buffer.get(value); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | |
| | | state = ELEMENT_READ_STATE_NEED_TYPE; |
| | | return ByteString.wrap(value); |
| | |
| | | builder.append(buffer.get()); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | |
| | | state = ELEMENT_READ_STATE_NEED_TYPE; |
| | | return builder; |
| | |
| | | try { |
| | | str = new String(readBuffer, 0, peekLength, "UTF-8"); |
| | | } catch (final Exception e) { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | StaticUtils.DEBUG_LOG |
| | | .warning("Unable to decode ASN.1 OCTETSTRING bytes as UTF-8 string: " |
| | | + e.toString()); |
| | | } |
| | | // TODO: I18N |
| | | IO_LOG.warn("Unable to decode ASN.1 OCTETSTRING bytes as UTF-8 string", e); |
| | | |
| | | str = new String(stringBuffer, 0, peekLength); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 OCTETSTRING(type=0x%x, length=%d, value=%s)", peekType, peekLength, |
| | | str)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, str); |
| | | |
| | | return str; |
| | | } |
| | |
| | | |
| | | readLimiter = readLimiter.startSequence(peekLength); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 START SEQUENCE(type=0x%x, length=%d)", peekType, peekLength)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 START SEQUENCE(type=0x{}, length={})", |
| | | byteToHex(peekType), peekLength); |
| | | |
| | | // Reset the state |
| | | state = ELEMENT_READ_STATE_NEED_TYPE; |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | package com.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_SEQUENCE_WRITE_NOT_STARTED; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | import java.nio.ByteBuffer; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.asn1.ASN1; |
| | | import org.forgerock.opendj.asn1.ASN1Writer; |
| | |
| | | writeLength(parent, buffer.length()); |
| | | parent.writeByteArray(buffer.getBackingArray(), 0, buffer.length()); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("WRITE ASN.1 END SEQUENCE(length=%d)", |
| | | buffer.length())); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 END SEQUENCE(length={})", buffer.length()); |
| | | |
| | | return parent; |
| | | } |
| | |
| | | writeLength(sequenceBuffer, 1); |
| | | sequenceBuffer.writeByte(booleanValue ? ASN1.BOOLEAN_VALUE_TRUE : ASN1.BOOLEAN_VALUE_FALSE); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", type, 1, String |
| | | .valueOf(booleanValue))); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 BOOLEAN(type=0x{}, length={}, value={})", |
| | | byteToHex(type), 1, String.valueOf(booleanValue)); |
| | | |
| | | return this; |
| | | } |
| | | |
| | |
| | | || ((intValue & 0x0000007F) == intValue)) { |
| | | writeLength(sequenceBuffer, 1); |
| | | sequenceBuffer.writeByte((byte) (intValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, intValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 1, intValue); |
| | | } else if (((intValue < 0) && ((intValue & 0xFFFF8000) == 0xFFFF8000)) |
| | | || ((intValue & 0x00007FFF) == intValue)) { |
| | | writeLength(sequenceBuffer, 2); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (intValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, intValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 2, intValue); |
| | | } else if (((intValue < 0) && ((intValue & 0xFF800000) == 0xFF800000)) |
| | | || ((intValue & 0x007FFFFF) == intValue)) { |
| | | writeLength(sequenceBuffer, 3); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (intValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, intValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 3, intValue); |
| | | } else { |
| | | writeLength(sequenceBuffer, 4); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 24) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (intValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, intValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 4, intValue); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | || ((longValue & 0x000000000000007FL) == longValue)) { |
| | | writeLength(sequenceBuffer, 1); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 1, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFFFF8000L) == 0xFFFFFFFFFFFF8000L)) |
| | | || ((longValue & 0x0000000000007FFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 2); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 2, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFF800000L) == 0xFFFFFFFFFF800000L)) |
| | | || ((longValue & 0x00000000007FFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 3); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 3, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFF80000000L) == 0xFFFFFFFF80000000L)) |
| | | || ((longValue & 0x000000007FFFFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 4); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 4, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFF8000000000L) == 0xFFFFFF8000000000L)) |
| | | || ((longValue & 0x0000007FFFFFFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 5); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 5, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 5, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFF800000000000L) == 0xFFFF800000000000L)) |
| | | || ((longValue & 0x00007FFFFFFFFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 6); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 6, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 6, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFF80000000000000L) == 0xFF80000000000000L)) |
| | | || ((longValue & 0x007FFFFFFFFFFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 7); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 7, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 7, longValue); |
| | | } else { |
| | | writeLength(sequenceBuffer, 8); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 56) & 0xFF)); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 8, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 8, longValue); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | sequenceBuffer.writeByte(type); |
| | | writeLength(sequenceBuffer, 0); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("WRITE ASN.1 NULL(type=0x%x, length=%d)", |
| | | type, 0)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 NULL(type=0x{}, length={})", byteToHex(type), 0); |
| | | |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(sequenceBuffer, length); |
| | | sequenceBuffer.writeByteArray(value, offset, length); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", type, length)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(type), length); |
| | | return this; |
| | | } |
| | | |
| | |
| | | sequenceBuffer.writeByte(value.byteAt(i)); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", type, value.length())); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(type), value.length()); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(sequenceBuffer, bytes.length); |
| | | sequenceBuffer.writeByteArray(bytes, 0, bytes.length); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d, " + "value=%s)", type, |
| | | bytes.length, value)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={}, value={})", byteToHex(type), |
| | | bytes.length, value); |
| | | return this; |
| | | } |
| | | |
| | |
| | | // Get a child sequence buffer |
| | | sequenceBuffer = sequenceBuffer.startSequence(type); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("WRITE ASN.1 START SEQUENCE(type=0x%x)", |
| | | type)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 START SEQUENCE(type=0x{})", byteToHex(type)); |
| | | return this; |
| | | } |
| | | |
| | |
| | | |
| | | package com.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.glassfish.grizzly.nio.transport.TCPNIOTransport; |
| | | import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; |
| | | import org.glassfish.grizzly.strategies.SameThreadIOStrategy; |
| | |
| | | try { |
| | | instance.shutdownNow(); |
| | | } catch (final IOException e) { |
| | | DEBUG_LOG.log(Level.WARNING, |
| | | "An error occurred while shutting down the Grizzly transport", e.getMessage()); |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("An error occurred while shutting down the Grizzly transport", e); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | package com.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | |
| | | import java.io.IOException; |
| | |
| | | if (future != null && future.checkForTimeout()) { |
| | | final long diff = (future.getTimestamp() + timeout) - currentTime; |
| | | if (diff <= 0 && pendingRequests.remove(requestID) != null) { |
| | | DEBUG_LOG.fine("Cancelling expired future result: " + future); |
| | | DEFAULT_LOG.debug("Cancelling expired future result: {}", future); |
| | | final Result result = Responses.newResult(ResultCode.CLIENT_SIDE_TIMEOUT); |
| | | future.adaptErrorResult(result); |
| | | abandonAsync(Requests.newAbandonRequest(future.getRequestID())); |
| | |
| | | package com.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.ldap.DefaultTCPNIOTransport.DEFAULT_TRANSPORT; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | |
| | | import java.io.Closeable; |
| | | import java.io.IOException; |
| | | import java.net.SocketAddress; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | |
| | | // Cannot handle here. |
| | | Thread.currentThread().interrupt(); |
| | | } catch (final Exception e) { |
| | | DEBUG_LOG.log(Level.WARNING, "Exception occurred while closing listener", e); |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Exception occurred while closing listener", e); |
| | | } |
| | | transport.release(); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package com.forgerock.opendj.ldap; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_LDAP_MODIFICATION_DECODE_INVALID_MOD_TYPE; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_LDAP_SEARCH_REQUEST_DECODE_INVALID_DEREF; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_LDAP_SEARCH_REQUEST_DECODE_INVALID_SCOPE; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.asn1.ASN1; |
| | | import org.forgerock.opendj.asn1.ASN1Reader; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * Static methods for decoding LDAP messages. |
| | | */ |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP ABANDON REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP ABANDON REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.abandonRequest(p, messageID, message); |
| | | } |
| | |
| | | final AddRequest message = Requests.newAddRequest(entry); |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP ADD REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP ADD REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.addRequest(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP ADD RESULT(messageID=%d, result=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP ADD RESULT(messageID={}, result={})", messageID, message); |
| | | |
| | | handler.addResult(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, request); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP BIND REQUEST(messageID=%d, auth=0x%x, request=%s)", messageID, |
| | | request.getAuthenticationType(), request)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP BIND REQUEST(messageID={}, auth=0x{}, request={})", messageID, |
| | | byteToHex(request.getAuthenticationType()), request); |
| | | |
| | | handler.bindRequest(p, messageID, protocolVersion, request); |
| | | } finally { |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP BIND RESULT(messageID=%d, result=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP BIND RESULT(messageID={}, result={})", messageID, message); |
| | | |
| | | handler.bindResult(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP COMPARE REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP COMPARE REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.compareRequest(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP COMPARE RESULT(messageID=%d, result=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP COMPARE RESULT(messageID={}, result={})", messageID, message); |
| | | |
| | | handler.compareResult(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP DELETE REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP DELETE REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.deleteRequest(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP DELETE RESULT(messageID=%d, result=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP DELETE RESULT(messageID={}, result={})", messageID, message); |
| | | |
| | | handler.deleteResult(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP EXTENDED REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP EXTENDED REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.extendedRequest(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP EXTENDED RESULT(messageID=%d, result=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP EXTENDED RESULT(messageID={}, result={})", messageID, message); |
| | | |
| | | handler.extendedResult(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP INTERMEDIATE RESPONSE(messageID=%d, response=%s)", messageID, |
| | | message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP INTERMEDIATE RESPONSE(messageID={}, response={})", |
| | | messageID, message); |
| | | |
| | | handler.intermediateResponse(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP MODIFY DN REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP MODIFY DN REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.modifyDNRequest(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP MODIFY DN RESULT(messageID=%d, result=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE MODIFY DN RESULT(messageID={}, result={})", messageID, message); |
| | | |
| | | handler.modifyDNResult(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP MODIFY REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP MODIFY REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.modifyRequest(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP MODIFY RESULT(messageID=%d, result=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP MODIFY RESULT(messageID={}, result={})", messageID, message); |
| | | |
| | | handler.modifyResult(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP SEARCH REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP SEARCH REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.searchRequest(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP SEARCH RESULT(messageID=%d, result=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP SEARCH RESULT(messageID={}, result={})", messageID, message); |
| | | |
| | | handler.searchResult(p, messageID, message); |
| | | } |
| | |
| | | final SearchResultEntry message = Responses.newSearchResultEntry(entry); |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP SEARCH RESULT ENTRY(messageID=%d, entry=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP SEARCH RESULT ENTRY(messageID={}, entry={})", messageID, message); |
| | | |
| | | handler.searchResultEntry(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP SEARCH RESULT REFERENCE(messageID=%d, reference=%s)", messageID, |
| | | message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP SEARCH RESULT REFERENCE(messageID={}, result={})", |
| | | messageID, message); |
| | | |
| | | handler.searchResultReference(p, messageID, message); |
| | | } |
| | |
| | | |
| | | decodeControls(reader, message); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "DECODE LDAP UNBIND REQUEST(messageID=%d, request=%s)", messageID, message)); |
| | | } |
| | | IO_LOG.trace("DECODE LDAP UNBIND REQUEST(messageID={}, request={})", messageID, message); |
| | | |
| | | handler.unbindRequest(p, messageID, message); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package com.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.ldap.LDAPConstants.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.opendj.asn1.ASN1Writer; |
| | | import org.forgerock.opendj.ldap.Attribute; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | |
| | | public void abandonRequest(final ASN1Writer writer, final int messageID, |
| | | final AbandonRequest request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP ABANDON REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP ABANDON REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeInteger(OP_TYPE_ABANDON_REQUEST, request.getRequestID()); |
| | | encodeMessageFooter(writer, request); |
| | |
| | | |
| | | public void addRequest(final ASN1Writer writer, final int messageID, final AddRequest request) |
| | | throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP ADD REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP ADD REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_ADD_REQUEST); |
| | | writer.writeOctetString(request.getName().toString()); |
| | |
| | | |
| | | public void addResult(final ASN1Writer writer, final int messageID, final Result result) |
| | | throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP ADD RESULT(messageID=%d, result=%s)", messageID, result)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP ADD RESULT(messageID={}, result={})", messageID, result); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeResultHeader(writer, OP_TYPE_ADD_RESPONSE, result); |
| | | encodeResultFooter(writer); |
| | |
| | | |
| | | public void bindRequest(final ASN1Writer writer, final int messageID, final int version, |
| | | final GenericBindRequest request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP BIND REQUEST(messageID=%d, auth=0x%x, request=%s)", messageID, |
| | | request.getAuthenticationType(), request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP BIND REQUEST(messageID={}, auth=0x{}, request={})", |
| | | messageID, byteToHex(request.getAuthenticationType()), request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_BIND_REQUEST); |
| | | |
| | |
| | | |
| | | public void bindResult(final ASN1Writer writer, final int messageID, final BindResult result) |
| | | throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP BIND RESULT(messageID=%d, result=%s)", messageID, result)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP BIND RESULT(messageID={}, result={})", messageID, result); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeResultHeader(writer, OP_TYPE_BIND_RESPONSE, result); |
| | | |
| | |
| | | |
| | | public void compareRequest(final ASN1Writer writer, final int messageID, |
| | | final CompareRequest request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP COMPARE REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP COMPARE REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_COMPARE_REQUEST); |
| | | writer.writeOctetString(request.getName().toString()); |
| | |
| | | |
| | | public void compareResult(final ASN1Writer writer, final int messageID, |
| | | final CompareResult result) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP COMPARE RESULT(messageID=%d, result=%s)", messageID, result)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP COMPARE RESULT(messageID={}, result={})", messageID, result); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeResultHeader(writer, OP_TYPE_COMPARE_RESPONSE, result); |
| | | encodeResultFooter(writer); |
| | |
| | | |
| | | public void deleteRequest(final ASN1Writer writer, final int messageID, |
| | | final DeleteRequest request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP DELETE REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP DELETE REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeOctetString(OP_TYPE_DELETE_REQUEST, request.getName().toString()); |
| | | encodeMessageFooter(writer, request); |
| | |
| | | |
| | | public void deleteResult(final ASN1Writer writer, final int messageID, final Result result) |
| | | throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP DELETE RESULT(messageID=%d, result=%s)", messageID, result)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP DELETE RESULT(messageID={}, result={})", messageID, result); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeResultHeader(writer, OP_TYPE_DELETE_RESPONSE, result); |
| | | encodeResultFooter(writer); |
| | |
| | | |
| | | public <R extends ExtendedResult> void extendedRequest(final ASN1Writer writer, |
| | | final int messageID, final ExtendedRequest<R> request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP EXTENDED REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP EXTENDED REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_EXTENDED_REQUEST); |
| | | writer.writeOctetString(TYPE_EXTENDED_REQUEST_OID, request.getOID()); |
| | |
| | | |
| | | public void extendedResult(final ASN1Writer writer, final int messageID, |
| | | final ExtendedResult result) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP EXTENDED RESULT(messageID=%d, result=%s)", messageID, result)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP EXTENDED RESULT(messageID={}, result={})", messageID, result); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeResultHeader(writer, OP_TYPE_EXTENDED_RESPONSE, result); |
| | | |
| | |
| | | |
| | | public void intermediateResponse(final ASN1Writer writer, final int messageID, |
| | | final IntermediateResponse response) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP INTERMEDIATE RESPONSE(messageID=%d, response=%s)", messageID, |
| | | response)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP INTERMEDIATE RESPONSE(messageID={}, response={})", messageID, response); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_INTERMEDIATE_RESPONSE); |
| | | |
| | |
| | | |
| | | public void modifyDNRequest(final ASN1Writer writer, final int messageID, |
| | | final ModifyDNRequest request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP MODIFY DN REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP MODIFY DN REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_MODIFY_DN_REQUEST); |
| | | writer.writeOctetString(request.getName().toString()); |
| | |
| | | |
| | | public void modifyDNResult(final ASN1Writer writer, final int messageID, final Result result) |
| | | throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP MODIFY DN RESULT(messageID=%d, result=%s)", messageID, result)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP MODIFY DN RESULT(messageID={}, result={})", messageID, result); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeResultHeader(writer, OP_TYPE_MODIFY_DN_RESPONSE, result); |
| | | encodeResultFooter(writer); |
| | |
| | | |
| | | public void modifyRequest(final ASN1Writer writer, final int messageID, |
| | | final ModifyRequest request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP MODIFY REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP MODIFY REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_MODIFY_REQUEST); |
| | | writer.writeOctetString(request.getName().toString()); |
| | |
| | | |
| | | public void modifyResult(final ASN1Writer writer, final int messageID, final Result result) |
| | | throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP MODIFY RESULT(messageID=%d, result=%s)", messageID, result)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP MODIFY RESULT(messageID={}, result={})", messageID, result); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeResultHeader(writer, OP_TYPE_MODIFY_RESPONSE, result); |
| | | encodeResultFooter(writer); |
| | |
| | | |
| | | public void searchRequest(final ASN1Writer writer, final int messageID, |
| | | final SearchRequest request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP SEARCH REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP SEARCH REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_SEARCH_REQUEST); |
| | | writer.writeOctetString(request.getName().toString()); |
| | |
| | | |
| | | public void searchResult(final ASN1Writer writer, final int messageID, final Result result) |
| | | throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP SEARCH RESULT(messageID=%d, result=%s)", messageID, result)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP SEARCH RESULT(messageID={}, result={})", messageID, result); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeResultHeader(writer, OP_TYPE_SEARCH_RESULT_DONE, result); |
| | | encodeResultFooter(writer); |
| | |
| | | |
| | | public void searchResultEntry(final ASN1Writer writer, final int messageID, |
| | | final SearchResultEntry entry) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP SEARCH RESULT ENTRY(messageID=%d, entry=%s)", messageID, entry)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP SEARCH RESULT ENTRY(messageID={}, entry={})", messageID, entry); |
| | | encodeMessageHeader(writer, messageID); |
| | | encodeEntry(writer, entry); |
| | | encodeMessageFooter(writer, entry); |
| | |
| | | |
| | | public void searchResultReference(final ASN1Writer writer, final int messageID, |
| | | final SearchResultReference reference) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP SEARCH RESULT REFERENCE(messageID=%d, reference=%s)", messageID, |
| | | reference)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP SEARCH RESULT REFERENCE(messageID={}, reference={})", messageID, reference); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeStartSequence(OP_TYPE_SEARCH_RESULT_REFERENCE); |
| | | for (final String url : reference.getURIs()) { |
| | |
| | | |
| | | public void unbindRequest(final ASN1Writer writer, final int messageID, |
| | | final UnbindRequest request) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP UNBIND REQUEST(messageID=%d, request=%s)", messageID, request)); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP UNBIND REQUEST(messageID={}, request={})", messageID, request); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeNull(OP_TYPE_UNBIND_REQUEST); |
| | | encodeMessageFooter(writer, request); |
| | |
| | | |
| | | public void unrecognizedMessage(final ASN1Writer writer, final int messageID, |
| | | final byte messageTag, final ByteString messageBytes) throws IOException { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | StaticUtils.DEBUG_LOG.finer(String.format( |
| | | "ENCODE LDAP UNKNOWN MESSAGE(messageID=%d, messageTag=%s, " |
| | | + "messageBytes=%s)", messageID, StaticUtils.byteToHex(messageTag), |
| | | messageBytes.toString())); |
| | | } |
| | | IO_LOG.trace("ENCODE LDAP UNKNOWN MESSAGE(messageID={}, messageTag={}, messageBytes={})", |
| | | messageID, StaticUtils.byteToHex(messageTag), messageBytes.toString()); |
| | | encodeMessageHeader(writer, messageID); |
| | | writer.writeOctetString(messageTag, messageBytes); |
| | | writer.writeEndSequence(); |
| | |
| | | |
| | | package com.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | import static java.util.Collections.newSetFromMap; |
| | | |
| | | import java.util.Set; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.logging.Level; |
| | | |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | | |
| | | /** |
| | |
| | | final Thread checkerThread = new Thread("OpenDJ LDAP SDK Connection Timeout Checker") { |
| | | @Override |
| | | public void run() { |
| | | DEBUG_LOG.fine("Timeout Checker Starting"); |
| | | DEFAULT_LOG.debug("Timeout Checker Starting"); |
| | | while (!shutdownRequested) { |
| | | final long currentTime = System.currentTimeMillis(); |
| | | long delay = 0; |
| | | |
| | | for (final LDAPConnection connection : connections) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | DEBUG_LOG.finer("Checking connection " + connection + " delay = " |
| | | + delay); |
| | | } |
| | | DEFAULT_LOG.trace("Checking connection {} delay = {}", connection, delay); |
| | | |
| | | // May update the connections set. |
| | | final long newDelay = connection.cancelExpiredRequests(currentTime); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | throw DecodeException.error(message); |
| | | } |
| | | } catch (final IOException e) { |
| | | StaticUtils.DEBUG_LOG.throwing( |
| | | "AccountUsabilityResponseControl.decodeControl", "decode", e); |
| | | StaticUtils.CONTROLS_LOG.debug("", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_ACCTUSABLERES_DECODE_ERROR.get(getExceptionMessage(e)); |
| | |
| | | } |
| | | |
| | | return newRequest; |
| | | } catch (final IOException ae) { |
| | | StaticUtils.DEBUG_LOG.throwing("GetSymmetricKeyRequest.Operation", "decodeRequest", |
| | | ae); |
| | | } catch (final IOException ioe) { |
| | | StaticUtils.DEFAULT_LOG.debug("", ioe); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_GET_SYMMETRIC_KEY_ASN1_DECODE_EXCEPTION.get(ae.getMessage()); |
| | | throw DecodeException.error(message, ae); |
| | | ERR_GET_SYMMETRIC_KEY_ASN1_DECODE_EXCEPTION.get(ioe.getMessage()); |
| | | throw DecodeException.error(message, ioe); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import java.io.Closeable; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.CharBuffer; |
| | |
| | | import java.util.concurrent.ThreadFactory; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | import java.util.zip.DataFormatException; |
| | | import java.util.zip.Deflater; |
| | | import java.util.zip.Inflater; |
| | |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * Common utility methods. |
| | | */ |
| | | public final class StaticUtils { |
| | | |
| | | private static final String DEFAULT_LOGGER_NAME = "org.forgerock.opendj.ldap"; |
| | | |
| | | /** |
| | | * The debug logger which should be used by the SDK. |
| | | * The default logger used by the SDK if there is no appropriate specific logger. |
| | | */ |
| | | public static final Logger DEBUG_LOG = Logger.getLogger("org.forgerock.opendj.ldap"); |
| | | public static final Logger DEFAULT_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME); |
| | | |
| | | /** |
| | | * The logger used by the SDK for controls related features. |
| | | */ |
| | | public static final Logger CONTROLS_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME + ".controls"); |
| | | |
| | | /** |
| | | * The logger used by the SDK for schema related features. |
| | | */ |
| | | public static final Logger SCHEMA_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME + ".schema"); |
| | | |
| | | /** |
| | | * The logger used by the SDK for IO related features (buffers, readers, writers). |
| | | */ |
| | | public static final Logger IO_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME + ".io"); |
| | | |
| | | /** |
| | | * Indicates whether the SDK is being used in debug mode. In debug mode |
| | |
| | | compress(inputBytes, 0, inputBytes.length, outputBytes, 0, outputBytes.length); |
| | | |
| | | if (compressedSize != -1) { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | StaticUtils.DEBUG_LOG.fine(String.format("Compression %d/%d%n", compressedSize, |
| | | inputBytes.length)); |
| | | } |
| | | |
| | | DEFAULT_LOG.debug("Compression {}/{}", compressedSize, inputBytes.length); |
| | | output.append(outputBytes, 0, compressedSize); |
| | | return true; |
| | | } |
| | |
| | | // Format the year yyyy. |
| | | int n = calendar.get(Calendar.YEAR); |
| | | if (n < 0) { |
| | | final IllegalArgumentException e = |
| | | new IllegalArgumentException("Year cannot be < 0:" + n); |
| | | StaticUtils.DEBUG_LOG.throwing("GeneralizedTimeSyntax", "format", e); |
| | | final IllegalArgumentException e = new IllegalArgumentException("Year cannot be < 0:" + n); |
| | | throw e; |
| | | } else if (n < 10) { |
| | | sb.append("000"); |
| | |
| | | } |
| | | |
| | | return returnArray; |
| | | } catch (final Exception e) { |
| | | DEBUG_LOG.warning("Unable to encode UTF-8 string " + s); |
| | | |
| | | return s.getBytes(); |
| | | } catch (final UnsupportedEncodingException e) { |
| | | // TODO: I18N |
| | | throw new RuntimeException("Unable to encode UTF-8 string " + s, e); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | if (DEBUG_TO_STDERR) { |
| | | System.err.println(builder.toString()); |
| | | } else if (DEBUG_LOG.isLoggable(Level.SEVERE)) { |
| | | DEBUG_LOG.severe(builder.toString()); |
| | | } else if (DEFAULT_LOG.isErrorEnabled()) { |
| | | // TODO: I18N |
| | | DEFAULT_LOG.error(builder.toString()); |
| | | } |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.asn1; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.LinkedList; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequenceReader; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * An ASN.1 reader that reads from a {@link ByteSequenceReader}. |
| | | */ |
| | |
| | | throw new IllegalStateException(message.toString()); |
| | | } |
| | | |
| | | if ((reader.remaining() > 0) && StaticUtils.DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | StaticUtils.DEBUG_LOG.fine("Ignoring " + reader.remaining() |
| | | + " unused trailing bytes in " + "ASN.1 SEQUENCE"); |
| | | if (reader.remaining() > 0) { |
| | | IO_LOG.debug("Ignoring {} unused trailing bytes in ASN.1 SEQUENCE", |
| | | reader.remaining()); |
| | | } |
| | | |
| | | reader = readerStack.removeFirst(); |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.asn1; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.LinkedList; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.SizeLimitInputStream; |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * An ASN1Reader that reads from an input stream. |
| | |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", peekType, peekLength, |
| | | String.valueOf(readByte != 0x00))); |
| | | if (IO_LOG.isTraceEnabled()) { |
| | | IO_LOG.trace("READ ASN.1 BOOLEAN(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, String.valueOf(readByte != 0x00)); |
| | | } |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return readByte != 0x00; |
| | | } |
| | |
| | | // Ignore all unused trailing components. |
| | | final SizeLimitInputStream subSq = (SizeLimitInputStream) in; |
| | | if (subSq.getSizeLimit() - subSq.getBytesRead() > 0) { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | StaticUtils.DEBUG_LOG.fine(String.format( |
| | | "Ignoring %d unused trailing bytes in ASN.1 SEQUENCE", subSq.getSizeLimit() |
| | | - subSq.getBytesRead())); |
| | | if (IO_LOG.isTraceEnabled()) { |
| | | IO_LOG.trace("Ignoring {} unused trailing bytes in ASN.1 SEQUENCE", |
| | | subSq.getSizeLimit() - subSq.getBytesRead()); |
| | | } |
| | | |
| | | subSq.skip(subSq.getSizeLimit() - subSq.getBytesRead()); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("READ ASN.1 END SEQUENCE")); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 END SEQUENCE"); |
| | | |
| | | in = streamStack.removeFirst(); |
| | | |
| | |
| | | intValue = (intValue << 8) | (readByte & 0xFF); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", peekType, peekLength, |
| | | intValue)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 INTEGER(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, intValue); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return intValue; |
| | |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("READ ASN.1 NULL(type=0x%x, length=%d)", |
| | | peekType, peekLength)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 NULL(type=0x{}, length={})", |
| | | byteToHex(peekType), peekLength); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | } |
| | |
| | | bytesNeeded -= bytesRead; |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return ByteString.wrap(value); |
| | |
| | | bytesNeeded -= bytesRead; |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength)); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return builder; |
| | | } |
| | |
| | | String str; |
| | | try { |
| | | str = new String(buffer, 0, peekLength, "UTF-8"); |
| | | } catch (final Exception e) { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | StaticUtils.DEBUG_LOG.warning("Unable to decode ASN.1 OCTETSTRING " |
| | | + "bytes as UTF-8 string: " + e.toString()); |
| | | } |
| | | |
| | | str = new String(buffer, 0, peekLength); |
| | | } catch (final UnsupportedEncodingException e) { |
| | | // TODO: I18N |
| | | throw new RuntimeException("Unable to decode ASN.1 OCTETSTRING bytes as UTF-8 string ", e); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 OCTETSTRING(type=0x%x, length=%d, value=%s)", peekType, peekLength, |
| | | str)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, str); |
| | | |
| | | return str; |
| | | } |
| | |
| | | |
| | | final SizeLimitInputStream subStream = new SizeLimitInputStream(in, peekLength); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "READ ASN.1 START SEQUENCE(type=0x%x, length=%d)", peekType, peekLength)); |
| | | } |
| | | IO_LOG.trace("READ ASN.1 START SEQUENCE(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | |
| | | streamStack.addFirst(in); |
| | | in = subStream; |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.asn1; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_SEQUENCE_WRITE_NOT_STARTED; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | |
| | | writeLength(1); |
| | | out.write(booleanValue ? ASN1.BOOLEAN_VALUE_TRUE : ASN1.BOOLEAN_VALUE_FALSE); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", type, 1, String |
| | | .valueOf(booleanValue))); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 BOOLEAN(type=0x{}, length={}, value={})", |
| | | byteToHex(type), 1, String.valueOf(booleanValue)); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(childStream.length()); |
| | | childStream.writeTo(parentStream); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("WRITE ASN.1 END SEQUENCE(length=%d)", |
| | | childStream.length())); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 END SEQUENCE(length={})", childStream.length()); |
| | | |
| | | childStream.reset(); |
| | | return this; |
| | |
| | | || ((intValue & 0x0000007F) == intValue)) { |
| | | writeLength(1); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, intValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 1, intValue); |
| | | } else if (((intValue < 0) && ((intValue & 0xFFFF8000) == 0xFFFF8000)) |
| | | || ((intValue & 0x00007FFF) == intValue)) { |
| | | writeLength(2); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, intValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 2, intValue); |
| | | } else if (((intValue < 0) && ((intValue & 0xFF800000) == 0xFF800000)) |
| | | || ((intValue & 0x007FFFFF) == intValue)) { |
| | | writeLength(3); |
| | | out.write((byte) ((intValue >> 16) & 0xFF)); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, intValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 3, intValue); |
| | | } else { |
| | | writeLength(4); |
| | | out.write((byte) ((intValue >> 24) & 0xFF)); |
| | | out.write((byte) ((intValue >> 16) & 0xFF)); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, intValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 4, intValue); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | || ((longValue & 0x000000000000007FL) == longValue)) { |
| | | writeLength(1); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 1, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFFFF8000L) == 0xFFFFFFFFFFFF8000L)) |
| | | || ((longValue & 0x0000000000007FFFL) == longValue)) { |
| | | writeLength(2); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 2, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFF800000L) == 0xFFFFFFFFFF800000L)) |
| | | || ((longValue & 0x00000000007FFFFFL) == longValue)) { |
| | | writeLength(3); |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 3, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFF80000000L) == 0xFFFFFFFF80000000L)) |
| | | || ((longValue & 0x000000007FFFFFFFL) == longValue)) { |
| | | writeLength(4); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 4, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFF8000000000L) == 0xFFFFFF8000000000L)) |
| | | || ((longValue & 0x0000007FFFFFFFFFL) == longValue)) { |
| | | writeLength(5); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 5, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 5, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFF800000000000L) == 0xFFFF800000000000L)) |
| | | || ((longValue & 0x00007FFFFFFFFFFFL) == longValue)) { |
| | | writeLength(6); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 6, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 6, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFF80000000000000L) == 0xFF80000000000000L)) |
| | | || ((longValue & 0x007FFFFFFFFFFFFFL) == longValue)) { |
| | | writeLength(7); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 7, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 7, longValue); |
| | | } else { |
| | | writeLength(8); |
| | | out.write((byte) ((longValue >> 56) & 0xFF)); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 8, longValue)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 8, longValue); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | out.write(type); |
| | | writeLength(0); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("WRITE ASN.1 NULL(type=0x%x, length=%d)", |
| | | type, 0)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 NULL(type=0x{}, length={})", byteToHex(type), 0); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(length); |
| | | out.write(value, offset, length); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", type, length)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(type), length); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(value.length()); |
| | | value.copyTo(out); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", type, value.length())); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(type), value.length()); |
| | | |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(bytes.length); |
| | | out.write(bytes); |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format( |
| | | "WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d, " + "value=%s)", type, |
| | | bytes.length, value)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={}, value={})", |
| | | byteToHex(type), bytes.length, value); |
| | | return this; |
| | | } |
| | | |
| | |
| | | out = streamStack.get(stackDepth); |
| | | } |
| | | |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { |
| | | StaticUtils.DEBUG_LOG.finest(String.format("WRITE ASN.1 START SEQUENCE(type=0x%x)", |
| | | type)); |
| | | } |
| | | IO_LOG.trace("WRITE ASN.1 START SEQUENCE(type=0x{})", byteToHex(type)); |
| | | return this; |
| | | } |
| | | |
| | |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_SCHEDULER; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | |
| | |
| | | import java.util.concurrent.ScheduledFuture; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.logging.Level; |
| | | |
| | | import com.forgerock.opendj.util.AsynchronousFutureResult; |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | | import com.forgerock.opendj.util.Validator; |
| | |
| | | private synchronized void checkIfAvailable() { |
| | | if (!isOperational.get() |
| | | && (pendingConnectFuture == null || pendingConnectFuture.isDone())) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format("Attempting reconnect to offline factory '%s'", |
| | | this)); |
| | | } |
| | | DEFAULT_LOG.debug("Attempting reconnect to offline factory '{}'", this); |
| | | pendingConnectFuture = factory.getConnectionAsync(this); |
| | | } |
| | | } |
| | |
| | | synchronized (stateLock) { |
| | | offlineFactoriesCount++; |
| | | if (offlineFactoriesCount == 1) { |
| | | // Enable monitoring. |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format("Starting monitoring thread")); |
| | | } |
| | | |
| | | DEFAULT_LOG.debug("Starting monitoring thread"); |
| | | monitoringFuture = |
| | | scheduler.get().scheduleWithFixedDelay(new MonitorRunnable(), 0, |
| | | monitoringInterval, monitoringIntervalTimeUnit); |
| | |
| | | synchronized (stateLock) { |
| | | offlineFactoriesCount--; |
| | | if (offlineFactoriesCount == 0) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format("Stopping monitoring thread")); |
| | | } |
| | | DEFAULT_LOG.debug("Stopping monitoring thread"); |
| | | |
| | | monitoringFuture.cancel(false); |
| | | monitoringFuture = null; |
| | |
| | | } |
| | | |
| | | private void handleListenerException(RuntimeException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.SEVERE)) { |
| | | DEBUG_LOG.log(Level.SEVERE, |
| | | "A run-time error occurred while processing a load-balancer event", e); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.error("A run-time error occurred while processing a load-balancer event", e); |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * A default event listener which just logs the event. |
| | | */ |
| | | private static final LoadBalancerEventListener DEFAULT_LISTENER = |
| | | new LoadBalancerEventListener() { |
| | | private static final LoadBalancerEventListener DEFAULT_LISTENER = new LoadBalancerEventListener() { |
| | | |
| | | @Override |
| | | public void handleConnectionFactoryOnline(ConnectionFactory factory) { |
| | | // Transition from offline to online. |
| | | if (DEBUG_LOG.isLoggable(Level.INFO)) { |
| | | DEBUG_LOG.info(String.format("Connection factory'%s' is now operational", |
| | | factory)); |
| | | } |
| | | } |
| | | @Override |
| | | public void handleConnectionFactoryOnline(ConnectionFactory factory) { |
| | | // Transition from offline to online. |
| | | // TODO: I18N |
| | | DEFAULT_LOG.info("Connection factory '{}' is now operational", factory); |
| | | } |
| | | |
| | | @Override |
| | | public void handleConnectionFactoryOffline(ConnectionFactory factory, |
| | | ErrorResultException error) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning(String.format( |
| | | "Connection factory '%s' is no longer operational: %s", factory, |
| | | error.getMessage())); |
| | | } |
| | | } |
| | | }; |
| | | @Override |
| | | public void handleConnectionFactoryOffline(ConnectionFactory factory, ErrorResultException error) { |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Connection factory '{}' is no longer operational: {}", factory, error.getMessage()); |
| | | } |
| | | }; |
| | | |
| | | private final List<MonitoredConnectionFactory> monitoredFactories; |
| | | private final ReferenceCountedObject<ScheduledExecutorService>.Reference scheduler; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.CharBuffer; |
| | | import java.nio.charset.Charset; |
| | | import java.util.Arrays; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | |
| | |
| | | String stringValue; |
| | | try { |
| | | stringValue = new String(b, offset, length, "UTF-8"); |
| | | } catch (final Exception e) { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | StaticUtils.DEBUG_LOG.warning("Unable to decode ByteString " |
| | | + "bytes as UTF-8 string: " + e.toString()); |
| | | } |
| | | |
| | | stringValue = new String(b, offset, length); |
| | | } catch (final UnsupportedEncodingException e) { |
| | | // TODO: I18N |
| | | throw new RuntimeException("Unable to decode bytes as UTF-8 string", e); |
| | | } |
| | | |
| | | return stringValue; |
| | |
| | | if (offset < 0) { |
| | | throw new IndexOutOfBoundsException(); |
| | | } |
| | | System.arraycopy(buffer, this.offset, bytes, offset, Math |
| | | .min(length, bytes.length - offset)); |
| | | System.arraycopy(buffer, this.offset, bytes, offset, Math.min(length, bytes.length - offset)); |
| | | return bytes; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.CharBuffer; |
| | | import java.nio.charset.Charset; |
| | | import java.util.logging.Level; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * A mutable sequence of bytes backed by a byte array. |
| | |
| | | // There is a multi-byte char. Defer to JDK |
| | | try { |
| | | return append(s.getBytes("UTF-8")); |
| | | } catch (final Exception e) { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | StaticUtils.DEBUG_LOG.warning("Unable to encode String " |
| | | + "to UTF-8 bytes: " + e.toString()); |
| | | } |
| | | |
| | | return append(s.getBytes()); |
| | | } catch (final UnsupportedEncodingException e) { |
| | | // TODO: I18N |
| | | throw new RuntimeException("Unable to encode String '" + s + "' to UTF-8 bytes", e); |
| | | } |
| | | } |
| | | } |
| | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_ENABLED; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_SCHEDULER; |
| | | import static com.forgerock.opendj.util.StaticUtils.getStackTraceIfDebugEnabled; |
| | | import static com.forgerock.opendj.util.StaticUtils.logIfDebugEnabled; |
| | |
| | | import java.util.concurrent.Semaphore; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.opendj.ldap.requests.AbandonRequest; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.BindRequest; |
| | |
| | | // Connection attempt failed, so decrease the pool size. |
| | | availableConnections.release(); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection attempt failed: %s, availableConnections=%d, maxPoolSize=%d", |
| | | error.getMessage(), currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection attempt failed: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize, error); |
| | | |
| | | QueueElement holder; |
| | | synchronized (queue) { |
| | |
| | | |
| | | @Override |
| | | public void handleResult(final Connection connection) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection attempt succeeded: availableConnections=%d, maxPoolSize=%d", |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection attempt succeeded: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | publishConnection(connection); |
| | | } |
| | | } |
| | |
| | | connection.close(); |
| | | factory.getConnectionAsync(connectionResultHandler); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection no longer valid: availableConnections=%d, maxPoolSize=%d", |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection no longer valid: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | } |
| | | |
| | | // Invoke listeners. |
| | |
| | | |
| | | // Close the idle connections. |
| | | if (!idleConnections.isEmpty()) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format("Closing %d idle pooled connections: " |
| | | + "availableConnections=%d, maxPoolSize=%d", idleConnections.size(), |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Closing {} idle pooled connections: availableConnections={}, maxPoolSize={}", |
| | | idleConnections.size(), currentPoolSize(), maxPoolSize); |
| | | for (final Connection connection : idleConnections) { |
| | | connection.close(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection pool is closing: availableConnections=%d, maxPoolSize=%d", |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection pool is closing: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | |
| | | if (idleTimeoutFuture != null) { |
| | | idleTimeoutFuture.cancel(false); |
| | |
| | | connection.close(); |
| | | availableConnections.release(); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection no longer valid: availableConnections=%d, poolSize=%d", |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection no longer valid: availableConnections={}, poolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | } |
| | | } else { |
| | | // Grow the pool if needed. |
| | |
| | | availableConnections.release(); |
| | | connection.close(); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Closing connection because connection pool is closing: " |
| | | + "availableConnections=%d, maxPoolSize=%d", currentPoolSize(), |
| | | maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug( |
| | | "Closing connection because connection pool is closing: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | |
| | | if (holder != null) { |
| | | final ErrorResultException e = |
| | |
| | | ERR_CONNECTION_POOL_CLOSING.get(toString()).toString()); |
| | | holder.getWaitingFuture().handleErrorResult(e); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection attempt failed: %s, availableConnections=%d, poolSize=%d", |
| | | e.getMessage(), currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection attempt failed: availableConnections={}, poolSize={}", |
| | | currentPoolSize(), maxPoolSize, e); |
| | | } |
| | | } else { |
| | | holder.getWaitingFuture().handleResult( |
| | |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_SCHEDULER; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.HBCF_CONNECTION_CLOSED_BY_CLIENT; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.HBCF_HEARTBEAT_FAILED; |
| | |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.concurrent.locks.AbstractQueuedSynchronizer; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.opendj.ldap.requests.AbandonRequest; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.BindRequest; |
| | |
| | | * that the heart beat was aborted by a client-side close. |
| | | */ |
| | | if (!(error instanceof CancelledResultException)) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning(String.format( |
| | | "Heartbeat failed for connection factory '%s': %s", factory, error |
| | | .getMessage())); |
| | | } |
| | | DEFAULT_LOG.warn("Heartbeat failed for connection factory '{}'", factory, error); |
| | | timestamp(error); |
| | | } |
| | | releaseHeartBeatLock(); |
| | |
| | | */ |
| | | final long currentTimeMillis = timeSource.currentTimeMillis(); |
| | | if (lastResponseTimestamp < (currentTimeMillis - timeoutMS)) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning(String.format( |
| | | "No heartbeat detected for connection '%s'", connection)); |
| | | } |
| | | DEFAULT_LOG.warn("No heartbeat detected for connection '{}'", connection); |
| | | handleConnectionError(false, newHeartBeatTimeoutError()); |
| | | } |
| | | } |
| | |
| | | if (isClosed.compareAndSet(false, true)) { |
| | | synchronized (validConnections) { |
| | | if (!validConnections.isEmpty()) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "HeartbeatConnectionFactory '%s' is closing while %d " |
| | | + "active connections remain", toString(), validConnections |
| | | .size())); |
| | | if (DEFAULT_LOG.isDebugEnabled()) { |
| | | DEFAULT_LOG.debug( |
| | | "HeartbeatConnectionFactory '{}' is closing while {} active connections remain", |
| | | toString(), validConnections.size()); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.schema.MatchingRule; |
| | | import org.forgerock.opendj.ldap.schema.MatchingRuleUse; |
| | |
| | | private static final class Visitor implements FilterVisitor<MatcherImpl, Schema> { |
| | | public MatcherImpl visitAndFilter(final Schema schema, final List<Filter> subFilters) { |
| | | if (subFilters.isEmpty()) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | DEBUG_LOG.finer("Empty add filter component. " + "Will always return TRUE"); |
| | | } |
| | | DEFAULT_LOG.trace("Empty add filter component. Will always return TRUE"); |
| | | return TRUE; |
| | | } |
| | | |
| | |
| | | try { |
| | | ad = AttributeDescription.valueOf(attributeDescription, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Attribute description {} is not recognized", attributeDescription, e); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | if ((rule = ad.getAttributeType().getApproximateMatchingRule()) == null) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an approximate matching rule"); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The attribute type {} does not define an approximate matching rule", |
| | | attributeDescription); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | try { |
| | | assertion = rule.getAssertion(assertionValue); |
| | | } catch (final DecodeException de) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The assertion value " + assertionValue + " is invalid: " |
| | | + de.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The assertion value {} is invalid", assertionValue, de); |
| | | return UNDEFINED; |
| | | } |
| | | return new AssertionMatcherImpl(ad, rule, null, assertion, false); |
| | |
| | | try { |
| | | ad = AttributeDescription.valueOf(attributeDescription, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Attribute description {} is not recognized: {}", |
| | | attributeDescription, e.getMessage()); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | if ((rule = ad.getAttributeType().getEqualityMatchingRule()) == null) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an equality matching rule"); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The attribute type {} does not define an equality matching rule", |
| | | attributeDescription); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | try { |
| | | assertion = rule.getAssertion(assertionValue); |
| | | } catch (final DecodeException de) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The assertion value " + assertionValue + " is invalid: " |
| | | + de.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The assertion value {} is invalid", assertionValue, de); |
| | | return UNDEFINED; |
| | | } |
| | | return new AssertionMatcherImpl(ad, rule, null, assertion, false); |
| | |
| | | try { |
| | | rule = schema.getMatchingRule(matchingRule); |
| | | } catch (final UnknownSchemaElementException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("Matching rule " + matchingRule + " is not recognized: " |
| | | + e.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Matching rule {} is not recognized", matchingRule); |
| | | return UNDEFINED; |
| | | } |
| | | } |
| | |
| | | try { |
| | | ad = AttributeDescription.valueOf(attributeDescription, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Attribute description {} is not recognized", attributeDescription, e); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | if (rule == null) { |
| | | if ((rule = ad.getAttributeType().getEqualityMatchingRule()) == null) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an equality matching rule"); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The attribute type {} does not define an equality matching rule", |
| | | attributeDescription); |
| | | return UNDEFINED; |
| | | } |
| | | } else { |
| | | try { |
| | | ruleUse = schema.getMatchingRuleUse(rule); |
| | | if (!ruleUse.hasAttribute(ad.getAttributeType())) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The matching rule " + matchingRule |
| | | + " is not valid for attribute type " |
| | | + attributeDescription); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The matching rule {} is not valid for attribute type {}", |
| | | matchingRule, attributeDescription); |
| | | return UNDEFINED; |
| | | } |
| | | } catch (final UnknownSchemaElementException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("No matching rule use is defined for " |
| | | + "matching rule " + matchingRule); |
| | | return UNDEFINED; |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("No matching rule use is defined for matching rule {}", matchingRule); |
| | | return UNDEFINED; |
| | | } |
| | | } |
| | | } else { |
| | | try { |
| | | ruleUse = schema.getMatchingRuleUse(rule); |
| | | } catch (final UnknownSchemaElementException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("No matching rule use is defined for " + "matching rule " |
| | | + matchingRule); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("No matching rule use is defined for matching rule {}", matchingRule); |
| | | return UNDEFINED; |
| | | } |
| | | } |
| | |
| | | try { |
| | | assertion = rule.getAssertion(assertionValue); |
| | | } catch (final DecodeException de) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The assertion value " + assertionValue + " is invalid: " |
| | | + de.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The assertion value {} is invalid", assertionValue, de); |
| | | return UNDEFINED; |
| | | } |
| | | return new AssertionMatcherImpl(ad, rule, ruleUse, assertion, dnAttributes); |
| | |
| | | try { |
| | | ad = AttributeDescription.valueOf(attributeDescription, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Attribute description {} is not recognized", attributeDescription, e); |
| | | |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | if ((rule = ad.getAttributeType().getOrderingMatchingRule()) == null) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an ordering matching rule"); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The attribute type {} does not define an ordering matching rule", |
| | | attributeDescription); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | try { |
| | | assertion = rule.getGreaterOrEqualAssertion(assertionValue); |
| | | } catch (final DecodeException de) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The assertion value " + assertionValue + " is invalid: " |
| | | + de.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The assertion value {} is invalid", assertionValue, de); |
| | | return UNDEFINED; |
| | | } |
| | | return new AssertionMatcherImpl(ad, rule, null, assertion, false); |
| | |
| | | try { |
| | | ad = AttributeDescription.valueOf(attributeDescription, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Attribute description {} is not recognized", attributeDescription, e); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | if ((rule = ad.getAttributeType().getOrderingMatchingRule()) == null) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an ordering matching rule"); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The attribute type {} does not define an ordering matching rule", |
| | | attributeDescription); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | try { |
| | | assertion = rule.getLessOrEqualAssertion(assertionValue); |
| | | } catch (final DecodeException de) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The assertion value " + assertionValue + " is invalid: " |
| | | + de.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The assertion value {} is invalid", assertionValue , de); |
| | | return UNDEFINED; |
| | | } |
| | | return new AssertionMatcherImpl(ad, rule, null, assertion, false); |
| | |
| | | |
| | | public MatcherImpl visitOrFilter(final Schema schema, final List<Filter> subFilters) { |
| | | if (subFilters.isEmpty()) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINER)) { |
| | | DEBUG_LOG.finer("Empty or filter component. " + "Will always return FALSE"); |
| | | } |
| | | DEFAULT_LOG.trace("Empty or filter component. Will always return FALSE"); |
| | | return FALSE; |
| | | } |
| | | |
| | |
| | | try { |
| | | ad = AttributeDescription.valueOf(attributeDescription, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Attribute description {} is not recognized", attributeDescription, e); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | |
| | | try { |
| | | ad = AttributeDescription.valueOf(attributeDescription, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("Attribute description {} is not recognized", attributeDescription, e); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | if ((rule = ad.getAttributeType().getSubstringMatchingRule()) == null) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an substring matching rule"); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The attribute type {} does not define an substring matching rule", |
| | | attributeDescription); |
| | | return UNDEFINED; |
| | | } |
| | | |
| | | try { |
| | | assertion = rule.getAssertion(initialSubstring, anySubstrings, finalSubstring); |
| | | } catch (final DecodeException de) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The substring assertion values contain an invalid value: " |
| | | + de.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The substring assertion values contain an invalid value", de); |
| | | return UNDEFINED; |
| | | } |
| | | return new AssertionMatcherImpl(ad, rule, null, assertion, false); |
| | |
| | | |
| | | public MatcherImpl visitUnrecognizedFilter(final Schema schema, final byte filterTag, |
| | | final ByteString filterBytes) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The type of filtering requested with tag " |
| | | + StaticUtils.byteToHex(filterTag) + " is not implemented"); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The type of filtering requested with tag {} is not implemented", |
| | | StaticUtils.byteToHex(filterTag)); |
| | | return UNDEFINED; |
| | | } |
| | | } |
| | |
| | | final ByteString normalizedValue = rule.normalizeAttributeValue(v); |
| | | return assertion.matches(normalizedValue); |
| | | } catch (final DecodeException de) { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) { |
| | | DEBUG_LOG.warning("The attribute value " + v.toString() + " is " |
| | | + "invalid for matching rule " + rule.getNameOrOID() |
| | | + ". Possible schema error? : " + de.getMessage()); |
| | | } |
| | | // TODO: I18N |
| | | DEFAULT_LOG.warn("The attribute value {} is invalid for matching rule {}. Possible schema error?", |
| | | v.toString(), rule.getNameOrOID(), de); |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | } |
| | |
| | | changeNumber = reader.readInteger(); |
| | | } |
| | | } catch (final IOException e) { |
| | | StaticUtils.DEBUG_LOG.throwing("EntryChangeNotificationControl.Decoder", |
| | | "decode", e); |
| | | StaticUtils.CONTROLS_LOG.debug("", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_ECN_CANNOT_DECODE_VALUE.get(getExceptionMessage(e)); |
| | |
| | | return new MatchedValuesRequestControl(control.isCritical(), Collections |
| | | .unmodifiableList(filters)); |
| | | } catch (final IOException e) { |
| | | StaticUtils.DEBUG_LOG.throwing("MatchedValuesControl.Decoder", "decode", e); |
| | | StaticUtils.CONTROLS_LOG.debug("", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_MATCHEDVALUES_CANNOT_DECODE_VALUE_AS_SEQUENCE |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | try { |
| | | secondsUntilExpiration = Integer.parseInt(control.getValue().toString()); |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("PasswordExpiringControl.Decoder", "decode", |
| | | e); |
| | | StaticUtils.CONTROLS_LOG.debug("", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_PWEXPIRING_CANNOT_DECODE_SECONDS_UNTIL_EXPIRATION |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | return new PasswordPolicyResponseControl(control.isCritical(), warningType, |
| | | warningValue, errorType); |
| | | } catch (final IOException e) { |
| | | StaticUtils.DEBUG_LOG.throwing("PasswordPolicyControl.ResponseDecoder", |
| | | "decode", e); |
| | | StaticUtils.CONTROLS_LOG.debug("", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_PWPOLICYRES_DECODE_ERROR.get(getExceptionMessage(e)); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | |
| | | reader.readEndSequence(); |
| | | } catch (final IOException e) { |
| | | StaticUtils.DEBUG_LOG.throwing("PersistentSearchControl.Decoder", "decode", |
| | | e); |
| | | StaticUtils.CONTROLS_LOG.debug("Unable to read sequence", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_PSEARCH_CANNOT_DECODE_VALUE.get(getExceptionMessage(e)); |
| | |
| | | } |
| | | reader.readEndSequence(); |
| | | } catch (final Exception ae) { |
| | | StaticUtils.DEBUG_LOG.throwing("PostReadRequestControl", "decodeControl", |
| | | ae); |
| | | StaticUtils.CONTROLS_LOG.debug("Unable to read sequence", ae); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_POSTREADREQ_CANNOT_DECODE_VALUE.get(ae.getMessage()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.controls; |
| | |
| | | try { |
| | | searchEntry = LDAPUtils.decodeSearchResultEntry(reader, options); |
| | | } catch (final IOException le) { |
| | | StaticUtils.DEBUG_LOG.throwing("PostReadResponseControl", "decodeControl", |
| | | le); |
| | | StaticUtils.CONTROLS_LOG.debug("Unable to read result entry ", le); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_POSTREADRESP_CANNOT_DECODE_VALUE.get(le.getMessage()); |
| | |
| | | attributes = emptyList(); |
| | | } |
| | | reader.readEndSequence(); |
| | | } catch (final Exception ae) { |
| | | StaticUtils.DEBUG_LOG |
| | | .throwing("PreReadRequestControl", "decodeControl", ae); |
| | | } catch (final Exception ex) { |
| | | StaticUtils.CONTROLS_LOG.debug("Unable to read sequence", ex); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_PREREADREQ_CANNOT_DECODE_VALUE.get(ae.getMessage()); |
| | | throw DecodeException.error(message, ae); |
| | | ERR_PREREADREQ_CANNOT_DECODE_VALUE.get(ex.getMessage()); |
| | | throw DecodeException.error(message, ex); |
| | | } |
| | | |
| | | if (attributes.isEmpty()) { |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.controls; |
| | |
| | | try { |
| | | searchEntry = LDAPUtils.decodeSearchResultEntry(reader, options); |
| | | } catch (final IOException le) { |
| | | StaticUtils.DEBUG_LOG.throwing("PreReadResponseControl", "decodeControl", |
| | | le); |
| | | StaticUtils.CONTROLS_LOG.debug("Unable to read result entry", le); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_PREREADRESP_CANNOT_DECODE_VALUE.get(le.getMessage()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | authorizationDNString = reader.readOctetStringAsString(); |
| | | reader.readEndSequence(); |
| | | } catch (final IOException e) { |
| | | StaticUtils.DEBUG_LOG.throwing("ProxiedAuthV1RequestControl", |
| | | "decodeControl", e); |
| | | StaticUtils.CONTROLS_LOG.debug("Unable to read sequence", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_PROXYAUTH1_CANNOT_DECODE_VALUE.get(getExceptionMessage(e)); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | authorizationID = control.getValue().toString(); |
| | | } |
| | | } catch (final IOException e) { |
| | | StaticUtils.DEBUG_LOG.throwing("ProxiedAuthV2RequestControl", |
| | | "decodeControl", e); |
| | | StaticUtils.CONTROLS_LOG.debug("Unable to read exceptionID", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_PROXYAUTH2_CANNOT_DECODE_VALUE.get(getExceptionMessage(e)); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.CONTROLS_LOG; |
| | | |
| | | import java.io.IOException; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.Validator; |
| | | |
| | | /** |
| | |
| | | try { |
| | | reader.readStartSequence(); |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("PagedResultsControl.Decoder", "decode", e); |
| | | CONTROLS_LOG.debug("Unable to read start sequence", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_LDAP_PAGED_RESULTS_DECODE_SEQUENCE.get(String.valueOf(e)); |
| | |
| | | try { |
| | | size = (int) reader.readInteger(); |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("PagedResultsControl.Decoder", "decode", e); |
| | | CONTROLS_LOG.debug("Unable to read size", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_LDAP_PAGED_RESULTS_DECODE_SIZE.get(String.valueOf(e)); |
| | |
| | | try { |
| | | cookie = reader.readOctetString(); |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("PagedResultsControl.Decoder", "decode", e); |
| | | CONTROLS_LOG.debug("Unable to read cookie", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_LDAP_PAGED_RESULTS_DECODE_COOKIE.get(String.valueOf(e)); |
| | |
| | | try { |
| | | reader.readEndSequence(); |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("PagedResultsControl.Decoder", "decode", e); |
| | | CONTROLS_LOG.debug("Unable to read end sequence", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_LDAP_PAGED_RESULTS_DECODE_SEQUENCE.get(String.valueOf(e)); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | try { |
| | | visibility = reader.readBoolean(); |
| | | } catch (final IOException e) { |
| | | StaticUtils.DEBUG_LOG.throwing("SubentriesRequestControl.Decoder", |
| | | "decode", e); |
| | | StaticUtils.CONTROLS_LOG.debug("Unable to read visbility", e); |
| | | final LocalizableMessage message = |
| | | ERR_SUBENTRIES_CANNOT_DECODE_VALUE.get(getExceptionMessage(e)); |
| | | throw DecodeException.error(message); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_OID_FIRST_COMPONENT_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_ATTRIBUTE_TYPE_NAME; |
| | | import static com.forgerock.opendj.util.StaticUtils.SCHEMA_LOG; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | | /** |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_ATTRTYPE_EMPTY_VALUE1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("AttributeTypeSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | ERR_ATTR_SYNTAX_ATTRTYPE_EXPECTED_OPEN_PARENTHESIS.get(definition, (reader |
| | | .pos() - 1), String.valueOf(c)); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("AttributeTypeSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | WARN_ATTR_SYNTAX_ATTRTYPE_INVALID_ATTRIBUTE_USAGE1.get(definition, |
| | | usageStr); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("AttributeTypeSyntax", "valueIsAcceptable", |
| | | e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } else if (tokenName.matches("^X-[A-Za-z_-]+$")) { |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_ATTRTYPE_ILLEGAL_TOKEN1.get(definition, tokenName); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("AttributeTypeSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_DCR_INVALID1; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_OID_FIRST_COMPONENT_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_DIT_CONTENT_RULE_NAME; |
| | | import static com.forgerock.opendj.util.StaticUtils.SCHEMA_LOG; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | | /** |
| | |
| | | // whitespace. That is illegal. |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_DCR_EMPTY_VALUE1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("DITConentRuleSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | ERR_ATTR_SYNTAX_DCR_EXPECTED_OPEN_PARENTHESIS.get(definition, |
| | | (reader.pos() - 1), String.valueOf(c)); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("DITContentRuleSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_DCR_ILLEGAL_TOKEN1.get(definition, tokenName); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("DITContentRuleSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | // whitespace. That is illegal. |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_DSR_EMPTY_VALUE1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("DITStructureRuleSyntax", "valueIsAcceptable", e); |
| | | StaticUtils.SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | ERR_ATTR_SYNTAX_DSR_EXPECTED_OPEN_PARENTHESIS.get(definition, |
| | | (reader.pos() - 1), String.valueOf(c)); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("DITStructureRuleSyntax", "valueIsAcceptable", e); |
| | | StaticUtils.SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_DSR_ILLEGAL_TOKEN1.get(definition, tokenName); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG |
| | | .throwing("DITStructureRuleSyntax", "valueIsAcceptable", e); |
| | | StaticUtils.SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | if (nameForm == null) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_DSR_NO_NAME_FORM.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("DITStructureRuleSyntax", "valueIsAcceptable", e); |
| | | StaticUtils.SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | return true; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | return true; |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("DoubleMetaphoneApproximateMatchingRule", |
| | | "hasSubstring", e); |
| | | if (StaticUtils.SCHEMA_LOG.isDebugEnabled()) { |
| | | StaticUtils.SCHEMA_LOG.debug("Unable to check that '" + value + "' has substring '" + substring |
| | | + "' at position " + start, e); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | try { |
| | | return ByteString.valueOf(Integer.parseInt(value.toString())); |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("IntegerEqualityMatchingRule", |
| | | "normalizeAttributeValue", e); |
| | | StaticUtils.SCHEMA_LOG.debug("", e); |
| | | |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value.toString()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | } |
| | | }; |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("IntegerFirstComponentEqualityMatchingRule", |
| | | "getAssertion", e); |
| | | StaticUtils.SCHEMA_LOG.debug("", e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_EMR_INTFIRSTCOMP_FIRST_COMPONENT_NOT_INT.get(value.toString()); |
| | |
| | | try { |
| | | return ByteString.valueOf(Integer.parseInt(value.toString())); |
| | | } catch (final Exception e) { |
| | | StaticUtils.DEBUG_LOG.throwing("IntegerOrderingMatchingRule", |
| | | "normalizeAttributeValue", e); |
| | | StaticUtils.SCHEMA_LOG.debug("", e); |
| | | |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value.toString()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_OID_FIRST_COMPONENT_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_LDAP_SYNTAX_NAME; |
| | | import static com.forgerock.opendj.util.StaticUtils.SCHEMA_LOG; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | | /** |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_ATTRSYNTAX_EMPTY_VALUE1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("LDAPSyntaxDescriptionSyntax", "valueIsAcceptable", |
| | | e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | ERR_ATTR_SYNTAX_ATTRSYNTAX_EXPECTED_OPEN_PARENTHESIS.get(definition, |
| | | (reader.pos() - 1), String.valueOf(c)); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("LDAPSyntaxDescriptionSyntax", "valueIsAcceptable", |
| | | e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_ATTRSYNTAX_ILLEGAL_TOKEN1.get(definition, tokenName); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("LDAPSyntaxDescriptionSyntax", |
| | | "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_INVALID_PATTERN.get(oid, |
| | | pattern); |
| | | final DecodeException de = DecodeException.error(message, e); |
| | | StaticUtils.DEBUG_LOG.throwing("LDAPSyntaxDescriptionSyntax", |
| | | "valueIsAcceptable", de); |
| | | SCHEMA_LOG.debug("", de); |
| | | throw de; |
| | | } |
| | | break; |
| | |
| | | WARN_ATTR_SYNTAX_LDAPSYNTAX_ENUM_DUPLICATE_VALUE.get(oid, |
| | | entry, j); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("LDAPSyntaxDescriptionSyntax", |
| | | "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_OID_FIRST_COMPONENT_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_MATCHING_RULE_NAME; |
| | | import static com.forgerock.opendj.util.StaticUtils.SCHEMA_LOG; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | | /** |
| | |
| | | // whitespace. That is illegal. |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_MR_EMPTY_VALUE1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("MatchingRuleSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | ERR_ATTR_SYNTAX_MR_EXPECTED_OPEN_PARENTHESIS.get(definition, |
| | | (reader.pos() - 1), String.valueOf(c)); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("MatchingRuleSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_MR_ILLEGAL_TOKEN1.get(definition, tokenName); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("MatchingRuleSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | if (syntax == null) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_MR_NO_SYNTAX.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("MatchingRuleSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | return true; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_OID_FIRST_COMPONENT_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_MATCHING_RULE_USE_NAME; |
| | | import static com.forgerock.opendj.util.StaticUtils.SCHEMA_LOG; |
| | | |
| | | import java.util.Set; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | | /** |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_MRUSE_EMPTY_VALUE1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("MatchingRuleUseSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | ERR_ATTR_SYNTAX_MRUSE_EXPECTED_OPEN_PARENTHESIS.get(definition, (reader |
| | | .pos() - 1), String.valueOf(c)); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("MatchingRuleUseSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_MRUSE_ILLEGAL_TOKEN1.get(definition, tokenName); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("MatchingRuleUseSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | if (attributes == null || attributes.size() == 0) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_MRUSE_NO_ATTR.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("MatchingRuleUseSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | return true; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_OID_FIRST_COMPONENT_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_NAME_FORM_NAME; |
| | | import static com.forgerock.opendj.util.StaticUtils.SCHEMA_LOG; |
| | | |
| | | import java.util.Set; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | | /** |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_NAME_FORM_EMPTY_VALUE1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("NameFormSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | ERR_ATTR_SYNTAX_NAME_FORM_EXPECTED_OPEN_PARENTHESIS.get(definition, (reader |
| | | .pos() - 1), c); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("NameFormSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_NAME_FORM_ILLEGAL_TOKEN1.get(definition, tokenName); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("NameFormSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_NAME_FORM_NO_STRUCTURAL_CLASS1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("NameFormSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_NAME_FORM_NO_REQUIRED_ATTR.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("NameFormSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | return true; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_OBJECTCLASS_INVALID1; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_OID_FIRST_COMPONENT_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_OBJECTCLASS_NAME; |
| | | import static com.forgerock.opendj.util.StaticUtils.SCHEMA_LOG; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | | /** |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_OBJECTCLASS_EMPTY_VALUE1.get(definition); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("ObjectClassSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | ERR_ATTR_SYNTAX_OBJECTCLASS_EXPECTED_OPEN_PARENTHESIS1.get(definition, |
| | | (reader.pos() - 1), String.valueOf(c)); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("ObjectClassSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_OBJECTCLASS_ILLEGAL_TOKEN1.get(definition, tokenName); |
| | | final DecodeException e = DecodeException.error(message); |
| | | StaticUtils.DEBUG_LOG.throwing("ObjectClassSyntax", "valueIsAcceptable", e); |
| | | SCHEMA_LOG.debug("", e); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS |
| | | * Portions copyright 2012-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_UTC_TIME_CANNOT_PARSE.get(valueString, String.valueOf(e)); |
| | | final DecodeException de = DecodeException.error(message, e); |
| | | StaticUtils.DEBUG_LOG.throwing("UTCTimeSyntax", "decodeUTCTimeValue", de); |
| | | StaticUtils.SCHEMA_LOG.debug("", de); |
| | | throw de; |
| | | } |
| | | } |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.forgerock.opendj.util.CompletedFutureResult; |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class AbstractLoadBalancingAlgorithmTestCase extends SdkTestCase { |
| | |
| | | */ |
| | | @BeforeClass() |
| | | public void disableLogging() { |
| | | StaticUtils.DEBUG_LOG.setLevel(Level.SEVERE); |
| | | setDefaultLogLevel(Level.SEVERE); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @AfterClass() |
| | | public void enableLogging() { |
| | | StaticUtils.DEBUG_LOG.setLevel(Level.INFO); |
| | | setDefaultLogLevel(Level.INFO); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.forgerock.opendj.util.CompletedFutureResult; |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * Tests the {@code ConnectionFactory} classes. |
| | |
| | | */ |
| | | @BeforeClass() |
| | | public void disableLogging() { |
| | | StaticUtils.DEBUG_LOG.setLevel(Level.SEVERE); |
| | | setDefaultLogLevel(Level.SEVERE); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @AfterClass() |
| | | public void enableLogging() { |
| | | StaticUtils.DEBUG_LOG.setLevel(Level.INFO); |
| | | setDefaultLogLevel(Level.INFO); |
| | | } |
| | | |
| | | @DataProvider |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.forgerock.opendj.util.CompletedFutureResult; |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * Tests the connection pool implementation.. |
| | |
| | | */ |
| | | @BeforeClass() |
| | | public void disableLogging() { |
| | | StaticUtils.DEBUG_LOG.setLevel(Level.SEVERE); |
| | | setDefaultLogLevel(Level.SEVERE); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @AfterClass() |
| | | public void enableLogging() { |
| | | StaticUtils.DEBUG_LOG.setLevel(Level.INFO); |
| | | setDefaultLogLevel(Level.INFO); |
| | | } |
| | | |
| | | @AfterMethod(alwaysRun = true) |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.forgerock.opendj.util.AsynchronousFutureResult; |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * Tests the LDAPListener class. |
| | |
| | | */ |
| | | @BeforeClass() |
| | | public void disableLogging() { |
| | | StaticUtils.DEBUG_LOG.setLevel(Level.SEVERE); |
| | | setDefaultLogLevel(Level.SEVERE); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @AfterClass() |
| | | public void enableLogging() { |
| | | StaticUtils.DEBUG_LOG.setLevel(Level.INFO); |
| | | setDefaultLogLevel(Level.INFO); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | import static org.fest.assertions.Fail.*; |
| | | |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | import org.forgerock.testng.ForgeRockTestCase; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * An abstract class that all types unit tests should extend. A type represents |
| | | * the classes found directly under the package org.forgerock.opendj.ldap. |
| | |
| | | void failWasExpected(Class<? extends Throwable> exceptionClass) { |
| | | fail("should throw an exception " + exceptionClass.getSimpleName()); |
| | | } |
| | | |
| | | /** |
| | | * Dynamically change log level using java.util.logging framework. |
| | | * <p> |
| | | * slf4j ERROR maps to java.util.logging SEVERE |
| | | * slf4j INFO maps to java.util.logging INFO |
| | | * slf4j DEBUG maps to java.util.logging FINE |
| | | * slf4j TRACE maps to java.util.logging FINEST |
| | | * |
| | | * @param level logging level to use |
| | | */ |
| | | void setDefaultLogLevel(Level level) { |
| | | Logger.getLogger(StaticUtils.DEFAULT_LOG.getName()).setLevel(level); |
| | | } |
| | | |
| | | } |