diff --git a/spring-hibernate4/pom.xml b/spring-hibernate4/pom.xml index fd0fe6f121..8773884831 100644 --- a/spring-hibernate4/pom.xml +++ b/spring-hibernate4/pom.xml @@ -1,196 +1,197 @@ - - 4.0.0 - org.baeldung - spring-hibernate4 - 0.1-SNAPSHOT + + 4.0.0 + org.baeldung + spring-hibernate4 + 0.1-SNAPSHOT - spring-hibernate4 - war + spring-hibernate4 + war - + - + - - org.springframework - spring-web - ${org.springframework.version} - - - org.springframework - spring-orm - ${org.springframework.version} - - - org.springframework - spring-context - ${org.springframework.version} - + + org.springframework + spring-web + ${org.springframework.version} + + + org.springframework + spring-context + ${org.springframework.version} + - + + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.javassist + javassist + 3.17.1-GA + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + runtime + - - org.hibernate - hibernate-core - ${hibernate.version} - - - org.javassist - javassist - 3.17.1-GA - - - mysql - mysql-connector-java - ${mysql-connector-java.version} - runtime - + - - - - org.hibernate - hibernate-validator - ${hibernate-validator.version} - + + org.hibernate + hibernate-validator + ${hibernate-validator.version} + - + - - com.google.guava - guava - ${guava.version} - + + com.google.guava + guava + ${guava.version} + - + - - org.apache.commons - commons-lang3 - 3.1 - test - + + org.apache.commons + commons-lang3 + 3.1 + test + - - org.springframework - spring-test - ${org.springframework.version} - test - + + org.springframework + spring-test + ${org.springframework.version} + test + - - junit - junit-dep - ${junit.version} - test - + + junit + junit-dep + ${junit.version} + test + - - org.hamcrest - hamcrest-core - ${org.hamcrest.version} - test - - - org.hamcrest - hamcrest-library - ${org.hamcrest.version} - test - + + org.hamcrest + hamcrest-core + ${org.hamcrest.version} + test + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + - - org.mockito - mockito-core - ${mockito.version} - test - + + org.mockito + mockito-core + ${mockito.version} + test + - + - - spring-hibernate4 - - - src/main/resources - true - - + + spring-hibernate4 + + + src/main/resources + true + + - + - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - - - - - - - + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + + + - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - true - - jetty8x - embedded - - - - - - - 8082 - - - - + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + true + + jetty8x + embedded + + + + + + + 8082 + + + + - + - + - - - 3.2.3.RELEASE - 3.1.4.RELEASE + + + 3.2.3.RELEASE + 3.1.4.RELEASE - - 4.2.2.Final - 5.1.25 + + 4.2.2.Final + 5.1.25 - - 1.7.5 - 1.0.11 + + 1.7.5 + 1.0.11 - - 5.0.1.Final + + 5.0.1.Final - - 14.0.1 - 3.1 + + 14.0.1 + 3.1 - - 1.3 - 4.11 - 1.9.5 + + 1.3 + 4.11 + 1.9.5 - 4.2.4 - 4.2.5 + 4.2.4 + 4.2.5 - 1.8.0 - 1.8.9 + 1.8.0 + 1.8.9 - - 1.4.2 - 2.14.1 - + + 1.4.2 + 2.14.1 + \ No newline at end of file diff --git a/spring-hibernate4/src/main/java/org/baeldung/spring/PersistenceConfig.java b/spring-hibernate4/src/main/java/org/baeldung/spring/PersistenceConfig.java index 765a37962f..0c79b1aaa8 100644 --- a/spring-hibernate4/src/main/java/org/baeldung/spring/PersistenceConfig.java +++ b/spring-hibernate4/src/main/java/org/baeldung/spring/PersistenceConfig.java @@ -21,7 +21,7 @@ import com.google.common.base.Preconditions; @Configuration @EnableTransactionManagement @PropertySource({ "classpath:persistence-mysql.properties" }) -@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) +@ComponentScan({ "org.baeldung.persistence" }) public class PersistenceConfig { @Autowired diff --git a/spring-security-rest-full/.project b/spring-security-rest-full/.project index f2aa3ca83e..e914491b96 100644 --- a/spring-security-rest-full/.project +++ b/spring-security-rest-full/.project @@ -1,6 +1,6 @@ - spring-security-basic-auth + spring-security-rest-full diff --git a/spring-security-rest-full/.settings/org.eclipse.wst.common.component b/spring-security-rest-full/.settings/org.eclipse.wst.common.component index 83a7bf94e7..174b04e48d 100644 --- a/spring-security-rest-full/.settings/org.eclipse.wst.common.component +++ b/spring-security-rest-full/.settings/org.eclipse.wst.common.component @@ -1,10 +1,10 @@ - + - - + + diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index 61f509f9e5..f39e977cec 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -1,5 +1 @@ ========= - -Relevant Article: -- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll) -- [Spring Security Basic Authentication](http://www.baeldung.com/spring-security-basic-authentication) diff --git a/spring-security-rest-full/pom.xml b/spring-security-rest-full/pom.xml index e6c8b17066..63905110a6 100644 --- a/spring-security-rest-full/pom.xml +++ b/spring-security-rest-full/pom.xml @@ -2,10 +2,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.baeldung - spring-security-basic-auth + spring-security-rest-full 0.1-SNAPSHOT - spring-security-basic-auth + spring-security-rest-full war @@ -72,6 +72,31 @@ ${org.springframework.version} + + + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.javassist + javassist + 3.17.1-GA + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + runtime + + @@ -128,7 +153,7 @@ - spring-security-basic-auth + spring-security-rest-full src/main/resources @@ -141,7 +166,7 @@ org.apache.maven.plugins maven-surefire-plugin - ${maven-surefire-plugin.version} + ${maven-surefire-plugin.version} @@ -155,7 +180,7 @@ org.codehaus.cargo cargo-maven2-plugin - ${cargo-maven2-plugin.version} + ${cargo-maven2-plugin.version} true @@ -178,39 +203,39 @@ - - 3.2.3.RELEASE - 3.1.4.RELEASE + + 3.2.3.RELEASE + 3.1.4.RELEASE - - 4.2.2.Final - 5.1.25 + + 4.2.2.Final + 5.1.25 - - 1.7.5 - 1.0.11 + + 1.7.5 + 1.0.11 - - 5.0.1.Final + + 5.0.1.Final - - 14.0.1 - 3.1 + + 14.0.1 + 3.1 - - 1.3 - 4.11 - 1.9.5 + + 1.3 + 4.11 + 1.9.5 - 4.2.4 - 4.2.5 + 4.2.4 + 4.2.5 - 1.8.0 - 1.8.9 + 1.8.0 + 1.8.9 - - 1.4.2 - 2.14.1 - + + 1.4.2 + 2.14.1 + \ No newline at end of file diff --git a/spring-security-rest-full/src/main/java/org/baeldung/security/basic/MyBasicAuthenticationEntryPoint.java b/spring-security-rest-full/src/main/java/org/baeldung/security/basic/MyBasicAuthenticationEntryPoint.java deleted file mode 100644 index 968237227f..0000000000 --- a/spring-security-rest-full/src/main/java/org/baeldung/security/basic/MyBasicAuthenticationEntryPoint.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.baeldung.security.basic; - -import java.io.IOException; -import java.io.PrintWriter; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; -import org.springframework.stereotype.Component; - -@Component -public class MyBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint { - - @Override - public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException { - response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\""); - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - final PrintWriter writer = response.getWriter(); - writer.println("HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage()); - } - - @Override - public void afterPropertiesSet() throws Exception { - setRealmName("Baeldung"); - super.afterPropertiesSet(); - } - -} diff --git a/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java b/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java index 4ea0053f48..0c79b1aaa8 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java @@ -1,14 +1,79 @@ package org.baeldung.spring; +import java.util.Properties; + +import javax.sql.DataSource; + +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.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.hibernate4.HibernateTransactionManager; +import org.springframework.orm.hibernate4.LocalSessionFactoryBean; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import com.google.common.base.Preconditions; @Configuration -@ComponentScan("org.baeldung.persistence") +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-mysql.properties" }) +@ComponentScan({ "org.baeldung.persistence" }) public class PersistenceConfig { + @Autowired + private Environment env; + public PersistenceConfig() { super(); } -} + @Bean + public LocalSessionFactoryBean sessionFactory() { + final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); + sessionFactory.setDataSource(restDataSource()); + sessionFactory.setPackagesToScan(new String[] { "org.baeldung.spring.persistence.model" }); + sessionFactory.setHibernateProperties(hibernateProperties()); + + return sessionFactory; + } + + @Bean + public DataSource restDataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public HibernateTransactionManager transactionManager() { + final HibernateTransactionManager txManager = new HibernateTransactionManager(); + txManager.setSessionFactory(sessionFactory().getObject()); + + return txManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + final Properties hibernateProperties() { + return new Properties() { + { + setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + + // setProperty("hibernate.globally_quoted_identifiers", "true"); + // note: necessary in launchpad-storage, but causing problems here + } + }; + } +} \ No newline at end of file diff --git a/spring-security-rest-full/src/main/resources/webSecurityConfig.xml b/spring-security-rest-full/src/main/resources/webSecurityConfig.xml index 2b55ca1c73..b43c76e1c8 100644 --- a/spring-security-rest-full/src/main/resources/webSecurityConfig.xml +++ b/spring-security-rest-full/src/main/resources/webSecurityConfig.xml @@ -10,7 +10,7 @@ - +