Exemplo n.º 1
0
  public CasCredentials requestServiceTicket(
      final String serviceURL, final HttpTGTProfile profile) {
    HttpURLConnection connection = null;
    try {
      final URL endpointURL = new URL(getAuthenticator().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()));
      out.write(payload);
      out.close();

      final int responseCode = connection.getResponseCode();
      if (responseCode == HttpConstants.OK) {
        final BufferedReader in =
            new BufferedReader(new InputStreamReader(connection.getInputStream()));
        return new CasCredentials(in.readLine(), getName());
      }
      throw new TechnicalException(
          "Service ticket request for `"
              + profile
              + "` failed: "
              + HttpUtils.buildHttpErrorMessage(connection));
    } catch (final IOException e) {
      throw new TechnicalException(e);
    } finally {
      HttpUtils.closeConnection(connection);
    }
  }
Exemplo n.º 2
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);
   }
 }