mirror of https://github.com/jacekkow/keycloak-protocol-cas

Matthias Piepkorn
2017-01-29 37a97a22fd9882543dbe8cc524c42af4dc9f14d1
commit | author | age
7f7e0c 1 package org.keycloak.protocol.cas.endpoints;
MP 2
3 import org.jboss.logging.Logger;
4 import org.jboss.resteasy.annotations.cache.NoCache;
5 import org.jboss.resteasy.spi.HttpRequest;
6 import org.keycloak.common.ClientConnection;
7 import org.keycloak.events.EventBuilder;
8 import org.keycloak.models.KeycloakSession;
9 import org.keycloak.models.RealmModel;
10 import org.keycloak.models.UserSessionModel;
11 import org.keycloak.protocol.cas.CASLoginProtocol;
12 import org.keycloak.services.managers.AuthenticationManager;
13
14 import javax.ws.rs.GET;
15 import javax.ws.rs.core.Context;
16 import javax.ws.rs.core.HttpHeaders;
17 import javax.ws.rs.core.Response;
18 import javax.ws.rs.core.UriInfo;
19
20 public class LogoutEndpoint {
21     private static final Logger logger = Logger.getLogger(org.keycloak.protocol.oidc.endpoints.LogoutEndpoint.class);
22
23     @Context
24     private KeycloakSession session;
25
26     @Context
27     private ClientConnection clientConnection;
28
29     @Context
30     private HttpRequest request;
31
32     @Context
33     private HttpHeaders headers;
34
35     @Context
36     private UriInfo uriInfo;
37
38     private RealmModel realm;
39     private EventBuilder event;
40
41     public LogoutEndpoint(RealmModel realm, EventBuilder event) {
42         this.realm = realm;
43         this.event = event;
44     }
45
46     @GET
47     @NoCache
48     public Response logout() {
49
50         AuthenticationManager.AuthResult authResult = AuthenticationManager.authenticateIdentityCookie(session, realm, false);
51         if (authResult != null) {
52             UserSessionModel userSession = authResult.getSession();
53             userSession.setNote(AuthenticationManager.KEYCLOAK_LOGOUT_PROTOCOL, CASLoginProtocol.LOGIN_PROTOCOL);
54
55             logger.debug("Initiating CAS browser logout");
56             Response response =  AuthenticationManager.browserLogout(session, realm, authResult.getSession(), uriInfo, clientConnection, headers);
57             logger.debug("finishing CAS browser logout");
58             return response;
59         }
60         return Response.ok().build();
61     }
62 }