001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.action;
016    
017    import com.liferay.portal.model.User;
018    import com.liferay.portal.util.PortalUtil;
019    import com.liferay.portlet.admin.util.OmniadminUtil;
020    
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.http.HttpServletResponse;
023    
024    import org.apache.struts.action.Action;
025    import org.apache.struts.action.ActionForm;
026    import org.apache.struts.action.ActionForward;
027    import org.apache.struts.action.ActionMapping;
028    
029    /**
030     * @author Amos Fong
031     */
032    public class UpdateLicenseAction extends Action {
033    
034            @Override
035            public ActionForward execute(
036                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
037                            HttpServletResponse response)
038                    throws Exception {
039    
040                    if (_isValidRequest(request)) {
041                            return mapping.findForward("portal.license");
042                    }
043                    else {
044                            response.sendRedirect(
045                                    PortalUtil.getPathContext() + "/c/portal/layout");
046    
047                            return null;
048                    }
049            }
050    
051            private boolean _isOmniAdmin(HttpServletRequest request) {
052                    User user = null;
053    
054                    try {
055                            user = PortalUtil.getUser(request);
056                    }
057                    catch (Exception e) {
058                    }
059    
060                    if ((user != null) && OmniadminUtil.isOmniadmin(user.getUserId())) {
061                            return true;
062                    }
063                    else {
064                            return false;
065                    }
066            }
067    
068            private boolean _isValidRequest(HttpServletRequest request) {
069                    if (_isOmniAdmin(request)) {
070                            return true;
071                    }
072                    else {
073                            return false;
074                    }
075            }
076    
077    }