/
SingleSignOnSessionStatusController.java
64 lines (57 loc) · 2.57 KB
/
SingleSignOnSessionStatusController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.apereo.cas.web.report;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apereo.cas.authentication.Authentication;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.ticket.registry.TicketRegistrySupport;
import org.apereo.cas.web.support.CookieRetrievingCookieGenerator;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* This is {@link SingleSignOnSessionStatusController}.
*
* @author Misagh Moayyed
* @since 5.1.0
*/
public class SingleSignOnSessionStatusController extends BaseCasMvcEndpoint {
private final CookieRetrievingCookieGenerator ticketGrantingTicketCookieGenerator;
private final TicketRegistrySupport ticketRegistrySupport;
public SingleSignOnSessionStatusController(final CookieRetrievingCookieGenerator ticketGrantingTicketCookieGenerator,
final TicketRegistrySupport ticketRegistrySupport,
final CasConfigurationProperties casProperties) {
super("ssostatus", "/sso", casProperties.getMonitor().getEndpoints().getSingleSignOnStatus());
this.ticketGrantingTicketCookieGenerator = ticketGrantingTicketCookieGenerator;
this.ticketRegistrySupport = ticketRegistrySupport;
}
/**
* Gets yes/no status.
*
* @param request the request
* @param response the response
* @return the status
*/
@GetMapping(produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String getStatus(final HttpServletRequest request, final HttpServletResponse response) {
ensureEndpointAccessIsAuthorized(request, response);
final String tgtId = this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request);
if (StringUtils.isBlank(tgtId)) {
response.setStatus(HttpStatus.GONE.value());
return result(false);
}
final Authentication auth = this.ticketRegistrySupport.getAuthenticationFrom(tgtId);
if (auth == null) {
response.setStatus(HttpStatus.GONE.value());
return result(false);
}
response.setStatus(HttpStatus.OK.value());
return result(true);
}
private String result(final boolean res) {
return BooleanUtils.toStringYesNo(res);
}
}