commit 78a1230e9666cf816e6480ef1ecc9919a82fc4a5 Author: Victor\Victor Carrasco Date: Wed Nov 5 10:03:38 2025 -0300 commit inicial diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..8a8f5ab --- /dev/null +++ b/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..79239d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.gradle/ +.sass-cache/ +build/ +target/ \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..9a680f3 --- /dev/null +++ b/.project @@ -0,0 +1,24 @@ + + + modulo-redireccion-contactame + Project modulo-redireccion-contactame created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + com.liferay.ide.core.liferayNature + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..62e3e7e --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir=../.. +eclipse.preferences.version=1 diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..048fa21 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/main/resources/META-INF/resources/configuration.jsp=UTF-8 +encoding//src/main/resources/content/Language.properties=UTF-8 diff --git a/bin/main/META-INF/resources/configuration.jsp b/bin/main/META-INF/resources/configuration.jsp new file mode 100644 index 0000000..c602a4e --- /dev/null +++ b/bin/main/META-INF/resources/configuration.jsp @@ -0,0 +1,47 @@ +<%@ include file="/init.jsp" %> + + + + + +
+
+ + + + + +
+ +
+ +
+
+
+
+ + + + + +
+
+
+
+ +

+
+
+ + + \ No newline at end of file diff --git a/bin/main/META-INF/resources/css/main.scss b/bin/main/META-INF/resources/css/main.scss new file mode 100644 index 0000000..64a398f --- /dev/null +++ b/bin/main/META-INF/resources/css/main.scss @@ -0,0 +1,2 @@ +.modulo-redireccion-contactame { +} \ No newline at end of file diff --git a/bin/main/META-INF/resources/images/loader.gif b/bin/main/META-INF/resources/images/loader.gif new file mode 100644 index 0000000..3288d10 Binary files /dev/null and b/bin/main/META-INF/resources/images/loader.gif differ diff --git a/bin/main/META-INF/resources/init.jsp b/bin/main/META-INF/resources/init.jsp new file mode 100644 index 0000000..32beea1 --- /dev/null +++ b/bin/main/META-INF/resources/init.jsp @@ -0,0 +1,24 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + + + + + + + + + +<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> + +<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@ +taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %><%@ +taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@ +taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> + + + + \ No newline at end of file diff --git a/bin/main/META-INF/resources/view.jsp b/bin/main/META-INF/resources/view.jsp new file mode 100644 index 0000000..1b03570 --- /dev/null +++ b/bin/main/META-INF/resources/view.jsp @@ -0,0 +1,38 @@ +<%@ include file="/init.jsp" %> + + + + + +
+
+ loading
+
+
+ +
+ + + +
+
+ +
+

+
+
+

