main
|
Last change
on this file was 700e2f9, checked in by 186079 <matej.milevski@…>, 5 days ago |
|
Init
|
-
Property mode
set to
100644
|
|
File size:
815 bytes
|
| Line | |
|---|
| 1 | package com.finki.icare.utils;
|
|---|
| 2 |
|
|---|
| 3 | import com.finki.icare.exceptions.ICareException;
|
|---|
| 4 | import com.finki.icare.config.JwtAuthenticationToken;
|
|---|
| 5 | import lombok.experimental.UtilityClass;
|
|---|
| 6 | import org.springframework.security.core.Authentication;
|
|---|
| 7 |
|
|---|
| 8 | @UtilityClass
|
|---|
| 9 | public class AuthUtils {
|
|---|
| 10 |
|
|---|
| 11 | public static Integer getUserId(Authentication authentication) {
|
|---|
| 12 | if (authentication instanceof JwtAuthenticationToken jwtAuth) {
|
|---|
| 13 | return jwtAuth.getUserId();
|
|---|
| 14 | }
|
|---|
| 15 | throw ICareException.unauthorized("Authentication required");
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | public static String getUserType(Authentication authentication) {
|
|---|
| 19 | if (authentication instanceof JwtAuthenticationToken jwtAuth) {
|
|---|
| 20 | return jwtAuth.getUserType();
|
|---|
| 21 | }
|
|---|
| 22 | throw ICareException.unauthorized("Authentication required");
|
|---|
| 23 | }
|
|---|
| 24 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.