Search in sources :

Example 1 with SwitchUserAuthenticationException

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"));
}
Also used : SwitchUserAuthenticationException(org.orcid.frontend.web.exception.SwitchUserAuthenticationException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) GivenPermissionByEntity(org.orcid.persistence.jpa.entities.GivenPermissionByEntity)

Aggregations

SwitchUserAuthenticationException (org.orcid.frontend.web.exception.SwitchUserAuthenticationException)1 GivenPermissionByEntity (org.orcid.persistence.jpa.entities.GivenPermissionByEntity)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1