Skip to content

Commit

Permalink
JWT auth via root / page
Browse files Browse the repository at this point in the history
  • Loading branch information
Daven00 committed Oct 4, 2023
1 parent a255382 commit ed9f730
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- master
- change-port
- jwt-auth-2

jobs:

Expand Down
6 changes: 5 additions & 1 deletion frontend/generated/vaadin-featureflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ window.Vaadin = window.Vaadin || {};
window.Vaadin.featureFlags = window.Vaadin.featureFlags || {};
window.Vaadin.featureFlags.exampleFeatureFlag = false;
window.Vaadin.featureFlags.viteForFrontendBuild = false;
window.Vaadin.featureFlags.mapComponent = false;
window.Vaadin.featureFlags.mapComponent = false;
window.Vaadin.featureFlags.spreadsheetComponent = false;
window.Vaadin.featureFlags.hillaPush = false;
window.Vaadin.featureFlags.newLicenseChecker = false;
window.Vaadin.featureFlags.collaborationEngineBackend = false;
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@
"@vaadin/vaadin-virtual-list": "23.1.0",
"@vaadin/vertical-layout": "23.1.0",
"@vaadin/virtual-list": "23.1.0",
"construct-style-sheets-polyfill": "3.0.4",
"construct-style-sheets-polyfill": "3.1.0",
"date-fns": "2.28.0",
"line-awesome": "1.3.0",
"lit": "2.1.4"
"lit": "2.2.3"
},
"devDependencies": {
"async": "3.2.2",
Expand Down Expand Up @@ -379,10 +379,10 @@
"@vaadin/vaadin-virtual-list": "23.1.0",
"@vaadin/vertical-layout": "23.1.0",
"@vaadin/virtual-list": "23.1.0",
"construct-style-sheets-polyfill": "3.0.4",
"construct-style-sheets-polyfill": "3.1.0",
"date-fns": "2.28.0",
"line-awesome": "1.3.0",
"lit": "2.1.4"
"lit": "2.2.3"
},
"devDependencies": {
"async": "3.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,43 @@
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@EnableWebSecurity
@Configuration
@Order(1)
@Order(1) // Set the order of this security configuration (lower order value = applied first)
public class SecurityConfiguration extends VaadinWebSecurityConfigurerAdapter {

public static final String LOGOUT_URL = "/";
public static final String LOGOUT_URL = "/"; // Specify the URL for logout

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
return new BCryptPasswordEncoder(); // Define the password encoder for password-based authentication
}

@Bean
public JWTAuthenticationFilter jwtAuthenticationFilter() {
return new JWTAuthenticationFilter();
}
//
// @Bean
// public MyAuthenticationSuccessHandler myAuthenticationSuccessHandler() {
// return new MyAuthenticationSuccessHandler();
// }
//
// @Bean
// public AuthenticationEntryPoint customAuthenticationEntryPoint() {
// return (request, response, authException) -> {
// // Redirect unauthenticated users to the login page
// response.sendRedirect("/login");
// };
// }

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class) // Add custom JWT filter before the UsernamePasswordAuthenticationFilter
.authorizeRequests().antMatchers("/api/**").authenticated()
.and().httpBasic();
super.configure(http);
Expand All @@ -36,6 +56,6 @@ protected void configure(HttpSecurity http) throws Exception {
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring().antMatchers("/images/*.png");
web.ignoring().antMatchers("/images/*.png"); // Ignore static resources (images) for better performance
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.privacydashboard.application.security;

import com.vaadin.flow.spring.security.VaadinWebSecurityConfigurerAdapter;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@Order(2)
public class UserApiSecurityConfiguration extends VaadinWebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/userapi/**")
.authorizeRequests()
.anyRequest().authenticated()
.and()
.addFilterBefore(new JWTAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
}
}
//package com.privacydashboard.application.security;
//
//import com.vaadin.flow.spring.security.VaadinWebSecurityConfigurerAdapter;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.annotation.Order;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//
//@Configuration
//@Order(2)
//public class UserApiSecurityConfiguration extends VaadinWebSecurityConfigurerAdapter {
// @Override
// protected void configure(HttpSecurity http) throws Exception {
// http.antMatcher("/userapi/**")
// .authorizeRequests()
// .anyRequest().authenticated()
// .and()
// .addFilterBefore(new JWTAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
// }
//}

0 comments on commit ed9f730

Please sign in to comment.