org.keycloak.admin.client.Keycloak类的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(341)

本文整理了Java中org.keycloak.admin.client.Keycloak类的一些代码示例,展示了Keycloak类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Keycloak类的具体详情如下:
包路径:org.keycloak.admin.client.Keycloak
类名称:Keycloak

Keycloak介绍

[英]Provides a Keycloak client. By default, this implementation uses a ResteasyClient with the default ResteasyClientBuilder settings. To customize the underling client, use a KeycloakBuilder to create a Keycloak client. To read Responses, you can use CreatedResponseUtil for objects created
[中]提供密钥斗篷客户端。默认情况下,此实现使用具有默认ResteasyClientBuilder设置的ResteasyClient。要自定义下划线客户端,请使用KeyClope生成器创建KeyClope客户端。要读取响应,可以对创建的对象使用CreatedResponseUtil

代码示例

代码示例来源:origin: FundRequest/platform

@Bean
  public RealmResource keycloak() {
    final Keycloak keycloak = Keycloak.getInstance(
        serverUrl,
        realm,
        username,
        password,
        clientId,
        clientSecret);
    return keycloak.realm(realm);
  }
}

代码示例来源:origin: EnMasseProject/enmasse

private RealmResource getRealmResource(Keycloak keycloak, String realmName) {
  List<RealmRepresentation> realms = keycloak.realms().findAll();
  for (RealmRepresentation realm : realms) {
    if (realm.getRealm().equals(realmName)) {
      return keycloak.realm(realmName);
    }
  }
  return null;
}

代码示例来源:origin: org.activiti/activiti-services-test

private AccessTokenResponse getAccessTokenResponse() {
  return Keycloak.getInstance(authServer, realm, keycloaktestuser, keycloaktestpassword, resource).tokenManager().getAccessToken();
}

代码示例来源:origin: org.keycloak/keycloak-admin-client

public static Keycloak getInstance(String serverUrl, String realm, String username, String password, String clientId, String clientSecret, SSLContext sslContext) {
  return getInstance(serverUrl, realm, username, password, clientId, clientSecret, sslContext, null);
}

代码示例来源:origin: org.keycloak/keycloak-admin-client

public RealmResource realm(String realmName) {
  return realms().realm(realmName);
}

代码示例来源:origin: EnMasseProject/enmasse

@Override
  public void deleteRealm(String realmName) {
    withKeycloak(kc -> {

      try {
        kc.realm(realmName).remove();
      } finally {
        realmState.remove(realmName);
      }

      return true;
    });
  }
}

代码示例来源:origin: thomasdarimont/spring-boot-admin-keycloak-example

/**
 * {@link HttpHeadersProvider} used to populate the {@link HttpHeaders} for
 * accessing the state of the disovered clients.
 *
 * @param keycloak
 * @return
 */
@Bean
public HttpHeadersProvider keycloakBearerAuthHeaderProvider(Keycloak keycloak) {
  return (app) -> {
    String accessToken = keycloak.tokenManager().getAccessTokenString();
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken);
    return headers;
  };
}

代码示例来源:origin: org.keycloak/keycloak-admin-client

public static Keycloak getInstance(String serverUrl, String realm, String username, String password, String clientId) {
  return new Keycloak(serverUrl, realm, username, password, clientId, null, PASSWORD, null, null);
}

代码示例来源:origin: org.keycloak/keycloak-admin-client

/**
 * Create a secure proxy based on an absolute URI.
 * All set up with appropriate token
 *
 * @param proxyClass
 * @param absoluteURI
 * @param <T>
 * @return
 */
public <T> T proxy(Class<T> proxyClass, URI absoluteURI) {
  return client.target(absoluteURI).register(newAuthFilter()).proxy(proxyClass);
}

代码示例来源:origin: org.activiti.cloud/activiti-cloud-services-identity-keycloak

private Keycloak getKeycloakInstance() {
  return Keycloak.getInstance(keycloakProperties.getAuthServerUrl(),
      keycloakProperties.getRealm(),
      activitiKeycloakProperties.getClientUser(),
      activitiKeycloakProperties.getClientPassword(),
      activitiKeycloakProperties.getAdminClientApp());
}

代码示例来源:origin: EnMasseProject/enmasse

@Override
public Set<String> getRealmNames() {
  return withKeycloak(kc -> kc.realms().findAll().stream()
      .map(RealmRepresentation::getRealm)
      .collect(Collectors.toSet()));
}

