Reputation: 1680
I'm developing a Java app to be deployed on Google App Engine. Google App Engine allows me to include a web.xml file in my WEB-INF folder in which I can configure different levels of auth for different URLs.
If I want only admin users to be able to access the foobar URL, I can use this config:
<security-constraint>
<web-resource-collection>
<web-resource-name>aname</web-resource-name>
<url-pattern>/foobar/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
If I want any users - even unauthenticated users - to be able to access the foobar URL, I can use this config:
<security-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Here's the problem. In my test environment, I would like to authorize only admins to access foobar. But in my production environment, I would like to allow all users (included unauthenticated users) to access foobar. How can I achieve this? How can I change the web.xml config per environment?
Upvotes: 0
Views: 190
Reputation: 1680
I decided to implement a solution similar to what Vikram suggested, but slightly different.
Rather than having a single web.xml file in my WEB-INF folder:
- WEB-INF
+ web.xml
I instead created two folders (one for each environment) in my WEB-INF folder:
- WEB-INF
+ local
| + web.xml
+ prod
+ web.xml
Now, in order for Google App Engine to pick up the config file, it needs to be located in WEB-INF, not in the subdirectories I've created. Therefore, during the build, I use the Maven War Plugin to copy the files from one of the two folders into the parent folder.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF/${configDirectory}</directory>
<filtering>false</filtering>
<targetPath>WEB-INF</targetPath>
<includes>
<include>web.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
And I use Maven Profiles to specify the name of the folder containing the files which I want to actually use.
<profiles>
<profile>
<id>local</id>
<properties>
<configDirectory>local</configDirectory>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<configDirectory>prod</configDirectory>
</properties>
</profile>
</profiles>
So, the web.xml file gets copied from the correct subdirectory to the parent directory, thereby allowing me to control which config gets used each time I build the app.
Upvotes: 1
Reputation: 1028
You can keep different web.xml for each environments and replace while deploying into each environment.
E.g web_dev.xml, web_test.xml, web_prod.xml Replace web_prod.xml to web.xml
Upvotes: 1