springjwt

Generating JWT token with JwtUtil class in Spring Boot resulting in NullPointerException


main dashboard main dashboardmain dashboardmain dashboardmain dashboardmain dashboardmain dashboard

main dashboard main dashboardmain dashboardmain dashboardmain dashboardmain dashboardmain dashboard

main dashboard main dashboardmain dashboardmain dashboardmain dashboardmain dashboardmain dashboard main dashboard main dashboardmain dashboardmain dashboardmain dashboardmain dashboardmain dashboard

 aiohappyeyeballs==2.4.6
aiohttp==3.11.12
aiosignal==1.3.2
aiosqlite==0.21.0
alembic==1.14.1
anyio==4.8.0
apache-airflow==2.10.4
apache-airflow-providers-common-compat==1.3.0
apache-airflow-providers-common-io==1.5.0
apache-airflow-providers-common-sql==1.21.0
apache-airflow-providers-fab==1.5.3
apache-airflow-providers-ftp==3.12.0
apache-airflow-providers-http==5.0.0
apache-airflow-providers-imap==3.8.0
apache-airflow-providers-smtp==1.9.0
apache-airflow-providers-sqlite==4.0.0
apispec==6.8.1
argcomplete==3.5.3
asgiref==3.8.1
attrs==25.1.0
babel==2.17.0
blinker==1.9.0
cachelib==0.9.0
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.4.1
click==8.1.8
clickclick==20.10.2
colorama==0.4.6
colorlog==6.9.0
ConfigUpdater==3.2
connexion==2.14.2
cron-descriptor==1.4.5
croniter==6.0.0
cryptography==44.0.1
Deprecated==1.2.18
dill==0.3.9
dnspython==2.7.0
email_validator==2.2.0
Flask==2.2.5
Flask-AppBuilder==4.5.3
Flask-Babel==2.0.0
Flask-Caching==2.3.0
Flask-JWT-Extended==4.7.1
Flask-Limiter==3.10.1
Flask-Login==0.6.3
Flask-Session==0.5.0
Flask-SQLAlchemy==2.5.1
Flask-WTF==1.2.2
frozenlist==1.5.0
fsspec==2025.2.0
google-re2==1.1.20240702
googleapis-common-protos==1.67.0
greenlet==3.1.1
grpcio==1.70.0
gunicorn==23.0.0
h11==0.14.0
httpcore==1.0.7
httpx==0.28.1
idna==3.10
importlib_metadata==8.5.0
inflection==0.5.1
itsdangerous==2.2.0
Jinja2==3.1.5
jmespath==1.0.1
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
lazy-object-proxy==1.10.0
limits==4.0.1
linkify-it-py==2.0.3
lockfile==0.12.2
Mako==1.3.9
markdown-it-py==3.0.0
MarkupSafe==3.0.2
marshmallow==3.26.1
marshmallow-oneofschema==3.1.1
marshmallow-sqlalchemy==0.28.2
mdit-py-plugins==0.4.2
mdurl==0.1.2
methodtools==0.4.7
more-itertools==10.6.0
multidict==6.1.0
opentelemetry-api==1.30.0
opentelemetry-exporter-otlp==1.30.0
opentelemetry-exporter-otlp-proto-common==1.30.0
opentelemetry-exporter-otlp-proto-grpc==1.30.0
opentelemetry-exporter-otlp-proto-http==1.30.0
opentelemetry-proto==1.30.0
opentelemetry-sdk==1.30.0
opentelemetry-semantic-conventions==0.51b0
ordered-set==4.1.0
packaging==24.2
pathspec==0.12.1
pendulum==3.0.0
pluggy==1.5.0
prison==0.2.1
propcache==0.2.1
protobuf==5.29.3
psutil==6.1.1
psycopg2==2.9.9
pycparser==2.22
Pygments==2.19.1
PyJWT==2.10.1
python-daemon==3.1.2
python-dateutil==2.9.0.post0
python-nvd3==0.15.0
python-slugify==8.0.4
pytz==2025.1
PyYAML==6.0.2
referencing==0.36.2
requests==2.32.3
requests-toolbelt==1.0.0
rfc3339-validator==0.1.4
rich==13.9.4
rich-argparse==1.7.0
rpds-py==0.22.3
setproctitle==1.3.4
setuptools==75.8.0
six==1.17.0
sniffio==1.3.1
SQLAlchemy==1.4.54
SQLAlchemy-JSONField==1.0.2
SQLAlchemy-Utils==0.41.2
sqlparse==0.5.3
tabulate==0.9.0
tenacity==9.0.0
termcolor==2.5.0
text-unidecode==1.3
time-machine==2.16.0
typing_extensions==4.12.2
tzdata==2025.1
uc-micro-py==1.0.3
universal_pathlib==0.2.6
urllib3==2.3.0
Werkzeug==2.2.3
wheel==0.45.1
wirerope==1.0.0
wrapt==1.17.2
WTForms==3.2.1
yarl==1.18.3
zipp==3.21.0


Solution

  • in class: public class MySecurityConfig extends WebSecurityConfigurerAdapter the WebSecurityConfigurerAdapter is deprecated, instead you can create class like this:

    @Configuration
    @EnableWebSecurity
    public class WebSecurityConfig {
        
        @Bean
        BCryptPasswordEncoder bCryptPasswordEncoder() {
            return new BCryptPasswordEncoder();
        }
        
        @Bean
        SecurityFilterChain filterChain(HttpSecurity http)throws Exception{
            http.authorizeHttpRequests(authz -> authz
                    .requestMatchers(HttpMethod.GET,"/testAPI").permitAll()
                    .requestMatchers("").permitAll()
                    .anyRequest().authenticated())
            .httpBasic(Customizer.withDefaults());
            return http.build();
        }
        
        @Bean
        UserDetailsService userDetailsService() {
            InMemoryUserDetailsManager userDetailsService = new 
        InMemoryUserDetailsManager();
            UserDetails userDetails = User
                    .withUsername("vinod")
                    .password(bCryptPasswordEncoder().encode("singh"))
                    .authorities("read").build();
            userDetailsService.createUser(userDetails);
            return userDetailsService;
        }
    
    }