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.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    }