Sfoglia il codice sorgente

Plugin autenticazione

Salvatore La Manna 4 anni fa
parent
commit
462a1e7446
  1. 27
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.classpath
  2. 37
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.project
  3. 12
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/.jsdtscope
  4. 7
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.jdt.core.prefs
  5. 8
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.common.component
  6. 7
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
  7. 11
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.common.project.facet.core.xml
  8. 1
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.jsdt.ui.superType.container
  9. 1
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.jsdt.ui.superType.name
  10. 6
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/build.xml
  11. 3
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/META-INF/MANIFEST.MF
  12. 1
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/.gitignore
  13. 16
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/liferay-hook.xml
  14. 11
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/liferay-plugin-package.properties
  15. 46
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/it/mwg/sicilia/constants/ApiConstants.java
  16. 113
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/it/mwg/sicilia/login/SiciliaAutoLogin.java
  17. 76
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/it/mwg/sicilia/login/SiciliaLoginFilter.java
  18. 126
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/it/mwg/sicilia/util/ApiUtil.java
  19. 2
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/portal.properties
  20. 5
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/web.xml
  21. 18
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/ivy.xml
  22. 1
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/ivy.xml.MD5
  23. 15
      liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/test/integration/arquillian.xml
  24. 4
      liferay-plugins-sdk-6.2/portlets/portos-fe-portlet/.settings/org.eclipse.wst.common.component
  25. 3
      liferay-plugins-sdk-6.2/portlets/portos-kaleo-controller-portlet/.settings/org.eclipse.wst.common.component
  26. 6
      liferay-plugins-sdk-6.2/portlets/portos-notification-portlet/.settings/org.eclipse.wst.common.component
  27. 3
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/.settings/org.eclipse.wst.common.component
  28. 11
      liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.classpath
  29. 7
      liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.settings/org.eclipse.jdt.core.prefs
  30. 14
      liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.settings/org.eclipse.wst.common.component
  31. 7
      liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
  32. 9
      liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.settings/org.eclipse.wst.common.project.facet.core.xml

27
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.classpath

@ -0,0 +1,27 @@
<?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/jdk1.7.0_79">
<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="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=sicilia-login-hook&amp;ivyXmlPath=ivy.xml&amp;confs=*&amp;ivySettingsPath=%24%7Bliferay_sdk_dir%3Asicilia-login-hook%7D%2Fivy-settings.xml&amp;loadSettingsOnDemand=false&amp;ivyUserDir=%24%7Bliferay_sdk_dir%3Asicilia-login-hook%7D%2F.ivy&amp;propertyFiles=">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="docroot/WEB-INF/classes"/>
</classpath>

37
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.project

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sicilia-login-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.apache.ivyde.eclipse.ivynature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

12
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/.jsdtscope

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="docroot"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

7
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.jdt.core.prefs

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

8
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.common.component

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="sicilia-login-hook">
<wb-resource deploy-path="/" source-path="/docroot" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/docroot/WEB-INF/src"/>
<property name="context-root" value="sicilia-login-hook"/>
<property name="java-output-path" value="/sicilia-login-hook/docroot/WEB-INF/classes"/>
</wb-module>
</project-modules>

7
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml

@ -0,0 +1,7 @@
<root>
<facet id="liferay.hook">
<node name="libprov">
<attribute name="provider-id" value="com.liferay.ide.eclipse.plugin.hook.libraryProvider"/>
</node>
</facet>
</root>

11
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.common.project.facet.core.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Liferay v6.2 CE (Tomcat 7)"/>
<fixed facet="jst.web"/>
<fixed facet="java"/>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="liferay.hook" version="6.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

1
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.jsdt.ui.superType.container

@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

1
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/.settings/org.eclipse.wst.jsdt.ui.superType.name

@ -0,0 +1 @@
Window

6
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/build.xml

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

3
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/META-INF/MANIFEST.MF

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

1
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/.gitignore vendored

@ -0,0 +1 @@
/classes/

16
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/liferay-hook.xml

@ -0,0 +1,16 @@
<?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>
<portal-properties>portal.properties</portal-properties>
<servlet-filter>
<servlet-filter-name>Sicilia SSO</servlet-filter-name>
<servlet-filter-impl>it.mwg.sicilia.login.SiciliaLoginFilter</servlet-filter-impl>
</servlet-filter>
<servlet-filter-mapping>
<servlet-filter-name>Sicilia SSO</servlet-filter-name>
<url-pattern>/c/portal/login</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</servlet-filter-mapping>
</hook>

11
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/liferay-plugin-package.properties

