| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.business; |
| 16 | |
| 17 | import net.sourceforge.hiveboard.Board; |
| 18 | import net.sourceforge.hivelock.SecurityException; |
| 19 | |
| 20 | final public class SecurityChecks |
| 21 | { |
| 22 | private SecurityChecks() |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | static public void checkError(String error) |
| 27 | { |
| 28 | if (error != null) |
| 29 | { |
| 30 | throw new SecurityException(error); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | static public void checkWriter(int who, Board board, String error) |
| 35 | { |
| 36 | if (board.getWriter() != who) |
| 37 | { |
| 38 | throw new SecurityException(error); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | static public void checkNotInitiator(int who, Board board, String error) |
| 43 | { |
| 44 | if (board.getInitiator() == who) |
| 45 | { |
| 46 | throw new SecurityException(error); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | static public void checkEmptyBoard(Board board, String error) |
| 51 | { |
| 52 | if (!board.getPresents().isEmpty()) |
| 53 | { |
| 54 | throw new SecurityException(error); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | static public void checkParticipant(int who, Board board, String error) |
| 59 | { |
| 60 | if (!board.getParticipants().contains(who)) |
| 61 | { |
| 62 | throw new SecurityException(error); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | static public void checkPresent(int who, Board board, String error) |
| 67 | { |
| 68 | if (!board.getPresents().contains(who)) |
| 69 | { |
| 70 | throw new SecurityException(error); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | static public void checkInitiator(int who, Board board, String error) |
| 75 | { |
| 76 | if (board.getInitiator() != who) |
| 77 | { |
| 78 | throw new SecurityException(error); |
| 79 | } |
| 80 | } |
| 81 | } |