Sfoglia il codice sorgente

Servlet filter per accedere al pannello di controllo con p_p_id 158

control-panel-filter
Gabriele Incoronato 4 settimane fa
parent
commit
6e813ed472
  1. 9
      liferay-plugins-sdk-6.2/build.gabri.properties
  2. 22
      liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.classpath
  3. 36
      liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.project
  4. 6
      liferay-plugins-sdk-6.2/hooks/portos-filter-hook/build.xml
  5. 3
      liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/META-INF/MANIFEST.MF
  6. 15
      liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-hook.xml
  7. 13
      liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-plugin-package.properties
  8. 99
      liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/src/it/tref/liferay/portos/filter/PortosAccesFilter.java
  9. 3
      liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/web.xml

9
liferay-plugins-sdk-6.2/build.gabri.properties

@ -0,0 +1,9 @@
# Managed by Liferay IDE (remove this comment to prevent future updates)
#Managed by Liferay IDE (remove this comment to prevent future updates)
app.server.tomcat.lib.global.dir = C:\\servers\\paesagistica\\liferay-portal-6.2-ce-ga6-patched6.2.5\\tomcat-7.0.62\\lib\\ext
app.server.tomcat.deploy.dir = C:\\servers\\paesagistica\\liferay-portal-6.2-ce-ga6-patched6.2.5\\tomcat-7.0.62\\webapps
app.server.parent.dir = C:\\servers\\paesagistica\\liferay-portal-6.2-ce-ga6-patched6.2.5
app.server.tomcat.dir = C:\\servers\\paesagistica\\liferay-portal-6.2-ce-ga6-patched6.2.5\\tomcat-7.0.62
app.server.type = tomcat
app.server.tomcat.portal.dir = C:\\servers\\paesagistica\\liferay-portal-6.2-ce-ga6-patched6.2.5\\tomcat-7.0.62\\webapps\\ROOT

22
liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.classpath

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="docroot/WEB-INF/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.liferay.ide.eclipse.server.tomcat.runtimeClasspathProvider/Liferay v6.2 CE (Tomcat 7)">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="com.liferay.ide.eclipse.server.plugin.container/hook">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="docroot/WEB-INF/classes"/>
</classpath>

36
liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.project

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>portos-filter-hook</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

6
liferay-plugins-sdk-6.2/hooks/portos-filter-hook/build.xml

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="portos-filter-hook" basedir="." default="deploy">
<import file="../build-common-hook.xml" />
</project>

3
liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/META-INF/MANIFEST.MF

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

15
liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-hook.xml

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">
<hook>
<servlet-filter>
<servlet-filter-name>Sample Filter</servlet-filter-name>
<servlet-filter-impl>it.tref.liferay.portos.filter.PortosAccesFilter</servlet-filter-impl>
</servlet-filter>
<servlet-filter-mapping>
<servlet-filter-name>Sample Filter</servlet-filter-name>
<url-pattern>/group/control_panel/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</servlet-filter-mapping>
</hook>

13
liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-plugin-package.properties

@ -0,0 +1,13 @@
name=Portos Filter
module-group-id=liferay
module-incremental-version=1
module-version=6.2.0.5
tags=
short-description=
long-description=
change-log=
page-url=http://www.liferay.com
author=Liferay, Inc.
licenses=LGPL
liferay-versions=6.2+
liferay-version=6.2.0+

99
liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/src/it/tref/liferay/portos/filter/PortosAccesFilter.java

@ -0,0 +1,99 @@
package it.tref.liferay.portos.filter;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Company;
import com.liferay.portal.model.Role;
import com.liferay.portal.model.User;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
import java.io.IOException;
import java.util.List;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PortosAccesFilter implements Filter {
final static Log _log = LogFactoryUtil.getLog(PortosAccesFilter.class.getName());
@Override
public void destroy() {
_log.debug("Called destroy()");
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) servletRequest;
_log.debug("httpReq.getRequestURI()=" + httpReq.getRequestURI());
_log.debug("httpReq.getRequestURL()=" + httpReq.getRequestURL());
String uri = (String) servletRequest.getAttribute(WebKeys.INVOKER_FILTER_URI);
_log.debug("Called SampleFilter.doFilter(" + servletRequest + ", " + servletResponse + ", " + filterChain
+ ") for URI " + uri);
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
boolean permesso = false;
boolean permessoRuoli = false;
try {
User user = PortalUtil.getUser(httpServletRequest);
if (user != null) {
List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
for (int i = 0; i < userRoles.size(); i++) {
if("Admin publication".equals((userRoles.get(i)).getName())){
permessoRuoli=true;
}
}
}
if ((user == null || (user.isDefaultUser() && !permessoRuoli))) {
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
httpServletResponse.setStatus(403);
_log.debug("Guest non permesso");
return;
}
if(httpServletRequest.getParameterMap().containsKey("p_p_id")&&
!httpServletRequest.getParameterMap().get("p_p_id")[0].isEmpty()&&
("158".equals( httpServletRequest.getParameterMap().get("p_p_id")[0]))){
if (user != null && PortalUtil.isCompanyAdmin(user) || permessoRuoli) {
permesso = true;
_log.debug("Admin passa il controllo :" + user.getFullName());
}
if (!permesso) {
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
//RequestLogUtil.createOrUpdateLog(httpReq);
httpServletResponse.setStatus(403);
} else {
filterChain.doFilter(servletRequest, servletResponse);
}
}else {
filterChain.doFilter(servletRequest, servletResponse);
}
} catch (Exception e) {
_log.error(e, e);
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
if (httpServletResponse.getStatus() != 403) {
filterChain.doFilter(servletRequest, servletResponse);
}
}
}
@Override
public void init(FilterConfig filterConfig) {
_log.debug("Called FIXPermissionFilter.init()");
}
}

3
liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/web.xml

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
</web-app>
Caricamento…
Annulla
Salva