@ -0,0 +1,11 @@
name=Sicilia Login Hook
module-group-id=liferay
module-incremental-version=1
tags=
short-description=
long-description=
change-log=
page-url=http://www.liferay.com
author=Liferay, Inc.
licenses=LGPL
liferay-versions=6.2.0+

46
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/it/mwg/sicilia/constants/ApiConstants.java

@ -0,0 +1,46 @@
package it.mwg.sicilia.constants;
import java.util.HashMap;
import java.util.Map;
public class ApiConstants {
public static final String LABEL_ERROR_CODE = "code";
public static final String LABEL_DESCRIPTION = "description";
public static final String LABEL_STATUS = "status";
public static final int ERROR_OK = 0;
public static final int ERROR_INVALID_AUTH = 1;
public static final int ERROR_INVALID_LOGIN = 2;
public static final int ERROR_INVALID_TOKEN = 3;
public static final int ERROR_INVALID_INPUT = 4;
public static final int ERROR_MISSING_PARAMETER = 5;
public static final int ERROR_INVALID_PASSWORD = 6;
public static final String STATUS_OK = "success";
public static final String STATUS_ERROR = "error";
public static final String API_USERNAME = "sismica";
public static final String API_PASSWORD = "4Tr-D%fO!sli5";
public static final String PARAMETER_AUTH = "auth";
public static final String PARAMETER_CALLBACK_URL = "callback";
public static final String PARAMETER_TOKEN = "token";
public static final String PARAMETER_USERNAME = "username";
public static final String PARAMETER_PASSWORD = "password";
public static final String PARAMETER_FIRST_NAME = "nome";
public static final String PARAMETER_LAST_NAME = "cognome";
public static final String PARAMETER_CODICE_FISCALE = "codice_fiscale";
private static final String SESSION_BASE = "SICILIA_HOOK_";
public static final String SESSION_AUTH = SESSION_BASE + PARAMETER_AUTH.toUpperCase();
public static final String SESSION_TOKEN = SESSION_BASE + PARAMETER_TOKEN.toUpperCase();
public static final String SESSION_USER_DATA = SESSION_BASE + "USER_DATA";
public static final String LOGIN_SERVER = "https://auth.mwg.it/";
private static final String ENDPOINT_BASE = LOGIN_SERVER + "api/v1/";
public static final String ENDPOINT_LOGIN = ENDPOINT_BASE + "login.cgi";
public static final String ENDPOINT_GET_TOKEN = ENDPOINT_BASE + "get_token.cgi";
public static final String ENDPOINT_GET_USER = ENDPOINT_BASE + "get_user.cgi";
public static final String HTTP_USER_AGENT = "Sicilia Login like Mozilla/5.0";
}

113
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/it/mwg/sicilia/login/SiciliaAutoLogin.java

@ -0,0 +1,113 @@
package it.mwg.sicilia.login;
import it.mwg.sicilia.constants.ApiConstants;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.security.SecureRandom;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.User;
import com.liferay.portal.security.auth.AutoLogin;
import com.liferay.portal.security.auth.AutoLoginException;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
/**
* @author Manifattura Web Group per Regione Siciliana
*
*/
public class SiciliaAutoLogin implements AutoLogin {
private static final Log _log = LogFactoryUtil.getLog(SiciliaAutoLogin.class);
@Override
public String[] login(HttpServletRequest request, HttpServletResponse response) throws AutoLoginException {
User user = null;
HttpSession session = request.getSession();
Map<String, String> userData = (Map<String, String>) session
.getAttribute(ApiConstants.SESSION_USER_DATA);
if (Validator.isNotNull(userData)) {
long companyId = PortalUtil.getCompanyId(request);
user = logUser(companyId, userData.get(ApiConstants.PARAMETER_CODICE_FISCALE),
userData.get(ApiConstants.PARAMETER_FIRST_NAME),
userData.get(ApiConstants.PARAMETER_LAST_NAME));
if (Validator.isNotNull(user)) {
return new String[] { String.valueOf(user.getUserId()), user.getPassword(),
String.valueOf(user.isPasswordEncrypted()) };
}
}
return null;
}
@Override
public String[] handleException(HttpServletRequest request, HttpServletResponse response, Exception e)
throws AutoLoginException {
_log.error(e);
return null;
}
private User logUser(long companyId, String screenName, String firstName, String lastName) {
_log.info("Cerco l'utente " + screenName + " (" + firstName + " " + lastName + ")");
User user = null;
try {
user = UserLocalServiceUtil.fetchUserByScreenName(companyId, screenName);
if (Validator.isNull(user)) {
long creatorUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
boolean autoPassword = true;
String password = randomPassword(24);
boolean autoScreenName = false;
String emailAddress = screenName + "@no-email.regione.sicilia.it";
long facebookId = 0;
String openId = StringPool.BLANK;
Locale locale = Locale.ITALY;
String middleName = StringPool.BLANK;
int prefixId = 0;
int suffixId = 0;
boolean male = true;
int birthdayMonth = 0;
int birthdayDay = 1;
int birthdayYear = 1970;
String jobTitle = StringPool.BLANK;
long[] groupIds = null;
long[] organizationIds = null;
long[] roleIds = null;
long[] userGroupIds = null;
boolean sendEmail = false;
ServiceContext serviceContext = new ServiceContext();
user = UserLocalServiceUtil.addUser(creatorUserId, companyId, autoPassword, password,
password, autoScreenName, screenName, emailAddress, facebookId, openId, locale,
firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth,
birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds,
userGroupIds, sendEmail, serviceContext);
user.setPasswordModified(true);
user.setPasswordModifiedDate(new Date());
user.setPasswordReset(false);
UserLocalServiceUtil.updateUser(user);
}
} catch (SystemException | PortalException e) {
_log.error("Errore durante l'autenticazione/creazione dell'utente " + screenName, e);
}
return user;
}
private String randomPassword(int length) {
SecureRandom rnd = new SecureRandom();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
sb.append((char) (32 + rnd.nextInt(95)));
}
return sb.toString();
}
}

