-2

I'm using Wicket 7.0 in an application I'm developing and I would like some advice regarding using Inmemory-users during development.

The idea is to have one single Inmemory user whom I set the roles of right before I log in.

My first intended approach is to instantiate the user at startup with "username" and password but without any roles. Then I would like to add/remove roles through ticking Checkboxes in a component in the Login-form and finally log in with the predefined user/pwd.

Can an instance of an Inmemory-user have it's roles changed when the application is running? Or should I delete it and create a new instance of it everytime I want it to have different roles? Is this even the best and simplest way to go about ti?

This is only during development for convenience.

Thanks in advance

Axel L
  • 1

1 Answers1

0

Inject UserDetailsManager and use its updateUser() method to update its roles:

@Service
public class SingleUserSwitchService {
    @Autowired
    private UserDetailsManager userDetailsManager;

    public void changeUserRoles(String ... roles) {
        Collection<GrantedAuthority> roles = ... // new roles
        User user = new User("login", "password", roles);
        userDetailsManager.updateUser(user);
    }
}

Here, I assume that your user login is 'login' and you hardcode the password.

Then you just need to call your service with the list of the desired roles.

Roman Puchkovskiy
  • 11,415
  • 5
  • 36
  • 72