jwt

please see https://github.com/murphp15/jwt-client-authorization-filter/blob/master/README.md

Лицензия

Лицензия

Категории

Категории

CLI Взаимодействие с пользователем
Группа

Группа

io.github.murphp15
Идентификатор

Идентификатор

jwt-client-authorization-filter
Последняя версия

Последняя версия

1.0.1
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

jwt
please see https://github.com/murphp15/jwt-client-authorization-filter/blob/master/README.md
Ссылка на сайт

Ссылка на сайт

https://github.com/murphp15/jwt-client-authorization-filter
Система контроля версий

Система контроля версий

https://github.com/murphp15/jwt-client-authorization-filter

Скачать jwt-client-authorization-filter

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-security jar 2.4.2

runtime (4)

Идентификатор библиотеки Тип Версия
io.jsonwebtoken : jjwt-impl jar 0.11.2
io.jsonwebtoken : jjwt-jackson jar 0.11.2
org.jetbrains.kotlin : kotlin-stdlib jar 1.4.21
javax.servlet : servlet-api jar 2.5

Модули Проекта

Данный проект не имеет модулей.

jwt-client-authorization-filter

This is an implemntation of a jwt authentication filter for spring boot. There are many tutorials that describe how to build one of these but none of them provide an artifact that can be used. This allows you to avoid copying and pasting code into your own projects. Example tutoirals: https://auth0.com/blog/implementing-jwt-authentication-on-spring-boot/, https://www.freecodecamp.org/news/how-to-setup-jwt-authorization-and-authentication-in-spring/, https://dzone.com/articles/implementing-jwt-authentication-on-spring-boot-api

maven coordinates

<dependency>
  <groupId>io.github.murphp15</groupId>
  <artifactId>jwt-client-authorization-filter</artifactId>
  <version>1.0.0</version>
</dependency>

Each microservice that needs to validate a token can use this by including it in their webSecurityConfigurationAdapter.

@Configuration
class WebSecurityConfig(val defaultUserDetailsRepo: UserDetailsCreator,
                        val tokenCreator: TokenCreator,
                        @Value("\${jwt.secret}") private val jwtSecret: String) : WebSecurityConfigurerAdapter() {


    override fun configure(http: HttpSecurity) {
        http.authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .addFilter(JwtAuthorizationFilter(authenticationManager(), defaultUserDetailsRepo, jwtSecret))
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .csrf().disable();
    }

By default a token is mapped to a org.springframework.security.core.userdetails.User with the username and the roles pulled from the jwt token. However if further augmentation of the authenticated user object is needed a custom version of user UserDetailsCreator can be provided.

e.g

interface UserDetailsCreator {
    fun createFromToken(username: String, roles: List<String>): UserDetails?
}


class  MyComplicatedCustomUserDetailsCreator : UserDetailsCreator {
    fun createFromToken(username: String, roles: List<String>): UserDetails = MyCustomUserObject("blah", roles = "ROLE_CAN_DO_STUFF")
}

Версии библиотеки

Версия
1.0.1
1.0.0