+
+
+
+ + \ No newline at end of file diff --git a/bin/main/content/Language.properties b/bin/main/content/Language.properties new file mode 100644 index 0000000..0474212 --- /dev/null +++ b/bin/main/content/Language.properties @@ -0,0 +1,8 @@ +javax.portlet.title.modulo_redireccion_contactame_ModuloRedireccionContactamePortlet=ModuloRedireccionContactame +moduloredireccioncontactame.caption=Hello from ModuloRedireccionContactame! + + +modulo.redireccion.contactame.sin.permiso=No tiene Permisos para modificar esta Configuración. + +modulo.redireccion.contactame.cargando=Un momento, por favor... +modulo.redireccion.contactame.sin.redirecion=Sin redirección \ No newline at end of file diff --git a/bin/main/modulo/redireccion/contactame/configuration/ModuloRedireccionContactameConfiguracion.class b/bin/main/modulo/redireccion/contactame/configuration/ModuloRedireccionContactameConfiguracion.class new file mode 100644 index 0000000..cca4d55 Binary files /dev/null and b/bin/main/modulo/redireccion/contactame/configuration/ModuloRedireccionContactameConfiguracion.class differ diff --git a/bin/main/modulo/redireccion/contactame/constants/ModuloRedireccionContactamePortletKeys.class b/bin/main/modulo/redireccion/contactame/constants/ModuloRedireccionContactamePortletKeys.class new file mode 100644 index 0000000..a39edd0 Binary files /dev/null and b/bin/main/modulo/redireccion/contactame/constants/ModuloRedireccionContactamePortletKeys.class differ diff --git a/bin/main/modulo/redireccion/contactame/portlet/ModuloRedireccionContactamePortlet.class b/bin/main/modulo/redireccion/contactame/portlet/ModuloRedireccionContactamePortlet.class new file mode 100644 index 0000000..344a57a Binary files /dev/null and b/bin/main/modulo/redireccion/contactame/portlet/ModuloRedireccionContactamePortlet.class differ diff --git a/bnd.bnd b/bnd.bnd new file mode 100644 index 0000000..d3f3533 --- /dev/null +++ b/bnd.bnd @@ -0,0 +1,6 @@ +Bundle-Name: modulo-redireccion-contactame +Bundle-SymbolicName: modulo.redireccion.contactame +Bundle-Version: 1.0.0 +Import-Package: *;resolution:=optional +-includeresource: \ +META-INF/lib/jjwt-0.7.0.jar=jjwt-0.7.0.jar;lib:=true \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f01482d --- /dev/null +++ b/build.gradle @@ -0,0 +1,23 @@ +dependencies { + compileOnly group: "com.liferay", name: "com.liferay.asset.taglib" + compileOnly group: "com.liferay", name: "com.liferay.comment.taglib" + compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib" + compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.dynamic.section" + compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.form.navigator" + compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.util" + compileOnly group: "com.liferay", name: "com.liferay.journal.taglib" + compileOnly group: "com.liferay", name: "com.liferay.layout.taglib" + compileOnly group: "com.liferay", name: "com.liferay.site.taglib" + compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel" + compileOnly group: "com.liferay.portal", name: "com.liferay.portal.impl" + compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib" + compileOnly group: "javax.portlet", name: "portlet-api" + compileOnly group: "javax.servlet", name: "javax.servlet-api" + compileOnly group: "jstl", name: "jstl" + compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.4.0" + + cssBuilder group: "com.liferay", name: "com.liferay.css.builder", version: "3.0.2" + + compileInclude group: 'io.jsonwebtoken', name: 'jjwt', version: '0.7.0' + +} diff --git a/lib/jjwt-0.7.0.jar b/lib/jjwt-0.7.0.jar new file mode 100644 index 0000000..5a5c3fa Binary files /dev/null and b/lib/jjwt-0.7.0.jar differ diff --git a/src/main/java/modulo/redireccion/contactame/configuration/ModuloRedireccionContactameConfiguracion.java b/src/main/java/modulo/redireccion/contactame/configuration/ModuloRedireccionContactameConfiguracion.java new file mode 100644 index 0000000..5267608 --- /dev/null +++ b/src/main/java/modulo/redireccion/contactame/configuration/ModuloRedireccionContactameConfiguracion.java @@ -0,0 +1,87 @@ +package modulo.redireccion.contactame.configuration; +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.kernel.portlet.ConfigurationAction; +import com.liferay.portal.kernel.portlet.DefaultConfigurationAction; +import com.liferay.portal.kernel.util.ParamUtil; +import com.liferay.portal.kernel.util.PortalUtil; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.PortletConfig; +import javax.portlet.PortletPreferences; +import javax.portlet.PortletRequest; +import javax.servlet.http.HttpServletRequest; + +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; + +import modulo.redireccion.contactame.constants.ModuloRedireccionContactamePortletKeys; + +@Component( + configurationPid = "modulo.redireccion.contactame.configuration.ModuloRedireccionContactameConfiguracion", + configurationPolicy = ConfigurationPolicy.OPTIONAL, + immediate = true, + property = { + "javax.portlet.name="+ModuloRedireccionContactamePortletKeys.MODULOREDIRECCIONCONTACTAME + }, + service = ConfigurationAction.class + ) +public class ModuloRedireccionContactameConfiguracion extends DefaultConfigurationAction{ + + private static final Log _log = LogFactoryUtil.getLog(ModuloRedireccionContactameConfiguracion.class); + + @Override + public String getJspPath(HttpServletRequest httpServletRequest) { + _log.info("[getJspPath()] Inicio ..."); + + HttpServletRequest httpOrigReq = PortalUtil.getOriginalServletRequest(httpServletRequest); + + String myValue = httpOrigReq.getParameter("p_p_id"); + + + if(myValue != null && myValue.contains("PortletConfiguration")) { + httpServletRequest.setAttribute( ModuloRedireccionContactamePortletKeys.ROLE_PERMISO, true); + }else { + httpServletRequest.setAttribute( ModuloRedireccionContactamePortletKeys.ROLE_PERMISO, false); + } + + PortletRequest pr=(PortletRequest) httpServletRequest.getAttribute("javax.portlet.request"); + PortletPreferences prefs=pr.getPreferences(); + + //Redireccion + httpServletRequest.setAttribute( ModuloRedireccionContactamePortletKeys.FIELD_URL_REDIRECT, + prefs.getValue(ModuloRedireccionContactamePortletKeys.FIELD_URL_REDIRECT, "") ); + httpServletRequest.setAttribute( ModuloRedireccionContactamePortletKeys.FIELD_CANAL, + prefs.getValue(ModuloRedireccionContactamePortletKeys.FIELD_CANAL, "") ); + httpServletRequest.setAttribute( ModuloRedireccionContactamePortletKeys.FIELD_URL_PERMANENCIA, + prefs.getValue(ModuloRedireccionContactamePortletKeys.FIELD_URL_PERMANENCIA, "") ); + + _log.info("[getJspPath()] fin ..."); + return super.getJspPath(httpServletRequest); + } + + @Override + public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) + throws Exception { + _log.info("[processAction()] Inicio ..."); + + String urlRedireccion = ParamUtil.getString(actionRequest, ModuloRedireccionContactamePortletKeys.FIELD_URL_REDIRECT); + String campoCanal = ParamUtil.getString(actionRequest, ModuloRedireccionContactamePortletKeys.FIELD_CANAL); + String urlPermanencia = ParamUtil.getString(actionRequest, ModuloRedireccionContactamePortletKeys.FIELD_URL_PERMANENCIA); + + _log.info("[processAction()] campo urlRedireccion : "+ urlRedireccion); + _log.info("[processAction()] campo Canal : "+ campoCanal); + _log.info("[processAction()] campo urlPermanencia : "+ urlPermanencia); + + PortletPreferences prefs=actionRequest.getPreferences(); + prefs.setValue(ModuloRedireccionContactamePortletKeys.FIELD_URL_REDIRECT, urlRedireccion); + prefs.setValue(ModuloRedireccionContactamePortletKeys.FIELD_CANAL, campoCanal); + prefs.setValue(ModuloRedireccionContactamePortletKeys.FIELD_URL_PERMANENCIA, urlPermanencia); + prefs.store(); + _log.info("[processAction()] Fin ..."); + super.processAction(portletConfig, actionRequest, actionResponse); + } + + +} diff --git a/src/main/java/modulo/redireccion/contactame/constants/ModuloRedireccionContactamePortletKeys.java b/src/main/java/modulo/redireccion/contactame/constants/ModuloRedireccionContactamePortletKeys.java new file mode 100644 index 0000000..88f30e5 --- /dev/null +++ b/src/main/java/modulo/redireccion/contactame/constants/ModuloRedireccionContactamePortletKeys.java @@ -0,0 +1,27 @@ +package modulo.redireccion.contactame.constants; + +/** + * @author Victor Carrasco + */ +public class ModuloRedireccionContactamePortletKeys { + + public static final String MODULOREDIRECCIONCONTACTAME = + "modulo_redireccion_contactame_ModuloRedireccionContactamePortlet"; + + public static final String ROLE_ADMINISTRATOR = "Administrator"; + public static final String ROLE_PERMISO = "permiso_role"; + + /*Flag Redireccion*/ + public static final String MOSTRAR_REDIRECCION = "monstrarRedireccion"; + + /*urls Redireccion*/ + public static final String URL_SEGUIMIENTO = "urlSeguimiento"; + public static final String URL_PERMANENCIA = "urlPermanenciaRedirect"; + + + /*Campos Redireccion*/ + public static final String FIELD_URL_REDIRECT = "urlRedireccion"; + public static final String FIELD_CANAL = "campoCanal"; + public static final String FIELD_URL_PERMANENCIA = "urlPermanencia"; + +} \ No newline at end of file diff --git a/src/main/java/modulo/redireccion/contactame/portlet/ModuloRedireccionContactamePortlet.java b/src/main/java/modulo/redireccion/contactame/portlet/ModuloRedireccionContactamePortlet.java new file mode 100644 index 0000000..0904034 --- /dev/null +++ b/src/main/java/modulo/redireccion/contactame/portlet/ModuloRedireccionContactamePortlet.java @@ -0,0 +1,128 @@ +package modulo.redireccion.contactame.portlet; + +import modulo.redireccion.contactame.constants.ModuloRedireccionContactamePortletKeys; + +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.kernel.model.User; +import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet; +import com.liferay.portal.kernel.theme.ThemeDisplay; +import com.liferay.portal.kernel.util.PortalUtil; +import com.liferay.portal.kernel.util.WebKeys; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import javax.portlet.Portlet; +import javax.portlet.PortletException; +import javax.portlet.PortletPreferences; +import javax.portlet.PortletRequest; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import javax.servlet.http.HttpServletRequest; + +import org.osgi.service.component.annotations.Component; +import static java.time.ZoneOffset.UTC; + +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +/** + * @author Victor Carrasco + */ +@Component( + immediate = true, + property = { + "com.liferay.portlet.display-category=category.sample", + "com.liferay.portlet.header-portlet-css=/css/main.css", + "com.liferay.portlet.instanceable=true", + "javax.portlet.display-name=ModuloRedireccionContactame", + "javax.portlet.init-param.template-path=/", + "javax.portlet.init-param.view-template=/view.jsp", + "javax.portlet.name=" + ModuloRedireccionContactamePortletKeys.MODULOREDIRECCIONCONTACTAME, + "javax.portlet.resource-bundle=content.Language", + "javax.portlet.security-role-ref=power-user,user" + }, + service = Portlet.class +) +public class ModuloRedireccionContactamePortlet extends MVCPortlet { + +private static final Log _log = LogFactoryUtil.getLog(ModuloRedireccionContactamePortlet.class); + + public static final String ISSUER = "cl.hites.sts"; + public static final int EXPIRACION = 30; + byte[] secretKey = new byte[64]; + @Override + public void doView(RenderRequest renderRequest, RenderResponse renderResponse) + throws IOException, PortletException { + + ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); + + PortletRequest pr=(PortletRequest) renderRequest.getAttribute("javax.portlet.request"); + PortletPreferences prefs=pr.getPreferences(); + + User user = themeDisplay.getUser(); + + HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(renderRequest); + HttpServletRequest httpOrigReq = PortalUtil.getOriginalServletRequest(httpReq); + String myValue = httpOrigReq.getParameter("p_l_mode"); + if(myValue != null && myValue.equals("edit")) { + renderRequest.setAttribute( "modoEdit", true); + }else { + renderRequest.setAttribute( "modoEdit", false); + if(!user.getDefaultUser()) { + String rut = user.getScreenName().trim(); + + String[] rutUsuario = rut.split("-"); rut = ""; + for (String rutUser : rutUsuario) { rut = rut + rutUser; } + _log.info("[doView()] rut : "+rut); + + String urlRedireccion = prefs.getValue(ModuloRedireccionContactamePortletKeys.FIELD_URL_REDIRECT, ""); + _log.info("[doView()] campo url Redireccion Contactame : " + urlRedireccion); + + String canal = prefs.getValue(ModuloRedireccionContactamePortletKeys.FIELD_CANAL, ""); + _log.info("[doView()] campo canal : " + canal); + + String urlPermanencia = prefs.getValue(ModuloRedireccionContactamePortletKeys.FIELD_URL_PERMANENCIA, ""); + _log.info("[doView()] campo url Permanencia Contactame : " + urlPermanencia); + + Map map = new HashMap<>(); + map.put("rut", rut); + map.put("canal", canal); + + String token = makeToken(rut,map); + + //String token2 = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNDIxMTUyNTUiLCJpc3MiOiJjbC5oaXRlcy5tb2JpbGUuc2VydmljZS5zZWN1cml0eSIsInVzZXJOYW1lIjoiMTQyMTE1MjUtNSIsImV4cCI6MTU3NTAyNzczMSwidXNlciI6IkdhYnJpZWxsIEFycm95byBBcnJveW8iLCJyb2wiOm51bGx9.v-Dldq5S6O3XQwGaK4wschpOpzAYh2ZWmuzUwn8ZkoE4mcjmN5LgnOJJv4WlmPW9ZI1hTmiEsOBXqUAZzrn96g"; + + if( token!=null&&!token.isEmpty()) { + + renderRequest.setAttribute( ModuloRedireccionContactamePortletKeys.MOSTRAR_REDIRECCION, true); + renderRequest.setAttribute( ModuloRedireccionContactamePortletKeys.URL_SEGUIMIENTO, urlRedireccion.concat(token)); + renderRequest.setAttribute( ModuloRedireccionContactamePortletKeys.URL_PERMANENCIA, urlPermanencia); + + }else { + renderRequest.setAttribute( ModuloRedireccionContactamePortletKeys.MOSTRAR_REDIRECCION, false); + } + }else { + renderRequest.setAttribute( ModuloRedireccionContactamePortletKeys.MOSTRAR_REDIRECCION, false); + } + } + super.doView(renderRequest, renderResponse); + } + private String makeToken(String userName, Map dataToEncripted) { + String result = ""; + Date expiration = Date.from(LocalDateTime.now(UTC).plusMinutes(EXPIRACION)/*.plusHours(2)*/.toInstant(UTC)); + result = Jwts.builder(). + setClaims(dataToEncripted). + setSubject(userName). + //setAudience(issuer). + setExpiration(expiration). + setIssuer(ISSUER). + signWith(SignatureAlgorithm.HS512, secretKey). + compact(); + return result; + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/resources/configuration.jsp b/src/main/resources/META-INF/resources/configuration.jsp new file mode 100644 index 0000000..c602a4e --- /dev/null +++ b/src/main/resources/META-INF/resources/configuration.jsp @@ -0,0 +1,47 @@ +<%@ include file="/init.jsp" %> + + + + + +
+
+ + + + + +
+ +
+ +
+
+
+
+ + + + + +
+
+
+
+ +

+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/META-INF/resources/css/main.scss b/src/main/resources/META-INF/resources/css/main.scss new file mode 100644 index 0000000..64a398f --- /dev/null +++ b/src/main/resources/META-INF/resources/css/main.scss @@ -0,0 +1,2 @@ +.modulo-redireccion-contactame { +} \ No newline at end of file diff --git a/src/main/resources/META-INF/resources/images/loader.gif b/src/main/resources/META-INF/resources/images/loader.gif new file mode 100644 index 0000000..3288d10 Binary files /dev/null and b/src/main/resources/META-INF/resources/images/loader.gif differ diff --git a/src/main/resources/META-INF/resources/init.jsp b/src/main/resources/META-INF/resources/init.jsp new file mode 100644 index 0000000..32beea1 --- /dev/null +++ b/src/main/resources/META-INF/resources/init.jsp @@ -0,0 +1,24 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + + + + + + + + + +<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> + +<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@ +taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %><%@ +taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@ +taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> + + + + \ No newline at end of file diff --git a/src/main/resources/META-INF/resources/view.jsp b/src/main/resources/META-INF/resources/view.jsp new file mode 100644 index 0000000..1b03570 --- /dev/null +++ b/src/main/resources/META-INF/resources/view.jsp @@ -0,0 +1,38 @@ +<%@ include file="/init.jsp" %> + + + + + +
+
+ loading
+
+
+ +
+ + + +
+
+ +
+

+
+
+

+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/content/Language.properties b/src/main/resources/content/Language.properties new file mode 100644 index 0000000..0474212 --- /dev/null +++ b/src/main/resources/content/Language.properties @@ -0,0 +1,8 @@ +javax.portlet.title.modulo_redireccion_contactame_ModuloRedireccionContactamePortlet=ModuloRedireccionContactame +moduloredireccioncontactame.caption=Hello from ModuloRedireccionContactame! + + +modulo.redireccion.contactame.sin.permiso=No tiene Permisos para modificar esta Configuración. + +modulo.redireccion.contactame.cargando=Un momento, por favor... +modulo.redireccion.contactame.sin.redirecion=Sin redirección \ No newline at end of file