Search in sources :

Example 1 with TokenTransfer

use of com.weibo.model.TokenTransfer in project motan by weibocom.

the class UserController method authenticate.

@RequestMapping(value = "/authenticate", method = RequestMethod.POST)
public TokenTransfer authenticate(@RequestParam("username") String username, @RequestParam("password") String password) {
    UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
    Authentication authentication = authManager.authenticate(authenticationToken);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    UserDetails userDetails = userDetailsService.loadUserByUsername(username);
    return new TokenTransfer(TokenUtils.createToken(userDetails));
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) TokenTransfer(com.weibo.model.TokenTransfer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

TokenTransfer (com.weibo.model.TokenTransfer)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1