Search in sources :

Example 36 with GemFireSecurityException

use of org.apache.geode.security.GemFireSecurityException in project geode by apache.

the class GMSMemberFactory method newMembershipManager.

public MembershipManager newMembershipManager(DistributedMembershipListener listener, DistributionConfig config, RemoteTransportConfig transport, DMStats stats) throws DistributionException {
    Services services = new Services(listener, config, transport, stats);
    try {
        services.init();
        services.start();
    } catch (ConnectionException e) {
        throw new DistributionException(LocalizedStrings.MemberFactory_UNABLE_TO_CREATE_MEMBERSHIP_MANAGER.toLocalizedString(), e);
    } catch (GemFireConfigException | SystemConnectException | GemFireSecurityException e) {
        throw e;
    } catch (RuntimeException e) {
        Services.getLogger().error("Unexpected problem starting up membership services", e);
        throw new SystemConnectException("Problem starting up membership services", e);
    }
    return (MembershipManager) services.getManager();
}
Also used : MemberServices(org.apache.geode.distributed.internal.membership.MemberServices) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireConfigException(org.apache.geode.GemFireConfigException) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) DistributionException(org.apache.geode.distributed.internal.DistributionException) ConnectionException(org.apache.geode.internal.tcp.ConnectionException) SystemConnectException(org.apache.geode.SystemConnectException)

Example 37 with GemFireSecurityException

use of org.apache.geode.security.GemFireSecurityException in project geode by apache.

the class GMSAuthenticator method invokeAuthenticator.

/**
   * Method is package protected to be used in testing.
   */
Principal invokeAuthenticator(Properties securityProps, DistributedMember member, Properties credentials) throws AuthenticationFailedException {
    String authMethod = securityProps.getProperty(SECURITY_PEER_AUTHENTICATOR);
    org.apache.geode.security.Authenticator auth = null;
    try {
        auth = SecurityService.getObjectOfType(authMethod, org.apache.geode.security.Authenticator.class);
        LogWriter logWriter = this.services.getLogWriter();
        LogWriter securityLogWriter = this.services.getSecurityLogWriter();
        // this.securityProps contains
        auth.init(this.securityProps, logWriter, securityLogWriter);
        // is expected
        return auth.authenticate(credentials, member);
    } catch (GemFireSecurityException gse) {
        throw gse;
    } catch (Exception ex) {
        throw new AuthenticationFailedException(HandShake_FAILED_TO_ACQUIRE_AUTHENTICATOR_OBJECT.toLocalizedString(), ex);
    } finally {
        if (auth != null)
            auth.close();
    }
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) Authenticator(org.apache.geode.distributed.internal.membership.gms.interfaces.Authenticator) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Example 38 with GemFireSecurityException

use of org.apache.geode.security.GemFireSecurityException in project geode by apache.

the class GeodeAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getName();
    String password = authentication.getCredentials().toString();
    Properties credentials = new Properties();
    if (username != null)
        credentials.put(ResourceConstants.USER_NAME, username);
    if (password != null)
        credentials.put(ResourceConstants.PASSWORD, password);
    try {
        securityService.login(credentials);
        return new UsernamePasswordAuthenticationToken(username, password, AuthorityUtils.NO_AUTHORITIES);
    } catch (GemFireSecurityException e) {
        throw new BadCredentialsException(e.getLocalizedMessage(), e);
    }
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Properties(java.util.Properties) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException)

Example 39 with GemFireSecurityException

use of org.apache.geode.security.GemFireSecurityException in project geode by apache.

the class GatewaySenderEventRemoteDispatcher method initializeConnection.

/**
   * Initializes the <code>Connection</code>.
   *
   * @throws GatewaySenderException
   */
