commit | author | age
|
7f7e0c
|
1 |
package org.keycloak.protocol.cas.endpoints; |
MP |
2 |
|
fdb9f6
|
3 |
import jakarta.ws.rs.GET; |
JK |
4 |
import jakarta.ws.rs.core.MediaType; |
|
5 |
import jakarta.ws.rs.core.MultivaluedMap; |
|
6 |
import jakarta.ws.rs.core.Response; |
7f7e0c
|
7 |
import org.jboss.resteasy.annotations.cache.NoCache; |
MP |
8 |
import org.keycloak.events.EventBuilder; |
|
9 |
import org.keycloak.events.EventType; |
e1b962
|
10 |
import org.keycloak.models.KeycloakSession; |
74023a
|
11 |
import org.keycloak.models.RealmModel; |
7f7e0c
|
12 |
import org.keycloak.protocol.cas.CASLoginProtocol; |
352436
|
13 |
import org.keycloak.protocol.cas.utils.CASValidationException; |
7f7e0c
|
14 |
|
74023a
|
15 |
public class ValidateEndpoint extends AbstractValidateEndpoint { |
7f7e0c
|
16 |
|
MP |
17 |
private static final String RESPONSE_OK = "yes\n"; |
|
18 |
private static final String RESPONSE_FAILED = "no\n"; |
|
19 |
|
e1b962
|
20 |
public ValidateEndpoint(KeycloakSession session, RealmModel realm, EventBuilder event) { |
JK |
21 |
super(session, realm, event); |
7f7e0c
|
22 |
} |
MP |
23 |
|
|
24 |
@GET |
|
25 |
@NoCache |
|
26 |
public Response build() { |
dee145
|
27 |
MultivaluedMap<String, String> params = session.getContext().getUri().getQueryParameters(); |
7f7e0c
|
28 |
String service = params.getFirst(CASLoginProtocol.SERVICE_PARAM); |
MP |
29 |
String ticket = params.getFirst(CASLoginProtocol.TICKET_PARAM); |
7124d2
|
30 |
boolean renew = params.containsKey(CASLoginProtocol.RENEW_PARAM); |
7f7e0c
|
31 |
|
MP |
32 |
event.event(EventType.CODE_TO_TOKEN); |
|
33 |
|
|
34 |
try { |
|
35 |
checkSsl(); |
|
36 |
checkRealm(); |
|
37 |
checkClient(service); |
|
38 |
|
|
39 |
checkTicket(ticket, renew); |
|
40 |
|
|
41 |
event.success(); |
|
42 |
return successResponse(); |
352436
|
43 |
} catch (CASValidationException e) { |
7f7e0c
|
44 |
return errorResponse(e); |
MP |
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
protected Response successResponse() { |
aa6e6a
|
49 |
StringBuilder sb = new StringBuilder(RESPONSE_OK); |
DR |
50 |
sb.append(clientSession.getUserSession().getUser().getUsername()); |
|
51 |
sb.append("\n"); |
|
52 |
return Response.ok(sb.toString()).type(MediaType.TEXT_PLAIN).build(); |
7f7e0c
|
53 |
} |
MP |
54 |
|
352436
|
55 |
protected Response errorResponse(CASValidationException e) { |
MP |
56 |
return Response.status(e.getStatus()).entity(RESPONSE_FAILED).type(MediaType.TEXT_PLAIN).build(); |
7f7e0c
|
57 |
} |
MP |
58 |
|
|
59 |
} |