From f168733da2f1c8629497a9aaf88ef7b8380473c7 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Tue, 16 May 2023 10:53:56 +0400 Subject: [PATCH] =?UTF-8?q?Lab=206=20MVC=20+=20SPA=20(=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=84=D0=B8=D0=BB=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.mv.db | Bin 151552 -> 143360 bytes front/vue_front/src/components/Profile.vue | 19 ++-- .../lab1/SecurityConfiguration.java | 45 ++++---- .../lab1/SecurityConfigurationSPA.java | 105 ++++++++++++++++++ src/main/resources/application.properties | 1 + src/main/resources/templates/error.html | 13 +++ 6 files changed, 156 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/webproglabs/lab1/SecurityConfigurationSPA.java create mode 100644 src/main/resources/templates/error.html diff --git a/data.mv.db b/data.mv.db index 3be22bde93dc78468dab39cd8023743df465f463..6deb6d78451fb45e3384145ec9df0b216d459d21 100644 GIT binary patch delta 11445 zcmeI2dyrJsoyYIF(>>iiGtLYQ^WZVe1LUC%-1nmwWN=l+L}f?>4ZEp$pNJ4<6a-0? z8Q6`QxLYfDs<>Iqu0k|oLX=61?M8M3X2rNxvg#j+YbvhE?v|D8RvwjDyJQR4-#Pbn zdZvLvC{kNxSIwNhedgZ&%{k}y`F+p%{dPW4*!f<5?qEqO+M9-*jU_E?Ke^#^UP%-L zq3GOs@8*pq$`(dE3h*&}#ahZu5F-pdcGmcc*^=VI972pYYcd;{gVgu?J)#<=_FoT=D`?i+s;)u20+fq`C_Y4njEt!5el7{7`BWZf3 zWqQSXH{ZL(b60F#n~bQCj;`*~(RC!TIP5t0j#!(W9VJmeh@y3(`{6VeN}@w2QpSJv z;_RiWP0f)sC$dNM#~b93nN=-GObxO;T~S3cWTQS~f=^A51ej^Y2K$-V21AIJl4yn| z6gO?y=G_eINVMSl$;A*I45ez3o!vM~xRw|vsIF0E9huN`4;P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DWneA&1LkWsQ&_I-Ns?=t(g$$?*gmkiLjcWy=Fj*f`N-SBAKp<*;n9hSyjD@NlM7Nc>q zhoy198Xb*`4zB+^PB)Aj7X=#6C?rX@ktzOeNR@}O{hH@cfYGayZc!U41t=z7))RvA zhS#$Ee8iKcu=n*+<8Gl&(t30YadO1Q6;mtYZMhup|By*`ZIOKN-I5?ELH8_Crk%5Esnv#9trw}_0|J_CO60Uy^HrjUlNE;aV(VJmVYG)3t zczrJ_xx}tx*#_$yZ#|AzKNiQHNOc;wx>+S~8eRl2)%vF98AGE9FZ+xW=cYK>l# z^nYS|uSt4Z>o96o(Jj4uP0}TIfql?`*mAE)`ul$Wf10EZzrNIVO794^Q-0vW<6wU% z+}u|{%n1k#qC*X=WVxLf~6p6Y|*_JXigw;Q4yhVi^Y=)$QFw&NB>^LZO{a6 sxubd+qY%55Y!?>cnFFtFFDu296;##ex8K13&0^@B$%&@jenBezAI$Lq

Профили

-

Список профилей

  • @@ -107,12 +104,18 @@ export default { this.refreshList(); }, async editUser() { - const response = await axios.put('http://localhost:8080/api/1.0/profile/' + this.selectedProfileId + '?login=' + this.loginModal + '&password=' + this.passwordModal, - { + // const response = await axios.put('http://localhost:8080/api/1.0/profile/' + this.selectedProfileId + '?login=' + this.loginModal + '&password=' + this.passwordModal, + // { + // headers: { + // 'Authorization': 'Bearer ' + localStorage.token + // } + // }); + await fetch('http://localhost:8080/api/1.0/profile/' + this.selectedProfileId + '?login=' + this.loginModal + '&password=' + this.passwordModal, { + method: 'PUT', headers: { - 'Authorization': 'Bearer ' + localStorage.token - } - }); + 'Authorization':'Bearer ' + localStorage['token'] + }, + }) this.refreshList(); }, async refreshList() { diff --git a/src/main/java/com/webproglabs/lab1/SecurityConfiguration.java b/src/main/java/com/webproglabs/lab1/SecurityConfiguration.java index 9baced0..7b54521 100644 --- a/src/main/java/com/webproglabs/lab1/SecurityConfiguration.java +++ b/src/main/java/com/webproglabs/lab1/SecurityConfiguration.java @@ -7,7 +7,9 @@ import com.webproglabs.lab1.lab34.model.UserRole; import com.webproglabs.lab1.lab34.services.ProfileService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; @@ -16,11 +18,20 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint; +import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint; +import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; + +import java.util.LinkedHashMap; @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(securedEnabled = true) +@Profile("mvc") public class SecurityConfiguration extends WebSecurityConfigurerAdapter { private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class); private static final String LOGIN_URL = "/login"; @@ -46,8 +57,10 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { } } -/* @Override + @Override protected void configure(HttpSecurity http) throws Exception { + + http.exceptionHandling().authenticationEntryPoint(delegatingEntryPoint()); http.headers().frameOptions().sameOrigin().and() .cors().and() .csrf().disable() @@ -60,24 +73,6 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .loginPage(LOGIN_URL).permitAll() .and() .logout().permitAll(); - }*/ - - @Override - protected void configure(HttpSecurity http) throws Exception { - log.info("Creating security configuration"); - http.cors() - .and() - .csrf().disable() - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .authorizeRequests() - .antMatchers("/", SPA_URL_MASK).permitAll() - .antMatchers(HttpMethod.POST, WebConfiguration.REST_API + "/profile" + ProfileController.URL_LOGIN).permitAll() - .anyRequest() - .authenticated() - .and() - .addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class) - .anonymous(); } @Override @@ -95,4 +90,16 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/swagger-resources/**") .antMatchers("/v3/api-docs/**"); } + + @Bean + public AuthenticationEntryPoint delegatingEntryPoint() { + final LinkedHashMap map = new LinkedHashMap(); + map.put(new AntPathRequestMatcher("/"), new LoginUrlAuthenticationEntryPoint("/login")); + map.put(new AntPathRequestMatcher("/api/1.0/**"), new Http403ForbiddenEntryPoint()); + + final DelegatingAuthenticationEntryPoint entryPoint = new DelegatingAuthenticationEntryPoint(map); + entryPoint.setDefaultEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")); + + return entryPoint; + } } \ No newline at end of file diff --git a/src/main/java/com/webproglabs/lab1/SecurityConfigurationSPA.java b/src/main/java/com/webproglabs/lab1/SecurityConfigurationSPA.java new file mode 100644 index 0000000..1508432 --- /dev/null +++ b/src/main/java/com/webproglabs/lab1/SecurityConfigurationSPA.java @@ -0,0 +1,105 @@ +package com.webproglabs.lab1; + +import com.webproglabs.lab1.lab34.controller.ProfileController; +import com.webproglabs.lab1.lab34.controller.mvc_controllers.UserSignupMvcController; +import com.webproglabs.lab1.lab34.jwt.JwtFilter; +import com.webproglabs.lab1.lab34.model.UserRole; +import com.webproglabs.lab1.lab34.services.ProfileService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint; +import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint; +import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; + +import java.util.LinkedHashMap; + +@Configuration +@EnableWebSecurity +@EnableGlobalMethodSecurity(securedEnabled = true) +@Profile("spa") +public class SecurityConfigurationSPA extends WebSecurityConfigurerAdapter { + private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class); + private static final String LOGIN_URL = "/login"; + public static final String SPA_URL_MASK = "/{path:[^\\.]*}"; + private final ProfileService userService; + private final JwtFilter jwtFilter; + + public SecurityConfigurationSPA(ProfileService userService) { + this.userService = userService; + this.jwtFilter = new JwtFilter(userService); + createAdminOnStartup(); + } + + private void createAdminOnStartup() { + final String admin = "admin"; + if (userService.findByLogin(admin) == null) { + log.info("Admin user successfully created"); + try { + userService.createUser(admin, admin, admin, UserRole.ADMIN); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + log.info("Creating security configuration"); + http.cors() + .and() + .csrf().disable() + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) + .and() + .authorizeRequests() + .antMatchers("/", SPA_URL_MASK).permitAll() + .antMatchers(HttpMethod.POST, WebConfiguration.REST_API + "/profile" + ProfileController.URL_LOGIN).permitAll() + .anyRequest() + .authenticated() + .and() + .addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class) + .anonymous(); + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userService); + } + + @Override + public void configure(WebSecurity web) { + web.ignoring() + .antMatchers("/css/**") + .antMatchers("/js/**") + .antMatchers("/templates/**") + .antMatchers("/webjars/**") + .antMatchers("/swagger-resources/**") + .antMatchers("/v3/api-docs/**"); + } + + @Bean + public AuthenticationEntryPoint delegatingEntryPoint() { + final LinkedHashMap map = new LinkedHashMap(); + map.put(new AntPathRequestMatcher("/"), new LoginUrlAuthenticationEntryPoint("/login")); + map.put(new AntPathRequestMatcher("/api/1.0/**"), new Http403ForbiddenEntryPoint()); + + final DelegatingAuthenticationEntryPoint entryPoint = new DelegatingAuthenticationEntryPoint(map); + entryPoint.setDefaultEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")); + + return entryPoint; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6455a46..e84707d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,3 +13,4 @@ spring.h2.console.settings.web-allow-others=false spring.security.user.password=user jwt.dev-token=my-secret-jwt jwt.dev=true +spring.profiles.active=mvc diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 0000000..9d66499 --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file