private boolean authenticate() { ClientEngineImpl clientEngine = getService(ClientEngineImpl.SERVICE_NAME); Connection connection = endpoint.getConnection(); ILogger logger = clientEngine.getLogger(getClass()); boolean authenticated; if (credentials == null) { authenticated = false; logger.severe("Could not retrieve Credentials object!"); } else if (clientEngine.getSecurityContext() != null) { authenticated = authenticate(clientEngine.getSecurityContext()); } else if (credentials instanceof UsernamePasswordCredentials) { UsernamePasswordCredentials usernamePasswordCredentials = (UsernamePasswordCredentials) credentials; authenticated = authenticate(usernamePasswordCredentials); } else { authenticated = false; logger.severe( "Hazelcast security is disabled.\nUsernamePasswordCredentials or cluster " + "group-name and group-password should be used for authentication!\n" + "Current credentials type is: " + credentials.getClass().getName()); } logger.log( (authenticated ? Level.INFO : Level.WARNING), "Received auth from " + connection + ", " + (authenticated ? "successfully authenticated" : "authentication failed")); return authenticated; }
private void checkPermissions(ClientEndpoint endpoint) { SecurityContext securityContext = clientEngine.getSecurityContext(); if (securityContext != null) { Permission permission = getRequiredPermission(); if (permission != null) { securityContext.checkPermission(endpoint.getSubject(), permission); } } }
private void interceptAfter(Credentials credentials) { final SecurityContext securityContext = clientEngine.getSecurityContext(); final String methodName = getMethodName(); if (securityContext != null && methodName != null) { final String objectType = getDistributedObjectType(); final String objectName = getDistributedObjectName(); securityContext.interceptAfter(credentials, objectType, objectName, methodName); } }
protected AbstractMessageTask(ClientMessage clientMessage, Node node, Connection connection) { this.clientMessage = clientMessage; this.logger = node.getLogger(getClass()); this.node = node; this.nodeEngine = node.nodeEngine; this.serializationService = node.getSerializationService(); this.connection = connection; this.parameters = decodeClientMessage(clientMessage); this.clientEngine = node.clientEngine; this.endpointManager = clientEngine.getEndpointManager(); this.endpoint = getEndpoint(); }
@Override public void removeEndpoint(final ClientEndpoint ce, boolean closeImmediately) { checkNotNull(ce, "endpoint can't be null"); ClientEndpointImpl endpoint = (ClientEndpointImpl) ce; endpoints.remove(endpoint.getConnection()); logger.info("Destroying " + endpoint); try { endpoint.destroy(); } catch (LoginException e) { logger.warning(e); } final Connection connection = endpoint.getConnection(); if (closeImmediately) { try { connection.close(); } catch (Throwable e) { logger.warning("While closing client connection: " + connection, e); } } else { nodeEngine .getExecutionService() .schedule( new Runnable() { public void run() { if (connection.isAlive()) { try { connection.close(); } catch (Throwable e) { logger.warning("While closing client connection: " + e.toString()); } } } }, DESTROY_ENDPOINT_DELAY_MS, TimeUnit.MILLISECONDS); } ClientEvent event = new ClientEvent( endpoint.getUuid(), ClientEventType.DISCONNECTED, endpoint.getSocketAddress(), endpoint.getClientType()); clientEngine.sendClientEvent(event); }
private ClientMessage createExceptionMessage(Throwable throwable) { ClientExceptionFactory clientExceptionFactory = clientEngine.getClientExceptionFactory(); int errorCode = clientExceptionFactory.getErrorCode(throwable); String message = throwable.getMessage(); StackTraceElement[] stackTrace = throwable.getStackTrace(); Throwable cause = throwable.getCause(); boolean hasCause = cause != null; String className = throwable.getClass().getName(); if (hasCause) { int causeErrorCode = clientExceptionFactory.getErrorCode(cause); String causeClassName = cause.getClass().getName(); return ErrorCodec.encode( errorCode, className, message, stackTrace, causeErrorCode, causeClassName); } else { return ErrorCodec.encode( errorCode, className, message, stackTrace, ClientProtocolErrorCodes.UNDEFINED, null); } }