Search in sources :

Example 1 with RestrictedPerson

use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.

the class UpdatePreferencesServlet method removeSubscription.

protected void removeSubscription(IPerson per, String elementId, IUserLayoutManager ulm) {
    // get the fragment owner's ID from the element string
    String userIdString = StringUtils.substringBetween(elementId, Constants.FRAGMENT_ID_USER_PREFIX, Constants.FRAGMENT_ID_LAYOUT_PREFIX);
    int userId = NumberUtils.toInt(userIdString, 0);
    // construct a new person object representing the fragment owner
    RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
    fragmentOwner.setID(userId);
    fragmentOwner.setUserName(userIdentityStore.getPortalUserName(userId));
    // attempt to find a subscription for this fragment
    IUserFragmentSubscription subscription = userFragmentInfoDao.getUserFragmentInfo(per, fragmentOwner);
    // if a subscription was found, remove it's registration
    if (subscription != null) {
        userFragmentInfoDao.deleteUserFragmentInfo(subscription);
        ulm.loadUserLayout(true);
    } else // otherwise, delete the node
    {
        ulm.deleteNode(elementId);
    }
}
Also used : RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) IUserFragmentSubscription(org.apereo.portal.fragment.subscribe.IUserFragmentSubscription)

Example 2 with RestrictedPerson

use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.

the class UserLayoutHelperImpl method resetUserLayout.

/**
     * @param personAttributes
     * @see
     *     org.apereo.portal.layout.IUserLayoutHelper#resetUserLayout(org.jasig.services.persondir.IPersonAttributes)
     */
public void resetUserLayout(final IPersonAttributes personAttributes) {
    // Create an empty RestrictedPerson object
    RestrictedPerson person = PersonFactory.createRestrictedPerson();
    // populate the person with the supplied attributes
    person.setAttributes(personAttributes.getAttributes());
    // get the integer uid into the person object without creating any new person data
    int uid = userIdentityStore.getPortalUID(person, false);
    person.setID(uid);
    try {
        // determine user profile
        IUserProfile userProfile = userLayoutStore.getUserProfileByFname(person, DEFAULT_LAYOUT_FNAME);
        // Finally set the layout id to 0.  This orphans the existing layout but it will be replaced by the default
        // when the user logs in
        userProfile.setLayoutId(0);
        // persist the change
        userLayoutStore.updateUserProfile(person, userProfile);
        logger.info("resetUserLayout complete for " + person);
    } catch (Exception e) {
        final String msg = "Exception caught during resetUserLayout for " + person;
        logger.error(msg, e);
        throw new PortalException(msg, e);
    }
}
Also used : IUserProfile(org.apereo.portal.IUserProfile) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 3 with RestrictedPerson

use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.

the class UserLayoutHelperImpl method resetUserLayoutAllProfiles.

/**
     * Resets a users layout for all the users profiles
     *
     * @param personAttributes
     */
public void resetUserLayoutAllProfiles(final IPersonAttributes personAttributes) {
    RestrictedPerson person = PersonFactory.createRestrictedPerson();
    person.setAttributes(personAttributes.getAttributes());
    // get the integer uid into the person object without creating any new person data
    int uid = userIdentityStore.getPortalUID(person, false);
    person.setID(uid);
    try {
        Hashtable<Integer, UserProfile> userProfileList = userLayoutStore.getUserProfileList(person);
        for (Integer key : userProfileList.keySet()) {
            UserProfile userProfile = userProfileList.get(key);
            userProfile.setLayoutId(0);
            userLayoutStore.updateUserProfile(person, userProfile);
            logger.info("resetUserLayout complete for " + person + "for profile " + userProfile);
        }
    } catch (Exception e) {
        final String msg = "Exception caught during resetUserLayout for " + person;
        logger.error(msg, e);
        throw new PortalException(msg, e);
    }
    return;
}
Also used : IUserProfile(org.apereo.portal.IUserProfile) UserProfile(org.apereo.portal.UserProfile) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 4 with RestrictedPerson

use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.

the class UpdatePreferencesServlet method subscribeToTab.