代码示例来源:origin: EnMasseProject/enmasse

if (!updated.equals(current)) {
  withKeycloak(kc -> {
    RealmResource realm = kc.realm(realmName);
    if (realm != null) {

代码示例来源:origin: org.keycloak/keycloak-admin-client

public static Keycloak getInstance(String serverUrl, String realm, String clientId, String authToken) {
  return new Keycloak(serverUrl, realm, null, null, clientId, null, PASSWORD, null, authToken);
}

代码示例来源:origin: org.keycloak/keycloak-admin-client

Keycloak(String serverUrl, String realm, String username, String password, String clientId, String clientSecret, String grantType, ResteasyClient resteasyClient, String authtoken) {
  config = new Config(serverUrl, realm, username, password, clientId, clientSecret, grantType);
  client = resteasyClient != null ? resteasyClient : new ResteasyClientBuilder().connectionPoolSize(10).build();
  authToken = authtoken;
  tokenManager = authtoken == null ? new TokenManager(config, client) : null;
  target = client.target(config.getServerUrl());
  target.register(newAuthFilter());
}

代码示例来源:origin: adorsys/xs2a

public boolean registerClient(String psuId, String password, String email) {
  Keycloak keycloak = Keycloak.getInstance(keycloakConfigProperties.getAuthServerUrl(), MASTER_REALM,
    keycloakAdminUsername,
    keycloakAdminPassword,
    ADMIN_CLI);
  try (Response response = keycloak.realm(keycloakConfigProperties.getRealm()).users().create(getUserRepresentation(psuId, password, email))) {
    log.info("Register keycloak client status: {}", response.getStatus());
    return response.getStatus() == 201;
  }
}

代码示例来源:origin: EnMasseProject/enmasse

@Override
public void deleteUsers(String namespace) {
  withKeycloak(keycloak -> {
    List<RealmRepresentation> realmReps = keycloak.realms().findAll();
    for (RealmRepresentation realmRep : realmReps) {
      String realmNs = realmRep.getAttributes().get("namespace");
      if (realmNs != null && realmNs.equals(namespace)) {
        String realm = realmRep.getRealm();
        List<UserRepresentation> userReps = keycloak.realm(realm).users().list(0, 100);
        while (!userReps.isEmpty()) {
          for (UserRepresentation userRep : userReps) {
            keycloak.realm(realm).users().delete(userRep.getId());
          }
          userReps = keycloak.realm(realm).users().list(0, 100);
        }
      }
    }
    return null;
  });
}

代码示例来源:origin: org.activiti.cloud.common/activiti-cloud-services-test

private AccessTokenResponse getAccessTokenResponse() {
  return Keycloak.getInstance(keycloakProperties.getAuthServerUrl(),
                keycloakProperties.getRealm(),
                keycloakTestUser,
                keycloakTestPassword,
                resource).tokenManager().getAccessToken();
}

代码示例来源:origin: org.activiti.cloud/activiti-cloud-services-identity-keycloak

protected RealmResource getRealm(){
  return getKeycloakInstance().realms().realm(keycloakProperties.getRealm());
}

代码示例来源:origin: org.keycloak/keycloak-admin-client

public static Keycloak getInstance(String serverUrl, String realm, String username, String password, String clientId, String clientSecret) {
  return new Keycloak(serverUrl, realm, username, password, clientId, clientSecret, PASSWORD, null, null);
}

代码示例来源:origin: EnMasseProject/enmasse

private UserList queryUsers(final Predicate<RealmRepresentation> realmPredicate, final Predicate<UserRepresentation> userPredicate) {
  return withKeycloak(keycloak -> {
    List<RealmRepresentation> realmReps = keycloak.realms().findAll();
    UserList userList = new UserList();
    for (RealmRepresentation realmRep : realmReps) {
      if (realmPredicate.test(realmRep)) {
        String realm = realmRep.getRealm();
        keycloak.realm(realm).users().list()
                .stream()
                .filter(userPredicate)
                .forEachOrdered(userRep -> {
                  List<GroupRepresentation> groupReps = keycloak.realm(realm).users().get(userRep.getId()).groups();
                  userList.getItems().add(buildUser(userRep, groupReps));
                });
      }
    }
    return userList;
  });
}

相关文章