use of javax.security.auth.x500.X500Principal in project jdk8u_jdk by JetBrains.
the class Synch method main.
public static void main(String[] args) {
Subject subject = new Subject();
final Set principals = subject.getPrincipals();
principals.add(new X500Principal("CN=Alice"));
new Thread() {
public void run() {
Principal last = new X500Principal("CN=Bob");
for (int i = 0; !finished; i++) {
Principal next = new X500Principal("CN=Bob" + i);
principals.add(next);
principals.remove(last);
last = next;
}
}
}.start();
for (int i = 0; i < 1000; i++) {
Subject.doAs(subject, new PrivilegedAction() {
public Object run() {
return Subject.doAs(new Subject(true, Collections.singleton(new X500Principal("CN=Claire")), Collections.EMPTY_SET, Collections.EMPTY_SET), new PrivilegedAction() {
public Object run() {
return null;
}
});
}
});
}
finished = true;
}
use of javax.security.auth.x500.X500Principal in project jdk8u_jdk by JetBrains.
the class NameFormat method main.
public static void main(String[] args) throws Exception {
// tests for leading/trailing escaped/non-escaped spaces
testName("cn=\\ duke ", "RFC1779", "CN=\" duke\"", 1);
testName("cn=\\ duke ", "RFC2253", "CN=\\ duke", 2);
testName("cn=\\ duke ", "CANONICAL", "cn=duke", 3);
testName("cn=\\ duke ", "toString", "CN=\" duke\"", 4);
testName("cn= duke", "RFC1779", "CN=duke", 5);
testName("cn= duke", "RFC2253", "CN=duke", 6);
testName("cn= duke", "CANONICAL", "cn=duke", 7);
testName("cn= duke", "toString", "CN=duke", 8);
testName("cn=duke\\ ", "RFC1779", "CN=\"duke \"", 9);
testName("cn=duke\\ ", "RFC2253", "CN=duke\\ ", 10);
testName("cn=duke\\ ", "CANONICAL", "cn=duke", 11);
testName("cn=duke\\ ", "toString", "CN=\"duke \"", 12);
testName("cn=duke\\ , ou= sun\\ ", "RFC1779", "CN=\"duke \", OU=\"sun \"", 13);
testName("cn=duke\\ , ou= sun\\ ", "RFC2253", "CN=duke\\ ,OU=sun\\ ", 14);
testName("cn=duke\\ , ou= sun\\ ", "CANONICAL", "cn=duke,ou=sun", 15);
testName("cn=duke\\ , ou= sun\\ ", "toString", "CN=\"duke \", OU=\"sun \"", 16);
// tests for trailing escaped backslash
testName("cn=duke \\\\\\,test,O=java", "CANONICAL", "cn=duke \\\\\\,test,o=java", 17);
testName("cn=duke\\\\, o=java", "CANONICAL", "cn=duke\\\\,o=java", 18);
X500Principal p = new X500Principal("cn=duke \\\\\\,test,o=java");
X500Principal p2 = new X500Principal(p.getName("CANONICAL"));
if (p.getName("CANONICAL").equals(p2.getName("CANONICAL"))) {
System.out.println("test 19 succeeded");
} else {
throw new SecurityException("test 19 failed\n" + p.getName("CANONICAL") + " not equal to " + p2.getName("CANONICAL"));
}
try {
p = new X500Principal("cn=duke \\\\,test,o=java");
throw new SecurityException("test 19.5 failed:\n" + p.getName("CANONICAL"));
} catch (IllegalArgumentException iae) {
System.out.println("test 19.5 succeeded");
iae.printStackTrace();
}
// tests for wrong exception thrown
try {
byte[] encoding = { (byte) 0x17, (byte) 0x80, (byte) 0x70, (byte) 0x41, (byte) 0x6b, (byte) 0x15, (byte) 0xdc, (byte) 0x84, (byte) 0xef, (byte) 0x58, (byte) 0xac, (byte) 0x88, (byte) 0xae, (byte) 0xb0, (byte) 0x19, (byte) 0x7c, (byte) 0x6f, (byte) 0xea, (byte) 0xf5, (byte) 0x56 };
p = new X500Principal(new java.io.DataInputStream(new java.io.ByteArrayInputStream(encoding)));
} catch (IllegalArgumentException iae) {
System.out.println("test 20 succeeded");
iae.printStackTrace();
} catch (Exception e) {
System.out.println("test 20 failed");
throw e;
}
// tests for escaping '+' in canonical form
testName("cn=se\\+an, ou= sun\\ ", "CANONICAL", "cn=se\\+an,ou=sun", 21);
// tests for embedded hex pairs
testName("CN=Before\\0dAfter,DC=example,DC=net", "toString", "CN=Before\\0DAfter, DC=example, DC=net", 22);
testName("CN=Before\\0dAfter,DC=example,DC=net", "RFC1779", "CN=Before\\0DAfter, " + "OID.0.9.2342.19200300.100.1.25=example, " + "OID.0.9.2342.19200300.100.1.25=net", 23);
testName("CN=Before\\0dAfter,DC=example,DC=net", "RFC2253", "CN=Before\\0DAfter,DC=example,DC=net", 24);
testName("CN=Before\\0dAfter,DC=example,DC=net", "CANONICAL", "cn=before\\0dafter,dc=#16076578616d706c65,dc=#16036e6574", 25);
testName("CN=Lu\\C4\\8Di\\C4\\87", "toString", "CN=Lu\\C4\\8Di\\C4\\87", 26);
testName("CN=Lu\\C4\\8Di\\C4\\87", "RFC1779", "CN=Lu\\C4\\8Di\\C4\\87", 27);
testName("CN=Lu\\C4\\8Di\\C4\\87", "RFC2253", "CN=Lu\\C4\\8Di\\C4\\87", 28);
testName("CN=Lu\\C4\\8Di\\C4\\87", "CANONICAL", "cn=lu\\c4\\8di\\c4\\87", 29);
try {
p = new X500Principal("cn=\\gg");
throw new SecurityException("test 30 failed");
} catch (IllegalArgumentException iae) {
System.out.println("test 30 succeeded");
}
try {
p = new X500Principal("cn=duke \\test");
throw new SecurityException("test 31 failed");
} catch (IllegalArgumentException iae) {
System.out.println("test 31 succeeded");
}
try {
p = new X500Principal("cn=duke \\?test");
throw new SecurityException("test 32 failed");
} catch (IllegalArgumentException iae) {
System.out.println("test 32 succeeded");
}
try {
// invalid non-escaped leading space
sun.security.x509.X500Name name = new sun.security.x509.X500Name("cn= duke test", "RFC2253");
throw new SecurityException("test 33 failed");
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
System.out.println("test 33 succeeded");
}
try {
// invalid non-escaped trailing space
sun.security.x509.X500Name name = new sun.security.x509.X500Name("cn=duke test ", "RFC2253");
throw new SecurityException("test 34 failed");
} catch (java.io.IOException ioe) {
System.out.println("test 34 succeeded");
}
testName("CN=SPECIAL CHARS,OU=\\#\\\"\\,\\<\\>\\+\\;,O=foo, " + "L=bar, ST=baz, C=JP", "RFC1779", "CN=SPECIAL CHARS, OU=\"#\\\",<>+;\", O=foo, L=bar, " + "ST=baz, C=JP", 35);
// test that double-quoted string is not escaped in RFC 1779 format
testName("CN=\"\\\"Duke\\\"\"", "RFC1779", "CN=\"Duke\"", 36);
}
use of javax.security.auth.x500.X500Principal in project jdk8u_jdk by JetBrains.
the class OIDMap method main.
public static void main(String[] args) throws Exception {
X500Principal p = null;
Map<String, String> m1, m2 = null;
// test null oidMap
p = new X500Principal("CN=user");
try {
p.getName("RFC2253", null);
throw new Exception("expected NullPointerException for null oidMap");
} catch (NullPointerException npe) {
}
// test improperly specified keyword
m1 = Collections.singletonMap("FOO", "1.2.3");
m2 = Collections.singletonMap("1.2.3", "*&$");
p = new X500Principal("FOO=user", m1);
try {
p.getName("RFC2253", m2);
throw new Exception("expected IllegalArgumentException for bad keyword");
} catch (IllegalArgumentException iae) {
}
try {
m2 = Collections.singletonMap("1.2.3", "1abc");
p.getName("RFC2253", m2);
throw new Exception("expected IllegalArgumentException for bad keyword");
} catch (IllegalArgumentException iae) {
}
try {
m2 = Collections.singletonMap("1.2.3", "");
p.getName("RFC2253", m2);
throw new Exception("expected IllegalArgumentException for bad keyword");
} catch (IllegalArgumentException iae) {
}
try {
m2 = Collections.singletonMap("1.2.3", "a1_b)a");
p.getName("RFC2253", m2);
throw new Exception("expected IllegalArgumentException for bad keyword");
} catch (IllegalArgumentException iae) {
}
// ignore improperly specified OID
m1 = Collections.singletonMap("*&D", "FOO");
p = new X500Principal("CN=user");
p.getName("RFC2253", m1);
// override builtin OIDs
m1 = Collections.singletonMap("2.5.4.3", "FOO");
p = new X500Principal("CN=user");
if (!p.getName("RFC2253", m1).startsWith("FOO")) {
throw new Exception("mapping did not override builtin OID");
}
// disallow CANONICAL format
try {
p.getName("CANONICAL", m1);
throw new Exception("expected IllegalArgumentException for CANONICAL format");
} catch (IllegalArgumentException iae) {
}
// disallow invalid format
try {
p.getName("YABBADABBADOO", m1);
throw new Exception("expected IllegalArgumentException for invalid format");
} catch (IllegalArgumentException iae) {
}
// map OIDs
m1 = Collections.singletonMap("1.1", "BAR");
p = new X500Principal("1.1=sean");
System.out.println(p.getName("RFC1779", m1));
System.out.println(p.getName("RFC2253", m1));
// FIXME: 1779 format is broken!
if (!p.getName("RFC1779", m1).startsWith("BAR")) {
throw new Exception("mapping did not override builtin OID");
}
}
use of javax.security.auth.x500.X500Principal in project jdk8u_jdk by JetBrains.
the class EscapedChars method main.
public static void main(String[] args) throws Exception {
String dn = "CN=\\#user";
X500Principal xp = new X500Principal(dn);
System.out.println("RFC2253 DN is " + xp.getName(X500Principal.RFC2253));
System.out.println("CANONICAL DN is is " + xp.getName(X500Principal.CANONICAL));
String dn1 = xp.getName(X500Principal.CANONICAL);
if (!(dn1.substring(3, 5).equals("\\#")))
throw new Exception("Leading # not escaped");
X500Principal xp1 = new X500Principal(dn1);
System.out.println("CANONICAL DN is " + xp1.getName(X500Principal.CANONICAL));
}
use of javax.security.auth.x500.X500Principal in project jdk8u_jdk by JetBrains.
the class InvalidConstructorInput method main.
public static void main(String[] args) {
try {
byte[] bytes = { 'a' };
X500Principal p = new X500Principal(bytes);
throw new SecurityException("test failed: #1");
} catch (RuntimeException re) {
}
try {
String dir = System.getProperty("test.src");
if (dir == null)
dir = ".";
FileInputStream fis = new FileInputStream(dir + "/InvalidConstructorInput.java");
X500Principal p = new X500Principal(fis);
throw new SecurityException("test failed: #2.1");
} catch (FileNotFoundException fnfe) {
throw new SecurityException("test failed: #2.2");
} catch (RuntimeException re) {
}
System.out.println("Test passed");
}
Aggregations