commit 2d18b50180399996708831742bd4d28d8b0791db Author: Victor\Victor Carrasco Date: Wed Nov 5 10:06:39 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..a23bf71 --- /dev/null +++ b/.project @@ -0,0 +1,24 @@ + + + modelo-redireccion-seguimiento + Project modelo-redireccion-seguimiento 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/bin/main/META-INF/resources/config.jsp b/bin/main/META-INF/resources/config.jsp new file mode 100644 index 0000000..6b1e846 --- /dev/null +++ b/bin/main/META-INF/resources/config.jsp @@ -0,0 +1,46 @@ +<%@ 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..ea5d1ad --- /dev/null +++ b/bin/main/META-INF/resources/css/main.scss @@ -0,0 +1,2 @@ +.modelo-redireccion-seguimiento { +} \ 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..7877443 --- /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..e22749c --- /dev/null +++ b/bin/main/META-INF/resources/view.jsp @@ -0,0 +1,33 @@ +<%@ 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..db18f94 --- /dev/null +++ b/bin/main/content/Language.properties @@ -0,0 +1,8 @@ +javax.portlet.title.modelo_redireccion_seguimiento_ModeloRedireccionSeguimientoPortlet=ModeloRedireccionSeguimiento +modeloredireccionseguimiento.caption=Hello from ModeloRedireccionSeguimiento! + + +modelo.redireccion.seguimiento.sin.permiso=No tiene Permisos para modificar esta Configuraci\uFFFDn. + +modelo.redireccion.seguimiento.cargando=Un momento, por favor... +modelo.redireccion.seguimiento.sin.redirecion=Sin redireccion \ No newline at end of file diff --git a/bin/main/modelo/redireccion/seguimiento/configuration/ModeloRedireccionSeguimientoConfiguracion.class b/bin/main/modelo/redireccion/seguimiento/configuration/ModeloRedireccionSeguimientoConfiguracion.class new file mode 100644 index 0000000..52a0055 Binary files /dev/null and b/bin/main/modelo/redireccion/seguimiento/configuration/ModeloRedireccionSeguimientoConfiguracion.class differ diff --git a/bin/main/modelo/redireccion/seguimiento/constants/ModeloRedireccionSeguimientoPortletKeys.class b/bin/main/modelo/redireccion/seguimiento/constants/ModeloRedireccionSeguimientoPortletKeys.class new file mode 100644 index 0000000..e7d2fbe Binary files /dev/null and b/bin/main/modelo/redireccion/seguimiento/constants/ModeloRedireccionSeguimientoPortletKeys.class differ diff --git a/bin/main/modelo/redireccion/seguimiento/portlet/ModeloRedireccionSeguimientoPortlet.class b/bin/main/modelo/redireccion/seguimiento/portlet/ModeloRedireccionSeguimientoPortlet.class new file mode 100644 index 0000000..eebaf46 Binary files /dev/null and b/bin/main/modelo/redireccion/seguimiento/portlet/ModeloRedireccionSeguimientoPortlet.class differ diff --git a/bnd.bnd b/bnd.bnd new file mode 100644 index 0000000..bb42bff --- /dev/null +++ b/bnd.bnd @@ -0,0 +1,6 @@ +Bundle-Name: modelo-redireccion-seguimiento +Bundle-SymbolicName: modelo.redireccion.seguimiento +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 diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..aa1afb4 --- /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" + + 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/modelo/redireccion/seguimiento/configuration/ModeloRedireccionSeguimientoConfiguracion.java b/src/main/java/modelo/redireccion/seguimiento/configuration/ModeloRedireccionSeguimientoConfiguracion.java new file mode 100644 index 0000000..ec228a3 --- /dev/null +++ b/src/main/java/modelo/redireccion/seguimiento/configuration/ModeloRedireccionSeguimientoConfiguracion.java @@ -0,0 +1,84 @@ +package modelo.redireccion.seguimiento.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 modelo.redireccion.seguimiento.constants.ModeloRedireccionSeguimientoPortletKeys; + +@Component( + configurationPid = "modelo.redireccion.seguimiento.configuration.ModeloRedireccionSeguimientoConfiguracion", + configurationPolicy = ConfigurationPolicy.OPTIONAL, + immediate = true, + property = { + "javax.portlet.name="+ ModeloRedireccionSeguimientoPortletKeys.MODELOREDIRECCIONSEGUIMIENTO + }, + service = ConfigurationAction.class + ) +public class ModeloRedireccionSeguimientoConfiguracion extends DefaultConfigurationAction{ + + + private static final Log _log = LogFactoryUtil.getLog(ModeloRedireccionSeguimientoConfiguracion.class); + + @Override + public String getJspPath(HttpServletRequest renderRequest) { + _log.info("[getJspPath()] Inicio ..."); + + HttpServletRequest httpOrigReq = PortalUtil.getOriginalServletRequest(renderRequest); + + String myValue = httpOrigReq.getParameter("p_p_id"); + + + if(myValue != null && myValue.contains("PortletConfiguration")) { + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.ROLE_PERMISO, true); + }else { + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.ROLE_PERMISO, false); + } + + PortletRequest pr=(PortletRequest) renderRequest.getAttribute("javax.portlet.request"); + PortletPreferences prefs=pr.getPreferences(); + + //Redireccion + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_REDIRECT, prefs.getValue(ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_REDIRECT, "") ); + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.FIELD_CANAL, prefs.getValue(ModeloRedireccionSeguimientoPortletKeys.FIELD_CANAL, "") ); + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_PERMANENCIA, prefs.getValue(ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_PERMANENCIA, "") ); + + _log.info("[getJspPath()] fin ..."); + return "/config.jsp"; + } + + @Override + public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) + throws Exception { + _log.info("[getJspPath()] Inicio ..."); + + String urlRedireccion = ParamUtil.getString(actionRequest, ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_REDIRECT); + String campoCanal = ParamUtil.getString(actionRequest, ModeloRedireccionSeguimientoPortletKeys.FIELD_CANAL); + String urlPermanencia = ParamUtil.getString(actionRequest, ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_PERMANENCIA); + + _log.info("[getJspPath()] urlRedireccion : "+urlRedireccion); + _log.info("[getJspPath()] campoCanal : "+campoCanal); + _log.info("[getJspPath()] urlPermanencia : "+urlPermanencia); + + PortletPreferences prefs=actionRequest.getPreferences(); + prefs.setValue(ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_REDIRECT, urlRedireccion); + prefs.setValue(ModeloRedireccionSeguimientoPortletKeys.FIELD_CANAL, campoCanal); + prefs.setValue(ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_PERMANENCIA, urlPermanencia); + prefs.store(); + _log.info("[getJspPath()] Fin ..."); + super.processAction(portletConfig, actionRequest, actionResponse); + } +} diff --git a/src/main/java/modelo/redireccion/seguimiento/constants/ModeloRedireccionSeguimientoPortletKeys.java b/src/main/java/modelo/redireccion/seguimiento/constants/ModeloRedireccionSeguimientoPortletKeys.java new file mode 100644 index 0000000..0ffa1ed --- /dev/null +++ b/src/main/java/modelo/redireccion/seguimiento/constants/ModeloRedireccionSeguimientoPortletKeys.java @@ -0,0 +1,25 @@ +package modelo.redireccion.seguimiento.constants; + +/** + * @author Victor Carrasco + */ +public class ModeloRedireccionSeguimientoPortletKeys { + + public static final String MODELOREDIRECCIONSEGUIMIENTO = + "modelo_redireccion_seguimiento_ModeloRedireccionSeguimientoPortlet"; + + public static final String ROLE_ADMINISTRATOR = "Administrator"; + public static final String ROLE_PERMISO = "permiso_role"; + + public static final String MOSTRAR_REDIRECCION = "monstrarRedireccion"; + + public static final String URL_SEGUIMIENTO = "urlSeguimiento"; + public static final String URL_PERMANENCIA = "urlPermanenciaRedirect"; + + /* Campos Configuracion*/ + /* 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/modelo/redireccion/seguimiento/portlet/ModeloRedireccionSeguimientoPortlet.java b/src/main/java/modelo/redireccion/seguimiento/portlet/ModeloRedireccionSeguimientoPortlet.java new file mode 100644 index 0000000..dca279a --- /dev/null +++ b/src/main/java/modelo/redireccion/seguimiento/portlet/ModeloRedireccionSeguimientoPortlet.java @@ -0,0 +1,135 @@ +package modelo.redireccion.seguimiento.portlet; + +import static java.time.ZoneOffset.UTC; + +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 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 io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import modelo.redireccion.seguimiento.constants.ModeloRedireccionSeguimientoPortletKeys; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + + +/** + * @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=ModeloRedireccionSeguimiento", + "javax.portlet.init-param.template-path=/", + "javax.portlet.init-param.view-template=/view.jsp", + "javax.portlet.name=" + ModeloRedireccionSeguimientoPortletKeys.MODELOREDIRECCIONSEGUIMIENTO, + "javax.portlet.resource-bundle=content.Language", + "javax.portlet.security-role-ref=power-user,user" + }, + service = Portlet.class +) +public class ModeloRedireccionSeguimientoPortlet extends MVCPortlet { + + private static final Log _log = LogFactoryUtil.getLog(ModeloRedireccionSeguimientoPortlet.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(ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_REDIRECT, ""); + _log.info("[doView()] url Redireccion Seguimiento : " +urlRedireccion); + + String canal = prefs.getValue(ModeloRedireccionSeguimientoPortletKeys.FIELD_CANAL, ""); + _log.info("[doView()] c : " +canal); + + String urlPermanencia = prefs.getValue(ModeloRedireccionSeguimientoPortletKeys.FIELD_URL_PERMANENCIA, ""); + _log.info("[doView()] c : " +urlPermanencia); + + Map map = new HashMap<>(); + map.put("rut", rut); + map.put("canal", canal); + + String token = makeToken(rut,map); + + if( token!=null&&!token.isEmpty()) { + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.MOSTRAR_REDIRECCION, true); + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.URL_SEGUIMIENTO, urlRedireccion.concat(token)); + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.URL_PERMANENCIA, urlPermanencia); + }else { + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.MOSTRAR_REDIRECCION, false); + } + }else { + renderRequest.setAttribute( ModeloRedireccionSeguimientoPortletKeys.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/config.jsp b/src/main/resources/META-INF/resources/config.jsp new file mode 100644 index 0000000..6b1e846 --- /dev/null +++ b/src/main/resources/META-INF/resources/config.jsp @@ -0,0 +1,46 @@ +<%@ 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..ea5d1ad --- /dev/null +++ b/src/main/resources/META-INF/resources/css/main.scss @@ -0,0 +1,2 @@ +.modelo-redireccion-seguimiento { +} \ 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..7877443 --- /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..e22749c --- /dev/null +++ b/src/main/resources/META-INF/resources/view.jsp @@ -0,0 +1,33 @@ +<%@ 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..db18f94 --- /dev/null +++ b/src/main/resources/content/Language.properties @@ -0,0 +1,8 @@ +javax.portlet.title.modelo_redireccion_seguimiento_ModeloRedireccionSeguimientoPortlet=ModeloRedireccionSeguimiento +modeloredireccionseguimiento.caption=Hello from ModeloRedireccionSeguimiento! + + +modelo.redireccion.seguimiento.sin.permiso=No tiene Permisos para modificar esta Configuraci\uFFFDn. + +modelo.redireccion.seguimiento.cargando=Un momento, por favor... +modelo.redireccion.seguimiento.sin.redirecion=Sin redireccion \ No newline at end of file