From 2b86a7869d7463e7eae668ddfea037b5f8524dd7 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 4 Jan 2015 12:44:17 +0200 Subject: [PATCH] registration project cleanup --- .../OnRegistrationCompleteEvent.java | 2 +- .../listener/RegistrationListener.java | 4 +-- .../java/org/baeldung/spring/AppConfig.java | 9 ++--- .../java/org/baeldung/spring/MvcConfig.java | 34 +++++++++---------- .../baeldung/spring/PersistenceJPAConfig.java | 4 +-- .../controller/RegistrationController.java | 2 +- ...tion.properties => persistence.properties} | 7 ---- .../src/main/resources/webSecurityConfig.xml | 7 ++-- 8 files changed, 32 insertions(+), 37 deletions(-) rename spring-security-login-and-registration/src/main/java/org/baeldung/{event => registration}/OnRegistrationCompleteEvent.java (95%) rename spring-security-login-and-registration/src/main/java/org/baeldung/{event => registration}/listener/RegistrationListener.java (93%) rename spring-security-login-and-registration/src/main/resources/{application.properties => persistence.properties} (68%) diff --git a/spring-security-login-and-registration/src/main/java/org/baeldung/event/OnRegistrationCompleteEvent.java b/spring-security-login-and-registration/src/main/java/org/baeldung/registration/OnRegistrationCompleteEvent.java similarity index 95% rename from spring-security-login-and-registration/src/main/java/org/baeldung/event/OnRegistrationCompleteEvent.java rename to spring-security-login-and-registration/src/main/java/org/baeldung/registration/OnRegistrationCompleteEvent.java index 9094099ecc..ede14537e8 100644 --- a/spring-security-login-and-registration/src/main/java/org/baeldung/event/OnRegistrationCompleteEvent.java +++ b/spring-security-login-and-registration/src/main/java/org/baeldung/registration/OnRegistrationCompleteEvent.java @@ -1,4 +1,4 @@ -package org.baeldung.event; +package org.baeldung.registration; import java.util.Locale; diff --git a/spring-security-login-and-registration/src/main/java/org/baeldung/event/listener/RegistrationListener.java b/spring-security-login-and-registration/src/main/java/org/baeldung/registration/listener/RegistrationListener.java similarity index 93% rename from spring-security-login-and-registration/src/main/java/org/baeldung/event/listener/RegistrationListener.java rename to spring-security-login-and-registration/src/main/java/org/baeldung/registration/listener/RegistrationListener.java index 5c848c7433..0ec64ba408 100644 --- a/spring-security-login-and-registration/src/main/java/org/baeldung/event/listener/RegistrationListener.java +++ b/spring-security-login-and-registration/src/main/java/org/baeldung/registration/listener/RegistrationListener.java @@ -1,10 +1,10 @@ -package org.baeldung.event.listener; +package org.baeldung.registration.listener; import java.util.UUID; -import org.baeldung.event.OnRegistrationCompleteEvent; import org.baeldung.persistence.model.User; import org.baeldung.persistence.service.IUserService; +import org.baeldung.registration.OnRegistrationCompleteEvent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.context.MessageSource; diff --git a/spring-security-login-and-registration/src/main/java/org/baeldung/spring/AppConfig.java b/spring-security-login-and-registration/src/main/java/org/baeldung/spring/AppConfig.java index 4708c53a14..219fcb729e 100644 --- a/spring-security-login-and-registration/src/main/java/org/baeldung/spring/AppConfig.java +++ b/spring-security-login-and-registration/src/main/java/org/baeldung/spring/AppConfig.java @@ -6,20 +6,21 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.env.Environment; import org.springframework.mail.javamail.JavaMailSenderImpl; @Configuration -@ComponentScan(basePackages = { "org.baeldung.event.service", "org.baeldung.event", "org.baeldung.persistence.service", "org.baeldung.persistence.dao" }) -@Import({ MvcConfig.class, PersistenceJPAConfig.class, SecSecurityConfig.class }) -@PropertySource("classpath:application.properties") +@ComponentScan(basePackages = { "org.baeldung.registration" }) +@PropertySource("classpath:email.properties") public class AppConfig { + @Autowired private Environment env; + // beans + @Bean public static PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); diff --git a/spring-security-login-and-registration/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-login-and-registration/src/main/java/org/baeldung/spring/MvcConfig.java index 3294ac2788..9948ca5342 100644 --- a/spring-security-login-and-registration/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-security-login-and-registration/src/main/java/org/baeldung/spring/MvcConfig.java @@ -23,7 +23,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; @Configuration -@ComponentScan(basePackages = { "org.baeldung.web.controller", "org.baeldung.persistence.service", "org.baeldung.persistence.dao" }) +@ComponentScan(basePackages = { "org.baeldung.web" }) @EnableWebMvc public class MvcConfig extends WebMvcConfigurerAdapter { @@ -31,7 +31,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter { super(); } - // API + // @Override public void addViewControllers(final ViewControllerRegistry registry) { @@ -51,15 +51,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter { registry.addViewController("/successRegister.html"); } - @Bean - public ViewResolver viewResolver() { - final InternalResourceViewResolver bean = new InternalResourceViewResolver(); - bean.setViewClass(JstlView.class); - bean.setPrefix("/WEB-INF/view/"); - bean.setSuffix(".jsp"); - return bean; - } - @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/", "/resources/"); @@ -72,6 +63,17 @@ public class MvcConfig extends WebMvcConfigurerAdapter { registry.addInterceptor(localeChangeInterceptor); } + // beans + + @Bean + public ViewResolver viewResolver() { + final InternalResourceViewResolver bean = new InternalResourceViewResolver(); + bean.setViewClass(JstlView.class); + bean.setPrefix("/WEB-INF/view/"); + bean.setSuffix(".jsp"); + return bean; + } + @Bean public LocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); @@ -91,21 +93,17 @@ public class MvcConfig extends WebMvcConfigurerAdapter { @Bean public EmailValidator usernameValidator() { - EmailValidator userNameValidator = new EmailValidator(); - return userNameValidator; + return new EmailValidator(); } @Bean public PasswordMatchesValidator passwordMatchesValidator() { - PasswordMatchesValidator passwordMatchesValidator = new PasswordMatchesValidator(); - return passwordMatchesValidator; + return new PasswordMatchesValidator(); } - // DIC 7 @Bean public HashGenerator hashGenerator() { - HashGenerator hashGenerator = new HashGenerator(); - return hashGenerator; + return new HashGenerator(); } } \ No newline at end of file diff --git a/spring-security-login-and-registration/src/main/java/org/baeldung/spring/PersistenceJPAConfig.java b/spring-security-login-and-registration/src/main/java/org/baeldung/spring/PersistenceJPAConfig.java index 0baac30ec1..e16dc16f3f 100644 --- a/spring-security-login-and-registration/src/main/java/org/baeldung/spring/PersistenceJPAConfig.java +++ b/spring-security-login-and-registration/src/main/java/org/baeldung/spring/PersistenceJPAConfig.java @@ -18,8 +18,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration @EnableTransactionManagement -@PropertySource({ "classpath:application.properties" }) -@ComponentScan({ "org.baeldung.persistence.model" }) +@PropertySource({ "classpath:persistence.properties" }) +@ComponentScan({ "org.baeldung.persistence" }) @EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao") public class PersistenceJPAConfig { diff --git a/spring-security-login-and-registration/src/main/java/org/baeldung/web/controller/RegistrationController.java b/spring-security-login-and-registration/src/main/java/org/baeldung/web/controller/RegistrationController.java index 69709c9190..a88f355577 100644 --- a/spring-security-login-and-registration/src/main/java/org/baeldung/web/controller/RegistrationController.java +++ b/spring-security-login-and-registration/src/main/java/org/baeldung/web/controller/RegistrationController.java @@ -9,7 +9,7 @@ import org.baeldung.persistence.model.User; import org.baeldung.persistence.model.VerificationToken; import org.baeldung.persistence.service.UserDto; import org.baeldung.persistence.service.IUserService; -import org.baeldung.event.OnRegistrationCompleteEvent; +import org.baeldung.registration.OnRegistrationCompleteEvent; import org.baeldung.validation.service.EmailExistsException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-security-login-and-registration/src/main/resources/application.properties b/spring-security-login-and-registration/src/main/resources/persistence.properties similarity index 68% rename from spring-security-login-and-registration/src/main/resources/application.properties rename to spring-security-login-and-registration/src/main/resources/persistence.properties index b338a128b0..06b2528f64 100644 --- a/spring-security-login-and-registration/src/main/resources/application.properties +++ b/spring-security-login-and-registration/src/main/resources/persistence.properties @@ -8,10 +8,3 @@ init-db=false hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=false hibernate.hbm2ddl.auto=create-drop -################### JavaMail Configuration ########################## -smtp.host=smtp.gmail.com -smtp.port=465 -smtp.protocol=smtps -smtp.username=xxx777@gmail.com -smtp.password= -support.email=xxx777@gmail.com diff --git a/spring-security-login-and-registration/src/main/resources/webSecurityConfig.xml b/spring-security-login-and-registration/src/main/resources/webSecurityConfig.xml index ed0e64ca4b..2cb2c9d717 100644 --- a/spring-security-login-and-registration/src/main/resources/webSecurityConfig.xml +++ b/spring-security-login-and-registration/src/main/resources/webSecurityConfig.xml @@ -5,6 +5,7 @@ xsi:schemaLocation=" http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> + @@ -19,7 +20,7 @@ - + + - + + \ No newline at end of file