Search in sources :

Example 81 with PerunBl

use of cz.metacentrum.perun.core.bl.PerunBl in project perun by CESNET.

the class ResourceAttributeProcessor method processVirtualAttributeChanged.

public void processVirtualAttributeChanged(String msg, MessageBeans beans) {
    PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
    if (beans.getAttribute() == null || beans.getResource() == null) {
        return;
    }
    try {
        Attribute virtAttr = perun.getAttributesManagerBl().getAttribute(ldapcManager.getPerunSession(), beans.getResource(), beans.getAttribute().getName());
        log.debug("Changing virtual attribute {} for resource {}", virtAttr, beans.getResource());
        perunResource.modifyEntry(beans.getResource(), virtAttr);
    } catch (InternalErrorException | AttributeNotExistsException | WrongAttributeAssignmentException | NamingException e) {
        log.error("Error changing virtual attribute:", e);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) NamingException(org.springframework.ldap.NamingException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 82 with PerunBl

use of cz.metacentrum.perun.core.bl.PerunBl in project perun by CESNET.

the class VirtualAttributeEventProcessor method processAllGroupAttributesRemoval.

public void processAllGroupAttributesRemoval(String msg, MessageBeans beans) {
    // ensure we have the correct beans available
    if (beans.getGroup() == null) {
        return;
    }
    try {
        PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
        Collection<PerunVirtualAttribute<User>> attrDefs = dependencyManager.getAllAttributeDependants();
        log.debug("Processing group {} all attribute removal, affected attributes {}", beans.getGroup(), attrDefs);
        if (attrDefs != null) {
            for (User user : perun.getGroupsManagerBl().getGroupUsers(ldapcManager.getPerunSession(), beans.getGroup())) {
                /* get attribute value for each dependent attribute */
                Collection<Pair<PerunAttribute<User>, AttributeDefinition>> userAttrs = this.getAttributeValues(perun, user, attrDefs);
                log.debug("Modifying user {} entry with the new values {}", user.getId(), userAttrs);
                perunUser.modifyEntry(user, userAttrs);
            }
        }
    } catch (InternalErrorException e) {
        log.error("Error processing group {} attributes removal: {}", beans.getGroup(), e.getMessage());
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) PerunVirtualAttribute(cz.metacentrum.perun.ldapc.model.PerunVirtualAttribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Pair(cz.metacentrum.perun.core.api.Pair)

Example 83 with PerunBl

use of cz.metacentrum.perun.core.bl.PerunBl in project perun by CESNET.

the class AbstractSynchronizer method fillPerunAttributeNames.

protected List<String> fillPerunAttributeNames(List<String> attrNames) {
    PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
    List<String> result = new ArrayList<String>();
    for (String name : attrNames) {
        if (name.endsWith(":")) {
            result.addAll(perun.getAttributesManagerBl().getAllSimilarAttributeNames(ldapcManager.getPerunSession(), name));
        } else {
            result.add(name);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PerunBl(cz.metacentrum.perun.core.bl.PerunBl)

Example 84 with PerunBl

use of cz.metacentrum.perun.core.bl.PerunBl in project perun by CESNET.

the class EgiuiPasswordManagerModule method validatePassword.

@Override
public void validatePassword(PerunSession sess, String userLogin, User user) throws InvalidLoginException {
    if (user == null) {
        user = ((PerunBl) sess.getPerun()).getModulesUtilsBl().getUserByLoginInNamespace(sess, userLogin, actualLoginNamespace);
    }
    if (user == null) {
        log.warn("No user was found by login '{}' in {} namespace.", userLogin, actualLoginNamespace);
    } else {
        // set extSources and extSource related attributes
        try {
            List<String> kerberosLogins = new ArrayList<>();
            ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "EGI");
            UserExtSource ues = new UserExtSource(extSource, userLogin + "@EGI");
            ues.setLoa(0);
            try {
                ((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            // Store also Kerberos logins
            Attribute kerberosLoginsAttr = ((PerunBl) sess.getPerun()).getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + "kerberosLogins");
            if (kerberosLoginsAttr != null && kerberosLoginsAttr.getValue() != null) {
                kerberosLogins.addAll((List<String>) kerberosLoginsAttr.getValue());
            }
            if (!kerberosLogins.contains(userLogin + "@EGI") && kerberosLoginsAttr != null) {
                kerberosLogins.add(userLogin + "@EGI");
                kerberosLoginsAttr.setValue(kerberosLogins);
                ((PerunBl) sess.getPerun()).getAttributesManagerBl().setAttribute(sess, user, kerberosLoginsAttr);
            }
        } catch (WrongAttributeAssignmentException | AttributeNotExistsException | ExtSourceNotExistsException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException(ex);
        }
    }
    // validate password
    super.validatePassword(sess, userLogin, user);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 85 with PerunBl

use of cz.metacentrum.perun.core.bl.PerunBl in project perun by CESNET.

the class EinfraservicesPasswordManagerModule method validatePassword.

@Override
public void validatePassword(PerunSession sess, String userLogin, User user) throws InvalidLoginException {
    if (user == null) {
        user = ((PerunBl) sess.getPerun()).getModulesUtilsBl().getUserByLoginInNamespace(sess, userLogin, actualLoginNamespace);
    }
    if (user == null) {
        log.warn("No user was found by login '{}' in {} namespace.", userLogin, actualLoginNamespace);
    } else {
        // set extSources and extSource related attributes
        try {
            ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "EINFRA-SERVICES");
            UserExtSource ues = new UserExtSource(extSource, userLogin + "@EINFRA-SERVICES");
            ues.setLoa(0);
            try {
                ((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            List<String> kerberosLogins = new ArrayList<>();
            // Store also Kerberos logins
            Attribute kerberosLoginsAttr = ((PerunBl) sess.getPerun()).getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + "kerberosLogins");
            if (kerberosLoginsAttr != null && kerberosLoginsAttr.getValue() != null) {
                kerberosLogins.addAll((List<String>) kerberosLoginsAttr.getValue());
            }
            if (!kerberosLogins.contains(userLogin + "@EINFRA-SERVICES") && kerberosLoginsAttr != null) {
                kerberosLogins.add(userLogin + "@EINFRA-SERVICES");
                kerberosLoginsAttr.setValue(kerberosLogins);
                ((PerunBl) sess.getPerun()).getAttributesManagerBl().setAttribute(sess, user, kerberosLoginsAttr);
            }
        } catch (WrongAttributeAssignmentException | AttributeNotExistsException | ExtSourceNotExistsException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException(ex);
        }
    }
    // validate password
    super.validatePassword(sess, userLogin, user);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

PerunBl (cz.metacentrum.perun.core.bl.PerunBl)130 Attribute (cz.metacentrum.perun.core.api.Attribute)93 Before (org.junit.Before)65 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)64 AttributesManagerBl (cz.metacentrum.perun.core.bl.AttributesManagerBl)48 User (cz.metacentrum.perun.core.api.User)41 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)37 ArrayList (java.util.ArrayList)22 Vo (cz.metacentrum.perun.core.api.Vo)21 Facility (cz.metacentrum.perun.core.api.Facility)19 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)19 ModulesUtilsBl (cz.metacentrum.perun.core.bl.ModulesUtilsBl)19 ExtSource (cz.metacentrum.perun.core.api.ExtSource)16 Member (cz.metacentrum.perun.core.api.Member)16 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)16 UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)16 UsersManagerBl (cz.metacentrum.perun.core.bl.UsersManagerBl)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 GroupsManagerBl (cz.metacentrum.perun.core.bl.GroupsManagerBl)13 Group (cz.metacentrum.perun.core.api.Group)12