Ejemplo n.º 1
0
 public void destroyTicketGrantingTicket(final CasRestProfile profile) {
   HttpURLConnection connection = null;
   try {
     final URL endpointURL = new URL(getCasRestAuthenticator().getCasRestUrl());
     final URL deleteURL =
         new URL(endpointURL, endpointURL.getPath() + "/" + profile.getTicketGrantingTicketId());
     connection = HttpUtils.openDeleteConnection(deleteURL);
     final int responseCode = connection.getResponseCode();
     if (responseCode != HttpConstants.OK) {
       throw new TechnicalException(
           "TGT delete request for `"
               + profile
               + "` failed: "
               + HttpUtils.buildHttpErrorMessage(connection));
     }
   } catch (final IOException e) {
     throw new TechnicalException(e);
   } finally {
     HttpUtils.closeConnection(connection);
   }
 }
Ejemplo n.º 2
0
  public TokenCredentials requestServiceTicket(
      final String serviceURL, final CasRestProfile profile) {
    HttpURLConnection connection = null;
    try {
      final URL endpointURL = new URL(getCasRestAuthenticator().getCasRestUrl());
      final URL ticketURL =
          new URL(endpointURL, endpointURL.getPath() + "/" + profile.getTicketGrantingTicketId());

      connection = HttpUtils.openPostConnection(ticketURL);
      final String payload = HttpUtils.encodeQueryParam("service", serviceURL);

      final BufferedWriter out =
          new BufferedWriter(
              new OutputStreamWriter(connection.getOutputStream(), HttpConstants.UTF8_ENCODING));
      out.write(payload);
      out.close();

      final int responseCode = connection.getResponseCode();
      if (responseCode == HttpConstants.OK) {
        try (final BufferedReader in =
            new BufferedReader(
                new InputStreamReader(connection.getInputStream(), HttpConstants.UTF8_ENCODING))) {
          return new TokenCredentials(in.readLine(), getClass().getSimpleName());
        }
      }
      throw new TechnicalException(
          "Service ticket request for `"
              + profile
              + "` failed: "
              + HttpUtils.buildHttpErrorMessage(connection));
    } catch (final IOException e) {
      throw new TechnicalException(e);
    } finally {
      HttpUtils.closeConnection(connection);
    }
  }