Search in sources :

Example 1 with UsernamePasswordCredentials

use of com.hazelcast.security.UsernamePasswordCredentials in project hazelcast by hazelcast.

the class ClientConnectionManagerImpl method encodeAuthenticationRequest.

private ClientMessage encodeAuthenticationRequest(boolean asOwner, SerializationService ss, byte serializationVersion, String uuid, String ownerUuid) {
    ClientMessage clientMessage;
    if (credentials.getClass().equals(UsernamePasswordCredentials.class)) {
        UsernamePasswordCredentials cr = (UsernamePasswordCredentials) credentials;
        clientMessage = ClientAuthenticationCodec.encodeRequest(cr.getUsername(), cr.getPassword(), uuid, ownerUuid, asOwner, ClientTypes.JAVA, serializationVersion, BuildInfoProvider.BUILD_INFO.getVersion());
    } else {
        Data data = ss.toData(credentials);
        clientMessage = ClientAuthenticationCustomCodec.encodeRequest(data, uuid, ownerUuid, asOwner, ClientTypes.JAVA, serializationVersion, BuildInfoProvider.BUILD_INFO.getVersion());
    }
    return clientMessage;
}
Also used : Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UsernamePasswordCredentials(com.hazelcast.security.UsernamePasswordCredentials)

Example 2 with UsernamePasswordCredentials

use of com.hazelcast.security.UsernamePasswordCredentials in project hazelcast by hazelcast.

the class AuthenticationBaseMessageTask method authenticate.

private AuthenticationStatus authenticate() {
    ILogger logger = clientEngine.getLogger(getClass());
    AuthenticationStatus status;
    if (credentials == null) {
        status = AuthenticationStatus.CREDENTIALS_FAILED;
        logger.severe("Could not retrieve Credentials object!");
    } else if (clientEngine.getSecurityContext() != null) {
        status = authenticate(clientEngine.getSecurityContext());
    } else if (credentials instanceof UsernamePasswordCredentials) {
        UsernamePasswordCredentials usernamePasswordCredentials = (UsernamePasswordCredentials) credentials;
        status = authenticate(usernamePasswordCredentials);
    } else {
        status = AuthenticationStatus.CREDENTIALS_FAILED;
        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());
    }
    return status;
}
Also used : AuthenticationStatus(com.hazelcast.client.impl.protocol.AuthenticationStatus) ILogger(com.hazelcast.logging.ILogger) UsernamePasswordCredentials(com.hazelcast.security.UsernamePasswordCredentials)

Example 3 with UsernamePasswordCredentials

use of com.hazelcast.security.UsernamePasswordCredentials in project hazelcast by hazelcast.

the class HazelcastClientInstanceImpl method initCredentials.

