source: backend/src/main/java/com/finki/icare/utils/AuthUtils.java

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
RevLine 
[700e2f9]1package com.finki.icare.utils;
2
3import com.finki.icare.exceptions.ICareException;
4import com.finki.icare.config.JwtAuthenticationToken;
5import lombok.experimental.UtilityClass;
6import org.springframework.security.core.Authentication;
7
8@UtilityClass
9public 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.