tomcat - How to restrict access to certain URLs a specific port? -


my web configuration declares 3 connectors, http on port 8080 , https on ports 8081 , 8082.

in servlet want restrict access urls patterns specific port, e.g. request /admin should rejected unless on port 8082. quite simple, can check port number in service method of servlet.

but need able allow customer change ports. if customer wants admin requests allowed on port 9000 (instead of 8083) strategy fails.

one approach can think of add additional attribute connector in server.xml , access in servlet. possible?

to elaborate, want add following in server.xml

<connector port="9000" connectortype="admin".... 

and somehow programmatic in servlet follows. realize getconnectorproperties not exist, example.

 if (request.getrequesturl().startswith("/admin")) {    string connectortype = request.getconnectionproperties().get("connectortype");    if (! "admin".equals(connectortype)) {      // return unauthorized 

any other suggestions how can address this?

it seems you're using different context roots (=apps) different ports. shouldn't done programmatically. applications accept different ports or protocols configured in server.xml different service components:

<server>     <!-- define 1 service open app -->     <service name="myopenapp">         <connector port="8080"/>         <engine name="myopenapp" defaulthost="localhost">             <host name="localhost"> <!-- default appbase webapps -->                 <context docbase="path/to/my/open/app"/>                 <!-- docbase relative appbase may refer absolute path -->             </host>         </engine>     </service>      <!-- , restricted -->     <service name="onlyforadmins">         <connector port="8081" sslenabled="true" scheme="https"/>         <connector port="8082" sslenabled="true" scheme="https"/>         <engine name="onlyforadmins" defaulthost="localhost">             <host name="localhost"> <!-- default appbase webapps -->                 <context docbase="path/to/admins/only"/>                 <!-- docbase relative appbase may refer absolute path -->             </host>         </engine>     </service> </server> 

note minimalistic example.

if need more complex url patterns can use web.xmls of applications (servlet-mappings , such).

and basically, isn't authorization error... it's unmapped url. applications don't support admin resources on non-ssl ports. you'll 404 page not found.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -