Reputation: 65
I've got two servers, lets call them server 1 and server 2. There is a web application on server 2, that, lets say, shows posts. This application is available on http://www.2.com/showPosts and everybody can access this page. This application also enables to remotely add posts. To do that you have to go to page http://www.2.com/addPost and fill a form.
What I'd like to do is to restrict access to this second page (/addPost) to only one single machine, that is server 1, so that only I can enter this page and fill this form, and everyone else gets 404. How to accomplish that?
edit: Thank you for your answers. I've done some more reading based on them and now can make my question a little more precise. What I exactly need to do is to authenticate a client by server, whis is the opposite of one-way ssl authentication, where you authenticate a server by a client. I think that any kind of ip based authentication is way too weak and I need some kind of a certificate.
Upvotes: 1
Views: 444
Reputation: 2539
If it is a Tomcat server you can define a filter in web.xml that will filter request only from allowed source.
Upvotes: 0
Reputation: 1170
You could use a .htaccess
file in the root directory:
<Directory AddPost>Allow from www.1.com</Directory>
This only lets www.1.com
access the page. If AddPost
is a file, use <Files AddPost></Files>
.
Hope this helps!
Upvotes: 1
Reputation: 7251
I suppose you are using Apache Web Server, then you can configure a virtual host and set an access rule to deny from all, allow from server1. Here the documentation.
Upvotes: 0
Reputation: 17955
You can also restrict the addPost address to localhost-only, and establish an ssh tunnel for update purposes.
Upvotes: 0
Reputation: 34920
ServletRequest#getRemoteAddr()
returns you the IP of the client that sent the request. You could filter such requests by matching client's IP. For the other clients you can for example redirect to predefined 404 error
page.
Upvotes: 0
Reputation: 10161
Protect your http://www.2.com/addPost with a cerificate only present in the Browser on the one single machine.
Upvotes: 0