diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.classpath b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.classpath new file mode 100644 index 00000000..d1ee4461 --- /dev/null +++ b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.classpath @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.project b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.project new file mode 100644 index 00000000..c557db9f --- /dev/null +++ b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/.project @@ -0,0 +1,37 @@ + + + portos-filter-hook + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.apache.ivyde.eclipse.ivynature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/build.xml b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/build.xml new file mode 100644 index 00000000..9716a290 --- /dev/null +++ b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/build.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/META-INF/MANIFEST.MF b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/META-INF/MANIFEST.MF new file mode 100644 index 00000000..254272e1 --- /dev/null +++ b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/.gitignore b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/.gitignore new file mode 100644 index 00000000..840e7d31 --- /dev/null +++ b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/.gitignore @@ -0,0 +1 @@ +/classes/ diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-hook.xml b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-hook.xml new file mode 100644 index 00000000..9ece9804 --- /dev/null +++ b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-hook.xml @@ -0,0 +1,16 @@ + + + + + + + Sample Filter + it.tref.liferay.portos.filter.PortosAccesFilter + + + Sample Filter + /group/control_panel/* + REQUEST + FORWARD + + \ No newline at end of file diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-plugin-package.properties b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/liferay-plugin-package.properties new file mode 100644 index 00000000..2d6a2f7c --- /dev/null +++ b/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.0+ +liferay-version=6.2.0+ \ No newline at end of file diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/src/it/tref/liferay/portos/filter/PortosAccesFilter.java b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/src/it/tref/liferay/portos/filter/PortosAccesFilter.java new file mode 100644 index 00000000..e00797c6 --- /dev/null +++ b/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 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()"); + + } + +} diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/web.xml b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/web.xml new file mode 100644 index 00000000..1aa8cdb8 --- /dev/null +++ b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/docroot/WEB-INF/web.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/test/integration/arquillian.xml b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/test/integration/arquillian.xml new file mode 100644 index 00000000..9413609b --- /dev/null +++ b/liferay-plugins-sdk-6.2/hooks/portos-filter-hook/test/integration/arquillian.xml @@ -0,0 +1,15 @@ + + + + + + 8099 + tomcat + tomcat + + + \ No newline at end of file