Search in sources :

Example 1 with ISOStandardDateFormat

use of org.apereo.cas.util.ISOStandardDateFormat in project cas by apereo.

the class SingleSignOnSessionsReportController method getActiveSsoSessions.

/**
     * Gets sso sessions.
     *
     * @param option the option
     * @return the sso sessions
     */
private Collection<Map<String, Object>> getActiveSsoSessions(final SsoSessionReportOptions option) {
    final Collection<Map<String, Object>> activeSessions = new ArrayList<>();
    final ISOStandardDateFormat dateFormat = new ISOStandardDateFormat();
    getNonExpiredTicketGrantingTickets().stream().map(TicketGrantingTicket.class::cast).filter(tgt -> !(option == SsoSessionReportOptions.DIRECT && tgt.getProxiedBy() != null)).forEach(tgt -> {
        final Authentication authentication = tgt.getAuthentication();
        final Principal principal = authentication.getPrincipal();
        final Map<String, Object> sso = new HashMap<>(SsoSessionAttributeKeys.values().length);
        sso.put(SsoSessionAttributeKeys.AUTHENTICATED_PRINCIPAL.toString(), principal.getId());
        sso.put(SsoSessionAttributeKeys.AUTHENTICATION_DATE.toString(), authentication.getAuthenticationDate());
        sso.put(SsoSessionAttributeKeys.AUTHENTICATION_DATE_FORMATTED.toString(), dateFormat.format(DateTimeUtils.dateOf(authentication.getAuthenticationDate())));
        sso.put(SsoSessionAttributeKeys.NUMBER_OF_USES.toString(), tgt.getCountOfUses());
        sso.put(SsoSessionAttributeKeys.TICKET_GRANTING_TICKET.toString(), tgt.getId());
        sso.put(SsoSessionAttributeKeys.PRINCIPAL_ATTRIBUTES.toString(), principal.getAttributes());
        sso.put(SsoSessionAttributeKeys.AUTHENTICATION_ATTRIBUTES.toString(), authentication.getAttributes());
        if (option != SsoSessionReportOptions.DIRECT) {
            if (tgt.getProxiedBy() != null) {
                sso.put(SsoSessionAttributeKeys.IS_PROXIED.toString(), Boolean.TRUE);
                sso.put(SsoSessionAttributeKeys.PROXIED_BY.toString(), tgt.getProxiedBy().getId());
            } else {
                sso.put(SsoSessionAttributeKeys.IS_PROXIED.toString(), Boolean.FALSE);
            }
        }
        sso.put(SsoSessionAttributeKeys.AUTHENTICATED_SERVICES.toString(), tgt.getServices());
        activeSessions.add(sso);
    });
    return activeSessions;
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) RequestParam(org.springframework.web.bind.annotation.RequestParam) LoggerFactory(org.slf4j.LoggerFactory) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HttpServletRequest(javax.servlet.http.HttpServletRequest) Authentication(org.apereo.cas.authentication.Authentication) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) DateTimeUtils(org.apereo.cas.util.DateTimeUtils) Collection(java.util.Collection) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ISOStandardDateFormat(org.apereo.cas.util.ISOStandardDateFormat) ModelAndView(org.springframework.web.servlet.ModelAndView) Principal(org.apereo.cas.authentication.principal.Principal) WebAsyncTask(org.springframework.web.context.request.async.WebAsyncTask) Ticket(org.apereo.cas.ticket.Ticket) HashMap(java.util.HashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Authentication(org.apereo.cas.authentication.Authentication) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Principal(org.apereo.cas.authentication.principal.Principal) ISOStandardDateFormat(org.apereo.cas.util.ISOStandardDateFormat)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 Authentication (org.apereo.cas.authentication.Authentication)1 Principal (org.apereo.cas.authentication.principal.Principal)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 Ticket (org.apereo.cas.ticket.Ticket)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1 DateTimeUtils (org.apereo.cas.util.DateTimeUtils)1 ISOStandardDateFormat (org.apereo.cas.util.ISOStandardDateFormat)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1