private void initializeConnection() throws GatewaySenderException, GemFireSecurityException {
    this.connectionLifeCycleLock.writeLock().lock();
    try {
        // Attempt to acquire a connection
        if (this.sender.getProxy() == null || this.sender.getProxy().isDestroyed()) {
            this.sender.initProxy();
        } else {
            this.processor.resetBatchId();
        }
        Connection con;
        try {
            if (this.sender.isParallel()) {
                /*
           * TODO - The use of acquireConnection should be removed from the gateway code. This
           * method is fine for tests, but these connections should really be managed inside the
           * pool code. If the gateway needs to persistent connection to a single server, which
           * should create have the OpExecutor that holds a reference to the connection (similar to
           * the way we do with thread local connections). Use {@link
           * ExecutablePool#setupServerAffinity(boolean)} for gateway code
           */
                con = this.sender.getProxy().acquireConnection();
                // For parallel sender, setting server location will not matter.
                // everytime it will ask for acquire connection whenever it needs it. I
                // am saving this server location for command purpose
                sender.setServerLocation(con.getServer());
            } else {
                synchronized (this.sender.getLockForConcurrentDispatcher()) {
                    ServerLocation server = this.sender.getServerLocation();
                    if (server != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("ServerLocation is: {}. Connecting to this serverLocation...", server);
                        }
                        con = this.sender.getProxy().acquireConnection(server);
                    } else {
                        if (logger.isDebugEnabled()) {
                            logger.debug("ServerLocation is null. Creating new connection. ");
                        }
                        con = this.sender.getProxy().acquireConnection();
                        // PRIMARY
                        if (this.sender.isPrimary()) {
                            if (sender.getServerLocation() == null) {
                                sender.setServerLocation(con.getServer());
                            }
                            new UpdateAttributesProcessor(this.sender).distribute(false);
                        }
                    }
                }
            }
        } catch (ServerConnectivityException e) {
            this.failedConnectCount++;
            Throwable ex = null;
            if (e.getCause() instanceof GemFireSecurityException) {
                ex = e.getCause();
                if (logConnectionFailure()) {
                    // only log this message once; another msg is logged once we connect
                    logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_COULD_NOT_CONNECT_1, new Object[] { this.processor.getSender().getId(), ex.getMessage() }));
                }
                throw new GatewaySenderException(ex);
            }
            List<ServerLocation> servers = this.sender.getProxy().getCurrentServers();
            String ioMsg = null;
            if (servers.size() == 0) {
                ioMsg = LocalizedStrings.GatewayEventRemoteDispatcher_THERE_ARE_NO_ACTIVE_SERVERS.toLocalizedString();
            } else {
                final StringBuilder buffer = new StringBuilder();
                for (ServerLocation server : servers) {
                    String endpointName = String.valueOf(server);
                    if (buffer.length() > 0) {
                        buffer.append(", ");
                    }
                    buffer.append(endpointName);
                }
                ioMsg = LocalizedStrings.GatewayEventRemoteDispatcher_NO_AVAILABLE_CONNECTION_WAS_FOUND_BUT_THE_FOLLOWING_ACTIVE_SERVERS_EXIST_0.toLocalizedString(buffer.toString());
            }
            ex = new IOException(ioMsg);
            // Set the serverLocation to null so that a new connection can be
            // obtained in next attempt
            this.sender.setServerLocation(null);
            if (this.failedConnectCount == 1) {
                // only log this message once; another msg is logged once we connect
                logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT, this.processor.getSender().getId()));
            }
            // same as the other exceptions that might occur in sendBatch.
            throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT.toLocalizedString(this.processor.getSender().getId()), ex);
        }
        if (this.failedConnectCount > 0) {
            Object[] logArgs = new Object[] { this.processor.getSender().getId(), con, Integer.valueOf(this.failedConnectCount) };
            logger.info(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_USING_1_AFTER_2_FAILED_CONNECT_ATTEMPTS, logArgs));
            this.failedConnectCount = 0;
        } else {
            Object[] logArgs = new Object[] { this.processor.getSender().getId(), con };
            logger.info(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_USING_1, logArgs));
        }
        this.connection = con;
        this.processor.checkIfPdxNeedsResend(this.connection.getQueueStatus().getPdxSize());
    } catch (ConnectionDestroyedException e) {
        throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT.toLocalizedString(this.processor.getSender().getId()), e);
    } finally {
        this.connectionLifeCycleLock.writeLock().unlock();
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) Connection(org.apache.geode.cache.client.internal.Connection) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) UpdateAttributesProcessor(org.apache.geode.internal.cache.UpdateAttributesProcessor) List(java.util.List) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)

Aggregations

GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)39 IOException (java.io.IOException)18 GemFireConfigException (org.apache.geode.GemFireConfigException)13 CancelException (org.apache.geode.CancelException)9 LocalRegion (org.apache.geode.internal.cache.LocalRegion)8 Part (org.apache.geode.internal.cache.tier.sockets.Part)8 AuthenticationRequiredException (org.apache.geode.security.AuthenticationRequiredException)8 GatewayConfigurationException (org.apache.geode.cache.GatewayConfigurationException)7 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)7 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)7 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)7 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)7 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)7 EOFException (java.io.EOFException)6 ByteBuffer (java.nio.ByteBuffer)6 Properties (java.util.Properties)6 InternalGemFireException (org.apache.geode.InternalGemFireException)5 EventID (org.apache.geode.internal.cache.EventID)5 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5