Пример #1
0
 public static String getIDPMetadataDescriptor(
     UriInfo uriInfo, KeycloakSession session, RealmModel realm) throws IOException {
   InputStream is = SamlService.class.getResourceAsStream("/idp-metadata-template.xml");
   String template = StreamUtil.readString(is);
   template =
       template.replace(
           "${idp.entityID}",
           RealmsResource.realmBaseUrl(uriInfo).build(realm.getName()).toString());
   template =
       template.replace(
           "${idp.sso.HTTP-POST}",
           RealmsResource.protocolUrl(uriInfo)
               .build(realm.getName(), SamlProtocol.LOGIN_PROTOCOL)
               .toString());
   template =
       template.replace(
           "${idp.sso.HTTP-Redirect}",
           RealmsResource.protocolUrl(uriInfo)
               .build(realm.getName(), SamlProtocol.LOGIN_PROTOCOL)
               .toString());
   template =
       template.replace(
           "${idp.sls.HTTP-POST}",
           RealmsResource.protocolUrl(uriInfo)
               .build(realm.getName(), SamlProtocol.LOGIN_PROTOCOL)
               .toString());
   template =
       template.replace(
           "${idp.signing.certificate}",
           PemUtils.encodeCertificate(session.keys().getActiveKey(realm).getCertificate()));
   return template;
 }
  private int invokeRESTEndpoint(String accessTokenString) {

    HttpClient client = new DefaultHttpClient();
    try {
      String restUrl = customerDb.toString();
      HttpGet get = new HttpGet(restUrl);
      get.addHeader("Authorization", "Bearer " + accessTokenString);
      try {
        HttpResponse response = client.execute(get);
        int status = response.getStatusLine().getStatusCode();
        if (status != 200) {
          return status;
        }

        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();
        try {
          String body = StreamUtil.readString(is);
          Assert.assertTrue(body.contains("Stian Thorgersen") && body.contains("Bill Burke"));
          return status;
        } finally {
          is.close();
        }
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    } finally {
      client.getConnectionManager().shutdown();
    }
  }