1 /*
2 * SymmetricDS is an open source database synchronization solution.
3 *
4 * Copyright (C) Keith Naas <knaas@users.sourceforge.net>
5 *
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see
19 * <http://www.gnu.org/licenses/>.
20 */
21 package org.jumpmind.symmetric.transport.handler;
22
23 import org.jumpmind.symmetric.service.INodeService;
24
25 public class AuthenticationResourceHandler extends AbstractTransportResourceHandler {
26
27 public enum AuthenticationStatus {
28 REGISTRATION_REQUIRED, FORBIDDEN, ACCEPTED;
29 };
30
31 private INodeService nodeService;
32
33 public AuthenticationStatus status(String nodeId, String securityToken) {
34 AuthenticationStatus retVal = AuthenticationStatus.ACCEPTED;
35
36 if (!nodeService.isNodeAuthorized(nodeId, securityToken)) {
37 if (nodeService.findNode(nodeId) == null) {
38 retVal = AuthenticationStatus.REGISTRATION_REQUIRED;
39 } else {
40 retVal = AuthenticationStatus.FORBIDDEN;
41 }
42 }
43 return retVal;
44 }
45
46 public void setNodeService(INodeService nodeService) {
47 this.nodeService = nodeService;
48 }
49
50 }