001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.events;
016    
017    import com.liferay.portal.kernel.events.Action;
018    import com.liferay.portal.kernel.events.ActionException;
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.exception.SystemException;
021    import com.liferay.portal.model.User;
022    import com.liferay.portal.security.auth.MembershipPolicyUtil;
023    import com.liferay.portal.service.GroupLocalServiceUtil;
024    import com.liferay.portal.service.OrganizationLocalServiceUtil;
025    import com.liferay.portal.service.RoleLocalServiceUtil;
026    import com.liferay.portal.service.UserGroupLocalServiceUtil;
027    import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
028    import com.liferay.portal.util.PortalUtil;
029    
030    import javax.servlet.http.HttpServletRequest;
031    import javax.servlet.http.HttpServletResponse;
032    
033    /**
034     * @author Sergio González
035     */
036    public class MembershipPolicyAction extends Action {
037    
038            @Override
039            public void run(HttpServletRequest request, HttpServletResponse response)
040                    throws ActionException {
041    
042                    try {
043                            User user = PortalUtil.getUser(request);
044    
045                            checkMembershipPolicy(user);
046                    }
047                    catch (Exception e) {
048                            throw new ActionException();
049                    }
050            }
051    
052            protected void checkMembershipPolicy(User user)
053                    throws PortalException, SystemException {
054    
055                    if (MembershipPolicyUtil.isApplicableUser(user)) {
056                            GroupLocalServiceUtil.checkMembershipPolicy(user);
057    
058                            OrganizationLocalServiceUtil.checkMembershipPolicy(user);
059    
060                            UserGroupLocalServiceUtil.checkMembershipPolicy(user);
061    
062                            RoleLocalServiceUtil.checkMembershipPolicy(user);
063    
064                            UserGroupRoleLocalServiceUtil.checkMembershipPolicy(user);
065                    }
066            }
067    
068    }