-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
3,627 additions
and
2,196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/admin_service/AdminDiscordProperties.kt → ...ervice/notifier/AdminDiscordProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...um/admin_service/CustomDiscordNotifier.kt → ...service/notifier/CustomDiscordNotifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...um/admin_service/NotifierConfiguration.kt → ...service/notifier/NotifierConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...n-service/src/main/kotlin/com/michibaum/admin_service/security/AdminServiceCredentials.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.michibaum.admin_service.security | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
@ConfigurationProperties(prefix = "spring.boot.admin.client") | ||
data class AdminServiceCredentials( | ||
var username: String = "", | ||
var password: String = "" | ||
) |
69 changes: 69 additions & 0 deletions
69
...ervice/src/main/kotlin/com/michibaum/admin_service/security/SecurityBeansConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.michibaum.admin_service.security | ||
|
||
import com.michibaum.authentication_library.AuthenticationClient | ||
import com.michibaum.authentication_library.security.ServletAuthenticationFilter | ||
import com.michibaum.authentication_library.security.ServletDelegateAuthenticationManager | ||
import com.michibaum.authentication_library.security.SpecificAuthenticationManager | ||
import com.michibaum.authentication_library.security.basic.BasicAuthenticationManager | ||
import com.michibaum.authentication_library.security.basic.CredentialsValidator | ||
import com.michibaum.authentication_library.security.basic.servlet.BasicAuthenticationConverter | ||
import com.michibaum.authentication_library.security.jwt.JwsValidator | ||
import com.michibaum.authentication_library.security.jwt.JwtAuthenticationManager | ||
import com.michibaum.authentication_library.security.jwt.servlet.JwtAuthenticationConverter | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Lazy | ||
import org.springframework.security.authentication.AuthenticationManager | ||
import org.springframework.security.web.authentication.AuthenticationConverter | ||
|
||
@Configuration | ||
class SecurityBeansConfiguration { | ||
|
||
@Bean | ||
fun adminServiceCredentials(): AdminServiceCredentials = | ||
AdminServiceCredentials() | ||
|
||
|
||
|
||
@Bean | ||
fun jwsValidator(@Lazy authenticationClient: AuthenticationClient): JwsValidator = | ||
JwsValidator(authenticationClient) | ||
|
||
@Bean | ||
fun credentialsValidator(adminServiceCredentials: AdminServiceCredentials): CredentialsValidator = | ||
CredentialsValidator { basic -> | ||
adminServiceCredentials.username == basic.getUsername() && | ||
adminServiceCredentials.password == basic.getPassword() | ||
} | ||
|
||
|
||
|
||
@Bean | ||
fun jwtAuthenticationManager(jwsValidator: JwsValidator): SpecificAuthenticationManager = | ||
JwtAuthenticationManager(jwsValidator) | ||
|
||
@Bean | ||
fun basicAuthenticationManager(credentialsValidator: CredentialsValidator): SpecificAuthenticationManager = | ||
BasicAuthenticationManager(credentialsValidator) | ||
|
||
@Bean | ||
fun authenticationManager(specificAuthenticationManagers: List<SpecificAuthenticationManager>): AuthenticationManager = | ||
ServletDelegateAuthenticationManager(specificAuthenticationManagers) | ||
|
||
|
||
|
||
@Bean | ||
fun jwtAuthenticationConverter(): AuthenticationConverter = | ||
JwtAuthenticationConverter() | ||
|
||
@Bean | ||
fun basicAuthenticationConverter(): AuthenticationConverter = | ||
BasicAuthenticationConverter() | ||
|
||
|
||
|
||
@Bean | ||
fun authenticationFilter(authenticationManager: AuthenticationManager, authenticationConverters: List<AuthenticationConverter>) = | ||
ServletAuthenticationFilter(authenticationManager, authenticationConverters) | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
admin-service/src/main/kotlin/com/michibaum/admin_service/security/SecurityConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.michibaum.admin_service.security | ||
|
||
import com.michibaum.authentication_library.security.ServletAuthenticationFilter | ||
import com.michibaum.permission_library.Permissions | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity | ||
import org.springframework.security.web.SecurityFilterChain | ||
import org.springframework.security.web.authentication.AuthenticationFilter | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter | ||
|
||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@EnableMethodSecurity | ||
class SecurityConfiguration { | ||
|
||
@Bean | ||
fun securityFilterChain( | ||
http: HttpSecurity, | ||
authenticationFilter: ServletAuthenticationFilter | ||
): SecurityFilterChain { | ||
return http | ||
.authorizeHttpRequests { | ||
it.requestMatchers( | ||
"/actuator", | ||
"/actuator/**" | ||
).hasAnyAuthority(Permissions.ADMIN_SERVICE.name) | ||
.anyRequest().authenticated() | ||
} | ||
.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter::class.java) | ||
.httpBasic { httpBasicSpec -> httpBasicSpec.disable() } | ||
.formLogin { formLoginSpec -> formLoginSpec.disable() } | ||
.csrf { csrfSpec -> csrfSpec.disable() } | ||
.logout { logoutSpec -> logoutSpec.disable() } | ||
.build() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 66 additions & 7 deletions
73
admin-service/src/test/kotlin/com/michibaum/admin_service/ActuatorIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.