[Users | Trunk]: Fix condition on verify role methods
This commit is contained in:
parent
76f86a9ab3
commit
f26ea5a8fd
|
@ -313,7 +313,7 @@ public class RegistryService {
|
||||||
if (verification != null && verification.getVerificationType().equals("manager")) {
|
if (verification != null && verification.getVerificationType().equals("manager")) {
|
||||||
Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
|
Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
|
||||||
if (coPersonId != null) {
|
if (coPersonId != null) {
|
||||||
if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
|
if (verification.getEmail().equalsIgnoreCase(authorizationService.getEmail())) {
|
||||||
if (verification.getVerificationCode().equals(code)) {
|
if (verification.getVerificationCode().equals(code)) {
|
||||||
Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
|
Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
|
||||||
if (couId != null) {
|
if (couId != null) {
|
||||||
|
@ -379,7 +379,7 @@ public class RegistryService {
|
||||||
if (verification != null && verification.getVerificationType().equals("member")) {
|
if (verification != null && verification.getVerificationType().equals("member")) {
|
||||||
Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
|
Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
|
||||||
if (coPersonId != null) {
|
if (coPersonId != null) {
|
||||||
if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
|
if (verification.getEmail().equalsIgnoreCase(authorizationService.getEmail())) {
|
||||||
if (verification.getVerificationCode().equals(code)) {
|
if (verification.getVerificationCode().equals(code)) {
|
||||||
Integer couId = calls.getCouId(verification.getType(), verification.getEntity(), false);
|
Integer couId = calls.getCouId(verification.getType(), verification.getEntity(), false);
|
||||||
if (couId != null) {
|
if (couId != null) {
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
package eu.dnetlib.openaire.usermanagement.utils;
|
package eu.dnetlib.openaire.usermanagement.utils;
|
||||||
|
|
||||||
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component("AuthorizationService")
|
@Component("AuthorizationService")
|
||||||
public class AuthorizationService {
|
public class AuthorizationService {
|
||||||
|
|
||||||
|
@ -47,4 +54,30 @@ public class AuthorizationService {
|
||||||
public boolean isCommunity(String type) {
|
public boolean isCommunity(String type) {
|
||||||
return mapType(type, false).equals("community");
|
return mapType(type, false).equals("community");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<String> getRoles() {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
if (authentication != null) {
|
||||||
|
List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
|
||||||
|
if (authorities != null) {
|
||||||
|
List<String> roles = new ArrayList<>();
|
||||||
|
authorities.forEach((authority) -> {
|
||||||
|
roles.add(authority.getAuthority());
|
||||||
|
});
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAaiId() {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getSub() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getUserInfo().getEmail() : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue