@Test public void deserializeCasAuthenticationTest() throws IOException, JSONException { CasAuthenticationToken token = mapper.readValue(CAS_TOKEN_JSON, CasAuthenticationToken.class); assertThat(token).isNotNull(); assertThat(token.getPrincipal()).isNotNull().isInstanceOf(User.class); assertThat(((User) token.getPrincipal()).getUsername()).isEqualTo("admin"); assertThat(((User) token.getPrincipal()).getPassword()).isEqualTo("1234"); assertThat(token.getUserDetails()).isNotNull().isInstanceOf(User.class); assertThat(token.getAssertion()).isNotNull().isInstanceOf(AssertionImpl.class); assertThat(token.getKeyHash()).isEqualTo(KEY.hashCode()); assertThat(token.getUserDetails().getAuthorities()) .extracting(GrantedAuthority::getAuthority) .containsOnly("ROLE_USER"); assertThat(token.getAssertion().getAuthenticationDate()).isEqualTo(START_DATE); assertThat(token.getAssertion().getValidFromDate()).isEqualTo(START_DATE); assertThat(token.getAssertion().getValidUntilDate()).isEqualTo(END_DATE); assertThat(token.getAssertion().getPrincipal().getName()).isEqualTo("assertName"); assertThat(token.getAssertion().getAttributes()).hasSize(0); }
/** * Removes expired entries from the assertion cache. */ private void cleanCache() { logger.debug("Cleaning assertion cache of size {}", ASSERTION_CACHE.size()); final Iterator<Map.Entry<TicketCredential, Assertion>> iter = ASSERTION_CACHE.entrySet().iterator(); final Calendar cutoff = Calendar.getInstance(); cutoff.setTimeInMillis(System.currentTimeMillis() - this.cacheTimeoutUnit.toMillis(this.cacheTimeout)); while (iter.hasNext()) { final Assertion assertion = iter.next().getValue(); final Calendar created = Calendar.getInstance(); created.setTime(assertion.getValidFromDate()); if (created.before(cutoff)) { logger.debug("Removing expired assertion for principal {}", assertion.getPrincipal()); iter.remove(); } } } }
public void run() { if (log.isDebugEnabled()) { log.debug("Cleaning assertion cache of size " + CasLoginModule.ASSERTION_CACHE.size()); } final Iterator iter = CasLoginModule.ASSERTION_CACHE.entrySet().iterator(); final Calendar cutoff = Calendar.getInstance(); cutoff.add(Calendar.MINUTE, -CasLoginModule.this.cacheTimeout); while (iter.hasNext()) { final Assertion assertion = (Assertion) ((Map.Entry) iter.next()).getValue(); final Calendar created = Calendar.getInstance(); created.setTime(assertion.getValidFromDate()); if (created.before(cutoff)) { if (log.isDebugEnabled()) { log.debug("Removing expired assertion for principal " + assertion.getPrincipal()); } iter.remove(); } } } }
/** * Log cas validation assertion. * * @param assertion the assertion */ protected void logCasValidationAssertion(final Assertion assertion) { LOGGER.debug("CAS Assertion Valid: [{}]", assertion.isValid()); LOGGER.debug("CAS Assertion Principal: [{}]", assertion.getPrincipal().getName()); LOGGER.debug("CAS Assertion authentication Date: [{}]", assertion.getAuthenticationDate()); LOGGER.debug("CAS Assertion ValidFrom Date: [{}]", assertion.getValidFromDate()); LOGGER.debug("CAS Assertion ValidUntil Date: [{}]", assertion.getValidUntilDate()); LOGGER.debug("CAS Assertion Attributes: [{}]", assertion.getAttributes()); LOGGER.debug("CAS Assertion Principal Attributes: [{}]", assertion.getPrincipal().getAttributes()); }
val validFromDate = ZonedDateTime.ofInstant(assertion.getValidFromDate().toInstant(), ZoneOffset.UTC); LOGGER.debug("Locating the assertion consumer service url for binding [{}]", binding); @NonNull
expirationTime = assertion.getValidUntilDate().getTime(); } else { Date validFromDate = assertion.getValidFromDate();