Skip to content

Commit

Permalink
0003126: Support viewing Remote Status of Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmichalek committed Jun 7, 2017
1 parent 8fbdf9a commit 33d1559
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
Expand Up @@ -41,6 +41,10 @@
* information.
*/
public interface INodeService {

public enum AuthenticationStatus {
SYNC_DISABLED, REGISTRATION_REQUIRED, FORBIDDEN, ACCEPTED;
};

public Node findNode(String nodeId);

Expand Down Expand Up @@ -209,5 +213,7 @@ public void ignoreNodeChannelForExternalId(boolean ignore, String channelId,

public List<String> getTablesFromTableMetaInfo(String nodeGroupId, String catalog, String schema);

public AuthenticationStatus getAuthenticationStatus(String nodeId, String securityToken);


}
Expand Up @@ -1022,5 +1022,26 @@ public NodeHost mapRow(Row rs) {
return nodeHost;
}
}

public AuthenticationStatus getAuthenticationStatus(String nodeId, String securityToken) {
AuthenticationStatus retVal = AuthenticationStatus.ACCEPTED;
Node node = findNode(nodeId, true);
if (node == null) {
retVal = AuthenticationStatus.REGISTRATION_REQUIRED;
} else if (!syncEnabled(node)) {
retVal = AuthenticationStatus.SYNC_DISABLED;
} else if (!isNodeAuthorized(nodeId, securityToken)) {
retVal = AuthenticationStatus.FORBIDDEN;
}
return retVal;
}

protected boolean syncEnabled(Node node) {
boolean syncEnabled = false;
if (node != null) {
syncEnabled = node.isSyncEnabled();
}
return syncEnabled;
}

}
Expand Up @@ -355,4 +355,9 @@ public List<String> getTablesFromTableMetaInfo(String nodeGroupId, String catalo
// TODO Auto-generated method stub
return null;
}

@Override
public AuthenticationStatus getAuthenticationStatus(String nodeId, String securityToken) {
return null;
}
}
Expand Up @@ -27,8 +27,8 @@
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.service.INodeService;
import org.jumpmind.symmetric.service.INodeService.AuthenticationStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,10 +39,6 @@ public class AuthenticationInterceptor implements IInterceptor {

Logger log = LoggerFactory.getLogger(getClass());

public enum AuthenticationStatus {
SYNC_DISABLED, REGISTRATION_REQUIRED, FORBIDDEN, ACCEPTED;
};

private INodeService nodeService;

public AuthenticationInterceptor(INodeService nodeService) {
Expand All @@ -59,7 +55,7 @@ public boolean before(HttpServletRequest req, HttpServletResponse resp) throws I
return false;
}

AuthenticationStatus status = getAuthenticationStatus(nodeId, securityToken);
AuthenticationStatus status = nodeService.getAuthenticationStatus(nodeId, securityToken);

if (AuthenticationStatus.ACCEPTED.equals(status)) {
log.debug("Node '{}' successfully authenticated", nodeId);
Expand All @@ -83,25 +79,4 @@ public void after(HttpServletRequest req, HttpServletResponse res) throws IOExce
ServletException {
}

protected AuthenticationStatus getAuthenticationStatus(String nodeId, String securityToken) {
AuthenticationStatus retVal = AuthenticationStatus.ACCEPTED;
Node node = nodeService.findNode(nodeId, true);
if (node == null) {
retVal = AuthenticationStatus.REGISTRATION_REQUIRED;
} else if (!syncEnabled(node)) {
retVal = AuthenticationStatus.SYNC_DISABLED;
} else if (!nodeService.isNodeAuthorized(nodeId, securityToken)) {
retVal = AuthenticationStatus.FORBIDDEN;
}
return retVal;
}

protected boolean syncEnabled(Node node) {
boolean syncEnabled = false;
if (node != null) {
syncEnabled = node.isSyncEnabled();
}
return syncEnabled;
}

}

0 comments on commit 33d1559

Please sign in to comment.