| | |
| | | protected RealmModel realm; |
| | | protected EventBuilder event; |
| | | protected ClientModel client; |
| | | protected String service; |
| | | protected AuthenticatedClientSessionModel clientSession; |
| | | protected String pgtIou; |
| | | |
| | |
| | | |
| | | event.detail(Details.REDIRECT_URI, service); |
| | | |
| | | client = realm.getClientsStream() |
| | | .filter(c -> CASLoginProtocol.LOGIN_PROTOCOL.equals(c.getProtocol())) |
| | | .filter(c -> RedirectUtils.verifyRedirectUri(session, service, c) != null) |
| | | .findFirst().orElse(null); |
| | | client = findClient(service); |
| | | if (client == null) { |
| | | event.error(Errors.CLIENT_NOT_FOUND); |
| | | throw new CASValidationException(CASErrorCode.INVALID_SERVICE, "Client not found", Response.Status.BAD_REQUEST); |
| | |
| | | throw new CASValidationException(CASErrorCode.INVALID_SERVICE, "Client disabled", Response.Status.BAD_REQUEST); |
| | | } |
| | | |
| | | this.service = RedirectUtils.verifyRedirectUri(session, service, client); |
| | | |
| | | event.client(client.getClientId()); |
| | | |
| | | session.getContext().setClient(client); |
| | | } |
| | | |
| | | protected ClientModel findClient(String service) { |
| | | return realm.getClientsStream() |
| | | .filter(c -> CASLoginProtocol.LOGIN_PROTOCOL.equals(c.getProtocol())) |
| | | .filter(c -> RedirectUtils.verifyRedirectUri(session, service, c) != null) |
| | | .findFirst().orElse(null); |
| | | } |
| | | |
| | | protected void checkTicket(String ticket, String prefix, boolean requireReauth) { |
| | | if (ticket == null) { |
| | | event.error(Errors.INVALID_CODE); |
| | |
| | | throw new CASValidationException(CASErrorCode.INVALID_TICKET, "Code is expired", Response.Status.BAD_REQUEST); |
| | | } |
| | | |
| | | // Service and proxy tickets are valid only for the service they were issued for |
| | | if (!isReusable && (service == null || !service.equals(codeData.getRedirectUriParam()))) { |
| | | event.error(Errors.INVALID_REDIRECT_URI); |
| | | throw new CASValidationException(CASErrorCode.INVALID_SERVICE, "Ticket was not issued for this service", Response.Status.BAD_REQUEST); |
| | | } |
| | | |
| | | clientSession.setNote(CASLoginProtocol.SESSION_TICKET, ticket); |
| | | |
| | | if (requireReauth && AuthenticationManager.isSSOAuthentication(clientSession)) { |
| | |
| | | |
| | | if (client == null) { |
| | | client = clientSession.getClient(); |
| | | } else { |
| | | } else if (!prefix.equals(CASLoginProtocol.PROXY_TICKET_PREFIX)) { |
| | | // Proxy tickets are issued from the proxying client's session for a (possibly) different target service |
| | | if (!client.getClientId().equals(clientSession.getClient().getClientId())) { |
| | | event.error(Errors.INVALID_CODE); |
| | | throw new CASValidationException(CASErrorCode.INVALID_SERVICE, "Invalid service", Response.Status.BAD_REQUEST); |