class 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();
    }

}