76
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/it/mwg/sicilia/login/SiciliaLoginFilter.java

@ -0,0 +1,76 @@
package it.mwg.sicilia.login;
import it.mwg.sicilia.constants.ApiConstants;
import it.mwg.sicilia.util.ApiUtil;
import java.io.IOException;
import java.util.Locale;
import java.util.Map;
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;
import javax.servlet.http.HttpSession;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
public class SiciliaLoginFilter implements Filter {
public static final Log _log = LogFactoryUtil.getLog(SiciliaLoginFilter.class);
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
String url = httpServletRequest.getRequestURL().toString();
String qs = httpServletRequest.getQueryString();
if (Validator.isNotNull(qs)) {
url += "?" + qs;
}
_log.info("Filtro: " + url);
HttpSession session = httpServletRequest.getSession();
String token = (String) session.getAttribute(ApiConstants.SESSION_TOKEN);
if (Validator.isNull(token)) {
token = ApiUtil.getToken(url);
_log.info("Ho creato il token " + token + ". Eseguo redirect");
session.setAttribute(ApiConstants.SESSION_TOKEN, token);
((HttpServletResponse) servletResponse).sendRedirect(ApiConstants.LOGIN_SERVER + "?t=" + token);
return;
} else {
Map<String, String> userData = ApiUtil.getUserInfo(token);
if (Validator.isNull(userData)) {
_log.info("Il token potrebbe essere scaduto. Lo ricreo ed eseguo redirect.");
token = ApiUtil.getToken(url);
session.setAttribute(ApiConstants.SESSION_TOKEN, token);
((HttpServletResponse) servletResponse).sendRedirect(ApiConstants.LOGIN_SERVER + "?t="
+ token);
return;
} else {
session.setAttribute(ApiConstants.SESSION_USER_DATA, userData);
}
}
chain.doFilter(servletRequest, servletResponse);
}
@Override
public void init(FilterConfig config) throws ServletException {
}
}

126
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/it/mwg/sicilia/util/ApiUtil.java

