There is a method

@RequestMapping(value = "updateEquip", method = RequestMethod.POST) public ModelAndView updateEquipment(@ModelAttribute("equipment") Equipment equipment, BindingResult result) { ModelAndView model = new ModelAndView(); user = userService.findByUserName(equipment.getUser().getUsername()); equipment.setUser(user); equipmentService.update(equipment); model.addObject("allEquip", equipmentService.getAllEquipments()); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); User user = userService.findByName(name); Set<UserRole> allRoles = user.getUserRole(); for (UserRole userRole : allRoles) { authRole = userRole.getRole(); } if (authRole == "ROLE_ADMIN") { model.setViewName("redirect: superAdmin"); } else if (authRole == "ROLE_ACCAUNT") { model.setViewName("redirect: accaunt"); }else { model.setViewName("redirect: login"); } return model; } 

If separately I send authRole to the page, then the value is correctly displayed depending on the role. And in this method, the condition does not work, with any authorization, it goes to the login page.

Why it does not go to the page if the condition is met?

    1 answer 1

    You do not properly compare strings.

    == compares the links, namely if they point to the same object .

    You should use the equals method, which compares objects based on their content.

    • Thank. You're right. And the second day could not understand the problem. - Farik013