Class JwtRoleConverter

java.lang.Object
ir.msob.jima.security.commons.JwtRoleConverter
All Implemented Interfaces:
org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,Collection<org.springframework.security.core.GrantedAuthority>>

public class JwtRoleConverter extends Object implements org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,Collection<org.springframework.security.core.GrantedAuthority>>
Converter class for extracting and converting JWT (JSON Web Token) claims related to roles into a collection of Spring Security GrantedAuthority objects.

This class implements the Spring Framework Converter interface and is intended to be used as part of the JWT decoding process to extract and convert role information from the JWT claims.

Usage: This converter is typically used in conjunction with a ReactiveJwtDecoder when configuring JWT decoding in a Spring Security context. It converts the 'roles' claim from the JWT into a collection of GrantedAuthority objects.

Example: ```java JwtRoleConverter jwtRoleConverter = new JwtRoleConverter(); // Instantiate the converter Jwt jwt = // ... obtain JWT from the authentication token Collection<GrantedAuthority> authorities = jwtRoleConverter.convert(jwt); // ... make use of the authorities in your security logic ```

Since:
0.1.0
Author:
Yaqub Abdi
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Collection<org.springframework.security.core.GrantedAuthority>
    convert(org.springframework.security.oauth2.jwt.Jwt jwt)
    Converts the 'roles' claim from the JWT into a collection of GrantedAuthority objects.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.core.convert.converter.Converter

    andThen
  • Constructor Details

    • JwtRoleConverter

      public JwtRoleConverter()
  • Method Details

    • convert

      public Collection<org.springframework.security.core.GrantedAuthority> convert(org.springframework.security.oauth2.jwt.Jwt jwt)
      Converts the 'roles' claim from the JWT into a collection of GrantedAuthority objects.
      Specified by:
      convert in interface org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,Collection<org.springframework.security.core.GrantedAuthority>>
      Parameters:
      jwt - The JWT from which to extract roles.
      Returns:
      A collection of GrantedAuthority objects representing the roles.