@Test public void testGetPrivateCredential() { final Object credential = new Object(); final Subject subject = new Subject(); subject.getPrivateCredentials().add(credential); assertThat(Subject.doAs(subject, new PrivilegedAction<Object>() { @Override public Object run() { return JaasUtils.getPrivateCredential(credential.getClass()); } })).isEqualTo(credential); }
public static <T> T getPrivateCredential(final Class<T> credentialClass) { if (credentialClass == null) throw new IllegalArgumentException("Credential class cannot be null."); final Set<T> credentials = getCurrentSubject().getPrivateCredentials(credentialClass); if (credentials.size() != 1) throw new IllegalArgumentException("Incorrect number of private credentials of type " + credentialClass.getCanonicalName() + " on subject : " + Integer.toString(credentials.size())); return credentials.iterator().next(); }
JaasUtils { public static <T> T getPrivateCredential(final Class<T> credentialClass) { if (credentialClass == null) throw new IllegalArgumentException("Credential class cannot be null."); final Set<T> credentials = getCurrentSubject().getPrivateCredentials(credentialClass); if (credentials.size() != 1) throw new IllegalArgumentException("Incorrect number of private credentials of type " + credentialClass.getCanonicalName() + " on subject : " + Integer.toString(credentials.size())); return credentials.iterator().next(); } }
JaasUtils { public static <T> T getPrivateCredential(final Class<T> credentialClass) { if (credentialClass == null) throw new IllegalArgumentException("Credential class cannot be null."); final Set<T> credentials = getCurrentSubject().getPrivateCredentials(credentialClass); if (credentials.size() != 1) throw new IllegalArgumentException("Incorrect number of private credentials of type " + credentialClass.getCanonicalName() + " on subject : " + Integer.toString(credentials.size())); return credentials.iterator().next(); }  }
JaasUtils { public static <T> T getPrivateCredential(final Class<T> credentialClass) { if (credentialClass == null) throw new IllegalArgumentException("Credential class cannot be null."); final Set<T> credentials = getCurrentSubject().getPrivateCredentials(credentialClass); if (credentials.size() != 1) throw new IllegalArgumentException("Incorrect number of private credentials of type " + credentialClass.getCanonicalName() + " on subject : " + Integer.toString(credentials.size())); return credentials.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 <T> T getPrivateCredential(final Class<T> credentialClass) { if (credentialClass == null) throw new IllegalArgumentException("Credential class cannot be null."); final Set<T> credentials = getCurrentSubject().getPrivateCredentials(credentialClass); if (credentials.size() != 1) throw new IllegalArgumentException("Incorrect number of private credentials of type " + credentialClass.getCanonicalName() + " on subject : " + Integer.toString(credentials.size())); return credentials.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);  }