private Credentials initCredentials(ClientConfig config) {
    final GroupConfig groupConfig = config.getGroupConfig();
    final ClientSecurityConfig securityConfig = config.getSecurityConfig();
    Credentials c = securityConfig.getCredentials();
    if (c == null) {
        final String credentialsClassname = securityConfig.getCredentialsClassname();
        if (credentialsClassname != null) {
            try {
                c = ClassLoaderUtil.newInstance(config.getClassLoader(), credentialsClassname);
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
        }
    }
    if (c == null) {
        c = new UsernamePasswordCredentials(groupConfig.getName(), groupConfig.getPassword());
    }
    return c;
}
Also used : GroupConfig(com.hazelcast.config.GroupConfig) ClientSecurityConfig(com.hazelcast.client.config.ClientSecurityConfig) UsernamePasswordCredentials(com.hazelcast.security.UsernamePasswordCredentials) Credentials(com.hazelcast.security.Credentials) TransactionException(com.hazelcast.transaction.TransactionException) UsernamePasswordCredentials(com.hazelcast.security.UsernamePasswordCredentials)

Example 4 with UsernamePasswordCredentials

use of com.hazelcast.security.UsernamePasswordCredentials in project hazelcast by hazelcast.

the class ClusterDiscoveryServiceBuilder method build.

public ClusterDiscoveryService build() {
    ArrayList<CandidateClusterContext> contexts = new ArrayList<>();
    for (ClientConfig config : configs) {
        ClientNetworkConfig networkConfig = config.getNetworkConfig();
        SocketInterceptor interceptor = initSocketInterceptor(networkConfig.getSocketInterceptorConfig());
        ICredentialsFactory credentialsFactory = initCredentialsFactory(config);
        if (credentialsFactory == null) {
            credentialsFactory = new StaticCredentialsFactory(new UsernamePasswordCredentials(null, null));
        }
        credentialsFactory.configure(new ClientCallbackHandler(config));
        DiscoveryService discoveryService = initDiscoveryService(config);
        AddressProvider provider;
        if (externalAddressProvider != null) {
            provider = externalAddressProvider;
        } else {
            provider = createAddressProvider(config, discoveryService);
        }
        final SSLConfig sslConfig = networkConfig.getSSLConfig();
        final SocketOptions socketOptions = networkConfig.getSocketOptions();
        contexts.add(new CandidateClusterContext(config.getClusterName(), provider, discoveryService, credentialsFactory, interceptor, clientExtension.createChannelInitializer(sslConfig, socketOptions)));
    }
    return new ClusterDiscoveryService(unmodifiableList(contexts), configsTryCount, lifecycleService);
}
Also used : SSLConfig(com.hazelcast.config.SSLConfig) SocketOptions(com.hazelcast.client.config.SocketOptions) ArrayList(java.util.ArrayList) UsernamePasswordCredentials(com.hazelcast.security.UsernamePasswordCredentials) DefaultAddressProvider(com.hazelcast.client.impl.spi.impl.DefaultAddressProvider) AddressProvider(com.hazelcast.client.impl.connection.AddressProvider) RemoteAddressProvider(com.hazelcast.client.impl.spi.impl.discovery.RemoteAddressProvider) ICredentialsFactory(com.hazelcast.security.ICredentialsFactory) SocketInterceptor(com.hazelcast.nio.SocketInterceptor) StaticCredentialsFactory(com.hazelcast.config.security.StaticCredentialsFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 5 with UsernamePasswordCredentials

use of com.hazelcast.security.UsernamePasswordCredentials in project hazelcast by hazelcast.

the class AuthenticationMessageTask method decodeClientMessage.

@Override
protected ClientAuthenticationCodec.RequestParameters decodeClientMessage(ClientMessage clientMessage) {
    ClientAuthenticationCodec.RequestParameters parameters = ClientAuthenticationCodec.decodeRequest(clientMessage);
    final UUID uuid = parameters.uuid;
    if (uuid != null) {
        clientUuid = uuid;
    }
    clusterName = parameters.clusterName;
    credentials = new UsernamePasswordCredentials(parameters.username, parameters.password);
    clientSerializationVersion = parameters.serializationVersion;
    clientVersion = parameters.clientHazelcastVersion;
    clientName = parameters.clientName;
    labels = Collections.unmodifiableSet(new HashSet<>(parameters.labels));
    return parameters;
}
Also used : ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) UUID(java.util.UUID) UsernamePasswordCredentials(com.hazelcast.security.UsernamePasswordCredentials) HashSet(java.util.HashSet)

Aggregations

UsernamePasswordCredentials (com.hazelcast.security.UsernamePasswordCredentials)6 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)1 ClientSecurityConfig (com.hazelcast.client.config.ClientSecurityConfig)1 SocketOptions (com.hazelcast.client.config.SocketOptions)1 AddressProvider (com.hazelcast.client.impl.connection.AddressProvider)1 AuthenticationStatus (com.hazelcast.client.impl.protocol.AuthenticationStatus)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientAuthenticationCodec (com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec)1 DefaultAddressProvider (com.hazelcast.client.impl.spi.impl.DefaultAddressProvider)1 RemoteAddressProvider (com.hazelcast.client.impl.spi.impl.discovery.RemoteAddressProvider)1 GroupConfig (com.hazelcast.config.GroupConfig)1 SSLConfig (com.hazelcast.config.SSLConfig)1 StaticCredentialsFactory (com.hazelcast.config.security.StaticCredentialsFactory)1 StringUtil.bytesToString (com.hazelcast.internal.util.StringUtil.bytesToString)1 ILogger (com.hazelcast.logging.ILogger)1 SocketInterceptor (com.hazelcast.nio.SocketInterceptor)1 Data (com.hazelcast.nio.serialization.Data)1 Credentials (com.hazelcast.security.Credentials)1 ICredentialsFactory (com.hazelcast.security.ICredentialsFactory)1