Search in sources :

Example 6 with AuthenticationFailedException

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

the class PKCSAuthenticator method populateMap.

private void populateMap() {
    try {
        final KeyStore keyStore = KeyStore.getInstance("JKS");
        final char[] passPhrase = this.pubKeyPass != null ? this.pubKeyPass.toCharArray() : null;
        final FileInputStream keyStoreFile = new FileInputStream(this.pubKeyFilePath);
        try {
            keyStore.load(keyStoreFile, passPhrase);
        } finally {
            keyStoreFile.close();
        }
        for (Enumeration e = keyStore.aliases(); e.hasMoreElements(); ) {
            final Object alias = e.nextElement();
            final Certificate cert = keyStore.getCertificate((String) alias);
            if (cert instanceof X509Certificate) {
                this.aliasCertificateMap.put(alias, cert);
            }
        }
    } catch (Exception e) {
        throw new AuthenticationFailedException("Exception while getting public keys: " + e.getMessage(), e);
    }
}
Also used : Enumeration(java.util.Enumeration) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) X509Certificate(java.security.cert.X509Certificate) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 7 with AuthenticationFailedException

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

the class UserPasswordAuthInit method getCredentials.

@Override
public Properties getCredentials(final Properties securityProperties, final DistributedMember server, final boolean isPeer) throws AuthenticationFailedException {
    String userName = securityProperties.getProperty(USER_NAME);
    if (userName == null) {
        throw new AuthenticationFailedException("UserPasswordAuthInit: user name property [" + USER_NAME + "] not set.");
    }
    String password = securityProperties.getProperty(PASSWORD);
    if (password == null) {
        password = "";
    }
    Properties securityPropertiesCopy = new Properties();
    securityPropertiesCopy.setProperty(USER_NAME, userName);
    securityPropertiesCopy.setProperty(PASSWORD, password);
    return securityPropertiesCopy;
}
Also used : AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) Properties(java.util.Properties)

Example 8 with AuthenticationFailedException

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

the class LauncherLifecycleCommands method doAutoConnect.

