Information
Protect web applications by configuring security constraints for all web resources using either deployment descriptor and/or annotations.
Specifying security constraints allows fine grained access control to protected resources. This can be done either using deployment descriptor and/or annotations.
Solution
Set <security-constraint> elements in the web.xml deployment descriptor file of each application or use annotations in the code.Example using security-constraint:
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>testing</role-name>
</auth-constraint>
</security-constraint>
Example using annotations:
@WebServlet("/myServlet")
@ServletSecurity(
httpMethodConstraints = {
@HttpMethodConstraint(value = "GET", rolesAllowed = "user"),
@HttpMethodConstraint(value = "POST", rolesAllowed = "manager",
transportGuarantee = TransportGuarantee.CONFIDENTIAL),
}
)
public class myServlet extends HttpServlet {
// servlet code...
}