use of org.orcid.persistence.jpa.entities.OrcidGrantedAuthority 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;
}
use of org.orcid.persistence.jpa.entities.OrcidGrantedAuthority in project ORCID-Source by ORCID.
the class RegistrationManagerImpl method createMinimalProfile.
/**
* Creates a minimal record
*
* @param orcidProfile
* The record to create
* @return the new record
*/
private String createMinimalProfile(Registration registration, boolean usedCaptcha, Locale locale, String ip) {
Date now = new Date();
String orcid = orcidGenerationManager.createNewOrcid();
ProfileEntity newRecord = new ProfileEntity();
newRecord.setId(orcid);
try {
newRecord.setHashedOrcid(encryptionManager.sha256Hash(orcid));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
newRecord.setOrcidType(OrcidType.USER);
newRecord.setDateCreated(now);
newRecord.setLastModified(now);
newRecord.setSubmissionDate(now);
newRecord.setClaimed(true);
newRecord.setEnableDeveloperTools(false);
newRecord.setRecordLocked(false);
newRecord.setReviewed(false);
newRecord.setEnableNotifications(DefaultPreferences.NOTIFICATIONS_ENABLED);
newRecord.setUsedRecaptchaOnRegistration(usedCaptcha);
newRecord.setUserLastIp(ip);
if (PojoUtil.isEmpty(registration.getSendEmailFrequencyDays())) {
newRecord.setSendEmailFrequencyDays(Float.valueOf(DefaultPreferences.SEND_EMAIL_FREQUENCY_DAYS));
} else {
newRecord.setSendEmailFrequencyDays(Float.valueOf(registration.getSendEmailFrequencyDays().getValue()));
}
if (registration.getSendMemberUpdateRequests() == null) {
newRecord.setSendMemberUpdateRequests(DefaultPreferences.SEND_MEMBER_UPDATE_REQUESTS);
} else {
newRecord.setSendMemberUpdateRequests(registration.getSendMemberUpdateRequests().getValue());
}
newRecord.setCreationMethod(PojoUtil.isEmpty(registration.getCreationType()) ? CreationMethod.DIRECT.value() : registration.getCreationType().getValue());
newRecord.setSendChangeNotifications(registration.getSendChangeNotifications().getValue());
newRecord.setSendOrcidNews(registration.getSendOrcidNews().getValue());
newRecord.setLocale(locale == null ? org.orcid.jaxb.model.common_v2.Locale.EN : org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.toString()));
// Visibility defaults
newRecord.setActivitiesVisibilityDefault(Visibility.fromValue(registration.getActivitiesVisibilityDefault().getVisibility().value()));
// Encrypt the password
newRecord.setEncryptedPassword(encryptionManager.hashForInternalUse(registration.getPassword().getValue()));
// Set the email
EmailEntity emailEntity = new EmailEntity();
emailEntity.setId(registration.getEmail().getValue().trim());
emailEntity.setProfile(newRecord);
emailEntity.setPrimary(true);
emailEntity.setCurrent(true);
emailEntity.setVerified(false);
// Email is private by default
emailEntity.setVisibility(Visibility.PRIVATE);
emailEntity.setSourceId(orcid);
Set<EmailEntity> emails = new HashSet<>();
emails.add(emailEntity);
newRecord.setEmails(emails);
// Set the name
RecordNameEntity recordNameEntity = new RecordNameEntity();
recordNameEntity.setDateCreated(now);
recordNameEntity.setLastModified(now);
recordNameEntity.setProfile(newRecord);
// Name is public by default
recordNameEntity.setVisibility(Visibility.PUBLIC);
if (!PojoUtil.isEmpty(registration.getFamilyNames())) {
recordNameEntity.setFamilyName(registration.getFamilyNames().getValue().trim());
}
if (!PojoUtil.isEmpty(registration.getGivenNames())) {
recordNameEntity.setGivenNames(registration.getGivenNames().getValue().trim());
}
newRecord.setRecordNameEntity(recordNameEntity);
// Set authority
OrcidGrantedAuthority authority = new OrcidGrantedAuthority();
authority.setProfileEntity(newRecord);
authority.setAuthority(OrcidWebRole.ROLE_USER.getAuthority());
Set<OrcidGrantedAuthority> authorities = new HashSet<OrcidGrantedAuthority>(1);
authorities.add(authority);
newRecord.setAuthorities(authorities);
profileDao.persist(newRecord);
profileDao.flush();
return newRecord.getId();
}
Aggregations