use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class OrcidAuthorizationCodeServiceTest method getUserAuthentication.
private Authentication getUserAuthentication() {
OrcidProfileUserDetails details = (OrcidProfileUserDetails) orcidUserDetailsService.loadUserByUsername("4444-4444-4444-4445");
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(details.getOrcid(), "password");
auth.setDetails(details);
return auth;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class DeveloperToolsControllerTest method getAuthentication.
@Override
protected Authentication getAuthentication() {
orcidProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4442");
OrcidProfileUserDetails details = null;
if (orcidProfile.getType() != null) {
details = new OrcidProfileUserDetails(orcidProfile.getOrcidIdentifier().getPath(), orcidProfile.getOrcidBio().getContactDetails().getEmail().get(0).getValue(), orcidProfile.getOrcidInternal().getSecurityDetails().getEncryptedPassword().getContent(), orcidProfile.getType(), orcidProfile.getGroupType());
} else {
details = new OrcidProfileUserDetails(orcidProfile.getOrcidIdentifier().getPath(), orcidProfile.getOrcidBio().getContactDetails().getEmail().get(0).getValue(), orcidProfile.getOrcidInternal().getSecurityDetails().getEncryptedPassword().getContent());
}
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(details, "4444-4444-4444-4442", getRole());
return auth;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class BaseController method isEmailOkForCurrentUser.
protected boolean isEmailOkForCurrentUser(String decryptedEmail) {
OrcidProfileUserDetails userDetails = getCurrentUser();
if (userDetails == null) {
return true;
}
OrcidProfile orcidProfile = getEffectiveProfile();
if (orcidProfile == null) {
return true;
}
List<Email> emails = orcidProfile.getOrcidBio().getContactDetails().getEmail();
for (Email email : emails) {
if (decryptedEmail.equalsIgnoreCase(email.getValue())) {
return true;
}
}
return false;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class OrcidUserDetailsService method loadUserByUsername.
/**
* Locates the user based on the username. In the actual implementation, the
* search may possibly be case insensitive, or case insensitive depending on
* how the implementation instance is configured. In this case, the
* <code>UserDetails</code> object that comes back may have a username that
* is of a different case than what was actually requested..
*
* @param username
* the username identifying the user whose data is required.
* @return a fully populated user record (never <code>null</code>)
* @throws org.springframework.security.core.userdetails.UsernameNotFoundException
* if the user could not be found or the user has no
* GrantedAuthority
*/
@Override
@Transactional(propagation = Propagation.REQUIRED)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
LOGGER.info("About to load user by username = {}", username);
ProfileEntity profile = obtainEntity(username);
if (profile == null) {
throw new UsernameNotFoundException("Bad username or password");
}
if (profile.getPrimaryRecord() != null) {
throw new DeprecatedProfileException("orcid.frontend.security.deprecated_with_primary", profile.getPrimaryRecord().getId(), profile.getId());
}
if (profile.getDeactivationDate() != null && !securityMgr.isAdmin()) {
throw new DisabledException("Account not active, please call helpdesk");
}
if (!profile.getClaimed() && !securityMgr.isAdmin()) {
throw new UnclaimedProfileExistsException("orcid.frontend.security.unclaimed_exists");
}
String primaryEmail = null;
// Clients doesnt have primary email, so, we need to cover that case.
if (profile.getPrimaryEmail() != null)
primaryEmail = profile.getPrimaryEmail().getId();
OrcidProfileUserDetails userDetails = null;
if (profile.getOrcidType() != null) {
OrcidType orcidType = OrcidType.fromValue(profile.getOrcidType().value());
userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword(), orcidType, profile.getGroupType());
} else {
userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword());
}
return userDetails;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class SecurityContextTestUtils method setupSecurityContextForWebUser.
public static void setupSecurityContextForWebUser(String userId, String email) {
OrcidProfileUserDetails details = new OrcidProfileUserDetails(userId, email, "password");
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(userId, "password");
auth.setDetails(details);
SecurityContextImpl securityContext = new SecurityContextImpl();
securityContext.setAuthentication(auth);
SecurityContextHolder.setContext(securityContext);
}
Aggregations