/** * Returns a single attribute value for the supplied oid. See {@link #getAttributeValues(String)}. * * @param oid to match * * @return attribute value */ public AttributeValueAssertion.Value getAttributeValue(final String oid) { final AttributeValueAssertion.Value[] values = getAttributeValues(oid); if (values == null || values.length == 0) { return null; } return values[0]; }
@Override public String toString() { return String.format( "[%s@%d::attributeValueAssertions=%s]", getClass().getName(), hashCode(), Arrays.toString(attributeValueAssertions)); } }
@Override public byte[] encode() { return rdn.encode(); } });
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { rdns.add(new RDN(AttributeValueAssertion.decode(encoded.slice()))); encoded.position(encoded.limit()); } });
/** * Converts bytes in the buffer to a DN by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the DN and the * limit is set beyond the last byte of DN data. * * @return decoded bytes as a DN */ public static DN decode(final ByteBuffer encoded) { return new DN(RDN.decode(encoded)); }
/** * Returns the CNs from the supplied certificate. * * @param cert to get CNs from * * @return CNs */ private String[] getCNs(final X509Certificate cert) { final List<String> names = new ArrayList<>(); final byte[] encodedDn = cert.getSubjectX500Principal().getEncoded(); if (encodedDn != null && encodedDn.length > 0) { final DN dn = DN.decode(ByteBuffer.wrap(encodedDn)); for (RDN rdn : dn.getRDNs()) { // for multi value RDNs the first value is used final String value = rdn.getAttributeValue("2.5.4.3", new StringValueTranscoder()); if (value != null) { names.add(value); } } } return names.toArray(new String[names.size()]); }
/** * Converts bytes in the buffer to RDNs by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the RDN and the * limit is set beyond the last byte of the RDN. * * @return decoded bytes as RDNs */ public static RDN[] decode(final ByteBuffer encoded) { final List<RDN> rdns = new ArrayList<>(); final DERParser parser = new DERParser(); parser.registerHandler( "/SEQ/SET", (parser1, encoded1) -> { rdns.add(new RDN(AttributeValueAssertion.decode(encoded1.slice()))); encoded1.position(encoded1.limit()); }); parser.parse(encoded); return rdns.toArray(new RDN[rdns.size()]); }
/** * Converts bytes in the buffer to a DN by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the DN and the * limit is set beyond the last byte of DN data. * * @return decoded bytes as a DN */ public static DN decode(final ByteBuffer encoded) { return new DN(RDN.decode(encoded)); }
/** * Returns the CNs from the supplied certificate. * * @param cert to get CNs from * * @return CNs */ private String[] getCNs(final X509Certificate cert) { final List<String> names = new ArrayList<>(); final byte[] encodedDn = cert.getSubjectX500Principal().getEncoded(); if (encodedDn != null && encodedDn.length > 0) { final DN dn = DN.decode(ByteBuffer.wrap(encodedDn)); for (RDN rdn : dn.getRDNs()) { // for multi value RDNs the first value is used final String value = rdn.getAttributeValue("2.5.4.3", new StringValueTranscoder()); if (value != null) { names.add(value); } } } return names.toArray(new String[names.size()]); }
/** * Converts bytes in the buffer to RDNs by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the RDN and the * limit is set beyond the last byte of the RDN. * * @return decoded bytes as RDNs */ public static RDN[] decode(final ByteBuffer encoded) { final List<RDN> rdns = new ArrayList<>(); final DERParser parser = new DERParser(); parser.registerHandler( "/SEQ/SET", (parser1, encoded1) -> { rdns.add(new RDN(AttributeValueAssertion.decode(encoded1.slice()))); encoded1.position(encoded1.limit()); }); parser.parse(encoded); return rdns.toArray(new RDN[rdns.size()]); }
/** * Returns a single attribute value for the supplied oid. See {@link #getAttributeValues(String, ValueTranscoder)}. * * @param <T> type of value * @param oid to match * @param transcoder to decode the binary value * * @return decoded attribute value */ public <T> T getAttributeValue(final String oid, final ValueTranscoder<T> transcoder) { final T[] values = getAttributeValues(oid, transcoder); if (values == null || values.length == 0) { return null; } return values[0]; }
@Override public String toString() { return String.format( "[%s@%d::attributeValueAssertions=%s]", getClass().getName(), hashCode(), Arrays.toString(attributeValueAssertions)); } }
/** * Converts bytes in the buffer to a DN by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the DN and the * limit is set beyond the last byte of DN data. * * @return decoded bytes as a DN */ public static DN decode(final ByteBuffer encoded) { return new DN(RDN.decode(encoded)); }
/** * Returns the CNs from the supplied certificate. * * @param cert to get CNs from * * @return CNs */ private String[] getCNs(final X509Certificate cert) { final List<String> names = new ArrayList<>(); final byte[] encodedDn = cert.getSubjectX500Principal().getEncoded(); if (encodedDn != null && encodedDn.length > 0) { final DN dn = DN.decode(ByteBuffer.wrap(encodedDn)); for (RDN rdn : dn.getRDNs()) { // for multi value RDNs the first value is used final String value = rdn.getAttributeValue("2.5.4.3", new StringValueTranscoder()); if (value != null) { names.add(value); } } } return names.toArray(new String[names.size()]); }
}, new DN( new RDN( new AttributeValueAssertion( "2.5.4.3", new AttributeValueAssertion.Value(UniversalDERTag.PRINTSTR, "www.ldaptive.org".getBytes("UTF-8")))), new RDN( new AttributeValueAssertion( "0.9.2342.19200300.100.1.25", new AttributeValueAssertion.Value(UniversalDERTag.IA5STR, "ldaptive".getBytes("UTF-8")))), new RDN( new AttributeValueAssertion( "0.9.2342.19200300.100.1.25", }, new DN( new RDN( new AttributeValueAssertion( "0.9.2342.19200300.100.1.1", "2.5.4.3", new AttributeValueAssertion.Value(UniversalDERTag.PRINTSTR, "www.ldaptive.org".getBytes("UTF-8")))), new RDN( new AttributeValueAssertion( "0.9.2342.19200300.100.1.25", new AttributeValueAssertion.Value(UniversalDERTag.IA5STR, "ldaptive".getBytes("UTF-8")))), new RDN( new AttributeValueAssertion( "0.9.2342.19200300.100.1.25",
/** * Returns a single attribute value for the supplied oid. See {@link #getAttributeValues(String)}. * * @param oid to match * * @return attribute value */ public AttributeValueAssertion.Value getAttributeValue(final String oid) { final AttributeValueAssertion.Value[] values = getAttributeValues(oid); if (values == null || values.length == 0) { return null; } return values[0]; }
@Override public String toString() { return String.format( "[%s@%d::attributeValueAssertions=%s]", getClass().getName(), hashCode(), Arrays.toString(attributeValueAssertions)); } }
/** * Returns a single attribute value for the supplied oid. See {@link #getAttributeValues(String)}. * * @param oid to match * * @return attribute value */ public AttributeValueAssertion.Value getAttributeValue(final String oid) { final AttributeValueAssertion.Value[] values = getAttributeValues(oid); if (values == null || values.length == 0) { return null; } return values[0]; }
/** * Returns a single attribute value for the supplied oid. See {@link #getAttributeValues(String, ValueTranscoder)}. * * @param <T> type of value * @param oid to match * @param transcoder to decode the binary value * * @return decoded attribute value */ public <T> T getAttributeValue(final String oid, final ValueTranscoder<T> transcoder) { final T[] values = getAttributeValues(oid, transcoder); if (values == null || values.length == 0) { return null; } return values[0]; }
/** * Returns a single attribute value for the supplied oid. See {@link #getAttributeValues(String, ValueTranscoder)}. * * @param <T> type of value * @param oid to match * @param transcoder to decode the binary value * * @return decoded attribute value */ public <T> T getAttributeValue(final String oid, final ValueTranscoder<T> transcoder) { final T[] values = getAttributeValues(oid, transcoder); if (values == null || values.length == 0) { return null; } return values[0]; }