[JAVA-9806] Upgrade Maven Cargo plugin to fix error
This commit is contained in:
parent
3f46e530e7
commit
80c3331851
|
@ -1,6 +1,6 @@
|
||||||
## Spring Security Login
|
## Spring Security Login
|
||||||
|
|
||||||
This module contains articles about login mechanisms with Spring Security
|
This module contains articles about login mechanisms with Spring Security.
|
||||||
|
|
||||||
### The Course
|
### The Course
|
||||||
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
||||||
|
@ -17,3 +17,12 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
||||||
```
|
```
|
||||||
mvn clean install
|
mvn clean install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Run the Project
|
||||||
|
|
||||||
|
- Run the application using Maven Cargo plugin.
|
||||||
|
```
|
||||||
|
mvn cargo:run
|
||||||
|
```
|
||||||
|
- Go to the login page at http://localhost:8082/spring-security-web-login/login.html
|
||||||
|
- Login using ```user1/user1Pass``` details.
|
|
@ -137,17 +137,9 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.cargo</groupId>
|
<groupId>org.codehaus.cargo</groupId>
|
||||||
<artifactId>cargo-maven2-plugin</artifactId>
|
<artifactId>cargo-maven3-plugin</artifactId>
|
||||||
<version>${cargo-maven2-plugin.version}</version>
|
<version>${cargo-maven3-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<wait>true</wait>
|
|
||||||
<container>
|
|
||||||
<containerId>jetty8x</containerId>
|
|
||||||
<type>embedded</type>
|
|
||||||
<systemProperties>
|
|
||||||
<!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
|
|
||||||
</systemProperties>
|
|
||||||
</container>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<properties>
|
<properties>
|
||||||
<cargo.servlet.port>8082</cargo.servlet.port>
|
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||||
|
@ -160,7 +152,7 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Maven plugins -->
|
<!-- Maven plugins -->
|
||||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
<cargo-maven3-plugin.version>1.9.9</cargo-maven3-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,9 +1,5 @@
|
||||||
package com.baeldung;
|
package com.baeldung;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.ServletRegistration;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -11,10 +7,13 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||||
import org.springframework.web.filter.DelegatingFilterProxy;
|
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.ServletRegistration;
|
||||||
|
|
||||||
public class AppInitializer implements WebApplicationInitializer {
|
public class AppInitializer implements WebApplicationInitializer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartup(final ServletContext sc) throws ServletException {
|
public void onStartup(final ServletContext sc) {
|
||||||
|
|
||||||
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ public class AppInitializer implements WebApplicationInitializer {
|
||||||
ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
|
ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
|
||||||
appServlet.setLoadOnStartup(1);
|
appServlet.setLoadOnStartup(1);
|
||||||
appServlet.addMapping("/");
|
appServlet.addMapping("/");
|
||||||
|
|
||||||
sc.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"))
|
sc.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"))
|
||||||
.addMappingForUrlPatterns(null, false, "/*");
|
.addMappingForUrlPatterns(null, false, "/*");
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,22 @@
|
||||||
package com.baeldung.security;
|
package com.baeldung.security;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
|
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
|
||||||
|
|
||||||
public static final Logger LOG = LoggerFactory.getLogger(CustomAccessDeniedHandler.class);
|
public static final Logger LOG = LoggerFactory.getLogger(CustomAccessDeniedHandler.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException exc) throws IOException, ServletException {
|
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException exc) throws IOException {
|
||||||
Authentication auth = SecurityContextHolder.getContext()
|
Authentication auth = SecurityContextHolder.getContext()
|
||||||
.getAuthentication();
|
.getAuthentication();
|
||||||
if (auth != null) {
|
if (auth != null) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.Calendar;
|
||||||
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
|
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
|
public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException {
|
||||||
httpServletResponse.setStatus(HttpStatus.UNAUTHORIZED.value());
|
httpServletResponse.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||||
|
|
||||||
String jsonPayload = "{\"message\" : \"%s\", \"timestamp\" : \"%s\" }";
|
String jsonPayload = "{\"message\" : \"%s\", \"timestamp\" : \"%s\" }";
|
||||||
|
|
|
@ -12,12 +12,6 @@ import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuc
|
||||||
|
|
||||||
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler implements LogoutSuccessHandler {
|
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler implements LogoutSuccessHandler {
|
||||||
|
|
||||||
public CustomLogoutSuccessHandler() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
// API
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLogoutSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws IOException, ServletException {
|
public void onLogoutSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws IOException, ServletException {
|
||||||
final String refererUrl = request.getHeader("Referer");
|
final String refererUrl = request.getHeader("Referer");
|
||||||
|
|
|
@ -23,10 +23,6 @@ import com.baeldung.security.CustomLogoutSuccessHandler;
|
||||||
@Profile("!https")
|
@Profile("!https")
|
||||||
public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
|
public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
public SecSecurityConfig() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
|
@ -81,7 +77,7 @@ public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
public AuthenticationFailureHandler authenticationFailureHandler() {
|
public AuthenticationFailureHandler authenticationFailureHandler() {
|
||||||
return new CustomAuthenticationFailureHandler();
|
return new CustomAuthenticationFailureHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PasswordEncoder passwordEncoder() {
|
public PasswordEncoder passwordEncoder() {
|
||||||
return new BCryptPasswordEncoder();
|
return new BCryptPasswordEncoder();
|
||||||
|
|
|
@ -17,10 +17,6 @@ import com.baeldung.security.CustomLogoutSuccessHandler;
|
||||||
@Profile("https")
|
@Profile("https")
|
||||||
public class ChannelSecSecurityConfig extends WebSecurityConfigurerAdapter {
|
public class ChannelSecSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
public ChannelSecSecurityConfig() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
|
|
|
@ -13,12 +13,6 @@ import org.springframework.web.servlet.view.JstlView;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class MvcConfig implements WebMvcConfigurer {
|
public class MvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
public MvcConfig() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
// API
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,6 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti
|
||||||
//@Profile("!https")
|
//@Profile("!https")
|
||||||
public class RedirectionSecurityConfig extends WebSecurityConfigurerAdapter {
|
public class RedirectionSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
public RedirectionSecurityConfig() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication()
|
||||||
|
|
Loading…
Reference in New Issue