简体   繁体   中英

Spring messaging + security how to login throught websockets?

I am developing a server with spring-messaging and STOMP over sockJs. I want to make authorization trhought websockets. So from client i did send some token, then i get needle user by token and i want to associate my session with this user, i did next:

private void authorizeUser(Profile profile) {

    SignedUser signedUser = new SignedUser(profile);
    List<GrantedAuthority> authorities = Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));

    UsernamePasswordAuthenticationToken authentication =
            new UsernamePasswordAuthenticationToken(signedUser, null, authorities);


    SecurityContextHolder.getContext().setAuthentication(authentication);
}

But session is not associated, can anyone help me with this issue?

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM