From 50456ef211e9181cdc3f9824d1a04211c2f90a3b Mon Sep 17 00:00:00 2001 From: amontenegro Date: Mon, 23 Sep 2024 16:27:06 -0600 Subject: [PATCH] Session is being loaded! --- .../v3/read_only/EmailManagerReadOnly.java | 4 +- .../impl/EmailManagerReadOnlyImpl.java | 13 +++- .../core/oauth/OrcidProfileUserDetails.java | 25 ++------ .../security/OrcidUserDetailsServiceImpl.java | 60 ++++++++--------- .../core/utils/SecurityContextTestUtils.java | 2 +- .../src/main/resources/ehcache_default.xml | 7 ++ .../main/resources/ehcache_orcid-api-web.xml | 7 ++ .../resources/ehcache_orcid-internal-api.xml | 7 ++ .../main/resources/ehcache_orcid-pub-web.xml | 9 ++- .../resources/ehcache_orcid-scheduler-web.xml | 9 ++- .../src/main/resources/ehcache_orcid-web.xml | 9 ++- .../security/OrcidUserDetailsServiceTest.java | 2 - .../web/controllers/BaseControllerUtil.java | 64 ++++++++++++++++++- .../web/controllers/HomeController.java | 10 ++- .../listener/LoginApplicationListener.java | 3 +- .../OrcidAuthenticationProviderTest.java | 4 +- .../web/controllers/AdminControllerTest.java | 2 +- .../controllers/ClientsControllerTest.java | 3 +- .../controllers/FundingsControllerTest.java | 2 +- .../controllers/GetMyDataControllerTest.java | 2 +- .../ManageMembersControllerTest.java | 2 +- .../ManageProfileControllerTest.java | 2 +- .../web/controllers/OrgControllerTest.java | 2 +- .../RegistrationControllerTest.java | 4 +- .../OAuthAuthorizeNotSignedInFilterTest.java | 2 +- .../frontend/web/util/BaseControllerTest.java | 2 +- 26 files changed, 174 insertions(+), 84 deletions(-) diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/EmailManagerReadOnly.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/EmailManagerReadOnly.java index 60865c6cc4e..4922d4e0f9d 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/EmailManagerReadOnly.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/EmailManagerReadOnly.java @@ -37,7 +37,9 @@ public interface EmailManagerReadOnly extends ManagerReadOnlyBase { EmailEntity find(String email); - Email findPrimaryEmail(String orcid); + Email findPrimaryEmail(String orcid); + + String findPrimaryEmailValueFromCache(String orcid); EmailFrequencyOptions getEmailFrequencyOptions(); diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/EmailManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/EmailManagerReadOnlyImpl.java index 6dbf3888dd9..0f9b0e08a9f 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/EmailManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/EmailManagerReadOnlyImpl.java @@ -27,6 +27,7 @@ import org.orcid.utils.OrcidStringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cache.annotation.Cacheable; /** * @@ -185,7 +186,17 @@ public Email findPrimaryEmail(String orcid) { } return jpaJaxbEmailAdapter.toEmail(emailDao.findPrimaryEmail(orcid)); } - + + @Override + @Cacheable("primary-email-value") + public String findPrimaryEmailValueFromCache(String orcid) { + if(PojoUtil.isEmpty(orcid)) { + return null; + } + EmailEntity entity = emailDao.findPrimaryEmail(orcid); + return entity.getEmail(); + } + @Override public boolean isUsersOnlyEmail(String orcid, String email) { List emails = emailDao.findByOrcid(orcid, getLastModified(orcid)); diff --git a/orcid-core/src/main/java/org/orcid/core/oauth/OrcidProfileUserDetails.java b/orcid-core/src/main/java/org/orcid/core/oauth/OrcidProfileUserDetails.java index e2ef41b699e..8cb455ceb24 100644 --- a/orcid-core/src/main/java/org/orcid/core/oauth/OrcidProfileUserDetails.java +++ b/orcid-core/src/main/java/org/orcid/core/oauth/OrcidProfileUserDetails.java @@ -13,26 +13,19 @@ public class OrcidProfileUserDetails implements UserDetails { private static final long serialVersionUID = 1L; - private String orcid; + private final String orcid; - private String primaryEmail; - - private String password; + private final String password; private Collection grantedAuthorities = new HashSet<>(); - public OrcidProfileUserDetails() { - } - - public OrcidProfileUserDetails(String orcid, String primaryEmail, String password) { + public OrcidProfileUserDetails(String orcid, String password) { this.orcid = orcid; - this.primaryEmail = primaryEmail; this.password = password; } - public OrcidProfileUserDetails(String orcid, String primaryEmail, String password, Collection grantedAuthorities) { + public OrcidProfileUserDetails(String orcid, String password, Collection grantedAuthorities) { this.orcid = orcid; - this.primaryEmail = primaryEmail; this.password = password; this.grantedAuthorities = grantedAuthorities; } @@ -122,10 +115,6 @@ public String getOrcid() { return orcid; } - public String getPrimaryEmail() { - return primaryEmail; - } - @Override public int hashCode() { final int prime = 31; @@ -133,7 +122,6 @@ public int hashCode() { result = prime * result + ((grantedAuthorities == null) ? 0 : grantedAuthorities.hashCode()); result = prime * result + ((orcid == null) ? 0 : orcid.hashCode()); result = prime * result + ((password == null) ? 0 : password.hashCode()); - result = prime * result + ((primaryEmail == null) ? 0 : primaryEmail.hashCode()); return result; } @@ -161,11 +149,6 @@ public boolean equals(Object obj) { return false; } else if (!password.equals(other.password)) return false; - if (primaryEmail == null) { - if (other.primaryEmail != null) - return false; - } else if (!primaryEmail.equals(other.primaryEmail)) - return false; return true; } diff --git a/orcid-core/src/main/java/org/orcid/core/security/OrcidUserDetailsServiceImpl.java b/orcid-core/src/main/java/org/orcid/core/security/OrcidUserDetailsServiceImpl.java index 9841f2c7c03..bcdfc327a1f 100644 --- a/orcid-core/src/main/java/org/orcid/core/security/OrcidUserDetailsServiceImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/security/OrcidUserDetailsServiceImpl.java @@ -53,13 +53,13 @@ public class OrcidUserDetailsServiceImpl implements OrcidUserDetailsService { @Resource private EmailDao emailDao; - - @Resource(name = "emailManagerReadOnlyV3") - protected EmailManagerReadOnly emailManagerReadOnly; - + @Resource private OrcidSecurityManager securityMgr; + @Resource (name = "emailManagerReadOnlyV3") + private EmailManagerReadOnly emailManagerReadOnly; + @Value("${org.orcid.core.baseUri}") private String baseUrl; @@ -107,43 +107,19 @@ public OrcidProfileUserDetails loadUserByProfile(ProfileEntity profile) { } private OrcidProfileUserDetails createUserDetails(ProfileEntity profile) { - String primaryEmail = retrievePrimaryEmail(profile); - + String primaryEmail = retrievePrimaryEmail(profile.getId()); OrcidProfileUserDetails userDetails = null; if (profile.getOrcidType() != null) { OrcidType orcidType = OrcidType.valueOf(profile.getOrcidType()); - userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword(), buildAuthorities(orcidType, profile.getGroupType() != null ? MemberType.valueOf(profile.getGroupType()) : null)); + userDetails = new OrcidProfileUserDetails(profile.getId(), profile.getEncryptedPassword(), buildAuthorities(orcidType, profile.getGroupType() != null ? MemberType.valueOf(profile.getGroupType()) : null)); } else { - userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword()); + userDetails = new OrcidProfileUserDetails(profile.getId(), profile.getEncryptedPassword()); } return userDetails; } - private String retrievePrimaryEmail(ProfileEntity profile) { - String orcid = profile.getId(); - try { - return emailDao.findPrimaryEmail(orcid).getEmail(); - } catch (javax.persistence.NoResultException nre) { - String alternativePrimaryEmail = emailDao.findNewestVerifiedOrNewestEmail(profile.getId()); - emailDao.updatePrimary(orcid, alternativePrimaryEmail); - - String message = String.format("User with orcid %s have no primary email, so, we are setting the newest verified email, or, the newest email in case non is verified as the primary one", orcid); - LOGGER.error(message); - - return alternativePrimaryEmail; - } catch (javax.persistence.NonUniqueResultException nure) { - String alternativePrimaryEmail = emailDao.findNewestPrimaryEmail(profile.getId()); - emailDao.updatePrimary(orcid, alternativePrimaryEmail); - - String message = String.format("User with orcid %s have more than one primary email, so, we are setting the latest modified primary as the primary one", orcid); - LOGGER.error(message); - - return alternativePrimaryEmail; - } - } - private void checkStatuses(ProfileEntity profile) { if (profile.getPrimaryRecord() != null) { throw new DeprecatedProfileException("orcid.frontend.security.deprecated_with_primary", profile.getPrimaryRecord().getId(), profile.getId()); @@ -207,9 +183,25 @@ else if (orcidType.equals(OrcidType.GROUP)) { } private List rolesAsList(OrcidWebRole... roles) { - // Make a mutable list - List list = new ArrayList(Arrays.asList(roles)); - return list; + return new ArrayList(Arrays.asList(roles)); + } + @Deprecated(forRemoval = true) + private String retrievePrimaryEmail(String orcid) { + try { + return emailDao.findPrimaryEmail(orcid).getEmail(); + } catch (javax.persistence.NoResultException nre) { + String alternativePrimaryEmail = emailDao.findNewestVerifiedOrNewestEmail(orcid); + emailDao.updatePrimary(orcid, alternativePrimaryEmail); + String message = String.format("User with orcid %s have no primary email, so, we are setting the newest verified email, or, the newest email in case non is verified as the primary one", orcid); + LOGGER.error(message); + return alternativePrimaryEmail; + } catch (javax.persistence.NonUniqueResultException nure) { + String alternativePrimaryEmail = emailDao.findNewestPrimaryEmail(orcid); + emailDao.updatePrimary(orcid, alternativePrimaryEmail); + String message = String.format("User with orcid %s have more than one primary email, so, we are setting the latest modified primary as the primary one", orcid); + LOGGER.error(message); + return alternativePrimaryEmail; + } } } diff --git a/orcid-core/src/main/java/org/orcid/core/utils/SecurityContextTestUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/SecurityContextTestUtils.java index 705212bafa9..943f19d36ab 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/SecurityContextTestUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/SecurityContextTestUtils.java @@ -124,7 +124,7 @@ static public void clearSecurityContext() { } static public void setupSecurityContextForWebUser(String userId, String email) { - OrcidProfileUserDetails details = new OrcidProfileUserDetails(userId, email, "password"); + OrcidProfileUserDetails details = new OrcidProfileUserDetails(userId, email); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(userId, "password"); auth.setDetails(details); SecurityContextImpl securityContext = new SecurityContextImpl(); diff --git a/orcid-core/src/main/resources/ehcache_default.xml b/orcid-core/src/main/resources/ehcache_default.xml index 4880c539ce2..16e65cd009f 100644 --- a/orcid-core/src/main/resources/ehcache_default.xml +++ b/orcid-core/src/main/resources/ehcache_default.xml @@ -294,6 +294,13 @@ 16 + + + + + 10 + + diff --git a/orcid-core/src/main/resources/ehcache_orcid-api-web.xml b/orcid-core/src/main/resources/ehcache_orcid-api-web.xml index 0d2cfddb0a6..bed700e4eb4 100644 --- a/orcid-core/src/main/resources/ehcache_orcid-api-web.xml +++ b/orcid-core/src/main/resources/ehcache_orcid-api-web.xml @@ -108,6 +108,13 @@ + + + + + 10 + + diff --git a/orcid-core/src/main/resources/ehcache_orcid-internal-api.xml b/orcid-core/src/main/resources/ehcache_orcid-internal-api.xml index f6dd9446114..94d8dee20e6 100644 --- a/orcid-core/src/main/resources/ehcache_orcid-internal-api.xml +++ b/orcid-core/src/main/resources/ehcache_orcid-internal-api.xml @@ -262,6 +262,13 @@ 64 + + + + + 10 + + diff --git a/orcid-core/src/main/resources/ehcache_orcid-pub-web.xml b/orcid-core/src/main/resources/ehcache_orcid-pub-web.xml index 743193dd174..a7e0c4821d1 100644 --- a/orcid-core/src/main/resources/ehcache_orcid-pub-web.xml +++ b/orcid-core/src/main/resources/ehcache_orcid-pub-web.xml @@ -108,7 +108,14 @@ - + + + + + 10 + + + diff --git a/orcid-core/src/main/resources/ehcache_orcid-scheduler-web.xml b/orcid-core/src/main/resources/ehcache_orcid-scheduler-web.xml index 9aa76231179..29aad9a2741 100644 --- a/orcid-core/src/main/resources/ehcache_orcid-scheduler-web.xml +++ b/orcid-core/src/main/resources/ehcache_orcid-scheduler-web.xml @@ -124,7 +124,14 @@ - + + + + + 10 + + + diff --git a/orcid-core/src/main/resources/ehcache_orcid-web.xml b/orcid-core/src/main/resources/ehcache_orcid-web.xml index 5ec3dbc86c4..968e488b408 100644 --- a/orcid-core/src/main/resources/ehcache_orcid-web.xml +++ b/orcid-core/src/main/resources/ehcache_orcid-web.xml @@ -140,7 +140,14 @@ - + + + + + 10 + + + diff --git a/orcid-core/src/test/java/org/orcid/core/security/OrcidUserDetailsServiceTest.java b/orcid-core/src/test/java/org/orcid/core/security/OrcidUserDetailsServiceTest.java index a30530479c1..0ada522208e 100644 --- a/orcid-core/src/test/java/org/orcid/core/security/OrcidUserDetailsServiceTest.java +++ b/orcid-core/src/test/java/org/orcid/core/security/OrcidUserDetailsServiceTest.java @@ -217,7 +217,6 @@ public void loadUserByProfile_MoreThanOnePrimaryAvailable() { assertNotNull(opud); opud.getUsername(); - assertEquals(email, opud.getPrimaryEmail()); assertEquals(ORCID, opud.getUsername()); } @@ -233,7 +232,6 @@ public void loadUserByProfile_NoPrimaryAvailable() { assertNotNull(opud); opud.getUsername(); - assertEquals(email, opud.getPrimaryEmail()); assertEquals(ORCID, opud.getUsername()); } diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/BaseControllerUtil.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/BaseControllerUtil.java index 179ad4408d2..3761f69060d 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/BaseControllerUtil.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/BaseControllerUtil.java @@ -1,20 +1,78 @@ package org.orcid.frontend.web.controllers; import org.orcid.core.oauth.OrcidProfileUserDetails; +import org.orcid.core.security.OrcidWebRole; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; +import javax.management.relation.InvalidRoleValueException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + public class BaseControllerUtil { public OrcidProfileUserDetails getCurrentUser(SecurityContext context) { if (context == null) return null; Authentication authentication = context.getAuthentication(); - if ((authentication instanceof UsernamePasswordAuthenticationToken || authentication instanceof PreAuthenticatedAuthenticationToken) - && authentication.getDetails() instanceof OrcidProfileUserDetails) { - return ((OrcidProfileUserDetails) authentication.getDetails()); + Object details = authentication.getDetails(); + if ((authentication instanceof UsernamePasswordAuthenticationToken || authentication instanceof PreAuthenticatedAuthenticationToken)) { + if(authentication.getDetails() instanceof OrcidProfileUserDetails) { + return ((OrcidProfileUserDetails) authentication.getDetails()); + } else { + // From the authorization server we will get a + String orcid = authentication.getName(); + Collection authorities = authentication.getAuthorities(); + + List orcidAuthorities = new ArrayList(); + authorities.forEach(x -> { + switch (x.getAuthority()) { + case "ROLE_USER": + orcidAuthorities.add(OrcidWebRole.ROLE_USER); + break; + case "ROLE_ADMIN": + orcidAuthorities.add(OrcidWebRole.ROLE_ADMIN); + break; + case "ROLE_GROUP": + orcidAuthorities.add(OrcidWebRole.ROLE_GROUP); + break; + case "ROLE_BASIC": + orcidAuthorities.add(OrcidWebRole.ROLE_BASIC); + break; + case "ROLE_PREMIUM": + orcidAuthorities.add(OrcidWebRole.ROLE_PREMIUM); + break; + case "ROLE_BASIC_INSTITUTION": + orcidAuthorities.add(OrcidWebRole.ROLE_BASIC_INSTITUTION); + break; + case "ROLE_PREMIUM_INSTITUTION": + orcidAuthorities.add(OrcidWebRole.ROLE_PREMIUM_INSTITUTION); + break; + case "ROLE_CREATOR": + orcidAuthorities.add(OrcidWebRole.ROLE_CREATOR); + break; + case "ROLE_PREMIUM_CREATOR": + orcidAuthorities.add(OrcidWebRole.ROLE_PREMIUM_CREATOR); + break; + case "ROLE_UPDATER": + orcidAuthorities.add(OrcidWebRole.ROLE_UPDATER); + break; + case "ROLE_PREMIUM_UPDATER": + orcidAuthorities.add(OrcidWebRole.ROLE_PREMIUM_UPDATER); + break; + case "ROLE_SELF_SERVICE": + orcidAuthorities.add(OrcidWebRole.ROLE_SELF_SERVICE); + break; + default: + throw new RuntimeException("Unsupported orcid authority for" + orcid + ": '" + x.getAuthority() + "'"); + } + }); + return new OrcidProfileUserDetails(orcid, null, orcidAuthorities); + } } else { return null; } diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/HomeController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/HomeController.java index e4831dafb13..93e54d12bab 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/HomeController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/HomeController.java @@ -19,12 +19,14 @@ import org.orcid.core.locale.LocaleManager; import org.orcid.core.manager.ProfileEntityCacheManager; import org.orcid.core.manager.v3.ProfileEntityManager; +import org.orcid.core.manager.v3.read_only.EmailManagerReadOnly; import org.orcid.core.oauth.OrcidProfileUserDetails; import org.orcid.core.security.OrcidWebRole; import org.orcid.core.stats.StatisticsManager; import org.orcid.core.togglz.Features; import org.orcid.core.utils.UTF8Control; import org.orcid.jaxb.model.common.AvailableLocales; +import org.orcid.jaxb.model.v3.release.record.Email; import org.orcid.persistence.jpa.entities.ProfileEntity; import org.orcid.pojo.PublicRecordPersonDetails; import org.orcid.pojo.UserStatus; @@ -79,7 +81,10 @@ public class HomeController extends BaseController { @Resource private StatisticsManager statisticsManager; - + + @Resource(name = "emailManagerReadOnlyV3") + protected EmailManagerReadOnly emailManagerReadOnly; + @RequestMapping(value = "/") public ModelAndView homeHandler(HttpServletRequest request) { ModelAndView mav = new ModelAndView("home"); @@ -177,7 +182,8 @@ private void removeJSessionIdCookie(HttpServletRequest request, HttpServletRespo // REAL_USER_ORCID = EFFECTIVE_USER_ORCID unless it is in delegation mode info.put("EFFECTIVE_USER_ORCID", effectiveOrcid); info.put("IN_DELEGATION_MODE", String.valueOf(!effectiveOrcid.equals(realUserOrcid))); - info.put("PRIMARY_EMAIL", userDetails.getPrimaryEmail()); + //TODO: Do we need the primary email in the user info? + info.put("PRIMARY_EMAIL", emailManagerReadOnly.findPrimaryEmailValueFromCache(effectiveOrcid)); info.put("HAS_VERIFIED_EMAIL", String.valueOf(emailManagerReadOnly.haveAnyEmailVerified(effectiveOrcid))); info.put("IS_PRIMARY_EMAIL_VERIFIED", String.valueOf(emailManagerReadOnly.isPrimaryEmailVerified(effectiveOrcid))); for(OrcidWebRole role : userDetails.getAuthorities()) { diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/listener/LoginApplicationListener.java b/orcid-web/src/main/java/org/orcid/frontend/web/listener/LoginApplicationListener.java index b05e2f4099d..414c53d0b3b 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/listener/LoginApplicationListener.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/listener/LoginApplicationListener.java @@ -32,9 +32,8 @@ public void onApplicationEvent(ApplicationEvent event) { if (principal instanceof OrcidProfileUserDetails) { OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal; String orcid = userDetails.getOrcid(); - String email = userDetails.getPrimaryEmail(); String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId(); - LOGGER.info("User logged in with orcid={}, email={}, sessionid={}", new Object[] { orcid, email, sessionId }); + LOGGER.info("User logged in with orcid={}, sessionid={}", new Object[] { orcid, sessionId }); } } } diff --git a/orcid-web/src/test/java/org/orcid/frontend/spring/OrcidAuthenticationProviderTest.java b/orcid-web/src/test/java/org/orcid/frontend/spring/OrcidAuthenticationProviderTest.java index 2f6bcb69620..78785b90110 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/spring/OrcidAuthenticationProviderTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/spring/OrcidAuthenticationProviderTest.java @@ -61,7 +61,7 @@ public void before() { @Override public UserDetails answer(InvocationOnMock invocation) throws Throwable { - return new OrcidProfileUserDetails((String) invocation.getArgument(0), "user@email.com", "password"); + return new OrcidProfileUserDetails((String) invocation.getArgument(0), "password"); } }); @@ -82,7 +82,7 @@ public HashSet answer(InvocationOnMock invocation) throws Thro @Override public OrcidProfileUserDetails answer(InvocationOnMock invocation) throws Throwable { ProfileEntity p = (ProfileEntity) invocation.getArgument(0); - return new OrcidProfileUserDetails(p.getId(), "email", p.getEncryptedPassword()); + return new OrcidProfileUserDetails(p.getId(), p.getEncryptedPassword()); } }); diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/AdminControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/AdminControllerTest.java index 519493b405c..6025ba58f6c 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/AdminControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/AdminControllerTest.java @@ -197,7 +197,7 @@ protected Authentication getAuthentication() { Email e = emailManager.findPrimaryEmail(orcid); List roles = getRole(); OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, - e.getEmail(), null, roles); + null, roles); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, p.getPassword(), getRole()); auth.setDetails(details); return auth; diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ClientsControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ClientsControllerTest.java index f8edafa1a9a..006bfe9ad6f 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ClientsControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ClientsControllerTest.java @@ -61,8 +61,7 @@ public static void removeDBUnitData() throws Exception { @Override protected Authentication getAuthentication() { - OrcidProfileUserDetails details = new OrcidProfileUserDetails("5555-5555-5555-5558", "5555-5555-5555-5558@user.com", - "e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + OrcidProfileUserDetails details = new OrcidProfileUserDetails("5555-5555-5555-5558", "e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("5555-5555-5555-5558", null, Arrays.asList(OrcidWebRole.ROLE_PREMIUM_INSTITUTION)); diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/FundingsControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/FundingsControllerTest.java index 711dd988f02..dfb48c60831 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/FundingsControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/FundingsControllerTest.java @@ -91,7 +91,7 @@ protected Authentication getAuthentication() { Email e = emailManagerReadOnly.findPrimaryEmail(orcid); List roles = Arrays.asList(OrcidWebRole.ROLE_USER); OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, - e.getEmail(), null, roles); + null, roles); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, p.getPassword(), roles); auth.setDetails(details); return auth; diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/GetMyDataControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/GetMyDataControllerTest.java index 1a008b43069..6d69ea0889c 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/GetMyDataControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/GetMyDataControllerTest.java @@ -475,7 +475,7 @@ private void validateOrg(OrganizationHolder oh) { private Authentication getAuthentication() { List roles = Arrays.asList(OrcidWebRole.ROLE_USER); - OrcidProfileUserDetails details = new OrcidProfileUserDetails(ORCID, "user_1@test.orcid.org", null, roles); + OrcidProfileUserDetails details = new OrcidProfileUserDetails(ORCID, null, roles); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ORCID, null, roles); auth.setDetails(details); return auth; diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ManageMembersControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ManageMembersControllerTest.java index 77b4ce21812..5ac40271d15 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ManageMembersControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ManageMembersControllerTest.java @@ -128,7 +128,7 @@ public static void afterClass() throws Exception { protected Authentication getAuthentication() { String orcid = "4444-4444-4444-4440"; OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, - "admin@user.com", null, Arrays.asList(OrcidWebRole.ROLE_ADMIN)); + null, Arrays.asList(OrcidWebRole.ROLE_ADMIN)); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, "password", Arrays.asList(OrcidWebRole.ROLE_ADMIN)); auth.setDetails(details); return auth; diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ManageProfileControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ManageProfileControllerTest.java index a89a4fa8d3a..bf9c3a7dba1 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ManageProfileControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/ManageProfileControllerTest.java @@ -1119,7 +1119,7 @@ public void testEditEmail_primaryEmailChange() { protected Authentication getAuthentication(String orcid) { List roles = Arrays.asList(OrcidWebRole.ROLE_USER); - OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, "user_1@test.orcid.org", null, roles); + OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, null, roles); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, null, roles); auth.setDetails(details); return auth; diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/OrgControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/OrgControllerTest.java index 28580a10d50..95f2f2562ed 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/OrgControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/OrgControllerTest.java @@ -62,7 +62,7 @@ protected Authentication getAuthentication() { Email e = emailManagerReadOnly.findPrimaryEmail(orcid); List roles = Arrays.asList(OrcidWebRole.ROLE_USER); OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, - e.getEmail(), null, roles); + null, roles); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, p.getPassword(), roles); auth.setDetails(details); return auth; diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/RegistrationControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/RegistrationControllerTest.java index 568c3c4c009..bf0ae30210e 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/RegistrationControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/RegistrationControllerTest.java @@ -163,7 +163,7 @@ public ProfileEntity answer(InvocationOnMock invocation) throws Throwable { when(orcidUserDetailsServiceMock.loadUserByProfile(Mockito.any(ProfileEntity.class))).thenAnswer(new Answer() { @Override public OrcidProfileUserDetails answer(InvocationOnMock invocation) throws Throwable { - return new OrcidProfileUserDetails("0000-0000-0000-0000", "user_1@test.orcid.org", "pwd"); + return new OrcidProfileUserDetails("0000-0000-0000-0000", "pwd"); } }); @@ -171,7 +171,7 @@ public OrcidProfileUserDetails answer(InvocationOnMock invocation) throws Throwa @Override public UsernamePasswordAuthenticationToken answer(InvocationOnMock invocation) throws Throwable { UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("0000-0000-0000-0000", "pwd", Arrays.asList(OrcidWebRole.ROLE_USER)); - auth.setDetails(new OrcidProfileUserDetails("0000-0000-0000-0000", "user_1@test.orcid.org", "pwd")); + auth.setDetails(new OrcidProfileUserDetails("0000-0000-0000-0000", "pwd")); return auth; } }); diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/filter/OAuthAuthorizeNotSignedInFilterTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/filter/OAuthAuthorizeNotSignedInFilterTest.java index f9a8371612f..ac008d996be 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/filter/OAuthAuthorizeNotSignedInFilterTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/filter/OAuthAuthorizeNotSignedInFilterTest.java @@ -121,7 +121,7 @@ public void hasOrcidProfileUserDetails() throws IOException, ServletException { when(request.getRequestURI()).thenReturn("http://test.com/oauth/authorize"); when(request.getQueryString()).thenReturn("test_param=param"); when(request.getSession()).thenReturn(session); - when(usernamePasswordAuthenticationToken.getDetails()).thenReturn(new OrcidProfileUserDetails()); + when(usernamePasswordAuthenticationToken.getDetails()).thenReturn(new OrcidProfileUserDetails("", null)); when(request.getSession(false)).thenReturn(session); when(session.getAttribute("SPRING_SECURITY_CONTEXT")).thenReturn(context); when(context.getAuthentication()).thenReturn(usernamePasswordAuthenticationToken); diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/util/BaseControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/util/BaseControllerTest.java index 07671d608e3..b815c928e1e 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/util/BaseControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/util/BaseControllerTest.java @@ -65,7 +65,7 @@ protected Authentication getAuthentication(String orcid) { Email e = emailManagerReadOnly.findPrimaryEmail(orcid); List roles = Arrays.asList(OrcidWebRole.ROLE_USER); OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, - e.getEmail(), null, roles); + null, roles); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, p.getPassword(), roles); auth.setDetails(details); return auth;