'How can I allow other applications to access API from my application in Spring?
I have an application in Spring and I want other applications to be able to send data to my application server. I am new to Spring and I don't know how to allow other applications to get/send data to the server through GET/POST request. What changes do I have to make in my Spring Security File.
This is part of my code in Spring security XML file
...
<global-method-security secured-annotations="enabled"/>
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login" access="permitAll" />
<intercept-url pattern="/home" access="isAuthenticated()" />
<intercept-url pattern="/*" access="isAuthenticated()" />
...
This is my API in the controller
@PostMapping(value = "/newBoook")
public ResponseEntity<?> saveLicense(HttpSession session, @RequestBody HashMap<String, JSONObject> bookDetails) throws JsonProcessingException {
if (serviceBookManagement.saveBookDetails(bookDetails)) {
return ResponseEntity.ok("Book has been successfully entered!");
}
return ResponseEntity.badRequest().body(new String("Sorry, there was an error while trying to process the request."));
}
Solution 1:[1]
You need to deploy your API on a Web Server and there are many cases and steps to follow.
- Use a Web Server such as Tomcat : in an embedded mode (a
jarfile) or a server mode (awarfile). - You can deploy your application in a local network or on a cloud provider to expose your API.
- Your API have to be secure also, to avoid your API to be hacked.
There are many aspects you will have to manage, but I think, this is a good beginning.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Harry Coder |
