Skip to content

Commit 0b98f0d

Browse files
buddhini81adamd1985
authored andcommitted
Code changes related to modifications in section 7 of the article (eugenp#1641)
* Change @ServletSecurity annotation to reflect usage of 2 different roles * Modification related to @ServletSecurity * Add new folder WEB-INF * Delete .gitkeep * Create web.xml inside WEB-INF * Update web.xml * Deleting this as its moved in to WEB-INF
1 parent d21d7a1 commit 0b98f0d

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎jee7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/README.txt‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ NOTES: @WebServlet annotation designates the AccountServlet class as a Servlet c
1212
An initialization parameter 'type' is being set to denote the type of the bank account.
1313

1414
@ServletSecurity annotation imposes security constraints on the AccountServlet based on
15-
the tomcat-users.xml (this code assumes there is a role 'admin' in your tomcat-users.xml)
16-
15+
the tomcat-users.xml.
16+
 
17+
This code assumes that your tomcat-users.xml looks as follows:
18+
19+
<role rolename="Admin"/>
20+
<role rolename="Member"/>
21+
<role rolename="Guest"/>
22+
<user username="Annie" password="admin" roles="Admin, Member, Guest" />
23+
<user username="Diane" password="coder" roles="Member, Guest" />
24+
<user username="Ted" password="newbie" roles="Guest" />
25+
 
1726
N.B : To see @ServletSecurity annotation in action, please uncomment the annotation code
1827
for @ServletSecurity.
1928

‎jee7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/src/main/java/com/baeldung/javaeeannotations/AccountServlet.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
initParams = { @WebInitParam(name = "type", value = "savings") }
1818
)
1919
/*@ServletSecurity(
20-
value = @HttpConstraint(rolesAllowed = {"admin"}),
21-
httpMethodConstraints = {@HttpMethodConstraint(value = "POST", rolesAllowed = {"admin"})}
20+
value = @HttpConstraint(rolesAllowed = {"Member"}),
21+
httpMethodConstraints = {@HttpMethodConstraint(value = "POST", rolesAllowed = {"Admin"})}
2222
)*/
2323
public class AccountServlet extends javax.servlet.http.HttpServlet {
2424

jee7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/src/main/webapp/web.xml renamed to jee7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/src/main/webapp/WEB-INF/web.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
<auth-method>BASIC</auth-method>
88
<realm-name>default</realm-name>
99
</login-config>
10-
11-
</web-app>
10+
</web-app>

0 commit comments

Comments
 (0)