use of org.orcid.frontend.web.exception.SwitchUserAuthenticationException in project ORCID-Source by ORCID.
the class OrcidSwitchUserFilter method attemptSwitchUser.
@Override
protected Authentication attemptSwitchUser(HttpServletRequest request) throws AuthenticationException {
String targetUserOrcid = request.getParameter(SPRING_SECURITY_SWITCH_USERNAME_KEY);
ProfileEntity profileEntity = sourceManager.retrieveSourceProfileEntity();
if (OrcidType.ADMIN.equals(OrcidType.valueOf(profileEntity.getOrcidType().name()))) {
return switchUser(request);
}
// If we are switching back to me it is OK
if (isSwitchingBack(request)) {
return switchUser(request);
}
List<GivenPermissionByEntity> givenPermissionBy = givenPermissionToDao.findByReceiver(profileEntity.getId());
for (GivenPermissionByEntity gpbe : givenPermissionBy) {
if (gpbe.getGiver().getId().equals(targetUserOrcid)) {
return switchUser(request);
}
}
throw new SwitchUserAuthenticationException(localeManager.resolveMessage("web.orcid.switchuser.exception"));
}
Aggregations