我从Spring Security切换到基于REST的客户端进行密钥隐藏。我正在使用Keycloak Admin REST Client 7.0.1。我尝试使用public凭据选项来验证身份验证和随后的用户创建尝试。但是,出现以下错误:
无法识别的字段“ access_token”(类org.keycloak.representations.AccessTokenResponse),未标记为可忽略
示例Java客户端
Keycloak keycloak = KeycloakBuilder.builder()
.serverUrl(serverUrl)
.realm(realm)
.grantType(OAuth2Constants.PASSWORD)
.clientId(clientId)
//.clientSecret(clientSecret)
.username("admin")
.password("somepassword")
.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build())
.build();
CredentialRepresentation credential = new CredentialRepresentation();
credential.setType(CredentialRepresentation.PASSWORD);
credential.setValue("test123");
credential.setTemporary(false);
UserRepresentation userRepresentation = new UserRepresentation();
userRepresentation.setUsername("testuser");
userRepresentation.setFirstName("Test");
userRepresentation.setLastName("User");
userRepresentation.setCredentials(asList(credential));
userRepresentation.setEnabled(true);
userRepresentation.setRealmRoles(asList("admin"));
try {
Response result = keycloak.realm("testrealm").users().create(userRepresentation);
log.info("result from keycloak: " + result);
if (result.getStatus() != 201) {
log.error("Couldn't create user.");
//System.exit(0);
}
} catch (Exception e){
log.error("Test user not created.... exception is " + e);
}