OSDN Git Service

bfb54fc6b39055136e2104bc2a8163bfc4ed1758
[rabbit-bts/RabbitBTS.git] / src / jp / sourceforge / rabbitBTS / controllers / BaseController.java
1 /*
2    Copyright 2009 senju@users.sourceforge.jp
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
17 package jp.sourceforge.rabbitBTS.controllers;
18
19 import org.springframework.validation.BindingResult;
20
21 /**
22  * Rabbit BTS用基底コントローラ
23  */
24 public abstract class BaseController implements IController {
25
26         private boolean csrfSafe;
27         boolean csrfChecked;
28
29         /**
30          * CSRF安全か返す。
31          * <p>
32          * POSTを扱うコントローラは必ずこのメソッドを使用しチェックしなければならない。
33          * 
34          * @param result
35          *            エラーメッセージセット用
36          * @return CSRF安全(処理続行可能)な場合trueを返す。
37          */
38         protected final boolean isCsrfSafe(BindingResult result) {
39                 if (!this.csrfSafe) {
40                         result.reject("csrf.detect");
41                 }
42                 this.csrfChecked = true;
43                 return this.csrfSafe;
44         }
45
46         protected final boolean isCsrfSafe() {
47                 this.csrfChecked = true;
48                 return this.csrfSafe;
49         }
50
51         @Override
52         public final void setCsrfSafe(boolean csrfSafe) {
53                 this.csrfSafe = csrfSafe;
54                 this.csrfChecked = false;
55         }
56
57         /**
58          * @return the csrfChecked
59          */
60         @Override
61         public final boolean isCsrfChecked() {
62                 return this.csrfChecked;
63         }
64
65 }