use of java.security.Principal in project jdk8u_jdk by JetBrains.
the class SimpleStandard method checkSubject.
/*
* ---------------
* PRIVATE METHODS
* ---------------
*/
/**
* Check that the principal contained in the Subject is of
* type JMXPrincipal and refers to the principalName identity.
*/
private void checkSubject(String op) {
AccessControlContext acc = AccessController.getContext();
Subject subject = Subject.getSubject(acc);
Set principals = subject.getPrincipals();
Principal principal = (Principal) principals.iterator().next();
if (!(principal instanceof JMXPrincipal))
throw new SecurityException(op + ": Authenticated subject contains " + "invalid principal type = " + principal.getClass().getName());
String identity = principal.getName();
if (!identity.equals(principalName))
throw new SecurityException(op + ": Authenticated subject contains " + "invalid principal name = " + identity);
}
use of java.security.Principal in project jdk8u_jdk by JetBrains.
the class Implies method main.
public static void main(String[] args) throws Exception {
X500Principal duke = new X500Principal("CN=Duke");
// should not throw NullPointerException
testImplies(duke, (Subject) null, false);
Set<Principal> principals = new HashSet<>();
principals.add(duke);
testImplies(duke, principals, true);
X500Principal tux = new X500Principal("CN=Tux");
principals.add(tux);
testImplies(duke, principals, true);
principals.add(new KerberosPrincipal("duke@java.com"));
testImplies(duke, principals, true);
principals.clear();
principals.add(tux);
testImplies(duke, principals, false);
System.out.println("test passed");
}
use of java.security.Principal 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 java.security.Principal in project jdk8u_jdk by JetBrains.
the class TestJMXAuthenticator method authenticate.
public Subject authenticate(Object credentials) {
String credentials_username = "";
String credentials_password = "";
Principal aPrincipal = null;
credentials_username = ((String[]) credentials)[0];
credentials_password = ((String[]) credentials)[1];
String authenticated_username = System.getProperty("susername");
String authenticated_password = System.getProperty("spassword");
String principal = System.getProperty("principal");
System.out.println("TestJMXAuthenticator::authenticate: Start");
System.out.println("TestJMXAuthenticator::authenticate: credentials username = " + credentials_username);
System.out.println("TestJMXAuthenticator::authenticate: credentials password = " + credentials_password);
System.out.println("TestJMXAuthenticator::authenticate: authenticated username = " + authenticated_username);
System.out.println("TestJMXAuthenticator::authenticate: authenticated password = " + authenticated_password);
System.out.println("TestJMXAuthenticator::authenticate: principal used for " + "authorization = " + principal);
if (credentials_username.equals(authenticated_username) && credentials_password.equals(authenticated_password)) {
System.out.println("TestJMXAuthenticator::authenticate: " + "Authenticator should succeed");
} else {
System.out.println("TestJMXAuthenticator::authenticate: " + "Authenticator should reject");
throw new SecurityException("TestJMXAuthenticator throws EXCEPTION");
}
// At this point, authentication has succeeded
// (no SecurityException thrown).
//
// If no authorization is required, the returned subject (empty or not)
// is useless.
// Otherwise, the returned subject must define a principal
// and authorization will be performed against this principal.
//
// Note that this custom JMXAuthenticator is used for test purpose and
// the username used to perform authentication may be different from the
// username used to perform authorization.
//
Subject subject = new Subject();
if (principal != null) {
System.out.println("TestJMXAuthenticator::authenticate: " + "Add " + principal + " principal to the returned subject");
subject.getPrincipals().add(new JMXPrincipal(principal));
}
return subject;
}
use of java.security.Principal in project opennms by OpenNMS.
the class OpenNMSLoginModule method createPrincipals.
public Set<Principal> createPrincipals(final GrantedAuthority authority) {
final String role = authority.getAuthority().replaceFirst("^[Rr][Oo][Ll][Ee]_", "");
final Set<Principal> principals = new HashSet<Principal>();
principals.add(new RolePrincipal(role));
principals.add(new RolePrincipal(role.toLowerCase()));
principals.add(new RolePrincipal(authority.getAuthority()));
LOG.debug("created principals from authority {}: {}", authority, principals);
return principals;
}
Aggregations