@ -0,0 +1,126 @@
package it.mwg.sicilia.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import it.mwg.sicilia.constants.ApiConstants;
import com.liferay.portal.kernel.json.JSONException;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Validator;
public class ApiUtil {
private static final Log _log = LogFactoryUtil.getLog(ApiUtil.class);
private static String auth = null;
public static String getToken(String callbackURL) {
if (Validator.isNull(auth)) {
login();
}
for (int i = 0; i < 10; i++) {
if (Validator.isNotNull(auth)) {
JSONObject map = JSONFactoryUtil.createJSONObject();
map.put(ApiConstants.PARAMETER_AUTH, auth).put(ApiConstants.PARAMETER_CALLBACK_URL,
callbackURL);
map = post(ApiConstants.ENDPOINT_GET_TOKEN, map);
if (Validator.isNotNull(map)) {
switch (map.getInt(ApiConstants.LABEL_ERROR_CODE)) {
case ApiConstants.ERROR_OK:
return map.getString(ApiConstants.PARAMETER_TOKEN);
case ApiConstants.ERROR_INVALID_AUTH:
_log.info("Auth scaduto. Eseguo nuovo login");
login();
break;
default:
_log.error("Errore durante la creazione del token: " + map.toString());
return null;
}
} else {
_log.error("Errore inatteso durante la creazione del token");
}
}
}
return null;
}
public static Map<String, String> getUserInfo(String token) {
_log.info("Recupero informazioni sull'utente con il token " + token + ", auth " + auth);
JSONObject map = JSONFactoryUtil.createJSONObject();
map.put(ApiConstants.PARAMETER_AUTH, auth).put(ApiConstants.PARAMETER_TOKEN, token);
map = post(ApiConstants.ENDPOINT_GET_USER, map);
if (Validator.isNotNull(map)) {
switch (map.getInt(ApiConstants.LABEL_ERROR_CODE)) {
case ApiConstants.ERROR_OK:
_log.info("Ho i dati dell'utente");
Map<String, String> ret = new HashMap<String, String>();
ret.put(ApiConstants.PARAMETER_FIRST_NAME, map.getString(ApiConstants.PARAMETER_FIRST_NAME));
ret.put(ApiConstants.PARAMETER_LAST_NAME, map.getString(ApiConstants.PARAMETER_LAST_NAME));
ret.put(ApiConstants.PARAMETER_CODICE_FISCALE,
map.getString(ApiConstants.PARAMETER_CODICE_FISCALE));
return ret;
default:
_log.error("Errore durante il recupero dei dati utente: " + map.toString());
}
}
return null;
}
private static void login() {
JSONObject map = JSONFactoryUtil.createJSONObject();
map.put(ApiConstants.PARAMETER_USERNAME, ApiConstants.API_USERNAME).put(
ApiConstants.PARAMETER_PASSWORD, ApiConstants.API_PASSWORD);
map = post(ApiConstants.ENDPOINT_LOGIN, map);
if (Validator.isNotNull(map)) {
if (ApiConstants.ERROR_OK == map.getInt(ApiConstants.LABEL_ERROR_CODE)) {
auth = map.getString(ApiConstants.PARAMETER_AUTH);
} else {
_log.error("Errore durante il login: " + map.toString());
}
}
}
private static JSONObject post(String endPoint, JSONObject json) {
try {
URL url = new URL(endPoint);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", ApiConstants.HTTP_USER_AGENT);
connection.setDoOutput(true);
OutputStream stream = connection.getOutputStream();
_log.info("Invio: " + json.toString() + " (" + endPoint + ")");
stream.write(json.toString().getBytes());
stream.flush();
stream.close();
int code = connection.getResponseCode();
if (code == HttpURLConnection.HTTP_OK) {
String response = readResponse(connection);
_log.info("Ricevo: " + response);
JSONObject ret = JSONFactoryUtil.createJSONObject(response);
return ret;
}
} catch (IOException | JSONException e) {
_log.error(e);
}
return null;
}
private static String readResponse(HttpURLConnection connection) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder builder = new StringBuilder();
String inputLine;
while ((inputLine = reader.readLine()) != null) {
builder.append(inputLine);
}
reader.close();
return builder.toString();
}
}

2
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/src/portal.properties

@ -0,0 +1,2 @@
#auth.pipeline.enable.liferay.check=false
auto.login.hooks=it.mwg.sicilia.login.SiciliaAutoLogin

5
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/docroot/WEB-INF/web.xml

@ -0,0 +1,5 @@
<?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>

18
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/ivy.xml

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<ivy-module
version="2.0"
xmlns:m2="http://ant.apache.org/ivy/maven"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
>
<info module="sicilia-login-hook" organisation="com.liferay">
<extends extendType="configurations,description,info" location="../../ivy.xml" module="com.liferay.sdk" organisation="com.liferay" revision="latest.integration" />
</info>
<dependencies defaultconf="default">
<dependency conf="test->default" name="arquillian-junit-container" org="org.jboss.arquillian.junit" rev="1.1.6.Final" />
<dependency conf="test->default" name="arquillian-tomcat-remote-7" org="org.jboss.arquillian.container" rev="1.0.0.CR6" />
<dependency conf="test->default" name="com.liferay.ant.arquillian" org="com.liferay" rev="1.0.0-SNAPSHOT" />
</dependencies>
</ivy-module>

1
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/ivy.xml.MD5

@ -0,0 +1 @@
f1563bf5bac3cf93500d1510b72dd9da

15
liferay-plugins-sdk-6.2/hooks/sicilia-login-hook/test/integration/arquillian.xml

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<arquillian
xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"
>
<container default="true" qualifier="tomcat">
<configuration>
<property name="jmxPort">8099</property>
<property name="pass">tomcat</property>
<property name="user">tomcat</property>
</configuration>
</container>
</arquillian>

