Search in sources :

Example 11 with IPerson

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

the class ServerNameGuestChainingProfileMapperTest method testGuestAuthorizedDomain.

@Test
public void testGuestAuthorizedDomain() throws Exception {
    ServerNameGuestChainingProfileMapper profileMapper = new ServerNameGuestChainingProfileMapper();
    profileMapper.setAuthorizedServerNames(configMap);
    profileMapper.afterPropertiesSet();
    final IPerson person = createGuestPerson();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServerName("test-cfa.portail.ent");
    final String fname = profileMapper.getProfileFname(person, request);
    Assert.assertEquals("guest-cfa-default", fname);
}
Also used : IPerson(org.apereo.portal.security.IPerson) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 12 with IPerson

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

the class GoogleAnalyticsController method renderAnalyticsHeader.

@RenderMapping
public String renderAnalyticsHeader(RenderRequest request, ModelMap model) throws IOException {
    // For which user account are we logging portal activity?
    final HttpServletRequest req = portalRequestUtils.getCurrentPortalRequest();
    final IPerson person = personManager.getPerson(req);
    final String username = person.getUserName();
    final IGroupMember groupMember = GroupService.getGroupMember(username, IPerson.class);
    final Map<String, Boolean> isMemberCache = new HashMap<>();
    final PortletPreferences preferences = request.getPreferences();
    final JsonNode config = this.portletPreferencesJsonDao.getJsonNode(preferences, GoogleAnalyticsConfigController.CONFIG_PREF_NAME);
    final JsonNode propertyConfig = config.get("defaultConfig");
    this.filterAnalyticsGroups(groupMember, propertyConfig, isMemberCache);
    final JsonNode hosts = config.get("hosts");
    if (hosts != null) {
        for (final Iterator<JsonNode> hostsItr = hosts.elements(); hostsItr.hasNext(); ) {
            final JsonNode institution = hostsItr.next();
            this.filterAnalyticsGroups(groupMember, institution, isMemberCache);
        }
    }
    model.put("data", config);
    if (propertyConfig == null || propertyConfig.get("propertyId") == null) {
        return "jsp/GoogleAnalytics/noop";
    } else {
        return "jsp/GoogleAnalytics/init";
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IGroupMember(org.apereo.portal.groups.IGroupMember) HashMap(java.util.HashMap) PortletPreferences(javax.portlet.PortletPreferences) JsonNode(com.fasterxml.jackson.databind.JsonNode) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 13 with IPerson

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

the class SubscribableTabsRESTController method getSubscriptionList.

@RequestMapping(value = "/subscribableTabs.json", method = RequestMethod.GET)
public ModelAndView getSubscriptionList(HttpServletRequest request) {
    Map<String, Object> model = new HashMap<String, Object>();
    /** Retrieve the IPerson and IAuthorizationPrincipal for the currently authenticated user */
    IUserInstance userInstance = userInstanceManager.getUserInstance(request);
    IPerson person = userInstance.getPerson();
    AuthorizationService authService = AuthorizationService.instance();
    IAuthorizationPrincipal principal = authService.newPrincipal(person.getUserName(), IPerson.class);
    /**
         * Build a collection of owner IDs for the fragments to which the authenticated user is
         * subscribed
         */
    // get the list of current subscriptions for this user
    List<IUserFragmentSubscription> subscriptions = userFragmentSubscriptionDao.getUserFragmentInfo(person);
    // transform it into the set of owners
    Set<String> subscribedOwners = new HashSet<String>();
    for (IUserFragmentSubscription subscription : subscriptions) {
        if (subscription.isActive()) {
            subscribedOwners.add(subscription.getFragmentOwner());
        }
    }
    /**
         * Iterate through the list of all currently defined DLM fragments and determine if the
         * current user has permissions to subscribe to each. Any subscribable fragments will be
         * transformed into a JSON-friendly bean and added to the model.
         */
    final List<SubscribableFragment> jsonFragments = new ArrayList<SubscribableFragment>();
    // get the list of fragment definitions from DLM
    final List<FragmentDefinition> fragmentDefinitions = configurationLoader.getFragments();
    final Locale locale = RequestContextUtils.getLocale(request);
    // iterate through the list
    for (FragmentDefinition fragmentDefinition : fragmentDefinitions) {
        if (isSubscribable(fragmentDefinition, principal)) {
            String owner = fragmentDefinition.getOwnerId();
            // this fragment
            if (principal.hasPermission("UP_FRAGMENT", "FRAGMENT_SUBSCRIBE", owner)) {
                // create a JSON fragment bean and add it to our list
                boolean subscribed = subscribedOwners.contains(owner);
                final String name = getMessage("fragment." + owner + ".name", fragmentDefinition.getName(), locale);
                final String description = getMessage("fragment." + owner + ".description", fragmentDefinition.getDescription(), locale);
                SubscribableFragment jsonFragment = new SubscribableFragment(name, description, owner, subscribed);
                jsonFragments.add(jsonFragment);
            }
        }
    }
    model.put("fragments", jsonFragments);
    return new ModelAndView("json", model);
}
Also used : Locale(java.util.Locale) FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserFragmentSubscription(org.apereo.portal.fragment.subscribe.IUserFragmentSubscription) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) AuthorizationService(org.apereo.portal.services.AuthorizationService) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with IPerson

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

the class MarketplaceRESTController method marketplaceEntriesFeed.

@RequestMapping(value = "/marketplace/entries.json", method = RequestMethod.GET)
public ModelAndView marketplaceEntriesFeed(HttpServletRequest request) {
    final IPerson user = personManager.getPerson(request);
    final Set<PortletCategory> empty = // Produces an complete/unfiltered collection
    Collections.emptySet();
    final Set<MarketplaceEntry> marketplaceEntries = marketplaceService.browseableMarketplaceEntriesFor(user, empty);
    return new ModelAndView("json", "portlets", marketplaceEntries);
}
Also used : IPerson(org.apereo.portal.security.IPerson) MarketplaceEntry(org.apereo.portal.rest.layout.MarketplaceEntry) ModelAndView(org.springframework.web.servlet.ModelAndView) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with IPerson

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

the class PortalEventFactoryImpl method createPortalEventBuilder.

/*
     * Implementation
     */
protected PortalEvent.PortalEventBuilder createPortalEventBuilder(Object source, HttpServletRequest request) {
    request = getCurrentPortalRequest(request);
    final IPerson person = this.getPerson(request);
    return this.createPortalEventBuilder(source, person, request);
}
Also used : IPerson(org.apereo.portal.security.IPerson)

Aggregations

IPerson (org.apereo.portal.security.IPerson)177 Test (org.junit.Test)46 PersonImpl (org.apereo.portal.security.provider.PersonImpl)41 ModelAndView (org.springframework.web.servlet.ModelAndView)41 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 HttpServletRequest (javax.servlet.http.HttpServletRequest)26 IUserInstance (org.apereo.portal.user.IUserInstance)26 ArrayList (java.util.ArrayList)22 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)22 HashMap (java.util.HashMap)20 IPersonAttributes (org.apereo.services.persondir.IPersonAttributes)16 EntityIdentifier (org.apereo.portal.EntityIdentifier)15 HttpSession (javax.servlet.http.HttpSession)14 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)14 PortalException (org.apereo.portal.PortalException)11 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 List (java.util.List)10 IUserProfile (org.apereo.portal.IUserProfile)9 ISecurityContext (org.apereo.portal.security.ISecurityContext)9