use of org.springframework.security.core.context.SecurityContext 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.getPrincipal();
if (principal instanceof OrcidProfileUserDetails) {
OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal;
isAdmin = OrcidType.ADMIN.equals(userDetails.getOrcidType());
userOrcid = userDetails.getOrcid();
}
}
}
return new SimpleFeatureUser(userOrcid, isAdmin);
}
};
}
use of org.springframework.security.core.context.SecurityContext in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method getClientIdFromAPIRequest.
@Override
public String getClientIdFromAPIRequest() {
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
if (authentication != null && OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) authentication;
OAuth2Request request = oAuth2Authentication.getOAuth2Request();
return request.getClientId();
}
return null;
}
use of org.springframework.security.core.context.SecurityContext in project ORCID-Source by ORCID.
the class BaseControllerUtilTest method getCurrentUserWrongAuthenticationClass.
@Test
public void getCurrentUserWrongAuthenticationClass() {
SecurityContext context = mock(SecurityContext.class);
TestingAuthenticationToken testingAuthenticationToken = mock(TestingAuthenticationToken.class);
when(context.getAuthentication()).thenReturn(testingAuthenticationToken);
assertNull(baseControllerUtil.getCurrentUser(context));
}
use of org.springframework.security.core.context.SecurityContext in project ORCID-Source by ORCID.
the class BaseControllerUtilTest method getCurrentUserUsernamePasswordAuthenticationToken.
@Test
public void getCurrentUserUsernamePasswordAuthenticationToken() {
SecurityContext context = mock(SecurityContext.class);
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = mock(UsernamePasswordAuthenticationToken.class);
OrcidProfileUserDetails orcidProfileUserDetails = mock(OrcidProfileUserDetails.class);
when(context.getAuthentication()).thenReturn(usernamePasswordAuthenticationToken);
when(usernamePasswordAuthenticationToken.getPrincipal()).thenReturn(orcidProfileUserDetails);
assertNotNull(baseControllerUtil.getCurrentUser(context));
}
use of org.springframework.security.core.context.SecurityContext in project ORCID-Source by ORCID.
the class BaseControllerUtilTest method getCurrentUserNoAuthentication.
@Test
public void getCurrentUserNoAuthentication() {
SecurityContext context = mock(SecurityContext.class);
assertNull(baseControllerUtil.getCurrentUser(context));
}
Aggregations