@Test public void testGetPrincipalNoPrincipals() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { Subject.doAs(new Subject(), new PrivilegedAction<Void>() { @Override public Void run() { JaasUtils.getPrincipal(Principal.class); return null; } }); }); assertThat(e.getMessage()).isEqualTo("Incorrect number of principals of type " + Principal.class.getCanonicalName() + " on subject: " + Integer.toString(0)); }
public static <P extends Principal> P getPrincipal(final Class<P> principalClass) { if (principalClass == null) throw new IllegalArgumentException("Principal class cannot be null."); final Set<P> principals = getCurrentSubject().getPrincipals(principalClass); if (principals.size() != 1) throw new IllegalArgumentException("Incorrect number of principals of type " + principalClass.getCanonicalName() + " on subject: " + Integer.toString(principals.size())); return principals.iterator().next(); }
JaasUtils { public static <P extends Principal> P getPrincipal(final Class<P> principalClass) { if (principalClass == null) throw new IllegalArgumentException("Principal class cannot be null."); final Set<P> principals = getCurrentSubject().getPrincipals(principalClass); if (principals.size() != 1) throw new IllegalArgumentException("Incorrect number of principals of type " + principalClass.getCanonicalName() + " on subject: " + Integer.toString(principals.size())); return principals.iterator().next(); } }
JaasUtils { public static <P extends Principal> P getPrincipal(final Class<P> principalClass) { if (principalClass == null) throw new IllegalArgumentException("Principal class cannot be null."); final Set<P> principals = getCurrentSubject().getPrincipals(principalClass); if (principals.size() != 1) throw new IllegalArgumentException("Incorrect number of principals of type " + principalClass.getCanonicalName() + " on subject: " + Integer.toString(principals.size())); return principals.iterator().next(); }  }
JaasUtils { public static <P extends Principal> P getPrincipal(final Class<P> principalClass) { if (principalClass == null) throw new IllegalArgumentException("Principal class cannot be null."); final Set<P> principals = getCurrentSubject().getPrincipals(principalClass); if (principals.size() != 1) throw new IllegalArgumentException("Incorrect number of principals of type " + principalClass.getCanonicalName() + " on subject: " + Integer.toString(principals.size())); return principals.iterator().next(); }  static Subject getCurrentSubject(); static P getPrincipal(final Class<P> principalClass); static T getPrivateCredential(final Class<T> credentialClass); static boolean hasPrincipal(final Class<? extends Principal> principalClass); }
JaasUtils { public static <P extends Principal> P getPrincipal(final Class<P> principalClass) { if (principalClass == null) throw new IllegalArgumentException("Principal class cannot be null."); final Set<P> principals = getCurrentSubject().getPrincipals(principalClass); if (principals.size() != 1) throw new IllegalArgumentException("Incorrect number of principals of type " + principalClass.getCanonicalName() + " on subject: " + Integer.toString(principals.size())); return principals.iterator().next(); }  static Subject getCurrentSubject(); static P getPrincipal(final Class<P> principalClass); static T getPrivateCredential(final Class<T> credentialClass); static boolean hasPrincipal(final Class<? extends Principal> principalClass);  }