in Education by
In my application when the current logged in user's usernam is changed i want to update the UserDetails principal for the current user. How can I do that? I'm getting the current username by following method : public UserDetails getSystemUser(){ try { UserDetails principal = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return principal; }catch (ClassCastException e){ return null; } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
To my knowledge there is no setusername method for this. Keep in mind this solution is untested it might or not work. So first clearcontext. Then create a new empty context and set the newly created authentication object with the updated username and all OTHER INFO needed. @ 'newusername' you should set your new updated username string or your customuserdetails object with your new updated username and all other info. Authentication oldAuthenticationObject = SecurityContextHolder.getContext().getAuthentication(); SecurityContextHolder.clearContext(); SecurityContext context = SecurityContextHolder.createEmptyContext(); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( NEWUSERNAME, null, oldAuthenticationObject.getAuthorities()); context.setAuthentication(authentication); SecurityContextHolder.setContext(context);

Related questions

0 votes
    Rather than rewriting the entire contents of an xml file when a single element is updated, is there a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 26, 2022 in Education by JackTerrance
0 votes
    Which of these package is used for graphical user interface? (a) java.applet (b) java.awt (c) java.awt. ... & Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    How can we take input text from user in HTML page? (a) input tag (b) inoutBufferedReader tag (c) meta ... & Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    I have to Update the Xml document object generated using Apache XMLbeans.There are two ways I am trying to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    Which of these methods calls update() method? (a) notify() (b) observeObject() (c) updateObserver() (d) ... Utility Classes of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    I would like to display a twitter user profile without having the app prompt the phone user for creating an ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Which of these methods can be used to know the degree of adjustment made by the user? (a) getValue() (b ... Event Handling of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    Which method creates unique fields in the HTML which are not shown to the user? (a) User authentication (b) URL ... JSP & API of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    this is my first question here, i hope you can help me. I've been trying to get a specific path ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    this is my first question here, i hope you can help me. I've been trying to get a specific path ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have a custom PyPi package. It is installed under Pyhon\Python38\Lib\site-packages\myCustomPackage. In the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I know that the name of the user account can be retrieved from the built in variable User!UserID but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
0 votes
    I recently moved my website to a shared hosting solution at asmallorange.com, but I had to set my ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
...