3
3
import org .jboss .logging .Logger ;
4
4
import org .jboss .resteasy .spi .HttpRequest ;
5
5
import org .keycloak .common .ClientConnection ;
6
- import org .keycloak .events .Details ;
7
6
import org .keycloak .events .Errors ;
8
7
import org .keycloak .events .EventBuilder ;
9
8
import org .keycloak .models .*;
12
11
import org .keycloak .protocol .cas .mappers .CASAttributeMapper ;
13
12
import org .keycloak .protocol .cas .representations .CASErrorCode ;
14
13
import org .keycloak .protocol .cas .utils .CASValidationException ;
14
+ import org .keycloak .protocol .oidc .utils .OAuth2CodeParser ;
15
15
import org .keycloak .protocol .oidc .utils .RedirectUtils ;
16
16
import org .keycloak .services .managers .AuthenticationManager ;
17
- import org .keycloak .services .managers .ClientSessionCode ;
18
17
import org .keycloak .services .util .DefaultClientSessionContext ;
19
18
20
19
import javax .ws .rs .core .Context ;
@@ -93,13 +92,8 @@ protected void checkTicket(String ticket, boolean requireReauth) {
93
92
94
93
String code = ticket .substring (CASLoginProtocol .SERVICE_TICKET_PREFIX .length ());
95
94
96
- String [] parts = code .split ("\\ ." );
97
- if (parts .length == 4 ) {
98
- event .detail (Details .CODE_ID , parts [2 ]);
99
- }
100
-
101
- ClientSessionCode .ParseResult <AuthenticatedClientSessionModel > parseResult = ClientSessionCode .parseResult (code , null , session , realm , client , event , AuthenticatedClientSessionModel .class );
102
- if (parseResult .isAuthSessionNotFound () || parseResult .isIllegalHash ()) {
95
+ OAuth2CodeParser .ParseResult parseResult = OAuth2CodeParser .parseCode (session , code , realm , event );
96
+ if (parseResult .isIllegalCode ()) {
103
97
event .error (Errors .INVALID_CODE );
104
98
105
99
// Attempt to use same code twice should invalidate existing clientSession
@@ -113,7 +107,7 @@ protected void checkTicket(String ticket, boolean requireReauth) {
113
107
114
108
clientSession = parseResult .getClientSession ();
115
109
116
- if (parseResult .isExpiredToken ()) {
110
+ if (parseResult .isExpiredCode ()) {
117
111
event .error (Errors .EXPIRED_CODE );
118
112
throw new CASValidationException (CASErrorCode .INVALID_TICKET , "Code is expired" , Response .Status .BAD_REQUEST );
119
113
}
0 commit comments