SUPPORT-8817: sync with ervu-lkrp-ul
This commit is contained in:
parent
9349af6def
commit
08c1555e4e
3 changed files with 41 additions and 0 deletions
|
|
@ -17,8 +17,11 @@ public class JwtAuthentication implements Authentication {
|
|||
private final Authentication authentication;
|
||||
private final String token;
|
||||
|
||||
private final UserIdsPair userIdsPair;
|
||||
|
||||
public JwtAuthentication(Authentication authentication, String userAccountId, String token) {
|
||||
this.userAccountId = userAccountId;
|
||||
this.userIdsPair = new UserIdsPair(userAccountId);
|
||||
this.authentication = authentication;
|
||||
this.token = token;
|
||||
}
|
||||
|
|
@ -31,6 +34,10 @@ public class JwtAuthentication implements Authentication {
|
|||
return userAccountId;
|
||||
}
|
||||
|
||||
public UserIdsPair getUserIdsPair() {
|
||||
return userIdsPair;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return authentication.getAuthorities();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package ru.micord.ervu.security.webbpm.jwt;
|
||||
|
||||
public class UserIdsPair {
|
||||
private final String esiaUserId;
|
||||
private final String ervuId;
|
||||
|
||||
public UserIdsPair(String idsConcatenated) {
|
||||
|
||||
if (idsConcatenated == null) {
|
||||
this.esiaUserId = null;
|
||||
this.ervuId = null;
|
||||
}
|
||||
else {
|
||||
String[] ids = idsConcatenated.split(":");
|
||||
this.esiaUserId = ids[0];
|
||||
this.ervuId = ids.length == 2 ? ids[1] : null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getEsiaUserId() {
|
||||
return esiaUserId;
|
||||
}
|
||||
|
||||
public String getErvuId() {
|
||||
return ervuId;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import org.springframework.security.core.Authentication;
|
|||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
import ru.micord.ervu.security.webbpm.jwt.JwtAuthentication;
|
||||
import ru.micord.ervu.security.webbpm.jwt.UserIdsPair;
|
||||
|
||||
public final class SecurityUtil {
|
||||
public static final String AUTH_TOKEN = "auth_token";
|
||||
|
|
@ -41,6 +42,12 @@ public final class SecurityUtil {
|
|||
.orElse(null);
|
||||
}
|
||||
|
||||
public static UserIdsPair getUserIdsPair() {
|
||||
return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication())
|
||||
.map(a -> ((JwtAuthentication) a).getUserIdsPair())
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static String getCurrentUsername() {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth != null && auth.isAuthenticated()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue