use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class OrcidTogglzConfiguration method getUserProvider.
@Override
public UserProvider getUserProvider() {
return new UserProvider() {
@Override
public FeatureUser getCurrentUser() {
boolean isAdmin = false;
String userOrcid = null;
SecurityContext context = SecurityContextHolder.getContext();
if (context != null && context.getAuthentication() != null) {
Authentication authentication = context.getAuthentication();
if (authentication != null) {
Object principal = authentication.getDetails();
if (principal instanceof OrcidProfileUserDetails) {
OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal;
isAdmin = userDetails.getAuthorities().contains(OrcidWebRole.ROLE_ADMIN);
userOrcid = userDetails.getOrcid();
}
}
}
return new SimpleFeatureUser(userOrcid, isAdmin);
}
};
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class OrcidUserDetailsServiceImpl method createUserDetails.
private OrcidProfileUserDetails createUserDetails(ProfileEntity profile) {
String primaryEmail = retrievePrimaryEmail(profile);
OrcidProfileUserDetails userDetails = null;
if (profile.getOrcidType() != null) {
OrcidType orcidType = OrcidType.fromValue(profile.getOrcidType().value());
userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword(), buildAuthorities(orcidType, profile.getGroupType()));
} else {
userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword());
}
if (!salesForceManager.retrieveAccountIdsByOrcid(profile.getId()).isEmpty()) {
userDetails.getAuthorities().add(OrcidWebRole.ROLE_SELF_SERVICE);
}
return userDetails;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class ManageProfileControllerTest method getAuthentication.
protected Authentication getAuthentication(String orcid) {
List<OrcidWebRole> roles = Arrays.asList(OrcidWebRole.ROLE_USER);
OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, "user_1@test.orcid.org", null, roles);
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, null, roles);
auth.setDetails(details);
return auth;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class AdminControllerTest method getAuthentication.
@Override
protected Authentication getAuthentication() {
orcidProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4440");
List<OrcidWebRole> roles = getRole();
OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcidProfile.retrieveOrcidPath(), orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue(), null, roles);
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcidProfile.retrieveOrcidPath(), orcidProfile.getPassword(), getRole());
auth.setDetails(details);
return auth;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class BaseControllerUtilTest method getCurrentUserPreAuthenticatedAuthenticationToken.
@Test
public void getCurrentUserPreAuthenticatedAuthenticationToken() {
SecurityContext context = mock(SecurityContext.class);
PreAuthenticatedAuthenticationToken usernamePasswordAuthenticationToken = mock(PreAuthenticatedAuthenticationToken.class);
OrcidProfileUserDetails orcidProfileUserDetails = mock(OrcidProfileUserDetails.class);
when(context.getAuthentication()).thenReturn(usernamePasswordAuthenticationToken);
when(usernamePasswordAuthenticationToken.getDetails()).thenReturn(orcidProfileUserDetails);
assertNotNull(baseControllerUtil.getCurrentUser(context));
}
Aggregations