private Authentication buildAuthentication(final PrincipalElectionStrategy principalElectionStrategy) { if (isEmpty()) { LOGGER.warn("No authentication event has been recorded; CAS cannot finalize the authentication result"); return null; } val authenticationAttributes = new HashMap<String, Object>(); val principalAttributes = new HashMap<String, Object>(); val authenticationBuilder = DefaultAuthenticationBuilder.newInstance(); buildAuthenticationHistory(this.authentications, authenticationAttributes, principalAttributes, authenticationBuilder); val primaryPrincipal = getPrimaryPrincipal(principalElectionStrategy, this.authentications, principalAttributes); authenticationBuilder.setPrincipal(primaryPrincipal); LOGGER.debug("Determined primary authentication principal to be [{}]", primaryPrincipal); authenticationBuilder.setAttributes(authenticationAttributes); LOGGER.trace("Collected authentication attributes for this result are [{}]", authenticationAttributes); authenticationBuilder.setAuthenticationDate(ZonedDateTime.now()); val auth = authenticationBuilder.build(); LOGGER.trace("Authentication result commenced at [{}]", auth.getAuthenticationDate()); return auth; }