public Attribute(Attribute attribute, boolean copyValue) { super(attribute); if(copyValue) { this.value = attribute.getValue(); this.valueCreatedAt = attribute.getValueCreatedAt(); this.valueCreatedBy = attribute.getValueCreatedBy(); this.valueModifiedAt = attribute.getValueModifiedAt(); this.valueModifiedBy = attribute.getValueModifiedBy(); } }
/** * Check if the attribute value contains value. In case of list, it uses method contains. In case of array it searches in both keys and values. * * @param value value * @return true if the attribute value contains value. */ @SuppressWarnings("unchecked") public boolean valueContains(String value) { if (this.getType().equals(String.class.getName()) || this.getType().equals(BeansUtils.largeStringClassName)) { return value == null ? this.getValue() == null : value.equals(this.getValue()); } else if (this.getType().equals(ArrayList.class.getName()) || this.getType().equals(BeansUtils.largeArrayListClassName)) { return this.getValue() == null ? value == null : ((ArrayList<String>) this.getValue()).contains(value); } else if (this.getType().equals(LinkedHashMap.class.getName())) { return this.getValue() == null ? value == null : (((LinkedHashMap<String, String>) this.getValue()).containsKey(value) || ((LinkedHashMap<String, String>) this.getValue()).containsValue(value)); } else return false; }
Attribute loginMu = perun.getAttributesManager().getAttribute(session, user, "urn:perun:user:attribute-def:def:login-namespace:mu"); if (eduroamIdentities.getValue() == null) { if (loginMu.getValue() != null) { identities.add(((String)loginMu.getValue())+"@eduroam.muni.cz"); if (loginMu.getValue() != null) { for (String value : (List<String>)eduroamIdentities.getValue()) { if (Objects.equals(value, ((String)loginMu.getValue())+"@eduroam.muni.cz")) { found = true; break; ((List<String>) eduroamIdentities.getValue()).add(((String)loginMu.getValue())+"@eduroam.muni.cz");
@Override public String serializeToString() { StringBuilder str = new StringBuilder(); String stringValue; if(getValue() == null) stringValue = null; else try { stringValue = BeansUtils.attributeValueToString(this); } catch (InternalErrorException ex) { //WARNING: This error is not catched. There is very low chance to occur. //When this happens, error is logged and there is need to look on attributeValueToString script above. log.error("Attribute value can't be serialize! {}",ex); stringValue = null; } return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", friendlyName=<").append(getFriendlyName() == null ? "\\0" : BeansUtils.createEscaping(getFriendlyName())).append(">").append( ", namespace=<").append(getNamespace() == null ? "\\0" : BeansUtils.createEscaping(getNamespace())).append(">").append( ", type=<").append(getType() == null ? "\\0" : BeansUtils.createEscaping(getType())).append(">").append( ", unique=<").append(isUnique()).append(">").append( ", value=<").append(BeansUtils.createEscaping(stringValue)).append(">").append( ']').toString(); }
@Override public String toString() { return this.getClass().getSimpleName() + ":[" + "id='" + getId() + '\'' + ", friendlyName='" + getFriendlyName() + '\'' + ", namespace='" + getNamespace() + '\'' + ", type='" + getType() + '\'' + ", unique='" + isUnique() + '\'' + ", value='" + getValue() + '\'' + ']'; } }
/** * Return email addresses of specific user. Now is only preferred mail required. If user has not email, then is returned empty array. * * @param user specific user * @return emails of user, if user has not emails is returned empty array * @throws VOOTException if cannot read emails of user */ private Email[] getEmails(User user) throws VOOTException{ //preferred mail Email[] emails = new Email[1]; try{ Attribute preferredEmailAttribute = perun.getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":preferredMail"); if(preferredEmailAttribute.getValue() != null){ Email email = new Email(); email.setType("mail"); email.setValue((String) preferredEmailAttribute.getValue()); emails[0] = email; }else{ emails = null; } }catch(Exception ex){ emails = null; } return emails; }
/** * Get User preferred Mail value from perun. * * @param user the user * @return value of user's preferredMail or null, if value is null or user not exists yet * @throws InternalErrorException if some exception (except UserNotExistsException) is thrown from RPC */ private String getUserPreferredMailValue(User user) throws InternalErrorException { cz.metacentrum.perun.core.api.Attribute preferredMailAttr = null; try { preferredMailAttr = Rpc.AttributesManager.getAttribute(ldapcManager.getRpcCaller(), user, cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_DEF + ":" + perunAttrPreferredMail); } catch(PrivilegeException ex) { throw new InternalErrorException("There are no privilegies for getting user's attribute.", ex); } catch(AttributeNotExistsException ex) { throw new InternalErrorException("There is no such attribute.", ex); } catch(UserNotExistsException ex) { //If user not exist in perun now, probably will be deleted in next step so its ok. The value is null anyway. return null; } catch(WrongAttributeAssignmentException ex) { throw new InternalErrorException("There is problem with wrong attribute assignment exception.", ex); } if(preferredMailAttr.getValue() == null) return null; else return (String) preferredMailAttr.getValue(); }
private EmailSCIM getEmail(User perunUser) { Attribute preferredEmailAttribute = new Attribute(); EmailSCIM email = new EmailSCIM(); try { preferredEmailAttribute = perunBl.getAttributesManagerBl().getAttribute(session, perunUser, AttributesManager.NS_USER_ATTR_DEF + ":preferredMail"); if (preferredEmailAttribute.getValue() != null) { email.setValue(preferredEmailAttribute.getValue().toString()); email.setPrimary(true); email.setType("preferred email"); return email; } } catch (InternalErrorException | WrongAttributeAssignmentException ex) { log.error("Internal exception occured while getting preferred email of user " + perunUser.getId(), ex); } catch (AttributeNotExistsException ex) { log.error("Attribute preferredMail doesn't exist for user " + perunUser.getId(), ex); } return null; } }
try { perun.getGroupsManagerBl().expireMemberInGroup(sess, member, group); log.info("Switching {} in {} to EXPIRED state, due to expiration {}.", member, group, perun.getAttributesManagerBl().getAttribute(sess, member, group, "urn:perun:member_group:attribute-def:def:membershipExpiration").getValue()); } catch (InternalErrorException e) { log.error("Consistency error while trying to expire member {} in {}, exception {}", member, group, e);
try { perun.getGroupsManagerBl().validateMemberInGroup(sess, member, group); log.info("Switching {} in {} to VALID state, due to changed expiration {}.", member, group, perun.getAttributesManagerBl().getAttribute(sess, member, group, "urn:perun:member_group:attribute-def:def:membershipExpiration").getValue()); } catch (InternalErrorException e) { log.error("Error during validating member {} in {}, exception {}", member, group, e);
/** * Expires members whose expiration is set to given date or before it. * * @throws InternalErrorException internal error * @throws WrongAttributeAssignmentException error * @throws AttributeNotExistsException error */ private void expireMembers(Calendar date) throws InternalErrorException, WrongAttributeAssignmentException, AttributeNotExistsException { List<Member> shouldBeExpired = perun.getSearcherBl().getMembersByExpiration(sess, "<=", date); for (Member member : shouldBeExpired) { if (member.getStatus().equals(Status.VALID)) { try { perun.getMembersManagerBl().expireMember(sess, member); log.info("Switching {} to EXPIRE state, due to expiration {}.", member, perun.getAttributesManagerBl().getAttribute(sess, member, "urn:perun:member:attribute-def:def:membershipExpiration").getValue()); } catch (MemberNotValidYetException e) { log.error("Consistency error while trying to expire member {}, exception {}", member, e); } } } }
, pair.getRight(), pair.getLeft(), a.getValue()); found = true; break;
/** * Validates member whose expiration is set after the given date * * @param date date * @throws InternalErrorException internal error * @throws WrongAttributeAssignmentException error * @throws AttributeNotExistsException error */ private void validateMembers(Calendar date) throws InternalErrorException, WrongAttributeAssignmentException, AttributeNotExistsException { List<Member> shouldntBeExpired = perun.getSearcherBl().getMembersByExpiration(sess, ">", date); for (Member member : shouldntBeExpired) { if (member.getStatus().equals(Status.EXPIRED)) { try { perun.getMembersManagerBl().validateMember(sess, member); log.info("Switching {} to VALID state, due to changed expiration {}.", member, perun.getAttributesManagerBl().getAttribute(sess, member, "urn:perun:member:attribute-def:def:membershipExpiration").getValue()); } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) { log.error("Error during validating member {}, exception {}", member, e); } } } }
/** * Add new bonaFideStatus to the user attribute. */ @Override public Application approveApplication(PerunSession session, Application app) throws PerunException { User user = app.getUser(); Group group = app.getGroup(); AttributesManager am = session.getPerun().getAttributesManager(); Attribute attestation = am.getAttribute(session, group, A_G_D_groupAttestation); String newValue = attestation.valueAsString(); Attribute bonaFideStatus = am.getAttribute(session, user, A_U_D_userBonaFideStatus); List<String> value = new ArrayList<>(); if (bonaFideStatus.getValue() != null && bonaFideStatus.valueAsList() != null) { value = bonaFideStatus.valueAsList(); } value.add(newValue); bonaFideStatus.setValue(value); am.setAttribute(session, user, bonaFideStatus); return app; }
attrSenderEmail = attrManager.getAttribute(registrarSession, app.getGroup(), URN_GROUP_FROM_EMAIL); if (attrSenderEmail == null || attrSenderEmail.getValue() == null) { attrSenderEmail = attrManager.getAttribute(registrarSession, app.getVo(), URN_VO_FROM_EMAIL); if (attrSenderEmail != null && attrSenderEmail.getValue() != null) { senderEmail = BeansUtils.attributeValueToString(attrSenderEmail); message.setReplyTo(senderEmail);
/** * Create proper UserExtSource */ @Override public Application approveApplication(PerunSession session, Application app) throws PerunException { PerunBl perun = (PerunBl)session.getPerun(); User user = app.getUser(); if (user == null) { log.error("At the end of approval action, we should have user present in application: {}", app); } else { Attribute userLogin = perun.getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:lifescience-hostel"); if (userLogin.getValue() != null) { ExtSource extSource = perun.getExtSourcesManagerBl().getExtSourceByName(session, "https://login.bbmri-eric.eu/lshostel/"); UserExtSource ues = new UserExtSource(extSource, userLogin + "@lifescience-hostel.org"); ues.setLoa(0); try { perun.getUsersManagerBl().addUserExtSource(session, user, ues); } catch (UserExtSourceExistsException ex) { // this is OK } } // User doesn't have login - don't set UES } return app; }
@Override public Application approveApplication(PerunSession session, Application app) throws PerunException { PerunBl perun = (PerunBl) session.getPerun(); Member member = perun.getMembersManagerBl().getMemberByUser(session, app.getVo(), app.getUser()); if (app.getGroup() == null && Objects.equals(app.getType(), Application.AppType.INITIAL)) { // IF VO INITIAL override VO rules to set unlimited (only to those with LoA = 2). Attribute loaAttr = perun.getAttributesManagerBl().getAttribute(session, member, AttributesManager.NS_MEMBER_ATTR_VIRT + ":loa"); int loa = Integer.valueOf((String) loaAttr.getValue()); if (loa == 2) { Attribute attr = perun.getAttributesManagerBl().getAttribute(session, member, AttributesManager.NS_MEMBER_ATTR_DEF + ":membershipExpiration"); attr.setValue("9999-01-01"); // set distant future as never expires perun.getAttributesManagerBl().setAttribute(session, member, attr); } } if ((app.getGroup() != null && Objects.equals(app.getType(), Application.AppType.INITIAL)) || (app.getGroup() == null && Objects.equals(app.getType(), Application.AppType.EXTENSION))) { // GROUP INITIAL OR VO EXTENSION -> set back standard expiration date based on VO rules Attribute attr = perun.getAttributesManagerBl().getAttribute(session, member, AttributesManager.NS_MEMBER_ATTR_DEF + ":membershipExpiration"); perun.getAttributesManagerBl().removeAttribute(session, member, attr); perun.getMembersManagerBl().extendMembership(session, member); } return app; }