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);
    }
  }