Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.annotation.Secured;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.List;
- @RestController
- @RequestMapping("/register")
- public class RegisterController {
- @Autowired
- private RegisterService registerService;
- @Autowired
- private UserDao userDao;
- private void setRegisterService(RegisterService registerService) {
- this.registerService = registerService;
- }
- @RequestMapping("/add/user")
- public void register(String username, String password) {
- if (username == null || username == "") {
- System.err.println("Input is invalid!");
- return;
- }
- if (password == null || password == "") {
- System.err.println("Input is invalid!");
- return;
- }
- List<User> list = registerService.getUsers();
- synchronized (list) {
- for (int i = 0; i < list.size(); i++) {
- if (list.get(i).username == username) {
- System.err.println("Input is invalid!");
- return;
- }
- }
- }
- System.out.println("Registering user...");
- synchronized (registerService) {
- registerService.register(username, password);
- }
- }
- @Secured({"DELETE_USERS"})
- @RequestMapping("/delete")
- public void delete(String username, String password) {
- if (username == null || username == "") {
- System.err.println("Username is invalid!");
- return;
- }
- userDao.delete(userDao.findById(username));
- }
- @Secured({"allow-user-listing"})
- @RequestMapping("/")
- public List rootPathMapping() {
- return registerService.getUsers();
- }
- }
Add Comment
Please, Sign In to add comment