private boolean doAutoConnect(final String locatorHostname, final int locatorPort, final String gemfirePropertiesPathname, final String gemfireSecurityPropertiesPathname, final InfoResultData infoResultData) {
    boolean connectSuccess = false;
    boolean jmxManagerAuthEnabled = false;
    boolean jmxManagerSslEnabled = false;
    Map<String, String> configurationProperties = loadConfigurationProperties(gemfireSecurityPropertiesPathname, loadConfigurationProperties(gemfirePropertiesPathname));
    Map<String, String> locatorConfigurationProperties = new HashMap<>(configurationProperties);
    String responseFailureMessage = null;
    for (int attempts = 0; (attempts < 10 && !connectSuccess); attempts++) {
        try {
            ConnectToLocatorResult connectToLocatorResult = ShellCommands.connectToLocator(locatorHostname, locatorPort, ShellCommands.getConnectLocatorTimeoutInMS() / 4, locatorConfigurationProperties);
            ConnectionEndpoint memberEndpoint = connectToLocatorResult.getMemberEndpoint();
            jmxManagerSslEnabled = connectToLocatorResult.isJmxManagerSslEnabled();
            if (!jmxManagerSslEnabled) {
                configurationProperties.clear();
            }
            getGfsh().setOperationInvoker(new JmxOperationInvoker(memberEndpoint.getHost(), memberEndpoint.getPort(), null, null, configurationProperties, null));
            String shellAndLogMessage = CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, "JMX Manager " + memberEndpoint.toString(false));
            infoResultData.addLine("\n");
            infoResultData.addLine(shellAndLogMessage);
            getGfsh().logToFile(shellAndLogMessage, null);
            connectSuccess = true;
            responseFailureMessage = null;
        } catch (IllegalStateException unexpected) {
            if (CauseFinder.indexOfCause(unexpected, ClassCastException.class, false) != -1) {
                responseFailureMessage = "The Locator might require SSL Configuration.";
            }
        } catch (SecurityException ignore) {
            getGfsh().logToFile(ignore.getMessage(), ignore);
            jmxManagerAuthEnabled = true;
            // no need to continue after SecurityException
            break;
        } catch (AuthenticationFailedException ignore) {
            getGfsh().logToFile(ignore.getMessage(), ignore);
            jmxManagerAuthEnabled = true;
            // no need to continue after AuthenticationFailedException
            break;
        } catch (SSLException ignore) {
            if (ignore instanceof SSLHandshakeException) {
                // try to connect again without SSL since the SSL handshake failed implying a plain text
                // connection...
                locatorConfigurationProperties.clear();
            } else {
                // another type of SSL error occurred (possibly a configuration issue); pass the buck...
                getGfsh().logToFile(ignore.getMessage(), ignore);
                responseFailureMessage = "Check your SSL configuration and try again.";
                break;
            }
        } catch (Exception ignore) {
            getGfsh().logToFile(ignore.getMessage(), ignore);
            responseFailureMessage = "Failed to connect; unknown cause: " + ignore.getMessage();
        }
    }
    if (!connectSuccess) {
        doOnConnectionFailure(locatorHostname, locatorPort, jmxManagerAuthEnabled, jmxManagerSslEnabled, infoResultData);
    }
    if (StringUtils.isNotBlank(responseFailureMessage)) {
        infoResultData.addLine("\n");
        infoResultData.addLine(responseFailureMessage);
    }
    return connectSuccess;
}
Also used : HashMap(java.util.HashMap) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) ConnectToLocatorResult(org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult) JmxOperationInvoker(org.apache.geode.management.internal.cli.shell.JmxOperationInvoker) SSLException(javax.net.ssl.SSLException) ConnectionEndpoint(org.apache.geode.management.internal.cli.util.ConnectionEndpoint) ConverterHint(org.apache.geode.management.cli.ConverterHint) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MalformedObjectNameException(javax.management.MalformedObjectNameException) SSLException(javax.net.ssl.SSLException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) ClusterConfigurationNotAvailableException(org.apache.geode.internal.process.ClusterConfigurationNotAvailableException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConnectionEndpoint(org.apache.geode.management.internal.cli.util.ConnectionEndpoint)

Example 9 with AuthenticationFailedException

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

the class GMSJoinLeaveJUnitTest method testProcessJoinMessageWithAuthenticationButNullCredentials.

@Test
public void testProcessJoinMessageWithAuthenticationButNullCredentials() throws IOException {
    initMocks();
    when(services.getAuthenticator()).thenReturn(authenticator);
    when(authenticator.authenticate(mockMembers[0], null)).thenThrow(new AuthenticationFailedException("we want to fail auth here"));
    when(services.getMessenger()).thenReturn(messenger);
    gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], null, -1, 0));
    assertTrue("JoinRequest should not have been added to view request", gmsJoinLeave.getViewRequests().size() == 0);
    verify(messenger).send(isA(JoinResponseMessage.class));
}
Also used : AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with AuthenticationFailedException

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

the class GMSJoinLeaveJUnitTest method testProcessJoinMessageWithBadAuthentication.

@Test
public void testProcessJoinMessageWithBadAuthentication() throws IOException {
    initMocks();
    when(services.getAuthenticator()).thenReturn(authenticator);
    when(authenticator.authenticate(mockMembers[0], credentials)).thenThrow(new AuthenticationFailedException("we want to fail auth here"));
    when(services.getMessenger()).thenReturn(messenger);
    gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], credentials, -1, 0));
    assertTrue("JoinRequest should not have been added to view request", gmsJoinLeave.getViewRequests().size() == 0);
    verify(messenger).send(isA(JoinResponseMessage.class));
}
Also used : AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)29 IOException (java.io.IOException)14 Properties (java.util.Properties)12 AuthenticationRequiredException (org.apache.geode.security.AuthenticationRequiredException)9 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)9 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)7 EOFException (java.io.EOFException)6 Signature (java.security.Signature)6 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)6 X509Certificate (java.security.cert.X509Certificate)5 GemFireConfigException (org.apache.geode.GemFireConfigException)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5 GatewayConfigurationException (org.apache.geode.cache.GatewayConfigurationException)5 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)5 KeyFactory (java.security.KeyFactory)4 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)4 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 MalformedURLException (java.net.MalformedURLException)3