[JAVA-9806] Upgrade Maven Cargo plugin to fix error

This commit is contained in:
Haroon Khan 2022-02-06 18:31:38 +00:00
parent 3f46e530e7
commit 80c3331851
10 changed files with 25 additions and 52 deletions

View File

@ -1,6 +1,6 @@
## 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 "Learn Spring Security" Classes: http://github.learnspringsecurity.com
@ -17,3 +17,12 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
```
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.

View File

@ -137,17 +137,9 @@
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>${cargo-maven2-plugin.version}</version>
<artifactId>cargo-maven3-plugin</artifactId>
<version>${cargo-maven3-plugin.version}</version>
<configuration>
<wait>true</wait>
<container>
<containerId>jetty8x</containerId>
<type>embedded</type>
<systemProperties>
<!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
</systemProperties>
</container>
<configuration>
<properties>
<cargo.servlet.port>8082</cargo.servlet.port>
@ -160,7 +152,7 @@
<properties>
<!-- 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>
</project>

View File

@ -1,9 +1,5 @@
package com.baeldung;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
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.servlet.DispatcherServlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;
public class AppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(final ServletContext sc) throws ServletException {
public void onStartup(final ServletContext sc) {
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
@ -24,7 +23,7 @@ public class AppInitializer implements WebApplicationInitializer {
ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
appServlet.setLoadOnStartup(1);
appServlet.addMapping("/");
sc.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"))
.addMappingForUrlPatterns(null, false, "/*");

View File

@ -1,25 +1,22 @@
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.LoggerFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
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 static final Logger LOG = LoggerFactory.getLogger(CustomAccessDeniedHandler.class);
@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()
.getAuthentication();
if (auth != null) {

View File

@ -13,7 +13,7 @@ import java.util.Calendar;
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
@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());
String jsonPayload = "{\"message\" : \"%s\", \"timestamp\" : \"%s\" }";

View File

@ -12,12 +12,6 @@ import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuc
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler implements LogoutSuccessHandler {
public CustomLogoutSuccessHandler() {
super();
}
// API
@Override
public void onLogoutSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws IOException, ServletException {
final String refererUrl = request.getHeader("Referer");

View File

@ -23,10 +23,6 @@ import com.baeldung.security.CustomLogoutSuccessHandler;
@Profile("!https")
public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
public SecSecurityConfig() {
super();
}
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
@ -81,7 +77,7 @@ public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
public AuthenticationFailureHandler authenticationFailureHandler() {
return new CustomAuthenticationFailureHandler();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();

View File

@ -17,10 +17,6 @@ import com.baeldung.security.CustomLogoutSuccessHandler;
@Profile("https")
public class ChannelSecSecurityConfig extends WebSecurityConfigurerAdapter {
public ChannelSecSecurityConfig() {
super();
}
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off

View File

@ -13,12 +13,6 @@ import org.springframework.web.servlet.view.JstlView;
@Configuration
public class MvcConfig implements WebMvcConfigurer {
public MvcConfig() {
super();
}
// API
@Override
public void addViewControllers(final ViewControllerRegistry registry) {

View File

@ -11,10 +11,6 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti
//@Profile("!https")
public class RedirectionSecurityConfig extends WebSecurityConfigurerAdapter {
public RedirectionSecurityConfig() {
super();
}
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()