use of org.orcid.core.oauth.OrcidProfileUserDetails 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.getDetails()).thenReturn(orcidProfileUserDetails);
assertNotNull(baseControllerUtil.getCurrentUser(context));
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class ManageMembersControllerTest method getAuthentication.
protected Authentication getAuthentication() {
List<OrcidWebRole> roles = Arrays.asList(OrcidWebRole.ROLE_GROUP);
OrcidProfileUserDetails details = new OrcidProfileUserDetails("5555-5555-5555-0000", "premium_institution@group.com", "", roles);
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(details, "5555-5555-5555-0000", roles);
return auth;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class OAuthAuthorizeNotSignedInFilterTest method hasOrcidProfileUserDetails.
@Test
public void hasOrcidProfileUserDetails() throws IOException, ServletException {
when(request.getContextPath()).thenReturn("http://test.com");
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(request.getSession(false)).thenReturn(session);
when(session.getAttribute("SPRING_SECURITY_CONTEXT")).thenReturn(context);
when(context.getAuthentication()).thenReturn(usernamePasswordAuthenticationToken);
when(usernamePasswordAuthenticationToken.getDetails()).thenReturn(orcidProfileUserDetails);
oaFilter.doFilter((ServletRequest) request, (ServletResponse) response, chain);
verify(response, never()).sendRedirect(Mockito.anyString());
verify(chain).doFilter(Mockito.any(), Mockito.any());
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class SourceManagerImpl method getRealUserIfInDelegationMode.
private String getRealUserIfInDelegationMode(Authentication authentication) {
if (authentication != null) {
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
if (authorities != null) {
for (GrantedAuthority authority : authorities) {
if (authority instanceof SwitchUserGrantedAuthority) {
SwitchUserGrantedAuthority suga = (SwitchUserGrantedAuthority) authority;
Authentication sourceAuthentication = suga.getSource();
if ((sourceAuthentication instanceof UsernamePasswordAuthenticationToken || sourceAuthentication instanceof PreAuthenticatedAuthenticationToken) && sourceAuthentication.getDetails() instanceof OrcidProfileUserDetails) {
return ((OrcidProfileUserDetails) sourceAuthentication.getDetails()).getOrcid();
}
}
}
}
}
return null;
}
use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.
the class SourceManagerImpl method getRealUserIfInDelegationMode.
private String getRealUserIfInDelegationMode(Authentication authentication) {
if (authentication != null) {
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
if (authorities != null) {
for (GrantedAuthority authority : authorities) {
if (authority instanceof SwitchUserGrantedAuthority) {
SwitchUserGrantedAuthority suga = (SwitchUserGrantedAuthority) authority;
Authentication sourceAuthentication = suga.getSource();
if ((sourceAuthentication instanceof UsernamePasswordAuthenticationToken || sourceAuthentication instanceof PreAuthenticatedAuthenticationToken) && sourceAuthentication.getDetails() instanceof OrcidProfileUserDetails) {
return ((OrcidProfileUserDetails) sourceAuthentication.getDetails()).getOrcid();
}
}
}
}
}
return null;
}
Aggregations