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