use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.
the class ExportImportTest method testDirRealmExportImport.
@Test
public void testDirRealmExportImport() throws Throwable {
testingClient.testing().exportImport().setProvider(DirExportProviderFactory.PROVIDER_ID);
String targetDirPath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "dirRealmExport";
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
testingClient.testing().exportImport().setDir(targetDirPath);
testingClient.testing().exportImport().setUsersPerFile(5);
testRealmExportImport();
RealmResource testRealmRealm = adminClient.realm("test-realm");
ExportImportUtil.assertDataImportedInRealm(adminClient, testingClient, testRealmRealm.toRepresentation());
// There should be 4 files in target directory (1 realm, 12 users, 5 users per file)
// (+ additional user service-account-test-app-authz that should not be there ???)
File[] files = new File(targetDirPath).listFiles();
assertEquals(4, files.length);
}
use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.
the class ExportImportTest method testDirFullExportImport.
@Test
public void testDirFullExportImport() throws Throwable {
testingClient.testing().exportImport().setProvider(DirExportProviderFactory.PROVIDER_ID);
String targetDirPath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "dirExport";
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
testingClient.testing().exportImport().setDir(targetDirPath);
testingClient.testing().exportImport().setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE);
testFullExportImport();
RealmResource testRealmRealm = adminClient.realm("test-realm");
ExportImportUtil.assertDataImportedInRealm(adminClient, testingClient, testRealmRealm.toRepresentation());
// There should be 6 files in target directory (3 realm, 3 user)
assertEquals(6, new File(targetDirPath).listFiles().length);
}
use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.
the class OpenShiftTokenReviewEndpointTest method hs256.
@Test
public void hs256() {
RealmResource realm = adminClient.realm("test");
RealmRepresentation rep = realm.toRepresentation();
try {
rep.setDefaultSignatureAlgorithm(Algorithm.HS256);
realm.update(rep);
Review r = new Review().algorithm(Algorithm.HS256).invoke().assertSuccess();
String userId = testRealm().users().search(r.username).get(0).getId();
OpenShiftTokenReviewResponseRepresentation.User user = r.response.getStatus().getUser();
assertEquals(userId, user.getUid());
assertEquals("test-user@localhost", user.getUsername());
assertNotNull(user.getExtra());
r.assertScope("openid", "email", "profile");
} finally {
rep.setDefaultSignatureAlgorithm(null);
realm.update(rep);
}
}
use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.
the class UserInfoTest method testNotBeforeTokens.
@Test
public void testNotBeforeTokens() {
Client client = AdminClientUtil.createResteasyClient();
try {
AccessTokenResponse accessTokenResponse = executeGrantAccessTokenRequest(client);
int time = Time.currentTime() + 60;
RealmResource realm = adminClient.realm("test");
RealmRepresentation rep = realm.toRepresentation();
rep.setNotBefore(time);
realm.update(rep);
Response response = UserInfoClientUtil.executeUserInfoRequest_getMethod(client, accessTokenResponse.getToken());
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
response.close();
events.expect(EventType.USER_INFO_REQUEST_ERROR).error(Errors.INVALID_TOKEN).user(Matchers.nullValue(String.class)).session(Matchers.nullValue(String.class)).detail(Details.AUTH_METHOD, Details.VALIDATE_ACCESS_TOKEN).client((String) null).assertEvent();
events.clear();
rep.setNotBefore(0);
realm.update(rep);
// do the same with client's notBefore
ClientResource clientResource = realm.clients().get(realm.clients().findByClientId("test-app").get(0).getId());
ClientRepresentation clientRep = clientResource.toRepresentation();
clientRep.setNotBefore(time);
clientResource.update(clientRep);
response = UserInfoClientUtil.executeUserInfoRequest_getMethod(client, accessTokenResponse.getToken());
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
response.close();
events.expect(EventType.USER_INFO_REQUEST_ERROR).error(Errors.INVALID_TOKEN).user(Matchers.nullValue(String.class)).session(Matchers.nullValue(String.class)).detail(Details.AUTH_METHOD, Details.VALIDATE_ACCESS_TOKEN).client((String) null).assertEvent();
clientRep.setNotBefore(0);
clientResource.update(clientRep);
} finally {
client.close();
}
}
use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.
the class UserInfoTest method testSuccess_dotsInClientId.
// KEYCLOAK-8838
@Test
public void testSuccess_dotsInClientId() throws Exception {
// Create client with dot in the name
ClientRepresentation clientRep = org.keycloak.testsuite.util.ClientBuilder.create().clientId("my.foo.client").addRedirectUri("http://foo.host").secret("password").directAccessGrants().build();
RealmResource realm = adminClient.realm("test");
Response resp = realm.clients().create(clientRep);
String clientUUID = ApiUtil.getCreatedId(resp);
resp.close();
getCleanup().addClientUuid(clientUUID);
// Create role with dot in the name
realm.clients().get(clientUUID).roles().create(RoleBuilder.create().name("my.foo.role").build());
// Assign role to the user
RoleRepresentation fooRole = realm.clients().get(clientUUID).roles().get("my.foo.role").toRepresentation();
UserResource userResource = ApiUtil.findUserByUsernameId(realm, "test-user@localhost");
userResource.roles().clientLevel(clientUUID).add(Collections.singletonList(fooRole));
// Login to the new client
OAuthClient.AccessTokenResponse accessTokenResponse = oauth.clientId("my.foo.client").doGrantAccessTokenRequest("password", "test-user@localhost", "password");
AccessToken accessToken = oauth.verifyToken(accessTokenResponse.getAccessToken());
Assert.assertNames(accessToken.getResourceAccess("my.foo.client").getRoles(), "my.foo.role");
events.clear();
// Send UserInfo request and ensure it is correct
Client client = AdminClientUtil.createResteasyClient();
try {
Response response = UserInfoClientUtil.executeUserInfoRequest_getMethod(client, accessTokenResponse.getAccessToken());
testSuccessfulUserInfoResponse(response, "my.foo.client");
} finally {
client.close();
}
}
Aggregations