Sunday, January 11, 2009

Authorization filter

A fastest way for setting an authorized access to your files - Authorization filter. Just one declaration in your web.xml file, describes user name/password pair:

<filter>
  <filter-name>AuthFilter</filter-name>
  <filter-class>com.cj.auth.AuthFilter</filter-class>
  <init-param>
    <param-name>name</param-name>
    <param-value>guest</param-value>
  </init-param>
  <init-param>
    <param-name>password</param-name>
    <param-value>12345</param-value>
  </init-param>
</filter>

and now just map this filter to some directory (file) you are going to protect:

<filter-mapping>
  <filter-name>AuthFilter</filter-name>
  <url-pattern>/closed/*.jsp</url-pattern>
</filter-mapping>

No comments: