use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class P2PAuthenticationDUnitTest method testP2PAuthenticationWithInvalidAuthInitialize.
/**
* AuthInitialize is incorrect
*/
@Test
public void testP2PAuthenticationWithInvalidAuthInitialize() throws Exception {
int locatorPort = getRandomAvailablePort(SOCKET);
CredentialGenerator gen = new DummyCredentialGenerator();
assertNotNull(gen.getAuthenticator());
assertNull(gen.getJavaProperties());
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
props.setProperty(SECURITY_PEER_AUTH_INIT, "Incorrect_AuthInitialize");
props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
startTheLocator(props, gen.getJavaProperties(), locatorPort);
try {
new SecurityTestUtils("tmp").createSystem(props, null);
fail("AuthenticationFailedException was expected as the AuthInitialize object passed is incorrect");
} catch (GemFireSecurityException expected) {
// success
} finally {
locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class P2PAuthenticationDUnitTest method testP2PLargeCredentialSucceeds.
/**
* The strategy is to test credential size greater than UDP datagram size.
*
* Here locator will accept the credentials from peer2 and the large credential from the first
* peer. Number of members in the DS should be four
*/
@Test
public void testP2PLargeCredentialSucceeds() throws Exception {
int locatorPort = getRandomAvailablePort(SOCKET);
final Host host = Host.getHost(0);
final VM peer2 = host.getVM(1);
final VM peer3 = host.getVM(2);
CredentialGenerator gen = new DummyCredentialGenerator();
gen.init();
assertNotNull(gen.getAuthenticator());
assertNull(gen.getJavaProperties());
assertNull(gen.getSystemProperties());
assertNotNull(gen.getValidCredentials(1));
String authInit = UserPasswordWithExtraPropsAuthInit.class.getName() + ".create";
Properties credentials = gen.getValidCredentials(1);
Properties props = new Properties();
props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
props.putAll(credentials);
startTheLocator(props, null, locatorPort);
try {
// Start the first peer with huge credentials
props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
String hugeStr = "20KString";
for (int i = 0; i <= 20000; i++) {
hugeStr += "A";
}
credentials = gen.getValidCredentials(3);
credentials.setProperty("security-keep-extra-props", "-");
credentials.setProperty("security-hugeentryone", hugeStr);
credentials.setProperty("security-hugeentrytwo", hugeStr);
credentials.setProperty("security-hugeentrythree", hugeStr);
props.putAll(credentials);
createDS(props, null);
// fail("AuthenticationFailedException was expected as credentials were passed beyond 50k");
// --?
// Start the second peer with the same authenticator as locator
props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
credentials = gen.getValidCredentials(7);
props.putAll(credentials);
createDS(peer2, props, null);
createDS(peer3, props, null);
// wait for view propagation
pause(2000);
// Verify the number of members on all peers and locator
locatorVM.invoke(() -> verifyMembers(4));
peer2.invoke(() -> verifyMembers(4));
peer3.invoke(() -> verifyMembers(4));
// Disconnect the peers
disconnectFromDS();
peer2.invoke(() -> disconnectFromDS());
peer3.invoke(() -> disconnectFromDS());
} finally {
locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class P2PAuthenticationDUnitTest method testP2PAuthenticationWithBothValidAndInValidCredentials.
@Test
public void testP2PAuthenticationWithBothValidAndInValidCredentials() throws Exception {
addIgnoredException("Authentication failed");
int locatorPort = getRandomAvailablePort(SOCKET);
CredentialGenerator gen = new DummyCredentialGenerator();
assertNotNull(gen.getAuthenticator());
assertNotNull(gen.getAuthInit());
assertNotNull(gen.getInvalidCredentials(1));
assertNull(gen.getJavaProperties());
assertNull(gen.getSystemProperties());
assertNotNull(gen.getValidCredentials(1));
assertNotNull(gen.getValidCredentials(3));
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
props.setProperty(SECURITY_PEER_AUTH_INIT, gen.getAuthInit());
props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
props.putAll(gen.getValidCredentials(1));
startTheLocator(props, null, locatorPort);
try {
// invalid credentials for the peer
props.putAll(gen.getInvalidCredentials(1));
try {
new SecurityTestUtils("tmp").createSystem(props, null);
fail("AuthenticationFailedException was expected as wrong credentials were passed");
} catch (GemFireSecurityException expected) {
// success
}
props.putAll(gen.getValidCredentials(3));
createDS(props, null);
verifyMembers(2);
disconnectFromDS();
} finally {
locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class P2PAuthenticationDUnitTest method testP2PViewChangeReject.
/**
* The strategy is to test view change reject by having two different authenticators on different
* VMs.
*
* Here locator will accept the credentials from peer2 but the first peer will reject them due to
* different authenticator. Hence the number of members reported by the first peer should be only
* two while others will report as three.
*/
@Ignore("disabled for some reason?")
@Test
public void testP2PViewChangeReject() throws Exception {
final Host host = Host.getHost(0);
final VM peer2 = host.getVM(1);
final VM peer3 = host.getVM(2);
CredentialGenerator gen = new LdapUserCredentialGenerator();
gen.init();
Properties extraProps = gen.getSystemProperties();
String authenticator = gen.getAuthenticator();
String authInit = gen.getAuthInit();
if (extraProps == null) {
extraProps = new Properties();
}
CredentialGenerator gen2 = new DummyCredentialGenerator();
gen2.init();
Properties extraProps2 = gen2.getSystemProperties();
String authenticator2 = gen2.getAuthenticator();
if (extraProps2 == null) {
extraProps2 = new Properties();
}
// Start the locator with the LDAP authenticator
Properties props = new Properties();
int port = getRandomAvailablePort(SOCKET);
final String locators = getIPLiteral() + "[" + port + "]";
props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
props.setProperty(SECURITY_PEER_AUTHENTICATOR, authenticator);
Properties credentials = gen.getValidCredentials(1);
Properties javaProps = gen.getJavaProperties();
props.putAll(credentials);
props.putAll(extraProps);
startTheLocator(props, javaProps, port);
try {
// Start the first peer with different authenticator
props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
props.setProperty(SECURITY_PEER_AUTHENTICATOR, authenticator2);
credentials = gen.getValidCredentials(3);
Properties javaProps2 = gen2.getJavaProperties();
props.putAll(credentials);
props.putAll(extraProps2);
createDS(props, javaProps2);
// Start the second peer with the same authenticator as locator
props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
props.setProperty(SECURITY_PEER_AUTHENTICATOR, authenticator);
credentials = gen.getValidCredentials(7);
javaProps = gen.getJavaProperties();
props.putAll(credentials);
props.putAll(extraProps);
createDS(peer2, props, javaProps);
createDS(peer3, props, javaProps);
// wait for view propagation
pause(2000);
// Verify the number of members on all peers and locator
locatorVM.invoke(() -> verifyMembers(4));
verifyMembers(2);
peer2.invoke(() -> verifyMembers(4));
peer3.invoke(() -> verifyMembers(4));
// Disconnect the first peer and check again
disconnectFromDS();
pause(2000);
locatorVM.invoke(() -> verifyMembers(3));
peer2.invoke(() -> verifyMembers(3));
peer3.invoke(() -> verifyMembers(3));
// Disconnect the second peer and check again
peer2.invoke(() -> disconnectFromDS());
pause(2000);
locatorVM.invoke(() -> verifyMembers(2));
peer3.invoke(() -> verifyMembers(2));
// Same for last peer
peer3.invoke(() -> disconnectFromDS());
pause(2000);
locatorVM.invoke(() -> verifyMembers(1));
} finally {
locatorVM.invoke(() -> stopLocator(port, ignoredExceptions));
}
}
use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class P2PAuthenticationDUnitTest method testP2PAuthenticationWithInvalidAuthenticator.
/**
* Authenticator is incorrect
*/
// GEODE-1089: random port
@Category(FlakyTest.class)
@Test
public void testP2PAuthenticationWithInvalidAuthenticator() throws Exception {
int locatorPort = getRandomAvailablePort(SOCKET);
CredentialGenerator gen = new DummyCredentialGenerator();
assertNotNull(gen.getAuthInit());
assertNull(gen.getJavaProperties());
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
props.setProperty(SECURITY_PEER_AUTH_INIT, gen.getAuthInit());
props.setProperty(SECURITY_PEER_AUTHENTICATOR, "xyz");
startTheLocator(props, null, locatorPort);
try {
new SecurityTestUtils("tmp").createSystem(props, null);
fail("AuthenticationFailedException was expected as the Authenticator object passed is incorrect");
} catch (GemFireSecurityException expected) {
// success
} finally {
locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
Aggregations