Search in sources :

Example 1 with RolesVO

use of org.olat.user.restapi.RolesVO in project OpenOLAT by OpenOLAT.

the class UserMgmtTest method testUpdateRoles.

@Test
public void testUpdateRoles() throws IOException, URISyntaxException {
    // create an author
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("author-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    RolesVO roles = new RolesVO();
    roles.setAuthor(true);
    roles.setUserManager(true);
    // get roles of author
    URI request = UriBuilder.fromUri(getContextURI()).path("/users/" + author.getKey() + "/roles").build();
    HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, roles);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    RolesVO modRoles = conn.parse(response, RolesVO.class);
    Assert.assertNotNull(modRoles);
    // check the roles
    Roles reloadRoles = securityManager.getRoles(author);
    Assert.assertTrue(reloadRoles.isAuthor());
    Assert.assertFalse(reloadRoles.isGroupManager());
    Assert.assertFalse(reloadRoles.isGuestOnly());
    Assert.assertFalse(reloadRoles.isInstitutionalResourceManager());
    Assert.assertFalse(reloadRoles.isInvitee());
    Assert.assertFalse(reloadRoles.isOLATAdmin());
    Assert.assertFalse(reloadRoles.isPoolAdmin());
    Assert.assertTrue(reloadRoles.isUserManager());
    conn.shutdown();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponse(org.apache.http.HttpResponse) Roles(org.olat.core.id.Roles) GroupRoles(org.olat.basesecurity.GroupRoles) Identity(org.olat.core.id.Identity) RolesVO(org.olat.user.restapi.RolesVO) URI(java.net.URI) Test(org.junit.Test)

Example 2 with RolesVO

use of org.olat.user.restapi.RolesVO in project openolat by klemens.

the class UserRestClient method createAuthor.

public UserVO createAuthor(String name) throws IOException, URISyntaxException {
    RestConnection restConnection = new RestConnection(deploymentUrl);
    assertTrue(restConnection.login(username, password));
    UserVO user = createUser(restConnection, name, "Auth");
    RolesVO roles = new RolesVO();
    roles.setAuthor(true);
    // update roles of author
    URI request = getUsersURIBuilder().path(user.getKey().toString()).path("roles").build();
    HttpPost method = restConnection.createPost(request, MediaType.APPLICATION_JSON);
    restConnection.addJsonEntity(method, roles);
    HttpResponse response = restConnection.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    restConnection.shutdown();
    return user;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) RestConnection(org.olat.restapi.RestConnection) UserVO(org.olat.user.restapi.UserVO) HttpResponse(org.apache.http.HttpResponse) RolesVO(org.olat.user.restapi.RolesVO) URI(java.net.URI)

Example 3 with RolesVO

use of org.olat.user.restapi.RolesVO in project openolat by klemens.

the class UserMgmtTest method testGetRoles.

@Test
public void testGetRoles() throws IOException, URISyntaxException {
    // create an author
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("author-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    // get roles of author
    URI request = UriBuilder.fromUri(getContextURI()).path("/users/" + author.getKey() + "/roles").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    RolesVO roles = conn.parse(response, RolesVO.class);
    Assert.assertNotNull(roles);
    Assert.assertTrue(roles.isAuthor());
    Assert.assertFalse(roles.isGroupManager());
    Assert.assertFalse(roles.isGuestOnly());
    Assert.assertFalse(roles.isInstitutionalResourceManager());
    Assert.assertFalse(roles.isInvitee());
    Assert.assertFalse(roles.isOlatAdmin());
    Assert.assertFalse(roles.isUserManager());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) RolesVO(org.olat.user.restapi.RolesVO) URI(java.net.URI) Test(org.junit.Test)

Example 4 with RolesVO

use of org.olat.user.restapi.RolesVO in project OpenOLAT by OpenOLAT.

the class UserRestClient method createAuthor.

public UserVO createAuthor(String name) throws IOException, URISyntaxException {
    RestConnection restConnection = new RestConnection(deploymentUrl);
    assertTrue(restConnection.login(username, password));
    UserVO user = createUser(restConnection, name, "Auth");
    RolesVO roles = new RolesVO();
    roles.setAuthor(true);
    // update roles of author
    URI request = getUsersURIBuilder().path(user.getKey().toString()).path("roles").build();
    HttpPost method = restConnection.createPost(request, MediaType.APPLICATION_JSON);
    restConnection.addJsonEntity(method, roles);
    HttpResponse response = restConnection.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    restConnection.shutdown();
    return user;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) RestConnection(org.olat.restapi.RestConnection) UserVO(org.olat.user.restapi.UserVO) HttpResponse(org.apache.http.HttpResponse) RolesVO(org.olat.user.restapi.RolesVO) URI(java.net.URI)

Example 5 with RolesVO

use of org.olat.user.restapi.RolesVO in project OpenOLAT by OpenOLAT.

the class UserMgmtTest method testGetRoles.

@Test
public void testGetRoles() throws IOException, URISyntaxException {
    // create an author
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("author-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    // get roles of author
    URI request = UriBuilder.fromUri(getContextURI()).path("/users/" + author.getKey() + "/roles").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    RolesVO roles = conn.parse(response, RolesVO.class);
    Assert.assertNotNull(roles);
    Assert.assertTrue(roles.isAuthor());
    Assert.assertFalse(roles.isGroupManager());
    Assert.assertFalse(roles.isGuestOnly());
    Assert.assertFalse(roles.isInstitutionalResourceManager());
    Assert.assertFalse(roles.isInvitee());
    Assert.assertFalse(roles.isOlatAdmin());
    Assert.assertFalse(roles.isUserManager());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) RolesVO(org.olat.user.restapi.RolesVO) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)6 HttpResponse (org.apache.http.HttpResponse)6 RolesVO (org.olat.user.restapi.RolesVO)6 HttpPost (org.apache.http.client.methods.HttpPost)4 Test (org.junit.Test)4 Identity (org.olat.core.id.Identity)4 HttpGet (org.apache.http.client.methods.HttpGet)2 GroupRoles (org.olat.basesecurity.GroupRoles)2 Roles (org.olat.core.id.Roles)2 RestConnection (org.olat.restapi.RestConnection)2 UserVO (org.olat.user.restapi.UserVO)2