Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
web:framework:spring:jwt [2025/03/14 08:17] – [Services] jcheron | web:framework:spring:jwt [2025/08/12 02:35] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 7: | Ligne 7: | ||
< | < | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
</ | </ | ||
Ligne 100: | Ligne 105: | ||
val source = UrlBasedCorsConfigurationSource() | val source = UrlBasedCorsConfigurationSource() | ||
val config = CorsConfiguration() | val config = CorsConfiguration() | ||
- | | + | config.allowedOrigins = allowedOrigins.split("," |
- | | + | config.allowedMethods = listOf(" |
- | config.allowedMethods = listOf(" | + | config.allowedHeaders = listOf(" |
- | config.allowedHeaders = listOf(" | + | config.allowCredentials = true |
- | config.allowCredentials = true | + | source.registerCorsConfiguration("/ |
- | source.registerCorsConfiguration("/ | + | |
- | } | + | |
return source | return source | ||
} | } | ||
Ligne 118: | Ligne 121: | ||
</ | </ | ||
+ | ===== RSA config ===== | ||
+ | <sxh kotlin> | ||
+ | @ConfigurationProperties(prefix = " | ||
+ | @JvmRecord | ||
+ | data class RsaKeyConfigProperties(val publicKey: RSAPublicKey, | ||
+ | </ | ||
+ | |||
+ | ==== Génération des clés RSA ==== | ||
+ | Avec git bash : | ||
+ | <sxh bash; | ||
+ | genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits: | ||
+ | </ | ||
+ | |||
+ | <sxh bash; | ||
+ | openssl rsa -in private.pem -pubout -out public.pem | ||
+ | </ | ||
==== AuthUser ==== | ==== AuthUser ==== | ||
<sxh kotlin> | <sxh kotlin> | ||
Ligne 142: | Ligne 161: | ||
===== Services ===== | ===== Services ===== | ||
+ | |||
+ | <sxh kotlin> | ||
+ | @Service | ||
+ | class JpaUserDetailsService( | ||
+ | val userRepository: | ||
+ | val logEventRepository: | ||
+ | ) : UserDetailsService { | ||
+ | |||
+ | |||
+ | @Throws(UsernameNotFoundException:: | ||
+ | @Transactional | ||
+ | override fun loadUserByUsername(usernameOrEmail: | ||
+ | val user: User = userRepository | ||
+ | .findByUsernameOrEmail(usernameOrEmail, | ||
+ | .orElseThrow { UsernameNotFoundException(" | ||
+ | return AuthUser(user) | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
<sxh kotlin> | <sxh kotlin> | ||
@Service | @Service |