While studying about security-constraints and filters in servlets, I made the following declarations in the web.xml file, which didn't work as I expected:
<security-constraint>
<web-resource-collection>
<web-resource-name>BeerSelector</web-resource-name>
<url-pattern>/SelectBeer.do</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>model.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/SelectBeer.do</url-pattern>
</filter-mapping>
According to what I read: filters should be encountered before the request reaches a certain url, so, how come the security-constraint is invoked first ?
I know that it makes sense from a security wise (to reach the filter you mush be authenticated), but I'd like to know the sequence triggered by the request.
Does the container searches first for the secured resources thus it triggers the security-constraint?
But this will contradict with the following paragraph quoted from Head First Servlets and Jsp "
Remember that in the DD, the is about what
happens after the request. In other words, the client has already made
the request when the Container starts looking at the
elements to decide how to respond. The request
data has already been sent over the wire
or maybe the request just triggers both: filter and security-constraint, but the security-constraint is favored over the filter ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…