Merge remote-tracking branch 'upstream/master'
This commit is contained in:
		
						commit
						06999f4a74
					
				
							
								
								
									
										17
									
								
								.travis.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.travis.yml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | |||||||
|  | language: java | ||||||
|  | 
 | ||||||
|  | install: travis_wait 40 mvn -q clean install | ||||||
|  | 
 | ||||||
|  | jdk: | ||||||
|  |   - oraclejdk8 | ||||||
|  | 
 | ||||||
|  | sudo: false | ||||||
|  | addons: | ||||||
|  |   apt: | ||||||
|  |     packages: | ||||||
|  |       - oracle-java8-installer | ||||||
|  | 
 | ||||||
|  | cache: | ||||||
|  |   directories: | ||||||
|  |   - .autoconf | ||||||
|  |   - $HOME/.m2 | ||||||
| @ -54,8 +54,6 @@ public class GenericEntityController { | |||||||
| 
 | 
 | ||||||
|     @GetMapping("/entity/findbyversion") |     @GetMapping("/entity/findbyversion") | ||||||
|     public ResponseEntity findByVersion(@Version String version) { |     public ResponseEntity findByVersion(@Version String version) { | ||||||
|         return version != null |         return version != null ? new ResponseEntity(entityList.stream().findFirst().get(), HttpStatus.OK) : new ResponseEntity(HttpStatus.NOT_FOUND); | ||||||
|             ? new ResponseEntity(entityList.stream().findFirst().get(), HttpStatus.OK) |  | ||||||
|             : new ResponseEntity(HttpStatus.NOT_FOUND); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,17 +1,12 @@ | |||||||
| package com.baeldung.annotation.servletcomponentscan; | package com.baeldung.annotation.servletcomponentscan; | ||||||
| 
 | 
 | ||||||
| import com.baeldung.annotation.servletcomponentscan.javaee.AttrListener; | import static org.junit.Assert.assertEquals; | ||||||
| import com.baeldung.annotation.servletcomponentscan.javaee.EchoServlet; | import static org.junit.Assert.assertNotNull; | ||||||
| import com.baeldung.annotation.servletcomponentscan.javaee.HelloFilter; | import static org.junit.Assert.assertTrue; | ||||||
| import com.baeldung.annotation.servletcomponentscan.javaee.HelloServlet; | 
 | ||||||
| import org.jboss.arquillian.container.test.api.Deployment; | import java.net.MalformedURLException; | ||||||
| import org.jboss.arquillian.container.test.api.RunAsClient; | import java.net.URI; | ||||||
| import org.jboss.arquillian.junit.Arquillian; | import java.net.URL; | ||||||
| import org.jboss.arquillian.test.api.ArquillianResource; |  | ||||||
| import org.jboss.shrinkwrap.api.ShrinkWrap; |  | ||||||
| import org.jboss.shrinkwrap.api.spec.WebArchive; |  | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| 
 | 
 | ||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
| import javax.servlet.FilterRegistration; | import javax.servlet.FilterRegistration; | ||||||
| @ -22,24 +17,31 @@ import javax.ws.rs.client.Entity; | |||||||
| import javax.ws.rs.client.WebTarget; | import javax.ws.rs.client.WebTarget; | ||||||
| import javax.ws.rs.core.MediaType; | import javax.ws.rs.core.MediaType; | ||||||
| import javax.ws.rs.core.Response; | import javax.ws.rs.core.Response; | ||||||
| import java.net.MalformedURLException; |  | ||||||
| import java.net.URI; |  | ||||||
| import java.net.URL; |  | ||||||
| 
 | 
 | ||||||
| import static org.junit.Assert.*; | import org.jboss.arquillian.container.test.api.Deployment; | ||||||
|  | import org.jboss.arquillian.container.test.api.RunAsClient; | ||||||
|  | import org.jboss.arquillian.junit.Arquillian; | ||||||
|  | import org.jboss.arquillian.test.api.ArquillianResource; | ||||||
|  | import org.jboss.shrinkwrap.api.ShrinkWrap; | ||||||
|  | import org.jboss.shrinkwrap.api.spec.WebArchive; | ||||||
|  | import org.junit.Test; | ||||||
|  | import org.junit.runner.RunWith; | ||||||
|  | 
 | ||||||
|  | import com.baeldung.annotation.servletcomponentscan.javaee.AttrListener; | ||||||
|  | import com.baeldung.annotation.servletcomponentscan.javaee.EchoServlet; | ||||||
|  | import com.baeldung.annotation.servletcomponentscan.javaee.HelloFilter; | ||||||
|  | import com.baeldung.annotation.servletcomponentscan.javaee.HelloServlet; | ||||||
| 
 | 
 | ||||||
| @RunWith(Arquillian.class) | @RunWith(Arquillian.class) | ||||||
| public class JavaEEAppTest { | public class JavaEEAppIntegrationTest { | ||||||
| 
 | 
 | ||||||
|     @Deployment |     @Deployment | ||||||
|     public static WebArchive createDeployment() { |     public static WebArchive createDeployment() { | ||||||
|         return ShrinkWrap |         return ShrinkWrap.create(WebArchive.class).addClass(JavaEEApp.class).addClasses(AttrListener.class, HelloFilter.class, HelloServlet.class, EchoServlet.class); | ||||||
|           .create(WebArchive.class) |  | ||||||
|           .addClass(JavaEEApp.class) |  | ||||||
|           .addClasses(AttrListener.class, HelloFilter.class, HelloServlet.class, EchoServlet.class); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Inject private ServletContext servletContext; |     @Inject | ||||||
|  |     private ServletContext servletContext; | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void givenServletContextListener_whenAccessSpecialAttrs_thenFound() throws MalformedURLException { |     public void givenServletContextListener_whenAccessSpecialAttrs_thenFound() throws MalformedURLException { | ||||||
| @ -54,21 +56,18 @@ public class JavaEEAppTest { | |||||||
|         FilterRegistration filterRegistration = servletContext.getFilterRegistration("hello filter"); |         FilterRegistration filterRegistration = servletContext.getFilterRegistration("hello filter"); | ||||||
| 
 | 
 | ||||||
|         assertNotNull(filterRegistration); |         assertNotNull(filterRegistration); | ||||||
|         assertTrue(filterRegistration |         assertTrue(filterRegistration.getServletNameMappings().contains("echo servlet")); | ||||||
|           .getServletNameMappings() |  | ||||||
|           .contains("echo servlet")); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @ArquillianResource private URL base; |     @ArquillianResource | ||||||
|  |     private URL base; | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     @RunAsClient |     @RunAsClient | ||||||
|     public void givenFilterAndServlet_whenGetHello_thenRespondFilteringHello() throws MalformedURLException { |     public void givenFilterAndServlet_whenGetHello_thenRespondFilteringHello() throws MalformedURLException { | ||||||
|         Client client = ClientBuilder.newClient(); |         Client client = ClientBuilder.newClient(); | ||||||
|         WebTarget target = client.target(URI.create(new URL(base, "hello").toExternalForm())); |         WebTarget target = client.target(URI.create(new URL(base, "hello").toExternalForm())); | ||||||
|         Response response = target |         Response response = target.request().get(); | ||||||
|           .request() |  | ||||||
|           .get(); |  | ||||||
| 
 | 
 | ||||||
|         assertEquals("filtering hello", response.readEntity(String.class)); |         assertEquals("filtering hello", response.readEntity(String.class)); | ||||||
|     } |     } | ||||||
| @ -78,9 +77,7 @@ public class JavaEEAppTest { | |||||||
|     public void givenFilterAndServlet_whenPostEcho_thenEchoFiltered() throws MalformedURLException { |     public void givenFilterAndServlet_whenPostEcho_thenEchoFiltered() throws MalformedURLException { | ||||||
|         Client client = ClientBuilder.newClient(); |         Client client = ClientBuilder.newClient(); | ||||||
|         WebTarget target = client.target(URI.create(new URL(base, "echo").toExternalForm())); |         WebTarget target = client.target(URI.create(new URL(base, "echo").toExternalForm())); | ||||||
|         Response response = target |         Response response = target.request().post(Entity.entity("echo", MediaType.TEXT_PLAIN_TYPE)); | ||||||
|           .request() |  | ||||||
|           .post(Entity.entity("echo", MediaType.TEXT_PLAIN_TYPE)); |  | ||||||
| 
 | 
 | ||||||
|         assertEquals("filtering echo", response.readEntity(String.class)); |         assertEquals("filtering echo", response.readEntity(String.class)); | ||||||
|     } |     } | ||||||
| @ -20,7 +20,7 @@ import static org.junit.Assert.*; | |||||||
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootAnnotatedApp.class) | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootAnnotatedApp.class) | ||||||
| @AutoConfigureMockMvc | @AutoConfigureMockMvc | ||||||
| @TestPropertySource(properties = { "security.basic.enabled=false", "server.tomcat.additional-tld-skip-patterns=tomee-*.jar,tomcat-*.jar,openejb-*.jar,cxf-*.jar,activemq-*.jar" }) | @TestPropertySource(properties = { "security.basic.enabled=false", "server.tomcat.additional-tld-skip-patterns=tomee-*.jar,tomcat-*.jar,openejb-*.jar,cxf-*.jar,activemq-*.jar" }) | ||||||
| public class SpringBootWithServletComponentTest { | public class SpringBootWithServletComponentIntegrationTest { | ||||||
| 
 | 
 | ||||||
|     @Autowired private ServletContext servletContext; |     @Autowired private ServletContext servletContext; | ||||||
| 
 | 
 | ||||||
| @ -20,7 +20,7 @@ import static org.junit.Assert.*; | |||||||
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootPlainApp.class) | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootPlainApp.class) | ||||||
| @AutoConfigureMockMvc | @AutoConfigureMockMvc | ||||||
| @TestPropertySource(properties = { "security.basic.enabled=false", "server.tomcat.additional-tld-skip-patterns=tomee-*.jar,tomcat-*.jar,openejb-*.jar,cxf-*.jar,activemq-*.jar" }) | @TestPropertySource(properties = { "security.basic.enabled=false", "server.tomcat.additional-tld-skip-patterns=tomee-*.jar,tomcat-*.jar,openejb-*.jar,cxf-*.jar,activemq-*.jar" }) | ||||||
| public class SpringBootWithoutServletComponentTest { | public class SpringBootWithoutServletComponentIntegrationTest { | ||||||
| 
 | 
 | ||||||
|     @Autowired private ServletContext servletContext; |     @Autowired private ServletContext servletContext; | ||||||
| 
 | 
 | ||||||
| @ -45,29 +45,22 @@ public class SpringBootApplicationIntegrationTest { | |||||||
|     public void givenRequestHasBeenMade_whenMeetsFindByDateOfGivenConditions_thenCorrect() throws Exception { |     public void givenRequestHasBeenMade_whenMeetsFindByDateOfGivenConditions_thenCorrect() throws Exception { | ||||||
|         MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); |         MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); | ||||||
| 
 | 
 | ||||||
|         mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbydate/{date}", "2011-12-03T10:15:30")) |         mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbydate/{date}", "2011-12-03T10:15:30")).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType(contentType)) | ||||||
|             .andExpect(MockMvcResultMatchers.status().isOk()) |                 .andExpect(jsonPath("$.id", equalTo(1))); | ||||||
|             .andExpect(MockMvcResultMatchers.content().contentType(contentType)) |  | ||||||
|             .andExpect(jsonPath("$.id", equalTo(1))); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect() throws Exception { |     public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect() throws Exception { | ||||||
|         MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); |         MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); | ||||||
| 
 | 
 | ||||||
|         mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbymode/{mode}", Modes.ALPHA.name())) |         mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbymode/{mode}", Modes.ALPHA.name())).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType(contentType)).andExpect(jsonPath("$.id", equalTo(1))); | ||||||
|             .andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
|             .andExpect(MockMvcResultMatchers.content().contentType(contentType)) |  | ||||||
|             .andExpect(jsonPath("$.id", equalTo(1))); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect() throws Exception { |     public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect() throws Exception { | ||||||
|         MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); |         MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); | ||||||
| 
 | 
 | ||||||
|         mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbyversion").header("Version", "1.0.0")) |         mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbyversion").header("Version", "1.0.0")).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType(contentType)) | ||||||
|             .andExpect(MockMvcResultMatchers.status().isOk()) |                 .andExpect(jsonPath("$.id", equalTo(1))); | ||||||
|             .andExpect(MockMvcResultMatchers.content().contentType(contentType)) |  | ||||||
|             .andExpect(jsonPath("$.id", equalTo(1))); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -44,8 +44,8 @@ public class ProductInfoRepositoryIntegrationTest { | |||||||
|     private static final String EXPECTED_PRICE = "50"; |     private static final String EXPECTED_PRICE = "50"; | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     @Ignore //TODO Remove Ignore annotations when running locally with Local DynamoDB instance |     @Ignore // TODO Remove Ignore annotations when running locally with Local DynamoDB instance | ||||||
|     public  void setup() throws Exception { |     public void setup() throws Exception { | ||||||
| 
 | 
 | ||||||
|         try { |         try { | ||||||
|             dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB); |             dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB); | ||||||
| @ -64,7 +64,7 @@ public class ProductInfoRepositoryIntegrationTest { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     @Ignore //TODO Remove Ignore annotations when running locally with Local DynamoDB instance |     @Ignore // TODO Remove Ignore annotations when running locally with Local DynamoDB instance | ||||||
|     public void givenItemWithExpectedCost_whenRunFindAll_thenItemIsFound() { |     public void givenItemWithExpectedCost_whenRunFindAll_thenItemIsFound() { | ||||||
| 
 | 
 | ||||||
|         ProductInfo productInfo = new ProductInfo(EXPECTED_COST, EXPECTED_PRICE); |         ProductInfo productInfo = new ProductInfo(EXPECTED_COST, EXPECTED_PRICE); | ||||||
|  | |||||||
| @ -47,22 +47,6 @@ | |||||||
|         	<version>${fileupload.version}</version> |         	<version>${fileupload.version}</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|          |          | ||||||
|          <dependency> |  | ||||||
|             <groupId>org.springframework.security</groupId> |  | ||||||
|             <artifactId>spring-security-web</artifactId> |  | ||||||
|             <version>${org.springframework.security.version}</version> |  | ||||||
|         </dependency> |  | ||||||
|         <dependency> |  | ||||||
|             <groupId>org.springframework.security</groupId> |  | ||||||
|             <artifactId>spring-security-config</artifactId> |  | ||||||
|             <version>${org.springframework.security.version}</version> |  | ||||||
|         </dependency> |  | ||||||
|         <dependency> |  | ||||||
|             <groupId>org.springframework.security</groupId> |  | ||||||
|             <artifactId>spring-security-taglibs</artifactId> |  | ||||||
|             <version>${org.springframework.security.version}</version> |  | ||||||
|         </dependency> |  | ||||||
|          |  | ||||||
|     </dependencies> |     </dependencies> | ||||||
|     <profiles> |     <profiles> | ||||||
|         <!-- Local --> |         <!-- Local --> | ||||||
| @ -115,7 +99,6 @@ | |||||||
|         <hibernate-validator.version>5.3.3.Final</hibernate-validator.version> |         <hibernate-validator.version>5.3.3.Final</hibernate-validator.version> | ||||||
|         <deploy-path>enter-location-of-server</deploy-path> |         <deploy-path>enter-location-of-server</deploy-path> | ||||||
| 		<fileupload.version>1.3.2</fileupload.version> | 		<fileupload.version>1.3.2</fileupload.version> | ||||||
| 		<org.springframework.security.version>4.2.1.RELEASE</org.springframework.security.version> |  | ||||||
|     </properties> |     </properties> | ||||||
| 
 | 
 | ||||||
| </project> | </project> | ||||||
|  | |||||||
| @ -3,7 +3,6 @@ package com.baeldung.springmvcforms.configuration; | |||||||
| import org.springframework.web.WebApplicationInitializer; | import org.springframework.web.WebApplicationInitializer; | ||||||
| import org.springframework.web.context.ContextLoaderListener; | import org.springframework.web.context.ContextLoaderListener; | ||||||
| import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; | ||||||
| import org.springframework.web.filter.DelegatingFilterProxy; |  | ||||||
| import org.springframework.web.servlet.DispatcherServlet; | import org.springframework.web.servlet.DispatcherServlet; | ||||||
| 
 | 
 | ||||||
| import javax.servlet.ServletContext; | import javax.servlet.ServletContext; | ||||||
| @ -25,9 +24,7 @@ public class WebInitializer implements WebApplicationInitializer { | |||||||
| 
 | 
 | ||||||
| 		servlet.setLoadOnStartup(1); | 		servlet.setLoadOnStartup(1); | ||||||
| 		servlet.addMapping("/"); | 		servlet.addMapping("/"); | ||||||
| 		 | 
 | ||||||
| 		container.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")) |  | ||||||
|         .addMappingForUrlPatterns(null, false, "/*"); |  | ||||||
| 	} | 	} | ||||||
| //	@Override | //	@Override | ||||||
| //	public void onStartup(ServletContext container) { | //	public void onStartup(ServletContext container) { | ||||||
|  | |||||||
| @ -1,12 +0,0 @@ | |||||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" |  | ||||||
|     pageEncoding="ISO-8859-1"%> |  | ||||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |  | ||||||
| <html> |  | ||||||
| <head> |  | ||||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |  | ||||||
| <title></title> |  | ||||||
| </head> |  | ||||||
| <body> |  | ||||||
| Your do not have permission to view this page. |  | ||||||
| </body> |  | ||||||
| </html> |  | ||||||
| @ -1,16 +0,0 @@ | |||||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" |  | ||||||
|     pageEncoding="ISO-8859-1"%> |  | ||||||
| <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> |  | ||||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |  | ||||||
| <html> |  | ||||||
| <head> |  | ||||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |  | ||||||
| <title>Insert title here</title> |  | ||||||
| </head> |  | ||||||
| <body> |  | ||||||
| Welcome admin! <a href="<c:url value='/admin_logout' /> " >Logout</a> |  | ||||||
| 
 |  | ||||||
| <br /><br /> |  | ||||||
| <a href="<c:url value='/protectedLinks' /> " >Back to links</a> |  | ||||||
| </body> |  | ||||||
| </html> |  | ||||||
| @ -1,16 +0,0 @@ | |||||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" |  | ||||||
|     pageEncoding="ISO-8859-1"%> |  | ||||||
| <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> |  | ||||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |  | ||||||
| <html> |  | ||||||
| <head> |  | ||||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |  | ||||||
| <title>Insert title here</title> |  | ||||||
| </head> |  | ||||||
| <body> |  | ||||||
| 
 |  | ||||||
| <a href="<c:url value="/userPage" />">User page</a> |  | ||||||
| <br /> |  | ||||||
| <a href="<c:url value="/adminPage" />">Admin page</a> |  | ||||||
| </body> |  | ||||||
| </html> |  | ||||||
| @ -1,15 +0,0 @@ | |||||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" |  | ||||||
|     pageEncoding="ISO-8859-1"%> |  | ||||||
| <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> |  | ||||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |  | ||||||
| <html> |  | ||||||
| <head> |  | ||||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |  | ||||||
| <title>Insert title here</title> |  | ||||||
| </head> |  | ||||||
| <body> |  | ||||||
| Welcome user! <a href="<c:url value='/user_logout' /> " >Logout</a> |  | ||||||
| <br /><br /> |  | ||||||
| <a href="<c:url value='/protectedLinks' /> " >Back to links</a> |  | ||||||
| </body> |  | ||||||
| </html> |  | ||||||
| @ -128,6 +128,12 @@ | |||||||
|             <artifactId>spring-security-taglibs</artifactId> |             <artifactId>spring-security-taglibs</artifactId> | ||||||
|             <version>${spring-security-taglibs.version}</version> |             <version>${spring-security-taglibs.version}</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|  | 		 | ||||||
|  | 		 <dependency> | ||||||
|  |             <groupId>org.springframework.security</groupId> | ||||||
|  |             <artifactId>spring-security-core</artifactId> | ||||||
|  |             <version>${spring-security-core.version}</version> | ||||||
|  |         </dependency> | ||||||
| 
 | 
 | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>javax.servlet.jsp.jstl</groupId> |             <groupId>javax.servlet.jsp.jstl</groupId> | ||||||
| @ -280,11 +286,15 @@ | |||||||
|         <start-class>org.baeldung.Application</start-class> |         <start-class>org.baeldung.Application</start-class> | ||||||
|         <!--If you want to run the example with the voters comment the tag above and uncomment the one below--> |         <!--If you want to run the example with the voters comment the tag above and uncomment the one below--> | ||||||
|         <!--<start-class>org.baeldung.voter.VoterApplication</start-class>--> |         <!--<start-class>org.baeldung.voter.VoterApplication</start-class>--> | ||||||
|         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |         <!--If you want to run the example with the multiple logins, comment the tag above and uncomment the one below--> | ||||||
|  |         <!--<start-class>org.baeldung.multiplelogin.MultipleLoginApplication</start-class>--> | ||||||
|  | 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||||
|         <java.version>1.8</java.version> |         <java.version>1.8</java.version> | ||||||
|         <derby.version>10.13.1.1</derby.version> |         <derby.version>10.13.1.1</derby.version> | ||||||
|         <taglibs-standard.version>1.1.2</taglibs-standard.version> |         <taglibs-standard.version>1.1.2</taglibs-standard.version> | ||||||
|         <spring-security-taglibs.version>4.2.0.RELEASE</spring-security-taglibs.version> |         <spring-security-taglibs.version>4.2.0.RELEASE</spring-security-taglibs.version> | ||||||
|  | 		  <spring-security-core.version>4.2.0.RELEASE</spring-security-core.version> | ||||||
|  |        | ||||||
|         <jstl.version>1.2</jstl.version> |         <jstl.version>1.2</jstl.version> | ||||||
|         <rest-assured.version>2.4.0</rest-assured.version> |         <rest-assured.version>2.4.0</rest-assured.version> | ||||||
|         <cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version> |         <cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version> | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ import org.springframework.context.annotation.FilterType; | |||||||
| 
 | 
 | ||||||
| @Configuration | @Configuration | ||||||
| @EnableAutoConfiguration | @EnableAutoConfiguration | ||||||
| @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.voter.*")) | @ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.voter.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.multiplelogin.*")}) | ||||||
| public class Application extends SpringBootServletInitializer { | public class Application extends SpringBootServletInitializer { | ||||||
|     public static void main(String[] args) { |     public static void main(String[] args) { | ||||||
|         SpringApplication.run(Application.class, args); |         SpringApplication.run(Application.class, args); | ||||||
|  | |||||||
| @ -0,0 +1,22 @@ | |||||||
|  | package org.baeldung.multiplelogin; | ||||||
|  | 
 | ||||||
|  | import org.springframework.boot.SpringApplication; | ||||||
|  | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||||||
|  | import org.springframework.boot.context.web.SpringBootServletInitializer; | ||||||
|  | import org.springframework.context.annotation.ComponentScan; | ||||||
|  | import org.springframework.context.annotation.Configuration; | ||||||
|  | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||||
|  | import org.springframework.boot.builder.SpringApplicationBuilder; | ||||||
|  | 
 | ||||||
|  | @SpringBootApplication | ||||||
|  | @ComponentScan("org.baeldung.multiplelogin") | ||||||
|  | public class MultipleLoginApplication extends SpringBootServletInitializer { | ||||||
|  |     public static void main(String[] args) { | ||||||
|  |         SpringApplication.run(MultipleLoginApplication.class, args); | ||||||
|  |     } | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||||||
|  | 		return application.sources(MultipleLoginApplication.class); | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -0,0 +1,45 @@ | |||||||
|  | package org.baeldung.multiplelogin; | ||||||
|  | 
 | ||||||
|  | import org.springframework.context.annotation.Bean; | ||||||
|  | import org.springframework.context.annotation.Configuration; | ||||||
|  | import org.springframework.web.servlet.ViewResolver; | ||||||
|  | import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||||||
|  | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | ||||||
|  | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||||||
|  | import org.springframework.web.servlet.view.InternalResourceViewResolver; | ||||||
|  | import org.springframework.web.servlet.view.JstlView; | ||||||
|  | import org.springframework.context.annotation.ComponentScan; | ||||||
|  | 
 | ||||||
|  | @EnableWebMvc | ||||||
|  | @Configuration | ||||||
|  | @ComponentScan("org.baeldung.controller") | ||||||
|  | public class MultipleLoginMvcConfig extends WebMvcConfigurerAdapter { | ||||||
|  | 
 | ||||||
|  |     public MultipleLoginMvcConfig() { | ||||||
|  |         super(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // API | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void addViewControllers(final ViewControllerRegistry registry) { | ||||||
|  |         super.addViewControllers(registry); | ||||||
|  | 
 | ||||||
|  |         registry.addViewController("/anonymous.html"); | ||||||
|  | 
 | ||||||
|  |         registry.addViewController("/login.html"); | ||||||
|  |         registry.addViewController("/homepage.html"); | ||||||
|  |         registry.addViewController("/console.html"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Bean | ||||||
|  |     public ViewResolver viewResolver() { | ||||||
|  |         final InternalResourceViewResolver bean = new InternalResourceViewResolver(); | ||||||
|  | 
 | ||||||
|  |         bean.setViewClass(JstlView.class); | ||||||
|  |         bean.setPrefix("/WEB-INF/view/"); | ||||||
|  |         bean.setSuffix(".jsp"); | ||||||
|  | 
 | ||||||
|  |         return bean; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.baeldung.springmvcforms.configuration; | package org.baeldung.multiplelogin; | ||||||
| 
 | 
 | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.context.annotation.Bean; | import org.springframework.context.annotation.Bean; | ||||||
| @ -16,7 +16,7 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager; | |||||||
| 
 | 
 | ||||||
| @Configuration | @Configuration | ||||||
| @EnableWebSecurity | @EnableWebSecurity | ||||||
| public class SecurityConfig { | public class MultipleLoginSecurityConfig { | ||||||
| 
 | 
 | ||||||
|     @Bean |     @Bean | ||||||
|     public UserDetailsService userDetailsService() throws Exception { |     public UserDetailsService userDetailsService() throws Exception { | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.baeldung.springmvcforms.controller; | package org.baeldung.multiplelogin; | ||||||
| 
 | 
 | ||||||
| import org.springframework.stereotype.Controller; | import org.springframework.stereotype.Controller; | ||||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||||
| @ -0,0 +1,10 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html> | ||||||
|  | <head> | ||||||
|  | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | ||||||
|  | <title></title> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  | You do not have permission to view this page. | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
| @ -0,0 +1,13 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html> | ||||||
|  | <head> | ||||||
|  | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | ||||||
|  | <title>Insert title here</title> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  | Welcome admin! <a th:href="@{/admin_logout}" >Logout</a> | ||||||
|  | 
 | ||||||
|  | <br /><br /> | ||||||
|  | <a th:href="@{/protectedLinks}" >Back to links</a> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
| @ -0,0 +1,27 @@ | |||||||
|  | <html> | ||||||
|  | <head></head> | ||||||
|  | 
 | ||||||
|  | <body> | ||||||
|  |     <h1>Login</h1> | ||||||
|  | 
 | ||||||
|  |     <form name='f' action="login" method='POST'> | ||||||
|  | 
 | ||||||
|  |         <table> | ||||||
|  |             <tr> | ||||||
|  |                 <td>User:</td> | ||||||
|  |                 <td><input type="text" name="username"></td> | ||||||
|  |             </tr> | ||||||
|  |             <tr> | ||||||
|  |                 <td>Password:</td> | ||||||
|  |                 <td><input type="password" name="password" /></td> | ||||||
|  |             </tr> | ||||||
|  | 			 | ||||||
|  |             <tr> | ||||||
|  |                 <td><input name="submit" type="submit" value="submit" /></td> | ||||||
|  |             </tr> | ||||||
|  |         </table> | ||||||
|  | 
 | ||||||
|  |     </form> | ||||||
|  | 
 | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
| @ -1,10 +1,7 @@ | |||||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" | <!DOCTYPE html> | ||||||
| 	pageEncoding="ISO-8859-1"%> |  | ||||||
| <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> |  | ||||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |  | ||||||
| <html> | <html> | ||||||
| <head> | <head> | ||||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | ||||||
| <title>Insert title here</title> | <title>Insert title here</title> | ||||||
| </head> | </head> | ||||||
| <body> | <body> | ||||||
| @ -15,7 +12,7 @@ | |||||||
|         <table> |         <table> | ||||||
|             <tr> |             <tr> | ||||||
|                 <td>User:</td> |                 <td>User:</td> | ||||||
|                 <td><input type="text" name="username" value=""></td> |                 <td><input type="text" name="username" /></td> | ||||||
|             </tr> |             </tr> | ||||||
|             <tr> |             <tr> | ||||||
|                 <td>Password:</td> |                 <td>Password:</td> | ||||||
| @ -28,11 +25,7 @@ | |||||||
| 
 | 
 | ||||||
|     </form> |     </form> | ||||||
| 
 | 
 | ||||||
|     <% |     <p th:if="${param.error}">Login failed!</p> | ||||||
|         if (request.getParameter("error") != null) { |  | ||||||
|             out.println("Login failed!"); |  | ||||||
|         } |  | ||||||
|     %> |  | ||||||
| 
 | 
 | ||||||
| </body> | </body> | ||||||
| </html> | </html> | ||||||
| @ -1,10 +1,7 @@ | |||||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" | <!DOCTYPE html> | ||||||
| 	pageEncoding="ISO-8859-1"%> |  | ||||||
| <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> |  | ||||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |  | ||||||
| <html> | <html> | ||||||
| <head> | <head> | ||||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | ||||||
| <title>Login</title> | <title>Login</title> | ||||||
| </head> | </head> | ||||||
| <body> | <body> | ||||||
| @ -15,7 +12,7 @@ | |||||||
|         <table> |         <table> | ||||||
|             <tr> |             <tr> | ||||||
|                 <td>User:</td> |                 <td>User:</td> | ||||||
|                 <td><input type="text" name="username" value=""></td> |                 <td><input type="text" name="username" /></td> | ||||||
|             </tr> |             </tr> | ||||||
|             <tr> |             <tr> | ||||||
|                 <td>Password:</td> |                 <td>Password:</td> | ||||||
| @ -27,11 +24,7 @@ | |||||||
|         </table> |         </table> | ||||||
| 
 | 
 | ||||||
|     </form> |     </form> | ||||||
|     <% |     <p th:if="${param.error}">Login failed!</p> | ||||||
|         if (request.getParameter("error") != null) { |  | ||||||
|             out.println("Login failed!"); |  | ||||||
|         } |  | ||||||
|     %> |  | ||||||
| 
 | 
 | ||||||
| </body> | </body> | ||||||
| </html> | </html> | ||||||
| @ -0,0 +1,13 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html> | ||||||
|  | <head> | ||||||
|  | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | ||||||
|  | <title>Insert title here</title> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  | 
 | ||||||
|  | <a th:href="@{/userPage}">User page</a> | ||||||
|  | <br /> | ||||||
|  | <a th:href="@{/adminPage}">Admin page</a> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
| @ -0,0 +1,12 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html> | ||||||
|  | <head> | ||||||
|  | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | ||||||
|  | <title>Insert title here</title> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  | Welcome user! <a th:href="@{/user_logout}" >Logout</a> | ||||||
|  | <br /><br /> | ||||||
|  | <a th:href="@{/protectedLinks}" >Back to links</a> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user