private Principal getPrincipalUser ( String className ) throws LoginException { // load the principal class ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( loader == null ) { loader = ClassLoader . getSystemClassLoader ( ) ; } Class < ? extends Principal > clazz ; try { // Declare a temp variable so that we can suppress warnings locally @ SuppressWarnings ( "unchecked" ) Class < ? extends Principal > tmpClazz = ( Class < ? extends Principal > ) loader . loadClass ( className ) ; clazz = tmpClazz ; } catch ( ClassNotFoundException e ) { throw new LoginException ( "Unable to find JAAS principal class:" + e . getMessage ( ) ) ; } // find corresponding user based on the principal Set < ? extends Principal > userSet = mSubject . getPrincipals ( clazz ) ; if ( ! userSet . isEmpty ( ) ) { if ( userSet . size ( ) == 1 ) { return userSet . iterator ( ) . next ( ) ; } throw new LoginException ( "More than one instance of Principal " + className + " is found" ) ; } return null ; }
Gets a principal user .