4
liferay-plugins-sdk-6.2/portlets/portos-fe-portlet/.settings/org.eclipse.wst.common.component

@ -2,10 +2,10 @@
<wb-module deploy-name="portos-fe-portlet"> <wb-module deploy-name="portos-fe-portlet">
<wb-resource deploy-path="/" source-path="/docroot" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/docroot" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/docroot/WEB-INF/src"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/docroot/WEB-INF/src"/>
<dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar"> <dependent-module archiveName="hms-taglib-hook-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/hms-taglib-hook/docroot/WEB-INF/lib/hms-taglib-hook-service.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="hms-taglib-hook-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/hms-taglib-hook/docroot/WEB-INF/lib/hms-taglib-hook-service.jar"> <dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<property name="context-root" value="portos-fe-portlet"/> <property name="context-root" value="portos-fe-portlet"/>

3
liferay-plugins-sdk-6.2/portlets/portos-kaleo-controller-portlet/.settings/org.eclipse.wst.common.component

@ -5,6 +5,9 @@
<dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar"> <dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="portos-kaleo-controller-portlet"/> <property name="context-root" value="portos-kaleo-controller-portlet"/>
<property name="java-output-path" value="/portos-kaleo-controller-portlet/docroot/WEB-INF/classes"/> <property name="java-output-path" value="/portos-kaleo-controller-portlet/docroot/WEB-INF/classes"/>
</wb-module> </wb-module>

6
liferay-plugins-sdk-6.2/portlets/portos-notification-portlet/.settings/org.eclipse.wst.common.component

@ -8,6 +8,12 @@
<dependent-module archiveName="portos-kaleo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-kaleo-portlet/docroot/WEB-INF/lib/portos-kaleo-portlet-service.jar"> <dependent-module archiveName="portos-kaleo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-kaleo-portlet/docroot/WEB-INF/lib/portos-kaleo-portlet-service.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="portos-kaleo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-kaleo-portlet/docroot/WEB-INF/lib/portos-kaleo-portlet-service.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="portos-notification-portlet"/> <property name="context-root" value="portos-notification-portlet"/>
<property name="java-output-path" value="/portos-notification-portlet/docroot/WEB-INF/classes"/> <property name="java-output-path" value="/portos-notification-portlet/docroot/WEB-INF/classes"/>
</wb-module> </wb-module>

3
liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/.settings/org.eclipse.wst.common.component

@ -5,6 +5,9 @@
<dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar"> <dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="portos-report-engine-portlet"/> <property name="context-root" value="portos-report-engine-portlet"/>
<property name="java-output-path" value="/portos-report-engine-portlet/docroot/WEB-INF/classes"/> <property name="java-output-path" value="/portos-report-engine-portlet/docroot/WEB-INF/classes"/>
</wb-module> </wb-module>

11
liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.classpath

@ -6,16 +6,17 @@
<attribute name="owner.project.facets" value="java"/> <attribute name="owner.project.facets" value="java"/>
</attributes> </attributes>
</classpathentry> </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.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="com.liferay.ide.eclipse.server.plugin.container/web"> <classpathentry kind="con" path="com.liferay.ide.eclipse.server.plugin.container/web">
<attributes> <attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </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="output" path="docroot/WEB-INF/classes"/> <classpathentry kind="output" path="docroot/WEB-INF/classes"/>
</classpath> </classpath>

7
liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.settings/org.eclipse.jdt.core.prefs

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

14
liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.settings/org.eclipse.wst.common.component

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="portos-kaleo-web">
<wb-resource deploy-path="/" source-path="/docroot" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/docroot/WEB-INF/src"/>
<dependent-module archiveName="portos-kaleo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-kaleo-portlet/docroot/WEB-INF/lib/portos-kaleo-portlet-service.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="portos-bo-portlet-service.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/portos-bo-portlet/docroot/WEB-INF/lib/portos-bo-portlet-service.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="portos-kaleo-web"/>
<property name="java-output-path" value="/portos-kaleo-web/docroot/WEB-INF/classes"/>
</wb-module>
</project-modules>

7
liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml

@ -0,0 +1,7 @@
<root>
<facet id="liferay.web">
<node name="libprov">
<attribute name="provider-id" value="com.liferay.ide.eclipse.plugin.web.libraryProvider"/>
</node>
</facet>
</root>

9
liferay-plugins-sdk-6.2/webs/portos-kaleo-web/.settings/org.eclipse.wst.common.project.facet.core.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Liferay v6.2 CE (Tomcat 7)"/>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.6"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="liferay.web" version="6.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
Caricamento…
Annulla
Salva