Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable post service call from client using spring rest security x509 authentication #1

Open
KMani1992 opened this issue May 2, 2018 · 0 comments

Comments

@KMani1992
Copy link

I have tried to enable post service call from REST client using spring rest security x509 authentication, but it throws below exception

"exception": "org.springframework.web.client.HttpClientErrorException",
"message": "403 null"
#I have referred this repository
https://github.com/chathurangat/spring-rest-security-x509-authentication

Any one can help to resolve the issue, thanks in advance

#Client Side Request Program
// configuring the keyStore and trustStore for the client application System.setProperty("javax.net.ssl.keyStore", "src/main/resources/clientkeystore.p12"); System.setProperty("javax.net.ssl.keyStorePassword", "3edc4rfv"); System.setProperty("javax.net.ssl.trustStore", "src/main/resources/clienttruststore.p12"); System.setProperty("javax.net.ssl.trustStorePassword", "3edc4rfv");

RestTemplate template=new RestTemplate();        
DTO dto=new DTO();
dto.setName("KMK");
RequestEntity request=null;
try {
    request = RequestEntity.post(new URI("https://localhost:8443/logged_info_post")).accept(MediaType.APPLICATION_JSON).body(dto);
} catch (URISyntaxException e) {        
    e.printStackTrace();
}
ResponseEntity<String> response = template.exchange(request, String.class);
return response.getBody();

#Server Side Program
@RequestMapping(value = "/logged_info_post", method = RequestMethod.POST ) public @responsebody String helloController_post(@requestbody DTO dto) { String loggedUser; Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

if (principal instanceof UserDetails) {
    loggedUser = ((UserDetails) principal).getUsername();
} else {
    loggedUser = principal.toString();
}
return "X.509 authentication done! REST client has been identified as ["+loggedUser+"] " + dto.getName();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant