|
18 | 18 |
|
19 | 19 | import javax.ws.rs.GET;
|
20 | 20 | import javax.ws.rs.core.*;
|
21 |
| -import java.lang.reflect.Method; |
22 | 21 |
|
23 | 22 | public class ValidateEndpoint {
|
24 | 23 | protected static final Logger logger = Logger.getLogger(ValidateEndpoint.class);
|
@@ -137,46 +136,24 @@ private void checkTicket(String ticket, boolean requireReauth) {
|
137 | 136 | event.detail(Details.CODE_ID, parts[2]);
|
138 | 137 | }
|
139 | 138 |
|
140 |
| - ClientSessionCode.ParseResult<AuthenticatedClientSessionModel> parseResult; |
141 |
| - try { |
142 |
| - // Keycloak >3.4 branch: Parameter event was added to ClientSessionCode.parseResult |
143 |
| - Method parseResultMethod = ClientSessionCode.class.getMethod("parseResult", |
144 |
| - String.class, KeycloakSession.class, RealmModel.class, EventBuilder.class, Class.class); |
145 |
| - parseResult = (ClientSessionCode.ParseResult<AuthenticatedClientSessionModel>) parseResultMethod.invoke( |
146 |
| - null, code, session, realm, event, AuthenticatedClientSessionModel.class); |
147 |
| - } catch (ReflectiveOperationException e) { |
148 |
| - // Keycloak <=3.3 branch |
149 |
| - parseResult = ClientSessionCode.parseResult(code, session, realm, AuthenticatedClientSessionModel.class); |
150 |
| - } |
| 139 | + ClientSessionCode.ParseResult<AuthenticatedClientSessionModel> parseResult = ClientSessionCode.parseResult(code, null, session, realm, client, event, AuthenticatedClientSessionModel.class); |
151 | 140 | if (parseResult.isAuthSessionNotFound() || parseResult.isIllegalHash()) {
|
152 | 141 | event.error(Errors.INVALID_CODE);
|
153 | 142 |
|
154 | 143 | // Attempt to use same code twice should invalidate existing clientSession
|
155 | 144 | AuthenticatedClientSessionModel clientSession = parseResult.getClientSession();
|
156 | 145 | if (clientSession != null) {
|
157 |
| - clientSession.setUserSession(null); |
| 146 | + clientSession.detachFromUserSession(); |
158 | 147 | }
|
159 | 148 |
|
160 | 149 | throw new CASValidationException(CASErrorCode.INVALID_TICKET, "Code not valid", Response.Status.BAD_REQUEST);
|
161 | 150 | }
|
162 | 151 |
|
163 | 152 | clientSession = parseResult.getClientSession();
|
164 | 153 |
|
165 |
| - try { |
166 |
| - // Keycloak >3.4 branch: Method isExpiredToken was added |
167 |
| - Method isExpiredToken = ClientSessionCode.ParseResult.class.getMethod("isExpiredToken"); |
168 |
| - if ((Boolean) isExpiredToken.invoke(parseResult)) { |
169 |
| - event.error(Errors.EXPIRED_CODE); |
170 |
| - throw new CASValidationException(CASErrorCode.INVALID_TICKET, "Code is expired", Response.Status.BAD_REQUEST); |
171 |
| - } |
172 |
| - } catch (ReflectiveOperationException e) { |
173 |
| - // Keycloak <=3.3 branch |
174 |
| - if (!parseResult.getCode().isValid(AuthenticatedClientSessionModel.Action.CODE_TO_TOKEN.name(), ClientSessionCode.ActionType.CLIENT)) { |
175 |
| - event.error(Errors.INVALID_CODE); |
176 |
| - throw new CASValidationException(CASErrorCode.INVALID_TICKET, "Code is expired", Response.Status.BAD_REQUEST); |
177 |
| - } |
178 |
| - |
179 |
| - parseResult.getCode().setAction(null); |
| 154 | + if (parseResult.isExpiredToken()) { |
| 155 | + event.error(Errors.EXPIRED_CODE); |
| 156 | + throw new CASValidationException(CASErrorCode.INVALID_TICKET, "Code is expired", Response.Status.BAD_REQUEST); |
180 | 157 | }
|
181 | 158 |
|
182 | 159 | clientSession.setNote(CASLoginProtocol.SESSION_SERVICE_TICKET, ticket);
|
|
0 commit comments