/**
     * Subscribe a user to a pre-formatted tab (pulled DLM fragment).
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
@RequestMapping(method = RequestMethod.POST, params = "action=subscribeToTab")
public ModelAndView subscribeToTab(HttpServletRequest request, HttpServletResponse response) throws IOException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IPerson per = getPerson(ui, response);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    // Get the fragment owner's name from the request and construct
    // an IPerson object representing that user
    String fragmentOwnerName = request.getParameter("sourceID");
    if (StringUtils.isBlank(fragmentOwnerName)) {
        logger.warn("Attempted to subscribe to tab with null owner ID");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Attempted to subscribe to tab with null owner ID"));
    }
    RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
    fragmentOwner.setUserName(fragmentOwnerName);
    // Mark the currently-authenticated user as subscribed to this fragment.
    // If an inactivated fragment registration already exists, update it
    // as an active subscription.  Otherwise, create a new fragment
    // subscription.
    IUserFragmentSubscription userFragmentInfo = userFragmentInfoDao.getUserFragmentInfo(per, fragmentOwner);
    if (userFragmentInfo == null) {
        userFragmentInfo = userFragmentInfoDao.createUserFragmentInfo(per, fragmentOwner);
    } else {
        userFragmentInfo.setActive(true);
        userFragmentInfoDao.updateUserFragmentInfo(userFragmentInfo);
    }
    try {
        // reload user layout and stylesheet to incorporate new DLM fragment
        ulm.loadUserLayout(true);
        // get the target node this new tab should be moved after
        String destinationId = request.getParameter("elementID");
        // get the user layout for the currently-authenticated user
        int uid = userIdentityStore.getPortalUID(fragmentOwner, false);
        final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(per, upm.getUserProfile());
        Document layoutDocument = userLayout.getLayout();
        // attempt to find the new subscribed tab in the layout so we can
        // move it
        StringBuilder expression = new StringBuilder("//folder[@type='root']/folder[starts-with(@ID,'").append(Constants.FRAGMENT_ID_USER_PREFIX).append(uid).append("')]");
        XPathFactory fac = XPathFactory.newInstance();
        XPath xpath = fac.newXPath();
        NodeList nodes = (NodeList) xpath.evaluate(expression.toString(), layoutDocument, XPathConstants.NODESET);
        String sourceId = nodes.item(0).getAttributes().getNamedItem("ID").getTextContent();
        ulm.moveNode(sourceId, ulm.getParentId(destinationId), destinationId);
        ulm.saveUserLayout();
        return new ModelAndView("jsonView", Collections.singletonMap("tabId", sourceId));
    } catch (XPathExpressionException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Xpath error"));
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserFragmentSubscription(org.apereo.portal.fragment.subscribe.IUserFragmentSubscription) Document(org.w3c.dom.Document) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) XPathFactory(javax.xml.xpath.XPathFactory) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with RestrictedPerson

use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.

the class EntityPersonAttributesGroupStore method contains.

@Override
public boolean contains(IEntityGroup group, IGroupMember member) {
    if (!IPERSON_CLASS.equals(member.getLeafType())) {
        // group.getLeafType() is (presumably) IPerson.class.
        return false;
    }
    if (member.isGroup()) {
        // PAGS groups may only contain other PAGS groups (and people, of course)
        final IEntityGroup ieg = (IEntityGroup) member;
        if (!PagsService.SERVICE_NAME_PAGS.equals(ieg.getServiceName().toString())) {
            return false;
        }
    }
    final MembershipCacheKey cacheKey = new MembershipCacheKey(group.getEntityIdentifier(), member.getUnderlyingEntityIdentifier());
    Element element = membershipCache.get(cacheKey);
    if (element == null) {
        logger.debug("Checking if group {} contains member {}/{}", group.getName(), member.getKey(), member.getLeafType().getSimpleName());
        // default
        boolean answer = false;
        final PagsGroup groupDef = convertEntityToGroupDef(group);
        if (member.isGroup()) {
            final String key = ((IEntityGroup) member).getLocalKey();
            answer = groupDef.hasMember(key);
        } else {
            try {
                final IPersonAttributeDao pa = PersonAttributeDaoLocator.getPersonAttributeDao();
                final IPersonAttributes personAttributes = pa.getPerson(member.getKey());
                if (personAttributes != null) {
                    final RestrictedPerson rp = PersonFactory.createRestrictedPerson();
                    rp.setAttributes(personAttributes.getAttributes());
                    answer = groupDef.contains(rp);
                }
            } catch (Exception ex) {
                logger.error("Exception acquiring attributes for member " + member + " while checking if group " + group + " contains this member.", ex);
                return false;
            }
        }
        element = new Element(cacheKey, answer);
        membershipCache.put(element);
    }
    return (Boolean) element.getObjectValue();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) PagsGroup(org.apereo.portal.groups.pags.PagsGroup) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) IPersonAttributeDao(org.jasig.services.persondir.IPersonAttributeDao) Element(net.sf.ehcache.Element) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) GroupsException(org.apereo.portal.groups.GroupsException)

Aggregations

RestrictedPerson (org.apereo.portal.security.provider.RestrictedPerson)5 PortalException (org.apereo.portal.PortalException)3 IUserProfile (org.apereo.portal.IUserProfile)2 IUserFragmentSubscription (org.apereo.portal.fragment.subscribe.IUserFragmentSubscription)2 XPath (javax.xml.xpath.XPath)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 XPathFactory (javax.xml.xpath.XPathFactory)1 Element (net.sf.ehcache.Element)1 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)1 UserProfile (org.apereo.portal.UserProfile)1 GroupsException (org.apereo.portal.groups.GroupsException)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 PagsGroup (org.apereo.portal.groups.pags.PagsGroup)1 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)1 DistributedUserLayout (org.apereo.portal.layout.dlm.DistributedUserLayout)1 IPerson (org.apereo.portal.security.IPerson)1 IUserInstance (org.apereo.portal.user.IUserInstance)1 IPersonAttributeDao (org.jasig.services.persondir.IPersonAttributeDao)1 IPersonAttributes (org.jasig.services.persondir.IPersonAttributes)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1