Project

General

Profile

« Previous | Next » 

Revision 60650

[Users | Trunk]: Fix condition on verify role methods

View differences:

modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/AuthorizationService.java
1 1
package eu.dnetlib.openaire.usermanagement.utils;
2 2

  
3
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
4
import org.springframework.security.core.Authentication;
5
import org.springframework.security.core.GrantedAuthority;
6
import org.springframework.security.core.context.SecurityContextHolder;
3 7
import org.springframework.stereotype.Component;
4 8

  
9
import java.util.ArrayList;
10
import java.util.List;
11

  
5 12
@Component("AuthorizationService")
6 13
public class AuthorizationService {
7 14

  
......
47 54
    public boolean isCommunity(String type) {
48 55
        return mapType(type, false).equals("community");
49 56
    }
57

  
58

  
59
    public List<String> getRoles() {
60
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
61
        if (authentication != null) {
62
            List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
63
            if (authorities != null) {
64
                List<String> roles = new ArrayList<>();
65
                authorities.forEach((authority) -> {
66
                    roles.add(authority.getAuthority());
67
                });
68
                return roles;
69
            }
70
        }
71
        return null;
72
    }
73

  
74
    public String getAaiId() {
75
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
76
        return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getSub() : null;
77
    }
78

  
79
    public String getEmail() {
80
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
81
        return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getUserInfo().getEmail() : null;
82
    }
50 83
}
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/api/RegistryService.java
313 313
        if (verification != null && verification.getVerificationType().equals("manager")) {
314 314
            Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
315 315
            if (coPersonId != null) {
316
                if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
316
                if (verification.getEmail().equalsIgnoreCase(authorizationService.getEmail())) {
317 317
                    if (verification.getVerificationCode().equals(code)) {
318 318
                        Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
319 319
                        if (couId != null) {
......
379 379
        if (verification != null && verification.getVerificationType().equals("member")) {
380 380
            Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
381 381
            if (coPersonId != null) {
382
                if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
382
                if (verification.getEmail().equalsIgnoreCase(authorizationService.getEmail())) {
383 383
                    if (verification.getVerificationCode().equals(code)) {
384 384
                        Integer couId = calls.getCouId(verification.getType(), verification.getEntity(), false);
385 385
                        if (couId != null) {

Also available in: Unified diff