Spring引导将Rest模板注入到登录筛选器

Spring引导将Rest模板注入到登录筛选器,spring,rest,templates,authentication,ldap,Spring,Rest,Templates,Authentication,Ldap,默认情况下,我的登录过滤器输出如下: "role": "ROLE_ABC", "succeed": "Success!", "id": 123, "username": "111222333", "token": "xxxxx" 现在我想注入rest tempalte的输出,rest模板的输出如下: { "ResponseHeader": { "ErrorCode": "0", "ErrorDescription": "Success", "TrxId":

默认情况下,我的登录过滤器输出如下:

"role": "ROLE_ABC",
"succeed": "Success!",
"id": 123,
"username": "111222333",
"token": "xxxxx"
现在我想注入rest tempalte的输出,rest模板的输出如下:

    {
  "ResponseHeader": {
    "ErrorCode": "0",
    "ErrorDescription": "Success",
    "TrxId": "123"
  },
  "UserInfo": {
    "UserId": "111222333",
    "FullName": ""
  }
}
现在,我想将rest模板的输出注入到我的默认登录过滤器中

这是我的代码,我不知道如何在登录过滤器中发送rest模板的请求体

@Autowired
RestTemplate restTemplate;

@Override
protected void successfulAuthentication(final HttpServletRequest req, final HttpServletResponse res, final FilterChain chain,
        final Authentication auth) throws IOException, ServletException {
    logger.info("successfulAuthentication");
    logger.info(auth);
    Set<String> roles = AuthorityUtils.authorityListToSet(auth.getAuthorities());
            String hasil=roles.toString().replace("[","").replace("]", "");
            AuthenticationService.addToken(res, auth.getName());

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json");
            headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
            headers.setContentType(MediaType.APPLICATION_JSON);
            headers.add("Authorization", "Basic uYycjhow9iJOFOJj=");

            HttpEntity<vwCredentials> entity = new HttpEntity<vwCredentials>(product,headers);
            ->variable "product" is request body,
              i confuse where should i put this code "@RequestBody vwCredentials product"

            ResponseEntity<vwJWTLDAP> respon = restTemplate.exchange(
            "http://123/LDAP/", HttpMethod.POST, entity, vwJWTLDAP.class);

            HashMap<String, Object> map = new HashMap<>();
            String email = auth.getName();
            User user = repository.findByEmail(email);
            map.put("id", user.getId());
            map.put("username", auth.getName());
            map.put("role", hasil);

            //map.put("LDAP", respon); -> I WANT TO CALL LIKE THIS WAY

    map.put("token", AuthenticationService.addToken(auth.getName()));
    map.put("succeed", "Success !");

    String authString = new Gson().toJson(map);


    PrintWriter out = res.getWriter();
    res.setContentType("application/json");
    res.setCharacterEncoding("UTF-8");
    out.print(authString);
    out.flush(); 

}
@Autowired
rest模板rest模板;
@凌驾
受保护的无效成功身份验证(最终HttpServletRequest请求、最终HttpServletResponse请求、最终FilterChain链、,
最终身份验证(auth)引发IOException、ServletException{
logger.info(“成功认证”);
logger.info(auth);
Set roles=AuthorityUtils.authorityListToSet(auth.getAuthories());
字符串hasil=roles.toString().replace(“[”,”).replace(“]”,”);
AuthenticationService.addToken(res,auth.getName());
HttpHeaders=新的HttpHeaders();
headers.set(“内容类型”、“应用程序/json”);
setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add(“Authorization”,“Basic uycjhow9ijofojj=”);
HttpEntity=新的HttpEntity(产品、标题);
->变量“product”是请求主体,
我不知道该将代码“@RequestBody”放在哪里
ResponseEntity respon=restemplate.exchange(
"http://123/LDAP/,HttpMethod.POST,实体,vwJWTLDAP.class);
HashMap=newHashMap();
字符串email=auth.getName();
User=repository.findByEmail(电子邮件);
put(“id”,user.getId());
put(“用户名”,auth.getName());
map.put(“角色”,hasil);
//map.put(“LDAP”,respon);->我想这样打电话
map.put(“token”,AuthenticationService.addToken(auth.getName());
map.put(“Success”,“Success!”);
String authString=new Gson().toJson(map);
PrintWriter out=res.getWriter();
res.setContentType(“应用程序/json”);
res.setCharacterEncoding(“UTF-8”);
out.print(authString);
out.flush();
}
}

我怎么能这样打电话//map.put(“LDAP”,respon);->我想这样打电话

您可以使用
getBody()
方法执行此操作。此方法是从类继承的

也就是说,获取它的一种方法是
map.put(“LDAP”,respon.getBody())

lass

您可以使用
getBody()
方法执行此操作。此方法是从类继承的


也就是说,获取它的一种方法是
map.put(“LDAP”,respon.getBody())

当然,我添加getBody()时仍然出现错误,因为我没有发送此行中的产品变量HttpEntity entity=new HttpEntity(product,headers);->变量“product”是请求体,我不知道应该把代码放在哪里“@RequestBody vwCredentials product”这是控制器的一部分,应该来自调用API的客户端。这是在主体中接收到的,然后您可以将其作为参数发送到您的服务。例如,它可能是这样的
@GetMapping(value=“/example”)public void方法(@RequestBody receivedBody){someService.someMethod(receivedBody)}
对不起,我仍然丢失了。你有什么推荐信吗?因此,我可以阅读如何实现它?当然,我添加getBody()时仍然出现错误,因为我没有在这一行中发送产品变量HttpEntity entity=new HttpEntity(product,headers);->变量“product”是请求体,我不知道应该把代码放在哪里“@RequestBody vwCredentials product”这是控制器的一部分,应该来自调用API的客户端。这是在主体中接收到的,然后您可以将其作为参数发送到您的服务。例如,它可能是这样的
@GetMapping(value=“/example”)public void方法(@RequestBody receivedBody){someService.someMethod(receivedBody)}
对不起,我仍然丢失了。你有什么推荐信吗?所以我可以阅读如何实现它?