#539 - Polishing.

Add author tags. Simplify dependency setup. Replace logger declarations with Lombok's CommonsLog. Simplify test annotations.

Disable WAN module as the WAN server does not stop after running tests. Reformat code.
This commit is contained in:
Mark Paluch
2020-02-27 10:21:46 +01:00
parent fa0021cffb
commit 54f7146e0f
121 changed files with 1160 additions and 1092 deletions

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security;
/**

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security;
import lombok.Data;
@@ -44,4 +43,4 @@ public class Customer implements Serializable {
this.firstName = firstName;
this.lastName = lastName;
}
}
}

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security;
import lombok.Data;
@@ -34,4 +33,4 @@ public class EmailAddress implements Serializable {
this.value = value;
}
}
}

View File

@@ -13,12 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security;
import lombok.Data;
import org.apache.geode.security.ResourcePermission;
import org.cp.elements.lang.Identifiable;
import java.io.Serializable;
import java.util.Arrays;
@@ -26,6 +23,8 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.geode.security.ResourcePermission;
/**
* The [Role] class is an Abstract Data Type (ADT) modeling a role of a user (e.g. Admin).
*
@@ -34,11 +33,10 @@ import java.util.Iterator;
* @see Comparable
* @see Iterable
* @see ResourcePermission
* @see org.cp.elements.lang.Identifiable
* @since 1.0.0
*/
@Data
public class Role implements Comparable<Role>, Identifiable<String>, Iterable<ResourcePermission>, Serializable {
public class Role implements Comparable<Role>, Iterable<ResourcePermission>, Serializable {
private String name;
private HashSet<ResourcePermission> permissions = new HashSet<>();
@@ -47,12 +45,10 @@ public class Role implements Comparable<Role>, Identifiable<String>, Iterable<Re
this.name = name;
}
@Override
public String getId() {
return name;
}
@Override
public void setId(String id) {
throw new UnsupportedOperationException("Operation Not Supported");
}
@@ -69,8 +65,8 @@ public class Role implements Comparable<Role>, Identifiable<String>, Iterable<Re
* Determines whether this [Role] has been assigned (granted) the given [permission][ResourcePermission].
*
* @param permission [ResourcePermission] to evaluate.
* @return a boolean value indicating whether this [Role] has been assigned (granted)
* the given [permission][ResourcePermission].
* @return a boolean value indicating whether this [Role] has been assigned (granted) the given
* [permission][ResourcePermission].
* @see ResourcePermission
*/
public boolean hasPermission(ResourcePermission permission) {

View File

@@ -13,12 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security;
import lombok.Data;
import org.apache.geode.security.ResourcePermission;
import org.cp.elements.lang.Identifiable;
import java.io.Serializable;
import java.security.Principal;
@@ -28,8 +25,13 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.apache.geode.security.ResourcePermission;
/**
* @author Patrick Johnson
*/
@Data
public class User implements Comparable<User>, Cloneable, Principal, Serializable, Iterable<Role>, Identifiable<String> {
public class User implements Comparable<User>, Cloneable, Principal, Serializable, Iterable<Role> {
private String name;
private List<Role> roles;
@@ -42,15 +44,13 @@ public class User implements Comparable<User>, Cloneable, Principal, Serializabl
}
public User(String name) {
this(name, new ArrayList<Role>());
this(name, new ArrayList<>());
}
@Override
public void setId(String id) {
throw new UnsupportedOperationException("Operation Not Supported");
}
@Override
public String getId() {
return name;
}
@@ -80,8 +80,7 @@ public class User implements Comparable<User>, Cloneable, Principal, Serializabl
* Determines whether this [User] has been granted (assigned) the given [permission][ResourcePermission].
*
* @param permission [ResourcePermission] to evalute.
* @return a boolean value indicating whether this [User] has been granted (assigned)
* the given [ResourcePermission].
* @return a boolean value indicating whether this [User] has been granted (assigned) the given [ResourcePermission].
* @see ResourcePermission
*/
public boolean hasPermission(ResourcePermission permission) {

View File

@@ -13,14 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.client;
import example.springdata.geode.client.security.Customer;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
/**
* @author Patrick Johnson
*/
public interface CustomerRepository extends CrudRepository<Customer, Long> {
@Override
List<Customer> findAll();
}

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.client;
import example.springdata.geode.client.security.Customer;
@@ -30,4 +29,4 @@ import org.springframework.data.gemfire.repository.config.EnableGemfireRepositor
@ClientCacheApplication(name = "SecurityClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1)
@EnableEntityDefinedRegions(basePackageClasses = Customer.class, clientRegionShortcut = ClientRegionShortcut.CACHING_PROXY)
public class SecurityEnabledClientConfiguration {
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import org.springframework.context.annotation.Configuration;
@@ -7,5 +22,4 @@ import org.springframework.data.gemfire.config.annotation.EnableSecurity;
@Configuration
@EnableSecurity(shiroIniResourcePath = "shiro.ini")
@Profile("shiro-ini-configuration")
public class ApacheShiroIniConfiguration {
}
public class ApacheShiroIniConfiguration {}

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import example.springdata.geode.client.security.User;
@@ -31,6 +30,7 @@ import java.util.Map;
* @since 1.0.0
*/
public abstract class CachingSecurityRepository implements SecurityRepository {
private Map<String, User> users = new HashMap<>();
@Override

View File

@@ -1,13 +1,28 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.gemfire.config.annotation.EnableSecurity;
/**
* @author Patrick Johnson
*/
@Configuration
@EnableSecurity(securityManagerClassName = "example.springdata.geode.client.security.server.SecurityManagerProxy")
@Profile({"default", "geode-security-manager-proxy-configuration"})
public class GeodeIntegratedSecurityProxyConfiguration {
}
@Profile({ "default", "geode-security-manager-proxy-configuration" })
public class GeodeIntegratedSecurityProxyConfiguration {}

View File

@@ -13,42 +13,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import example.springdata.geode.client.security.Role;
import example.springdata.geode.client.security.User;
import org.apache.geode.security.ResourcePermission;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import lombok.extern.apachecommons.CommonsLog;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@Repository
public class JdbcSecurityRepository extends CachingSecurityRepository implements InitializingBean {
import org.apache.geode.security.ResourcePermission;
private Logger logger = LoggerFactory.getLogger(this.getClass());
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
/**
* @author Patrick Johnson
*/
@Repository
@CommonsLog
public class JdbcSecurityRepository extends CachingSecurityRepository implements InitializingBean {
private final JdbcTemplate jdbcTemplate;
private static final String ROLES_QUERY = "SELECT name FROM geode_security.roles";
private static final String ROLE_PERMISSIONS_QUERY = ""
+ " SELECT rolePerms.resource, rolePerms.operation, rolePerms.region_name, rolePerms.key_name"
+ " FROM geode_security.roles_permissions rolePerms"
+ " INNER JOIN geode_security.roles roles ON roles.id = rolePerms.role_id "
+ " WHERE roles.name = ?";
+ " INNER JOIN geode_security.roles roles ON roles.id = rolePerms.role_id " + " WHERE roles.name = ?";
private static final String USERS_QUERY = "SELECT name, credentials FROM geode_security.users";
private static final String USER_ROLES_QUERY = ""
+ " SELECT roles.name"
+ " FROM geode_security.roles roles"
private static final String USER_ROLES_QUERY = "" + " SELECT roles.name" + " FROM geode_security.roles roles"
+ " INNER JOIN geode_security.users_roles userRoles ON roles.id = userRoles.role_id"
+ " INNER JOIN geode_security.users users ON userRoles.user_id = users.id"
+ " WHERE users.name = ?";
+ " INNER JOIN geode_security.users users ON userRoles.user_id = users.id" + " WHERE users.name = ?";
public JdbcSecurityRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
@@ -61,15 +59,14 @@ public class JdbcSecurityRepository extends CachingSecurityRepository implements
roles.forEach((role) -> {
this.jdbcTemplate.query(ROLE_PERMISSIONS_QUERY, Collections.singleton(role.getName()).toArray(),
(RowMapper<Object>) (resultSet, i) -> role.withPermissions(newResourcePermission(
resultSet.getString(1), resultSet.getString(2),
resultSet.getString(3), resultSet.getString(4))));
(RowMapper<Object>) (resultSet, i) -> role.withPermissions(newResourcePermission(resultSet.getString(1),
resultSet.getString(2), resultSet.getString(3), resultSet.getString(4))));
roleMapping.put(role.getName(), role);
});
List<User> users = this.jdbcTemplate.query(USERS_QUERY, (resultSet, i) ->
createUser(resultSet.getString(1)).withCredentials(resultSet.getString(2)));
List<User> users = this.jdbcTemplate.query(USERS_QUERY,
(resultSet, i) -> createUser(resultSet.getString(1)).withCredentials(resultSet.getString(2)));
users.forEach((role) -> {
this.jdbcTemplate.query(USER_ROLES_QUERY, Collections.singleton(role.getName()).toArray(),
@@ -78,7 +75,7 @@ public class JdbcSecurityRepository extends CachingSecurityRepository implements
save(role);
});
logger.debug("Users {}", users);
log.debug(String.format("Users %s", users));
}
protected ResourcePermission newResourcePermission(String resource, String operation, String region, String key) {

View File

@@ -13,19 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication(scanBasePackageClasses = SecurityEnabledServerConfiguration.class)
/**
* @author Patrick Johnson
*/
@SpringBootApplication
public class SecurityEnabledServer {
public static void main(String[] args) {
new SpringApplicationBuilder(SecurityEnabledServer.class)
.web(WebApplicationType.NONE)
.build()
.run(args);
new SpringApplicationBuilder(SecurityEnabledServer.class).web(WebApplicationType.NONE).build().run(args);
}
}
}

View File

@@ -13,11 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import example.springdata.geode.client.security.Customer;
import javax.sql.DataSource;
import org.apache.geode.cache.RegionShortcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -29,32 +32,25 @@ import org.springframework.data.gemfire.config.annotation.EnableManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource;
/**
* @author Patrick Johnson
*/
@Configuration
@EnableLocator
@EnableIndexing
@EnableManager
@Import({ApacheShiroIniConfiguration.class, GeodeIntegratedSecurityProxyConfiguration.class})
@Import({ ApacheShiroIniConfiguration.class, GeodeIntegratedSecurityProxyConfiguration.class })
@CacheServerApplication(port = 0, logLevel = "error")
@EnableEntityDefinedRegions(basePackageClasses = Customer.class, serverRegionShortcut = RegionShortcut.REPLICATE)
public class SecurityEnabledServerConfiguration {
@Bean
DataSource hsqlDataSource() {
return new EmbeddedDatabaseBuilder()
.setName("geode_security")
.setScriptEncoding("UTF-8")
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/geode-security-schema-ddl.sql")
.addScript("sql/define-roles-table-ddl.sql")
.addScript("sql/define-roles-permissions-table-ddl.sql")
.addScript("sql/define-users-table-ddl.sql")
.addScript("sql/define-users-roles-table-ddl.sql")
.addScript("sql/insert-roles-dml.sql")
.addScript("sql/insert-roles-permissions-dml.sql")
.addScript("sql/insert-users-dml.sql")
.addScript("sql/insert-users-roles-dml.sql")
.build();
return new EmbeddedDatabaseBuilder().setName("geode_security").setScriptEncoding("UTF-8")
.setType(EmbeddedDatabaseType.HSQL).addScript("sql/geode-security-schema-ddl.sql")
.addScript("sql/define-roles-table-ddl.sql").addScript("sql/define-roles-permissions-table-ddl.sql")
.addScript("sql/define-users-table-ddl.sql").addScript("sql/define-users-roles-table-ddl.sql")
.addScript("sql/insert-roles-dml.sql").addScript("sql/insert-roles-permissions-dml.sql")
.addScript("sql/insert-users-dml.sql").addScript("sql/insert-users-roles-dml.sql").build();
}
}

View File

@@ -13,22 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import org.apache.geode.security.AuthenticationFailedException;
import org.apache.geode.security.ResourcePermission;
import org.cp.elements.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.support.LazyWiringDeclarableSupport;
import java.util.Properties;
import org.apache.geode.security.AuthenticationFailedException;
import org.apache.geode.security.ResourcePermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.support.LazyWiringDeclarableSupport;
import org.springframework.util.Assert;
/**
* The {@link SecurityManagerProxy} class is a Proxy delegating to an underlying Apache Geode
* {@link org.apache.geode.security.SecurityManager} implementation, that maybe a Spring managed bean
* in a Spring context that may have been configured and auto-wired the Spring container, or possibly
* other managed environment (Cloud or Java EE Server, etc).
* {@link org.apache.geode.security.SecurityManager} implementation, that maybe a Spring managed bean in a Spring
* context that may have been configured and auto-wired the Spring container, or possibly other managed environment
* (Cloud or Java EE Server, etc).
*
* @author John Blum
* @see org.apache.geode.security.SecurityManager
@@ -42,8 +42,8 @@ public class SecurityManagerProxy extends LazyWiringDeclarableSupport
private org.apache.geode.security.SecurityManager securityManager;
/**
* Constructs an instance of the {@link SecurityManagerProxy}, whick will delegate all Apache Geode
* security operations to a Spring managed {@link org.apache.geode.security.SecurityManager} bean.
* Constructs an instance of the {@link SecurityManagerProxy}, whick will delegate all Apache Geode security
* operations to a Spring managed {@link org.apache.geode.security.SecurityManager} bean.
*/
public SecurityManagerProxy() {
// TODO remove init() call when GEODE-2083 (https://issues.apache.org/jira/browse/GEODE-2083) is resolved!
@@ -56,13 +56,13 @@ public class SecurityManagerProxy extends LazyWiringDeclarableSupport
}
/**
* Returns a reference to the Apache Geode {@link org.apache.geode.security.SecurityManager} instance
* delegated to by this {@link SecurityManagerProxy}.
* Returns a reference to the Apache Geode {@link org.apache.geode.security.SecurityManager} instance delegated to by
* this {@link SecurityManagerProxy}.
*
* @return a reference to the underlying, Apache Geode {@link org.apache.geode.security.SecurityManager}
* instance delegated to by this {@link SecurityManagerProxy}.
* @throws IllegalStateException if the configured Apache Geode {@link org.apache.geode.security.SecurityManager}
* was not properly initialized.
* @return a reference to the underlying, Apache Geode {@link org.apache.geode.security.SecurityManager} instance
* delegated to by this {@link SecurityManagerProxy}.
* @throws IllegalStateException if the configured Apache Geode {@link org.apache.geode.security.SecurityManager} was
* not properly initialized.
* @see org.apache.geode.security.SecurityManager
*/
protected org.apache.geode.security.SecurityManager getSecurityManager() {
@@ -71,13 +71,13 @@ public class SecurityManagerProxy extends LazyWiringDeclarableSupport
}
/**
* Sets a reference to the Apache Geode {@link org.apache.geode.security.SecurityManager} instance
* delegated to by this {@link SecurityManagerProxy}.
* Sets a reference to the Apache Geode {@link org.apache.geode.security.SecurityManager} instance delegated to by
* this {@link SecurityManagerProxy}.
*
* @param securityManager reference to the underlying, Apache Geode {@link org.apache.geode.security.SecurityManager}
* instance delegated to by this {@link SecurityManagerProxy}.
* @throws IllegalArgumentException if the Apache Geode {@link org.apache.geode.security.SecurityManager} reference
* is {@literal null}.
* instance delegated to by this {@link SecurityManagerProxy}.
* @throws IllegalArgumentException if the Apache Geode {@link org.apache.geode.security.SecurityManager} reference is
* {@literal null}.
* @see org.apache.geode.security.SecurityManager
*/
@Autowired

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import example.springdata.geode.client.security.Constants;

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import example.springdata.geode.client.security.Role;
@@ -24,8 +23,8 @@ import java.util.Arrays;
import java.util.List;
/**
* The [SecurityRepository] interface is a contract for Data Access Objects (DAO) implementing this interface
* to perform CRUD and query operations on [User] information, pertinent to the security of the system.
* The [SecurityRepository] interface is a contract for Data Access Objects (DAO) implementing this interface to perform
* CRUD and query operations on [User] information, pertinent to the security of the system.
*
* @author John Blum
* @author Udo Kohlmeyer
@@ -35,6 +34,7 @@ import java.util.List;
* @since 1.0.0
*/
public interface SecurityRepository {
/**
* Finds all [Users][User] of the system.
*
@@ -154,4 +154,3 @@ public interface SecurityRepository {
return saved;
}
}

View File

@@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.server;
import example.springdata.geode.client.security.Role;
import example.springdata.geode.client.security.User;
import org.apache.geode.security.AuthenticationFailedException;
import org.apache.geode.security.ResourcePermission;
import org.springframework.stereotype.Service;
import java.util.Properties;
import org.apache.geode.security.AuthenticationFailedException;
import org.apache.geode.security.ResourcePermission;
import org.springframework.stereotype.Service;
/**
* The [SimpleSecurityManager] class is an example Apache Geode [SecurityManager] provider implementation
* used to secure Apache Geode.
* The [SimpleSecurityManager] class is an example Apache Geode [SecurityManager] provider implementation used to secure
* Apache Geode.
*
* @author John Blum
* @see SecurityManagerSupport
@@ -81,8 +82,8 @@ public class SimpleSecurityManager extends SecurityManagerSupport {
*/
@Override
public boolean authorize(Object principal, ResourcePermission permission) {
logDebug("Principal [{}] is requesting access to a Resource {} with the required Permission [{}]",
principal, permission.getResource(), permission);
logDebug("Principal [{}] is requesting access to a Resource {} with the required Permission [{}]", principal,
permission.getResource(), permission);
return isAuthorized(principal, permission);
}

View File

@@ -13,42 +13,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.client;
import static org.assertj.core.api.Assertions.*;
import example.springdata.geode.client.security.Customer;
import example.springdata.geode.client.security.EmailAddress;
import example.springdata.geode.client.security.server.SecurityEnabledServer;
import lombok.extern.apachecommons.CommonsLog;
import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import org.apache.geode.cache.Region;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Patrick Johnson
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = SecurityEnabledClientConfiguration.class)
@SpringBootTest(classes = SecurityEnabledClientConfiguration.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@CommonsLog
public class SecurityEnabledClientShiroTests extends ForkingClientServerIntegrationTestsSupport {
@Autowired
private CustomerRepository customerRepository;
@Autowired private CustomerRepository customerRepository;
@Resource(name = "Customers")
private Region<Long, Customer> customers;
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Resource(name = "Customers") private Region<Long, Customer> customers;
@BeforeClass
public static void setup() throws IOException {
@@ -57,20 +58,27 @@ public class SecurityEnabledClientShiroTests extends ForkingClientServerIntegrat
@Test
public void securityWasConfiguredCorrectly() {
logger.info("Inserting 3 entries for keys: 1, 2, 3");
log.info("Inserting 3 entries for keys: 1, 2, 3");
Customer john = new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith");
Customer frank = new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport");
Customer jude = new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons");
customerRepository.save(john);
customerRepository.save(frank);
customerRepository.save(jude);
assertThat(customers.keySetOnServer().size()).isEqualTo(3);
logger.info("Customers saved on server:");
log.info("Customers saved on server:");
List<Customer> customerList = customerRepository.findAll();
assertThat(customerList.size()).isEqualTo(3);
assertThat(customerList.contains(john)).isTrue();
assertThat(customerList.contains(frank)).isTrue();
assertThat(customerList.contains(jude)).isTrue();
customerList.forEach(customer -> logger.info("\t Entry: \n \t\t " + customer));
customerList.forEach(customer -> log.info("\t Entry: \n \t\t " + customer));
}
}
}

View File

@@ -13,42 +13,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.geode.client.security.client;
import static org.assertj.core.api.Assertions.*;
import example.springdata.geode.client.security.Customer;
import example.springdata.geode.client.security.EmailAddress;
import example.springdata.geode.client.security.server.SecurityEnabledServer;
import lombok.extern.apachecommons.CommonsLog;
import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import org.apache.geode.cache.Region;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Patrick Johnson
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = SecurityEnabledClientConfiguration.class)
@SpringBootTest(classes = SecurityEnabledClientConfiguration.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@CommonsLog
public class SecurityEnabledClientTests extends ForkingClientServerIntegrationTestsSupport {
@Autowired
private CustomerRepository customerRepository;
@Autowired private CustomerRepository customerRepository;
@Resource(name = "Customers")
private Region<Long, Customer> customers;
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Resource(name = "Customers") private Region<Long, Customer> customers;
@BeforeClass
public static void setup() throws IOException {
@@ -57,20 +58,28 @@ public class SecurityEnabledClientTests extends ForkingClientServerIntegrationTe
@Test
public void SecurityWasConfiguredCorrectly() {
logger.info("Inserting 3 entries for keys: 1, 2, 3");
log.info("Inserting 3 entries for keys: 1, 2, 3");
Customer john = new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith");
Customer frank = new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport");
Customer jude = new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons");
customerRepository.save(john);
customerRepository.save(frank);
customerRepository.save(jude);
assertThat(customers.keySetOnServer().size()).isEqualTo(3);
logger.info("Customers saved on server:");
assertThat(customers.keySetOnServer()).hasSize(3);
log.info("Customers saved on server:");
List<Customer> customerList = customerRepository.findAll();
assertThat(customerList.size()).isEqualTo(3);
assertThat(customerList.contains(john)).isTrue();
assertThat(customerList.contains(frank)).isTrue();
assertThat(customerList.contains(jude)).isTrue();
customerList.forEach(customer -> logger.info("\t Entry: \n \t\t " + customer));
customerList.forEach(customer -> log.info("\t Entry: \n \t\t " + customer));
}
}
}