Jhipster 踩过的坑

本贴最后更新于 2679 天前,其中的信息可能已经东海扬尘

1)

Description:

Field userRepository in com.ejtone.ejt1.security.UserDetailsService required a bean of type 'com.ejtone.ejt1.repository.UserRepository' that could not be found.

Action:

Consider defining a bean of type 'com.ejtone.ejt1.repository.UserRepository' in your configuration.

因为修改的包名,并未全部修改掉

2)

无法加载主类
方法:mvn -N io.takari:maven:wrapper

3)

Spring Secruity 和 JWT
登录操作是有两次请求完成,在把 Token 传给前端后需要前端带着这个 Token 来认证权限

@PostMapping("/users/quicklogin")
    @Timed
    public ResponseEntity<?> authorizeByQuick(@Valid @RequestBody PhoneVM phoneVM, HttpServletResponse response) {

        if(codisService.compareCode(phoneVM.getPhone(),phoneVM.getCode())){

            User user=userRepository.findOneByPhone(phoneVM.getPhone()).get();
            List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
            grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));

            UsernamePasswordAuthenticationToken authenticationToken =
                new UsernamePasswordAuthenticationToken(user.getLogin(), null,grantedAuths);
            authenticationToken.setDetails(user);
//            Authentication authentication = this.authenticationManager.authenticate(authenticationToken);
            SecurityContextHolder.getContext().setAuthentication(authenticationToken);
            boolean rememberMe = (phoneVM.isRememberMe() == null) ? false : phoneVM.isRememberMe();

            String jwt = tokenProvider.createToken(authenticationToken, rememberMe);
            response.addHeader(JWTConfigurer.AUTHORIZATION_HEADER, "Bearer " + jwt);
            return ResponseEntity.ok(new JWTToken(jwt));
        }else {
            return new ResponseEntity<Object>("code not true",HttpStatus.BAD_REQUEST);
        }
    }

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...