use of io.gravitee.rest.api.portal.rest.model.UserConfig in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetCurrentUserWithManagementConfigWithUrl.
@Test
public void shouldGetCurrentUserWithManagementConfigWithUrl() {
when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
ConsoleSettingsEntity consoleConfigEntity = new ConsoleSettingsEntity();
Management managementConfig = new Management();
managementConfig.setUrl("URL");
consoleConfigEntity.setManagement(managementConfig);
when(configService.getConsoleSettings()).thenReturn(consoleConfigEntity);
final Response response = target().request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
Mockito.verify(userService).findByIdWithRoles(userId.capture());
assertEquals(USER_NAME, userId.getValue());
User user = response.readEntity(User.class);
assertNotNull(user);
UserConfig config = user.getConfig();
assertNotNull(config);
assertEquals("URL", config.getManagementUrl());
assertNotNull(user.getLinks());
}
use of io.gravitee.rest.api.portal.rest.model.UserConfig in project gravitee-management-rest-api by gravitee-io.
the class UserResource method getCurrentUser.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getCurrentUser() {
final String authenticatedUser = getAuthenticatedUser();
try {
UserEntity userEntity = userService.findByIdWithRoles(authenticatedUser);
User currentUser = userMapper.convert(userEntity);
boolean withManagement = (authenticatedUser != null && permissionService.hasManagementRights(authenticatedUser));
if (withManagement) {
Management managementConfig = this.configService.getConsoleSettings().getManagement();
if (managementConfig != null && managementConfig.getUrl() != null) {
UserConfig userConfig = new UserConfig();
userConfig.setManagementUrl(managementConfig.getUrl());
currentUser.setConfig(userConfig);
}
}
currentUser.setLinks(userMapper.computeUserLinks(userURL(uriInfo.getBaseUriBuilder()), userEntity.getUpdatedAt()));
return Response.ok(currentUser).build();
} catch (final UserNotFoundException unfe) {
response.addCookie(cookieGenerator.generate(null));
return status(Response.Status.UNAUTHORIZED).build();
}
}
Aggregations