Commit bf8ce944 authored by Alexander Dolzhenko's avatar Alexander Dolzhenko
Browse files

add methods for user details

parent 6e5a7c20
......@@ -28,6 +28,7 @@ import org.genesys2.server.service.OAuth2ClientDetailsService;
import org.genesys2.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.ClientDetails;
......@@ -43,6 +44,9 @@ public class OAuthManagementController extends RequestsController {
final static String CLAZZ = OAuthClientDetails.class.getName();
@Value("${base.url}")
private String baseUrl;
@Autowired
protected UserService userService;
......@@ -111,7 +115,7 @@ public class OAuthManagementController extends RequestsController {
@PreAuthorize("hasAnyRole('VETTEDUSER','ADMINISTRATOR')")
@RequestMapping(value = "/save-client", method = RequestMethod.POST)
@ResponseBody
public String createClientEntry(@RequestBody OAuthClientDetails requestClient) {
public String saveClientEntry(@RequestBody OAuthClientDetails requestClient) {
OAuthClientDetails clientDetails;
......@@ -213,4 +217,32 @@ public class OAuthManagementController extends RequestsController {
}
@RequestMapping(value = "/client/{clientId:.+}/get_widget")
@PreAuthorize("hasRole('ADMINISTRATOR')")
@ResponseBody
public Object getWidget(@PathVariable(value = "clientId") String clientId) {
Map<String, Object> resultMap = new HashMap<>();
if (!clientId.equals("")) {
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId);
String script =
"<script>(function(d, s, id) {\n" +
"var js, gjs = d.getElementsByTagName(s)[0];\n" +
"if (d.getElementById(id)) return;\n" +
"js = d.createElement(s); js.id = id;\n" +
"js.src = '" + baseUrl + "/webapi/genesys-webapi.js?client_id=" + clientDetails.getClientId() + "&client_secret=" + clientDetails.getClientSecret() + "';\n" +
"gjs.parentNode.insertBefore(js, gjs);\n" +
"}(document, 'script', 'genesys-api'));</script>";
resultMap.put("client", clientDetails);
resultMap.put("script", script);
}
List<OAuthClientDetails> clientDetailses = clientDetailsService.listClientDetails();
resultMap.put("clientDetails", clientDetailses);
return resultMap;
}
}
......@@ -20,7 +20,9 @@ import org.apache.commons.lang.StringUtils;
import org.genesys2.server.exception.NotUniqueUserException;
import org.genesys2.server.exception.UserException;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.EMailVerificationService;
import org.genesys2.server.service.OAuth2ClientDetailsService;
import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.UserService;
import org.genesys2.server.servlet.controller.rest.model.UserChangedDataJson;
import org.genesys2.server.servlet.model.UserList;
......@@ -35,10 +37,12 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@Controller("restUsersController")
@PreAuthorize("isAuthenticated()")
@PreAuthorize("isAuthenticated() && hasRole('ADMINISTRATOR')")
@RequestMapping(value = {"/api/v0/users", "/json/v0/users"})
public class UsersController extends RestController {
......@@ -51,32 +55,37 @@ public class UsersController extends RestController {
@Autowired
private OAuth2ClientDetailsService clientDetailsService;
@Autowired
private EMailVerificationService emailVerificationService;
@Autowired
private TeamService teamService;
@RequestMapping(value = "", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Object getUsers(@RequestParam(value = "startRow", required = false, defaultValue = "0") Integer startRow,
public Object getUsers(@RequestParam(value = "startRow", required = false, defaultValue = "0") Integer startRow,
@RequestParam(value = "pageSize", required = false, defaultValue = "0") Integer pageSize) throws UserException {
return new UserList(userService.listWrapped(startRow, pageSize));
}
@RequestMapping(value = "/available_roles", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Object getAvailableRoles() throws UserException {
return userService.listAvailableRoles();
}
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Object getUser(@PathVariable Long id) throws UserException {
return userService.getUserById(id);
Map <String, Object> resultMap = new HashMap<>();
User user = userService.getUserById(id);
resultMap.put("user", user);
resultMap.put("userTeams", teamService.listUserTeams(user));
return resultMap;
}
@RequestMapping(value = "/user/uuid/{id:.+}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Object getUserByUuid(@PathVariable String id) throws UserException {
return userService.getUserByUuid(id);
}
......@@ -99,7 +108,6 @@ public class UsersController extends RestController {
@RequestMapping(value = "/user/data", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
@PreAuthorize("hasRole('ADMINISTRATOR')")
public String updateData(@RequestBody UserChangedDataJson userData) {
final User user = userService.getUserByUuid(userData.getUuid());
......@@ -128,7 +136,6 @@ public class UsersController extends RestController {
@RequestMapping(value = "/user/roles", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
@PreAuthorize("hasRole('ADMINISTRATOR')")
public String updateRoles(@RequestBody UserChangedDataJson userData) {
final User user = userService.getUserByUuid(userData.getUuid());
if (user == null) {
......@@ -139,5 +146,22 @@ public class UsersController extends RestController {
return JSON_OK;
}
@RequestMapping(value = "user/{uuid:.+}/send", method = RequestMethod.GET)
@ResponseBody
public String sendEmail(@PathVariable("uuid") String uuid) {
final User user = userService.getUserByUuid(uuid);
emailVerificationService.sendVerificationEmail(user);
return JSON_OK;
}
@RequestMapping("user/{uuid:.+}/vetted-user")
@ResponseBody
public String addRoleVettedUser(@PathVariable("uuid") String uuid) {
userService.addVettedUserRole(uuid);
return JSON_OK;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment