KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > getahead > dwrdemo > filter > RandomSecurityAjaxFilter


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.getahead.dwrdemo.filter;
17
18 import java.lang.reflect.Method JavaDoc;
19
20 import org.directwebremoting.AjaxFilter;
21 import org.directwebremoting.AjaxFilterChain;
22
23
24 /**
25  * An example filter that uses a fairly random event to define it's security
26  * policy: If the current system time (in milliseconds) is even then the call
27  * is allowed, otherwise it is denied.
28  * @author Joe Walker [joe at getahead dot ltd dot uk]
29  */

30 public class RandomSecurityAjaxFilter implements AjaxFilter
31 {
32     /* (non-Javadoc)
33      * @see uk.ltd.getahead.dwr.AjaxFilter#doFilter(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], uk.ltd.getahead.dwr.AjaxFilterChain)
34      */

35     public Object JavaDoc doFilter(Object JavaDoc obj, Method JavaDoc method, Object JavaDoc[] params, AjaxFilterChain chain) throws Exception JavaDoc
36     {
37         if (System.currentTimeMillis() % 2 == 1)
38         {
39             return chain.doFilter(obj, method, params);
40         }
41         else
42         {
43             throw new SecurityException JavaDoc("Wrong time. Try again later");
44         }
45     }
46 }
47
Popular Tags