protected Principal authenticateAndGetPrincipal(final UsernamePasswordCredential credential) throws Throwable {
        val lc = getLoginContext(credential);
        try {
            lc.login();
            val principals = lc.getSubject().getPrincipals();
            LOGGER.debug("JAAS principals extracted from subject are [{}]", principals);
            if (principals != null && !principals.isEmpty()) {
                val secPrincipal = principals.iterator().next();
                LOGGER.debug("JAAS principal detected from subject login context is [{}]", secPrincipal.getName());
                return this.principalFactory.createPrincipal(secPrincipal.getName());
            }
        } finally {
            if (lc != null) {
                lc.logout();
            }
        }
        return null;
    }
Authenticate and get principal principal.

@param credential the credential
@return the principal
@throws GeneralSecurityException the general security exception
core/cas-server-core-authentication-api/src/main/java/org/apereo/cas/authentication/handler/support/jaas/JaasAuthenticationHandler.java