Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:18:00+00:00 2026-05-31T18:18:00+00:00

I am looking for a way to login/logout users with DWR, so that I

  • 0

I am looking for a way to login/logout users with DWR, so that I could just create a DWR bean with methods login and logout.

public class AuthorizationHandler {

    @Autowired
    private UserRepository userRepository;


    public Map<String, String> loginUser(String userName, String password) {
        Map<String, String> map = new HashMap<>();
        if (userRepository.validate(userName, password)) {
            // login the user here       
            map.put("success", true);
            map.put("redirect", ...);
        } else {
            map.put("success", false);
        }
        return map;
    }


    public Map<String, String> logoutUser() {
        // logout the user here
        Map<String, String> map = new HashMap<>();
        map.put("success", "ok");
        return map;
    }
}

My problem is that I can’t find a way to work with users and to log them in/out programmatically. All the tutorial uses xml based configuration, but what is behind is sort of hidden.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:18:01+00:00Added an answer on May 31, 2026 at 6:18 pm

    In one of my application I had a similar requirement, please find the steps I followed

    public void authenticateSession(HttpSession session, UserDetails user) {
        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
                user.getUsername(), user.getPassword());
        UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(
                user, authRequest.getCredentials(), user.getAuthorities());
        result.setDetails(authRequest.getDetails());
    
        SecurityContext ctx = SecurityContextHolder.createEmptyContext();
        ctx.setAuthentication(result);
    
        session.setAttribute(
                UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY,
                TextEscapeUtils.escapeEntities(user.getUsername()));
        session.setAttribute(
                HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
                ctx);
    
        AuthenticationSuccessEvent event = new AuthenticationSuccessEvent(
                result);
        applicationContext.publishEvent(event);
    }
    

    This method authenticates the passed session with the passed user object.

    In your case you have to obtain the UserDetails object and pass it to this method along with the current session.

    You can use the UserDetailsService interface to load the UserDetails.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for an easy way to create logins and associated users into
I'm looking to create a site that will utilize our Active Directory login system.
I am looking for the best way to check that a database login exists
I am looking for a way to make my own login formular in PHP
I am looking for scalable way to do the following: User login Fetch all
I am looking for the best way to do a One Time Login for
I'm looking for way to create list view as like in IOS with pinned
I'm looking for a way to work with an API which requires login, and
I'm looking for a way to add properties to my already defined class at
I'm looking for a way for users to be able to connect to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.