SpringSecurityConfig.ktprojectforge-application/src/main/kotlin/org/projectforge/security/SpringSecurityConfig.kt, содержащий код Kotlin для уровня безопасности.Аннотации: Bean, Configuration, Throws, Override
Классы: SpringSecurityConfig
Spring Beans: allowWebDavMethodsFirewall, passwordEncoder
Функции (4): securityFilterChain, allowWebDavMethodsFirewall, userDetailsService, passwordEncoder
Свойства (2): firewall, manager
Импорты: 13 пакетов
Пакет: org.projectforge.security
package org.projectforge.security
import org.projectforge.framework.utils.NumberHelper
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.Customizer
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.provisioning.InMemoryUserDetailsManager
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.firewall.HttpFirewall
import org.springframework.security.web.firewall.StrictHttpFirewall
@Configuration
open class SpringSecurityConfig {
@Bean
@Throws(Exception::class)
open fun securityFilterChain(http: HttpSecurity, firewall: HttpFirewall): SecurityFilterChain {
http
.authorizeHttpRequests(Customizer { authorize ->
authorize
.anyRequest().permitAll()
} // Разрешить все запросы без аутентификации
)
.csrf({ csrf -> csrf.disable() }) // CSRF выполняется PF.
// Настройка брандмауэра для разрешения методов WebDAV:
http.setSharedObject(HttpFirewall::class.java, firewall)
return http.build()
}
@Bean
open fun allowWebDavMethodsFirewall(): HttpFirewall {
val firewall = StrictHttpFirewall()
// HTTP-методы для WebDAV явно разрешены
firewall.setAllowedHttpMethods(
listOf(
"GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD",
"PROPFIND", "REPORT", //"PROPPATCH", "MKCOL", "COPY", "MOVE",
//"LOCK", "UNLOCK", "REPORT"
)
)
return firewall
}
@Bean
@Override
open fun userDetailsService(): UserDetailsService {
/**
* Пароль генерируется случайным образом и не сохраняется в базе данных.
* Пользователи не поддерживаются, случайный пароль лучше, чем пароль по умолчанию, на всякий случай.
*/
val manager = InMemoryUserDetailsManager();
manager.createUser(
User.withUsername("user")
.password(passwordEncoder().encode(NumberHelper.getSecureRandomAlphanumeric(20)))
.roles("USER")
.build()
);
return manager;
}
@Bean
open fun passwordEncoder(): PasswordEncoder {
return BCryptPasswordEncoder();
}
}
868d6abb7 2025 -> 2026 63081666f Заголовки исходных файлов: 2024-> 2025. 953455ae5 WIP: Carddav 7f2c255ae WIP: CardDav 921638f43 WIP