cleanup work

This commit is contained in:
Eugen 2013-06-03 18:01:44 +03:00
parent bc0ca7a54c
commit 3201a925ca
9 changed files with 293 additions and 237 deletions

View File

@ -1,196 +1,197 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.baeldung</groupId> <modelVersion>4.0.0</modelVersion>
<artifactId>spring-hibernate4</artifactId> <groupId>org.baeldung</groupId>
<version>0.1-SNAPSHOT</version> <artifactId>spring-hibernate4</artifactId>
<version>0.1-SNAPSHOT</version>
<name>spring-hibernate4</name> <name>spring-hibernate4</name>
<packaging>war</packaging> <packaging>war</packaging>
<dependencies> <dependencies>
<!-- Spring --> <!-- Spring -->
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId> <artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version> <version>${org.springframework.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId> <artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version> <version>${org.springframework.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- persistence --> <!-- persistence -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.17.1-GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
<scope>runtime</scope>
</dependency>
<dependency> <!-- validation -->
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.17.1-GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
<scope>runtime</scope>
</dependency>
<!-- validation --> <dependency>
<groupId>org.hibernate</groupId>
<dependency> <artifactId>hibernate-validator</artifactId>
<groupId>org.hibernate</groupId> <version>${hibernate-validator.version}</version>
<artifactId>hibernate-validator</artifactId> </dependency>
<version>${hibernate-validator.version}</version>
</dependency>
<!-- utils --> <!-- utils -->
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>${guava.version}</version> <version>${guava.version}</version>
</dependency> </dependency>
<!-- test scoped --> <!-- test scoped -->
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.1</version> <version>3.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version> <version>${org.springframework.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit-dep</artifactId> <artifactId>junit-dep</artifactId>
<version>${junit.version}</version> <version>${junit.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId> <artifactId>hamcrest-core</artifactId>
<version>${org.hamcrest.version}</version> <version>${org.hamcrest.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId> <artifactId>hamcrest-library</artifactId>
<version>${org.hamcrest.version}</version> <version>${org.hamcrest.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>${mockito.version}</version> <version>${mockito.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>spring-hibernate4</finalName> <finalName>spring-hibernate4</finalName>
<resources> <resources>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<filtering>true</filtering> <filtering>true</filtering>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version> <version>${maven-surefire-plugin.version}</version>
<configuration> <configuration>
<excludes> <excludes>
<!-- <exclude>**/*ProductionTest.java</exclude> --> <!-- <exclude>**/*ProductionTest.java</exclude> -->
</excludes> </excludes>
<systemPropertyVariables> <systemPropertyVariables>
<!-- <provPersistenceTarget>h2</provPersistenceTarget> --> <!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.codehaus.cargo</groupId> <groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId> <artifactId>cargo-maven2-plugin</artifactId>
<version>${cargo-maven2-plugin.version}</version> <version>${cargo-maven2-plugin.version}</version>
<configuration> <configuration>
<wait>true</wait> <wait>true</wait>
<container> <container>
<containerId>jetty8x</containerId> <containerId>jetty8x</containerId>
<type>embedded</type> <type>embedded</type>
<systemProperties> <systemProperties>
<!-- <provPersistenceTarget>cargo</provPersistenceTarget> --> <!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
</systemProperties> </systemProperties>
</container> </container>
<configuration> <configuration>
<properties> <properties>
<cargo.servlet.port>8082</cargo.servlet.port> <cargo.servlet.port>8082</cargo.servlet.port>
</properties> </properties>
</configuration> </configuration>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<properties> <properties>
<!-- Spring --> <!-- Spring -->
<org.springframework.version>3.2.3.RELEASE</org.springframework.version> <org.springframework.version>3.2.3.RELEASE</org.springframework.version>
<org.springframework.security.version>3.1.4.RELEASE</org.springframework.security.version> <org.springframework.security.version>3.1.4.RELEASE</org.springframework.security.version>
<!-- persistence --> <!-- persistence -->
<hibernate.version>4.2.2.Final</hibernate.version> <hibernate.version>4.2.2.Final</hibernate.version>
<mysql-connector-java.version>5.1.25</mysql-connector-java.version> <mysql-connector-java.version>5.1.25</mysql-connector-java.version>
<!-- logging --> <!-- logging -->
<org.slf4j.version>1.7.5</org.slf4j.version> <org.slf4j.version>1.7.5</org.slf4j.version>
<logback.version>1.0.11</logback.version> <logback.version>1.0.11</logback.version>
<!-- various --> <!-- various -->
<hibernate-validator.version>5.0.1.Final</hibernate-validator.version> <hibernate-validator.version>5.0.1.Final</hibernate-validator.version>
<!-- util --> <!-- util -->
<guava.version>14.0.1</guava.version> <guava.version>14.0.1</guava.version>
<commons-lang3.version>3.1</commons-lang3.version> <commons-lang3.version>3.1</commons-lang3.version>
<!-- testing --> <!-- testing -->
<org.hamcrest.version>1.3</org.hamcrest.version> <org.hamcrest.version>1.3</org.hamcrest.version>
<junit.version>4.11</junit.version> <junit.version>4.11</junit.version>
<mockito.version>1.9.5</mockito.version> <mockito.version>1.9.5</mockito.version>
<httpcore.version>4.2.4</httpcore.version> <httpcore.version>4.2.4</httpcore.version>
<httpclient.version>4.2.5</httpclient.version> <httpclient.version>4.2.5</httpclient.version>
<rest-assured.version>1.8.0</rest-assured.version> <rest-assured.version>1.8.0</rest-assured.version>
<groovy.version>1.8.9</groovy.version> <groovy.version>1.8.9</groovy.version>
<!-- Maven plugins --> <!-- Maven plugins -->
<cargo-maven2-plugin.version>1.4.2</cargo-maven2-plugin.version> <cargo-maven2-plugin.version>1.4.2</cargo-maven2-plugin.version>
<maven-surefire-plugin.version>2.14.1</maven-surefire-plugin.version> <maven-surefire-plugin.version>2.14.1</maven-surefire-plugin.version>
</properties> </properties>
</project> </project>

View File

@ -21,7 +21,7 @@ import com.google.common.base.Preconditions;
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
@PropertySource({ "classpath:persistence-mysql.properties" }) @PropertySource({ "classpath:persistence-mysql.properties" })
@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) @ComponentScan({ "org.baeldung.persistence" })
public class PersistenceConfig { public class PersistenceConfig {
@Autowired @Autowired

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>spring-security-basic-auth</name> <name>spring-security-rest-full</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="spring-security-basic-auth"> <wb-module deploy-name="spring-security-rest-full">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="spring-security-basic-auth"/> <property name="context-root" value="spring-security-rest-full"/>
<property name="java-output-path" value="/spring-security-basic-auth/target/classes"/> <property name="java-output-path" value="/spring-security-rest-full/target/classes"/>
</wb-module> </wb-module>
</project-modules> </project-modules>

View File

@ -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)

View File

@ -2,10 +2,10 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId> <groupId>org.baeldung</groupId>
<artifactId>spring-security-basic-auth</artifactId> <artifactId>spring-security-rest-full</artifactId>
<version>0.1-SNAPSHOT</version> <version>0.1-SNAPSHOT</version>
<name>spring-security-basic-auth</name> <name>spring-security-rest-full</name>
<packaging>war</packaging> <packaging>war</packaging>
<dependencies> <dependencies>
@ -72,6 +72,31 @@
<version>${org.springframework.version}</version> <version>${org.springframework.version}</version>
</dependency> </dependency>
<!-- persistence -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.17.1-GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
<scope>runtime</scope>
</dependency>
<!-- web --> <!-- web -->
<dependency> <dependency>
@ -128,7 +153,7 @@
</dependencies> </dependencies>
<build> <build>
<finalName>spring-security-basic-auth</finalName> <finalName>spring-security-rest-full</finalName>
<resources> <resources>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
@ -141,7 +166,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version> <version>${maven-surefire-plugin.version}</version>
<configuration> <configuration>
<excludes> <excludes>
<!-- <exclude>**/*ProductionTest.java</exclude> --> <!-- <exclude>**/*ProductionTest.java</exclude> -->
@ -155,7 +180,7 @@
<plugin> <plugin>
<groupId>org.codehaus.cargo</groupId> <groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId> <artifactId>cargo-maven2-plugin</artifactId>
<version>${cargo-maven2-plugin.version}</version> <version>${cargo-maven2-plugin.version}</version>
<configuration> <configuration>
<wait>true</wait> <wait>true</wait>
<container> <container>
@ -178,39 +203,39 @@
</build> </build>
<properties> <properties>
<!-- Spring --> <!-- Spring -->
<org.springframework.version>3.2.3.RELEASE</org.springframework.version> <org.springframework.version>3.2.3.RELEASE</org.springframework.version>
<org.springframework.security.version>3.1.4.RELEASE</org.springframework.security.version> <org.springframework.security.version>3.1.4.RELEASE</org.springframework.security.version>
<!-- persistence --> <!-- persistence -->
<hibernate.version>4.2.2.Final</hibernate.version> <hibernate.version>4.2.2.Final</hibernate.version>
<mysql-connector-java.version>5.1.25</mysql-connector-java.version> <mysql-connector-java.version>5.1.25</mysql-connector-java.version>
<!-- logging --> <!-- logging -->
<org.slf4j.version>1.7.5</org.slf4j.version> <org.slf4j.version>1.7.5</org.slf4j.version>
<logback.version>1.0.11</logback.version> <logback.version>1.0.11</logback.version>
<!-- various --> <!-- various -->
<hibernate-validator.version>5.0.1.Final</hibernate-validator.version> <hibernate-validator.version>5.0.1.Final</hibernate-validator.version>
<!-- util --> <!-- util -->
<guava.version>14.0.1</guava.version> <guava.version>14.0.1</guava.version>
<commons-lang3.version>3.1</commons-lang3.version> <commons-lang3.version>3.1</commons-lang3.version>
<!-- testing --> <!-- testing -->
<org.hamcrest.version>1.3</org.hamcrest.version> <org.hamcrest.version>1.3</org.hamcrest.version>
<junit.version>4.11</junit.version> <junit.version>4.11</junit.version>
<mockito.version>1.9.5</mockito.version> <mockito.version>1.9.5</mockito.version>
<httpcore.version>4.2.4</httpcore.version> <httpcore.version>4.2.4</httpcore.version>
<httpclient.version>4.2.5</httpclient.version> <httpclient.version>4.2.5</httpclient.version>
<rest-assured.version>1.8.0</rest-assured.version> <rest-assured.version>1.8.0</rest-assured.version>
<groovy.version>1.8.9</groovy.version> <groovy.version>1.8.9</groovy.version>
<!-- Maven plugins --> <!-- Maven plugins -->
<cargo-maven2-plugin.version>1.4.2</cargo-maven2-plugin.version> <cargo-maven2-plugin.version>1.4.2</cargo-maven2-plugin.version>
<maven-surefire-plugin.version>2.14.1</maven-surefire-plugin.version> <maven-surefire-plugin.version>2.14.1</maven-surefire-plugin.version>
</properties> </properties>
</project> </project>

View File

@ -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();
}
}

View File

@ -1,14 +1,79 @@
package org.baeldung.spring; 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.ComponentScan;
import org.springframework.context.annotation.Configuration; 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 @Configuration
@ComponentScan("org.baeldung.persistence") @EnableTransactionManagement
@PropertySource({ "classpath:persistence-mysql.properties" })
@ComponentScan({ "org.baeldung.persistence" })
public class PersistenceConfig { public class PersistenceConfig {
@Autowired
private Environment env;
public PersistenceConfig() { public PersistenceConfig() {
super(); 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
}
};
}
}

View File

@ -10,7 +10,7 @@
<http use-expressions="true"> <http use-expressions="true">
<intercept-url pattern="/**" access="isAuthenticated()" /> <intercept-url pattern="/**" access="isAuthenticated()" />
<http-basic entry-point-ref="myBasicAuthenticationEntryPoint" /> <http-basic />
</http> </http>