Search in sources :

Example 1 with OrcidType

use of org.orcid.jaxb.model.message.OrcidType in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method getGrantedAuthorities.

private Set<OrcidGrantedAuthority> getGrantedAuthorities(ProfileEntity profileEntity) {
    OrcidGrantedAuthority authority = new OrcidGrantedAuthority();
    authority.setProfileEntity(profileEntity);
    OrcidType userType = (profileEntity.getOrcidType() == null) ? OrcidType.USER : OrcidType.fromValue(profileEntity.getOrcidType().value());
    if (userType.equals(OrcidType.USER))
        authority.setAuthority(OrcidWebRole.ROLE_USER.getAuthority());
    else if (userType.equals(OrcidType.ADMIN))
        authority.setAuthority(OrcidWebRole.ROLE_ADMIN.getAuthority());
    else if (userType.equals(OrcidType.GROUP)) {
        switch(profileEntity.getGroupType()) {
            case BASIC:
                authority.setAuthority(OrcidWebRole.ROLE_BASIC.getAuthority());
                break;
            case PREMIUM:
                authority.setAuthority(OrcidWebRole.ROLE_PREMIUM.getAuthority());
                break;
            case BASIC_INSTITUTION:
                authority.setAuthority(OrcidWebRole.ROLE_BASIC_INSTITUTION.getAuthority());
                break;
            case PREMIUM_INSTITUTION:
                authority.setAuthority(OrcidWebRole.ROLE_PREMIUM_INSTITUTION.getAuthority());
                break;
        }
    }
    Set<OrcidGrantedAuthority> authorities = new HashSet<OrcidGrantedAuthority>(1);
    authorities.add(authority);
    return authorities;
}
Also used : OrcidType(org.orcid.jaxb.model.message.OrcidType) OrcidGrantedAuthority(org.orcid.persistence.jpa.entities.OrcidGrantedAuthority) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 2 with OrcidType

use of org.orcid.jaxb.model.message.OrcidType in project ORCID-Source by ORCID.

the class OrcidUserDetailsService method loadUserByUsername.

/**
     * Locates the user based on the username. In the actual implementation, the
     * search may possibly be case insensitive, or case insensitive depending on
     * how the implementation instance is configured. In this case, the
     * <code>UserDetails</code> object that comes back may have a username that
     * is of a different case than what was actually requested..
     * 
     * @param username
     *            the username identifying the user whose data is required.
     * @return a fully populated user record (never <code>null</code>)
     * @throws org.springframework.security.core.userdetails.UsernameNotFoundException
     *             if the user could not be found or the user has no
     *             GrantedAuthority
     */
@Override
@Transactional(propagation = Propagation.REQUIRED)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    LOGGER.info("About to load user by username = {}", username);
    ProfileEntity profile = obtainEntity(username);
    if (profile == null) {
        throw new UsernameNotFoundException("Bad username or password");
    }
    if (profile.getPrimaryRecord() != null) {
        throw new DeprecatedProfileException("orcid.frontend.security.deprecated_with_primary", profile.getPrimaryRecord().getId(), profile.getId());
    }
    if (profile.getDeactivationDate() != null && !securityMgr.isAdmin()) {
        throw new DisabledException("Account not active, please call helpdesk");
    }
    if (!profile.getClaimed() && !securityMgr.isAdmin()) {
        throw new UnclaimedProfileExistsException("orcid.frontend.security.unclaimed_exists");
    }
    String primaryEmail = null;
    // Clients doesnt have primary email, so, we need to cover that case.
    if (profile.getPrimaryEmail() != null)
        primaryEmail = profile.getPrimaryEmail().getId();
    OrcidProfileUserDetails userDetails = null;
    if (profile.getOrcidType() != null) {
        OrcidType orcidType = OrcidType.fromValue(profile.getOrcidType().value());
        userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword(), orcidType, profile.getGroupType());
    } else {
        userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword());
    }
    return userDetails;
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) OrcidType(org.orcid.jaxb.model.message.OrcidType) DisabledException(org.springframework.security.authentication.DisabledException) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OrcidType (org.orcid.jaxb.model.message.OrcidType)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 OrcidProfileUserDetails (org.orcid.core.oauth.OrcidProfileUserDetails)1 OrcidGrantedAuthority (org.orcid.persistence.jpa.entities.OrcidGrantedAuthority)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 DisabledException (org.springframework.security.authentication.DisabledException)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 Transactional (org.springframework.transaction.annotation.Transactional)1