use of org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest in project ignite by apache.
the class GridClientNioTcpConnection method buildAuthRequest.
/**
* Builds authentication request message with credentials taken from credentials object.
*
* @return AuthenticationRequest message.
*/
private GridClientAuthenticationRequest buildAuthRequest() {
GridClientAuthenticationRequest req = new GridClientAuthenticationRequest();
req.clientId(clientId);
req.credentials(credentials());
req.userAttributes(userAttrs);
return req;
}
use of org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest in project ignite by apache.
the class GridClientNioTcpConnection method makeAuthRequest.
/**
*/
private <R> GridClientFutureAdapter<R> makeAuthRequest() throws GridClientConnectionResetException, GridClientClosedException {
TcpClientFuture<R> fut = new TcpClientFuture<>();
fut.retryState(TcpClientFuture.STATE_REQUEST_RETRY);
GridClientAuthenticationRequest req = buildAuthRequest();
return makeRequest(req, fut, false);
}
use of org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest in project ignite by apache.
the class GridClientNioTcpConnection method handleClientResponse.
/**
* Handler responses addressed to this client.
*
* @param fut Response future.
* @param resp Response.
*/
@SuppressWarnings("unchecked")
private void handleClientResponse(TcpClientFuture fut, GridClientResponse resp) {
if (resp.sessionToken() != null)
sesTok = resp.sessionToken();
GridClientMessage src = fut.pendingMessage();
switch(fut.retryState()) {
case TcpClientFuture.STATE_INITIAL:
{
if (resp.successStatus() == GridClientResponse.STATUS_AUTH_FAILURE) {
if (credentials() == null) {
fut.onDone(new GridClientAuthenticationException("Authentication failed on server " + "(client has no credentials) [clientId=" + clientId + ", srvAddr=" + serverAddress() + ", errMsg=" + resp.errorMessage() + ']'));
removePending(resp.requestId());
return;
}
fut.retryState(TcpClientFuture.STATE_AUTH_RETRY);
GridClientAuthenticationRequest req = buildAuthRequest();
req.requestId(resp.requestId());
ses.send(req);
return;
}
break;
}
case TcpClientFuture.STATE_AUTH_RETRY:
{
if (resp.successStatus() == GridClientResponse.STATUS_SUCCESS) {
fut.retryState(TcpClientFuture.STATE_REQUEST_RETRY);
src.sessionToken(sesTok);
ses.send(src);
return;
}
break;
}
}
removePending(resp.requestId());
if (resp.successStatus() == GridClientResponse.STATUS_AUTH_FAILURE)
fut.onDone(new GridClientAuthenticationException("Client authentication failed [clientId=" + clientId + ", srvAddr=" + serverAddress() + ", errMsg=" + resp.errorMessage() + ']'));
else if (resp.successStatus() == GridClientResponse.STATUS_ILLEGAL_ARGUMENT)
fut.onDone(new IllegalArgumentException(resp.errorMessage()));
else if (resp.errorMessage() != null)
fut.onDone(new GridClientException(resp.errorMessage()));
else
fut.onDone(resp.result());
}
use of org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest in project ignite by apache.
the class GridTcpRestNioListener method createRestRequest.
/**
* Creates a REST request object from client TCP binary packet.
*
* @param ses NIO session.
* @param msg Request message.
* @return REST request object.
*/
@Nullable
private GridRestRequest createRestRequest(GridNioSession ses, GridClientMessage msg) {
GridRestRequest restReq = null;
if (msg instanceof GridClientAuthenticationRequest) {
GridClientAuthenticationRequest req = (GridClientAuthenticationRequest) msg;
restReq = new GridRestAuthenticationRequest();
restReq.command(NOOP);
ses.addMeta(CREDS_KEY, req.credentials());
ses.addMeta(USER_ATTR_KEY, req.userAttributes());
} else if (msg instanceof GridClientCacheRequest) {
GridClientCacheRequest req = (GridClientCacheRequest) msg;
GridRestCacheRequest restCacheReq = new GridRestCacheRequest();
restCacheReq.cacheName(req.cacheName());
restCacheReq.cacheFlags(req.cacheFlagsOn());
restCacheReq.key(req.key());
restCacheReq.value(req.value());
restCacheReq.value2(req.value2());
Map vals = req.values();
if (vals != null)
restCacheReq.values(new HashMap<Object, Object>(vals));
restCacheReq.command(cacheCmdMap.get(req.operation()));
restReq = restCacheReq;
} else if (msg instanceof GridClientTaskRequest) {
GridClientTaskRequest req = (GridClientTaskRequest) msg;
GridRestTaskRequest restTaskReq = new GridRestTaskRequest();
restTaskReq.command(EXE);
restTaskReq.taskName(req.taskName());
restTaskReq.params(Arrays.asList(req.argument()));
restReq = restTaskReq;
} else if (msg instanceof GridClientTopologyRequest) {
GridClientTopologyRequest req = (GridClientTopologyRequest) msg;
GridRestTopologyRequest restTopReq = new GridRestTopologyRequest();
restTopReq.includeMetrics(req.includeMetrics());
restTopReq.includeAttributes(req.includeAttributes());
if (req.nodeId() != null) {
restTopReq.command(NODE);
restTopReq.nodeId(req.nodeId());
} else if (req.nodeIp() != null) {
restTopReq.command(NODE);
restTopReq.nodeIp(req.nodeIp());
} else
restTopReq.command(TOPOLOGY);
restReq = restTopReq;
} else if (msg instanceof GridClientStateRequest) {
GridClientStateRequest req = (GridClientStateRequest) msg;
GridRestChangeStateRequest restChangeReq = new GridRestChangeStateRequest();
if (req.isReqCurrentState()) {
restChangeReq.reqCurrentState();
restChangeReq.command(CLUSTER_CURRENT_STATE);
} else {
restChangeReq.active(req.active());
restChangeReq.command(req.active() ? CLUSTER_ACTIVATE : CLUSTER_DEACTIVATE);
}
restReq = restChangeReq;
} else if (msg instanceof GridClientClusterStateRequest) {
GridClientClusterStateRequest req = (GridClientClusterStateRequest) msg;
boolean forceDeactivation = !(msg instanceof GridClientClusterStateRequestV2) || ((GridClientClusterStateRequestV2) msg).forceDeactivation();
GridRestClusterStateRequest restChangeReq = new GridRestClusterStateRequest();
if (req.isReqCurrentState()) {
restChangeReq.reqCurrentMode();
restChangeReq.command(CLUSTER_STATE);
} else {
restChangeReq.state(req.state());
restChangeReq.command(CLUSTER_SET_STATE);
restChangeReq.forceDeactivation(forceDeactivation);
}
restReq = restChangeReq;
} else if (msg instanceof GridClientClusterNameRequest)
restReq = new GridRestClusterNameRequest();
else if (msg instanceof GridClientNodeStateBeforeStartRequest) {
GridClientNodeStateBeforeStartRequest reqClient = (GridClientNodeStateBeforeStartRequest) msg;
if (reqClient instanceof GridClientWarmUpRequest) {
GridClientWarmUpRequest warmUpReqClient = (GridClientWarmUpRequest) reqClient;
restReq = new GridRestWarmUpRequest().stopWarmUp(warmUpReqClient.stopWarmUp());
restReq.command(WARM_UP);
} else {
restReq = new GridRestNodeStateBeforeStartRequest();
restReq.command(NODE_STATE_BEFORE_START);
}
}
if (restReq != null) {
restReq.destinationId(msg.destinationId());
restReq.clientId(msg.clientId());
restReq.sessionToken(msg.sessionToken());
restReq.address(ses.remoteAddress());
restReq.certificates(ses.certificates());
restReq.credentials(ses.meta(CREDS_KEY));
restReq.userAttributes(ses.meta(USER_ATTR_KEY));
}
return restReq;
}
Aggregations