Этот главный ключ шифрует/расшифровывает значения в таблице. Когда пользователь входит в систему, главный ключ должен быть расшифрован и сохранен в основном сеансе пользователя, чтобы он мог управлять своими зашифрованными данными.
Я создал следующий фильтр, однако пароль больше нет в запросе. Я думаю, что он был удален после успешной аутентификации.
Код: Выделить всё
@Slf4j
public class MasterKeyFilter extends GenericFilterBean {
@Override
public void doFilter(
ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
log.info("MasterKeyFilter triggered");
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
String password = obtainPassword(request);
if (authentication.getPrincipal() instanceof WallabyAuthenticatedUser user) {
user.setMasterKey(decodeMasterKey(user.getMasterKey(), password));
}
}
chain.doFilter(request, response);
}
private String obtainPassword(ServletRequest request) {
return request.getParameter("password");
}
private String decodeMasterKey(String encryptedMasterKey, String password) {
return MasterKeyEncryptionUtil.decryptMasterKey(encryptedMasterKey, password);
}
}
Код: Выделить всё
@EnableWebSecurity
@Configuration
public class SecurityConfiguration extends VaadinWebSecurity {
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
AuthenticationManager authenticationManager = authenticationManager(http.getSharedObject(AuthenticationConfiguration.class));
http.addFilterBefore(new MasterKeyFilter(), UsernamePasswordAuthenticationFilter.class);
http.authorizeHttpRequests(
authorize -> authorize.requestMatchers(new AntPathRequestMatcher("/images/*.png")).permitAll());
http.authorizeHttpRequests(authorize -> authorize
.requestMatchers(new AntPathRequestMatcher("/line-awesome/**/*.svg")).permitAll());
super.configure(http);
setLoginView(http, LoginView.class);
}
}
Что я пробовал:
- Расширение AbstractAuthenticationProcessingFilter, но это нарушает вход в систему li>
Добавление фильтра перед UsernamePasswordAuthenticationFilter по-прежнему та же проблема
Любые советы приветствуются!
Подробнее здесь: https://stackoverflow.com/questions/791 ... pring-boot