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

Jacek Kowalski
2023-11-24 eda11afe10b463af8fc93991f8eb2dd77fbc2c21
commit | author | age
7f7e0c 1 package org.keycloak.protocol.cas;
MP 2
fdb9f6 3 import jakarta.ws.rs.Path;
JK 4 import jakarta.ws.rs.core.Context;
5 import jakarta.ws.rs.core.HttpHeaders;
6 import jakarta.ws.rs.core.Response;
7 import jakarta.ws.rs.core.UriBuilder;
7f7e0c 8 import org.jboss.resteasy.spi.HttpRequest;
MP 9 import org.jboss.resteasy.spi.ResteasyProviderFactory;
10 import org.keycloak.events.EventBuilder;
11 import org.keycloak.models.KeycloakSession;
12 import org.keycloak.models.RealmModel;
74023a 13 import org.keycloak.protocol.cas.endpoints.*;
7f7e0c 14 import org.keycloak.services.resources.RealmsResource;
MP 15
16 public class CASLoginProtocolService {
58cce9 17     private KeycloakSession session;
7f7e0c 18     private RealmModel realm;
MP 19     private EventBuilder event;
20
21     @Context
22     private HttpHeaders headers;
23
24     @Context
25     private HttpRequest request;
26
58cce9 27     public CASLoginProtocolService(KeycloakSession session, EventBuilder event) {
G 28         this.session = session;
29         this.realm = session.getContext().getRealm();
7f7e0c 30         this.event = event;
MP 31     }
32
33     public static UriBuilder serviceBaseUrl(UriBuilder baseUriBuilder) {
34         return baseUriBuilder.path(RealmsResource.class).path("{realm}/protocol/" + CASLoginProtocol.LOGIN_PROTOCOL);
35     }
36
37     @Path("login")
38     public Object login() {
58cce9 39         AuthorizationEndpoint endpoint = new AuthorizationEndpoint(session, event);
7f7e0c 40         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
MP 41         return endpoint;
42     }
43
44     @Path("logout")
45     public Object logout() {
b88dc3 46         LogoutEndpoint endpoint = new LogoutEndpoint(realm);
7f7e0c 47         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
MP 48         return endpoint;
49     }
50
51     @Path("validate")
52     public Object validate() {
53         ValidateEndpoint endpoint = new ValidateEndpoint(realm, event);
54         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
55         return endpoint;
56     }
57
74023a 58     @Path("samlValidate")
EH 59     public Object validateSaml11() {
60         SamlValidateEndpoint endpoint = new SamlValidateEndpoint(realm, event);
61         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
62         return endpoint;
63     }
64
7f7e0c 65     @Path("serviceValidate")
MP 66     public Object serviceValidate() {
67         ServiceValidateEndpoint endpoint = new ServiceValidateEndpoint(realm, event);
68         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
69         return endpoint;
70     }
71
72     @Path("proxyValidate")
73     public Object proxyValidate() {
5a0869 74         //TODO implement
MP 75         return serviceValidate();
7f7e0c 76     }
MP 77
78     @Path("proxy")
79     public Object proxy() {
5a0869 80         return Response.serverError().entity("Not implemented").build();
7f7e0c 81     }
MP 82
83     @Path("p3/serviceValidate")
84     public Object p3ServiceValidate() {
85         return serviceValidate();
86     }
87
88     @Path("p3/proxyValidate")
89     public Object p3ProxyValidate() {
90         return proxyValidate();
91     }
92 }