使用spring security 用户授权的写法

try {
    //授权跳转admin/main
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(sessionUser.getName(), sessionUser.getPwd());
    token.setDetails(new WebAuthenticationDetails(request));
    Authentication authenticatedUser = authenticationManager.authenticate(token);
    SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
    request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());

    return getReturnMap(true,"用户注册成功");
} catch (AuthenticationException e) {
    return getReturnMap(false,"用户授权异常");
    logger.error("----->>>>>[RegCtl.complete]: " + e.getMessage());
}
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注