Java Code Examples for javax.naming.ldap.Rdn#escapeValue()

The following examples show how to use javax.naming.ldap.Rdn#escapeValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LDAPTest.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Test
public void testRdnEscapeValue() {
    String before = "Jive Software, Inc";
    String after = "Jive Software\\, Inc";
    String converted = Rdn.escapeValue(before);
    assertTrue("Conversion result "+before+" to "+converted, converted.equals(after));
    
    before = "Test.User; (+1)";
    after = "Test.User\\; (\\+1)";
    converted = Rdn.escapeValue(before);
    assertTrue("Conversion result "+before+" to "+converted, converted.equals(after));
    
    before = "Wildcard *";
    after = "Wildcard *";
    converted = Rdn.escapeValue(before);
    assertTrue("Conversion result "+before+" to "+converted, converted.equals(after));
    
    before = "Group/Section";
    after = "Group/Section";
    converted = Rdn.escapeValue(before);
    assertTrue("Conversion result "+before+" to "+converted, converted.equals(after));
}
 
Example 2
Source File: EscapeUnescapeTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 3
Source File: EscapeUnescapeTests.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 4
Source File: EscapeUnescapeTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 5
Source File: EscapeUnescapeTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 6
Source File: EscapeUnescapeTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 7
Source File: EscapeUnescapeTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 8
Source File: EscapeUnescapeTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 9
Source File: EscapeUnescapeTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 10
Source File: EscapeUnescapeTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void printEscapedVal(Object[] values) {
    String escVal;
    for (int i = 0; i < values.length; i++) {
        escVal = Rdn.escapeValue(values[i]);
        System.out.println("Orig val: " + values[i] +
                            "       Escaped val: " + escVal);
    }
}
 
Example 11
Source File: EscapeUnescapeTests.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }
 
Example 12
Source File: EscapeUnescapeTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }
 
Example 13
Source File: DSSASN1Utils.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static String getUtf8String(final X500Principal x500Principal) {

		final byte[] encoded = x500Principal.getEncoded();
		final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded);
		final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray();
		final StringBuilder stringBuilder = new StringBuilder();
		/**
		 * RFC 4514 LDAP: Distinguished Names
		 * 2.1. Converting the RDNSequence
		 *
		 * If the RDNSequence is an empty sequence, the result is the empty or
		 * zero-length string.
		 *
		 * Otherwise, the output consists of the string encodings of each
		 * RelativeDistinguishedName in the RDNSequence (according to Section
		 * 2.2), starting with the last element of the sequence and moving
		 * backwards toward the first.
		 * ...
		 */
		for (int ii = asn1Encodables.length - 1; ii >= 0; ii--) {

			final ASN1Encodable asn1Encodable = asn1Encodables[ii];

			final DLSet dlSet = (DLSet) asn1Encodable;
			for (int jj = 0; jj < dlSet.size(); jj++) {

				final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(jj);
				if (dlSequence.size() != 2) {

					throw new DSSException("The DLSequence must contains exactly 2 elements.");
				}
				final ASN1Encodable attributeType = dlSequence.getObjectAt(0);
				final ASN1Encodable attributeValue = dlSequence.getObjectAt(1);
				String string = getString(attributeValue);

				/**
				 * RFC 4514 LDAP: Distinguished Names
				 * ...
				 * Other characters may be escaped.
				 *
				 * Each octet of the character to be escaped is replaced by a backslash
				 * and two hex digits, which form a single octet in the code of the
				 * character. Alternatively, if and only if the character to be escaped
				 * is one of
				 *
				 * ' ', '"', '#', '+', ',', ';', '<', '=', '>', or '\'
				 * (U+0020, U+0022, U+0023, U+002B, U+002C, U+003B,
				 * U+003C, U+003D, U+003E, U+005C, respectively)
				 *
				 * it can be prefixed by a backslash ('\' U+005C).
				 */
				string = Rdn.escapeValue(string);
				if (stringBuilder.length() != 0) {
					stringBuilder.append(',');
				}
				stringBuilder.append(attributeType).append('=').append(string);
			}
		}
		return stringBuilder.toString();
	}
 
Example 14
Source File: EscapeUnescapeTests.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }
 
Example 15
Source File: EscapeUnescapeTests.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }
 
Example 16
Source File: EscapeUnescapeTests.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }
 
Example 17
Source File: EscapeUnescapeTests.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }
 
Example 18
Source File: EscapeUnescapeTests.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }
 
Example 19
Source File: EscapeUnescapeTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }
 
Example 20
Source File: EscapeUnescapeTests.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        /**
         * Unescape tests
         */
        String[] invalids = new String[] {"\\", "\\\\\\" };

        String[] valids = new String[] {"\\\\", "\\\\\\\\"};

        String val;
        Object unescVal = null;
        System.out.println("##### Unescape value tests #####");

        for (int i = 0; i < valids.length; i++) {
            unescVal = Rdn.unescapeValue(valids[i]);
            System.out.println("Orig val: " + valids[i] +
                                "       Unescaped val: " + unescVal);
        }

        boolean isExcepThrown = false;
        for (int i = 0; i < invalids.length; i++) {
            val = "Juicy" + invalids[i] + "Fruit";
            try {
                unescVal = Rdn.unescapeValue(val);
            } catch (IllegalArgumentException e) {
                System.out.println("Caught the right exception: " + e);
                isExcepThrown = true;
            }
            if (!isExcepThrown) {
                throw new Exception(
                        "Unescaped successfully an invalid string "
                        + val + " as Rdn: " + unescVal);
            }
            isExcepThrown = false;
        }

        /**
         * Escape tests
         */
        String[] values = new String[] {";", "<<<", "###", "=="};
        System.out.println("##### Escape value tests #####");
        printEscapedVal(values);

        // leading space, trailing space
        values = new String[] {"  leading space", "trailing space  "};
        printEscapedVal(values);

        // binary values
        byte[] bytes = new byte[] {1, 2, 3, 4};
        String escVal = Rdn.escapeValue(bytes);
        System.out.println("Orig val: " + bytes +
                                "       Escaped val: " + escVal);
    }