Sfoglia il codice sorgente

Merge branch 'p-2marzo' into mappe-2marzo

master 21.07
Salvatore La Manna 4 anni fa
parent
commit
e0d9053209
  1. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-codec.jar
  2. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-collections4.jar
  3. 0
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-logging.jar
  4. 0
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/log4j.jar
  5. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/poi.jar
  6. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-asm.jar
  7. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-beans.jar
  8. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-context.jar
  9. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-core.jar
  10. 0
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/util-bridges.jar
  11. 0
      liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/util-taglib.jar
  12. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-collections.jar
  13. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-io.jar
  14. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-lang.jar
  15. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/javassist.jar
  16. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-api.jar
  17. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-impl.jar
  18. BIN
      liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/velocity.jar
  19. 572
      liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/tld/c.tld
  20. 5
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/AccessToken.java
  21. 51
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java
  22. 30
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/CommandList.java
  23. 9
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetApplications.java
  24. 54
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetSourceCode.java
  25. 17
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Login.java
  26. 114
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Manual.java
  27. 61
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ManualHtml.java
  28. 62
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/VerifyApplication.java
  29. 17
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/ApiUtil.java
  30. 1
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/startup/Startup.java
  31. 3
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/README.txt
  32. 29
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/functions.php
  33. 38
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Client.php
  34. 18
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Config.php
  35. 3
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/FileConfig.php
  36. 5
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/config/api.json
  37. 33
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/client.php

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-codec.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-collections4.jar

File binario non mostrato.

0
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-logging.jar → liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-logging.jar

0
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/log4j.jar → liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/log4j.jar

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/poi.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-asm.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-beans.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-context.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-core.jar

File binario non mostrato.

0
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/util-bridges.jar → liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/util-bridges.jar

0
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/util-taglib.jar → liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/util-taglib.jar

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-collections.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-io.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-lang.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/javassist.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-api.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-impl.jar

File binario non mostrato.

BIN
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/velocity.jar

File binario non mostrato.

572
liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/tld/c.tld

@ -1,572 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<taglib 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-jsptaglibrary_2_1.xsd"
version="2.1">
<description>JSTL 1.2 core library</description>
<display-name>JSTL core</display-name>
<tlib-version>1.2</tlib-version>
<short-name>c</short-name>
<uri>http://java.sun.com/jsp/jstl/core</uri>
<validator>
<description>
Provides core validation features for JSTL tags.
</description>
<validator-class>
org.apache.taglibs.standard.tlv.JstlCoreTLV
</validator-class>
</validator>
<tag>
<description>
Catches any Throwable that occurs in its body and optionally
exposes it.
</description>
<name>catch</name>
<tag-class>org.apache.taglibs.standard.tag.common.core.CatchTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
Name of the exported scoped variable for the
exception thrown from a nested action. The type of the
scoped variable is the type of the exception thrown.
</description>
<name>var</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Simple conditional tag that establishes a context for
mutually exclusive conditional operations, marked by
&lt;when&gt; and &lt;otherwise&gt;
</description>
<name>choose</name>
<tag-class>com.liferay.taglib.core.ChooseTag</tag-class>
<body-content>JSP</body-content>
</tag>
<tag>
<description>
Simple conditional tag, which evalutes its body if the
supplied condition is true and optionally exposes a Boolean
scripting variable representing the evaluation of this condition
</description>
<name>if</name>
<tag-class>com.liferay.taglib.core.IfTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
The test condition that determines whether or
not the body content should be processed.
</description>
<name>test</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>boolean</type>
</attribute>
<attribute>
<description>
Name of the exported scoped variable for the
resulting value of the test condition. The type
of the scoped variable is Boolean.
</description>
<name>var</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Scope for var.
</description>
<name>scope</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Retrieves an absolute or relative URL and exposes its contents
to either the page, a String in 'var', or a Reader in 'varReader'.
</description>
<name>import</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.ImportTag</tag-class>
<tei-class>org.apache.taglibs.standard.tei.ImportTEI</tei-class>
<body-content>JSP</body-content>
<attribute>
<description>
The URL of the resource to import.
</description>
<name>url</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Name of the exported scoped variable for the
resource's content. The type of the scoped
variable is String.
</description>
<name>var</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Scope for var.
</description>
<name>scope</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Name of the exported scoped variable for the
resource's content. The type of the scoped
variable is Reader.
</description>
<name>varReader</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Name of the context when accessing a relative
URL resource that belongs to a foreign
context.
</description>
<name>context</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Character encoding of the content at the input
resource.
</description>
<name>charEncoding</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
The basic iteration tag, accepting many different
collection types and supporting subsetting and other
functionality
</description>
<name>forEach</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.ForEachTag</tag-class>
<tei-class>org.apache.taglibs.standard.tei.ForEachTEI</tei-class>
<body-content>JSP</body-content>
<attribute>
<description>
Collection of items to iterate over.
</description>
<name>items</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
<deferred-value>
<type>java.lang.Object</type>
</deferred-value>
</attribute>
<attribute>
<description>
If items specified:
Iteration begins at the item located at the
specified index. First item of the collection has
index 0.
If items not specified:
Iteration begins with index set at the value
specified.
</description>
<name>begin</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<description>
If items specified:
Iteration ends at the item located at the
specified index (inclusive).
If items not specified:
Iteration ends when index reaches the value
specified.
</description>
<name>end</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<description>
Iteration will only process every step items of
the collection, starting with the first one.
</description>
<name>step</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<description>
Name of the exported scoped variable for the
current item of the iteration. This scoped
variable has nested visibility. Its type depends
on the object of the underlying collection.
</description>
<name>var</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Name of the exported scoped variable for the
status of the iteration. Object exported is of type
javax.servlet.jsp.jstl.core.LoopTagStatus. This scoped variable has nested
visibility.
</description>
<name>varStatus</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Iterates over tokens, separated by the supplied delimeters
</description>
<name>forTokens</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.ForTokensTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
String of tokens to iterate over.
</description>
<name>items</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<description>
The set of delimiters (the characters that
separate the tokens in the string).
</description>
<name>delims</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
Iteration begins at the token located at the
specified index. First token has index 0.
</description>
<name>begin</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<description>
Iteration ends at the token located at the
specified index (inclusive).
</description>
<name>end</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<description>
Iteration will only process every step tokens
of the string, starting with the first one.
</description>
<name>step</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<description>
Name of the exported scoped variable for the
current item of the iteration. This scoped
variable has nested visibility.
</description>
<name>var</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Name of the exported scoped variable for the
status of the iteration. Object exported is of
type
javax.servlet.jsp.jstl.core.LoopTag
Status. This scoped variable has nested
visibility.
</description>
<name>varStatus</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Like &lt;%= ... &gt;, but for expressions.
</description>
<name>out</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.OutTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
Expression to be evaluated.
</description>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Default value if the resulting value is null.
</description>
<name>default</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Determines whether characters &lt;,&gt;,&amp;,'," in the
resulting string should be converted to their
corresponding character entity codes. Default value is
true.
</description>
<name>escapeXml</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Subtag of &lt;choose&gt; that follows &lt;when&gt; tags
and runs only if all of the prior conditions evaluated to
'false'
</description>
<name>otherwise</name>
<tag-class>com.liferay.taglib.core.OtherwiseTag</tag-class>
<body-content>JSP</body-content>
</tag>
<tag>
<description>
Adds a parameter to a containing 'import' tag's URL.
</description>
<name>param</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.ParamTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
Name of the query string parameter.
</description>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Value of the parameter.
</description>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Redirects to a new URL.
</description>
<name>redirect</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.RedirectTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
The URL of the resource to redirect to.
</description>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Name of the context when redirecting to a relative URL
resource that belongs to a foreign context.
</description>
<name>context</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Removes a scoped variable (from a particular scope, if specified).
</description>
<name>remove</name>
<tag-class>org.apache.taglibs.standard.tag.common.core.RemoveTag</tag-class>
<body-content>empty</body-content>
<attribute>
<description>
Name of the scoped variable to be removed.
</description>
<name>var</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Scope for var.
</description>
<name>scope</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Sets the result of an expression evaluation in a 'scope'
</description>
<name>set</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.SetTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
Name of the exported scoped variable to hold the value
specified in the action. The type of the scoped variable is
whatever type the value expression evaluates to.
</description>
<name>var</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Expression to be evaluated.
</description>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<deferred-value>
<type>java.lang.Object</type>
</deferred-value>
</attribute>
<attribute>
<description>
Target object whose property will be set. Must evaluate to
a JavaBeans object with setter property property, or to a
java.util.Map object.
</description>
<name>target</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Name of the property to be set in the target object.
</description>
<name>property</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Scope for var.
</description>
<name>scope</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Creates a URL with optional query parameters.
</description>
<name>url</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.UrlTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
Name of the exported scoped variable for the
processed url. The type of the scoped variable is
String.
</description>
<name>var</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
Scope for var.
</description>
<name>scope</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description>
URL to be processed.
</description>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Name of the context when specifying a relative URL
resource that belongs to a foreign context.
</description>
<name>context</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Subtag of &lt;choose&gt; that includes its body if its
condition evalutes to 'true'
</description>
<name>when</name>
<tag-class>com.liferay.taglib.core.WhenTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
The test condition that determines whether or not the
body content should be processed.
</description>
<name>test</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>boolean</type>
</attribute>
</tag>
</taglib>

5
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/AccessToken.java

@ -52,11 +52,10 @@ public class AccessToken {
token = Base64.encode(cipher.doFinal(payload.toString().getBytes()), 0); token = Base64.encode(cipher.doFinal(payload.toString().getBytes()), 0);
} }
public AccessToken(String token) throws Exception { public AccessToken(long companyId, String token) throws Exception {
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); KeyFactory keyFactory = KeyFactory.getInstance("RSA");
// TODO companyId String key = ApiSettingLocalServiceUtil.get(companyId, ApiConstants.API_PUBLIC_KEY);
String key = ApiSettingLocalServiceUtil.get(20155, ApiConstants.API_PUBLIC_KEY);
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(Base64.decode(key)); X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(Base64.decode(key));
PublicKey publicKey = keyFactory.generatePublic(pubKeySpec); PublicKey publicKey = keyFactory.generatePublic(pubKeySpec);
Cipher cipher = Cipher.getInstance("RSA"); Cipher cipher = Cipher.getInstance("RSA");

51
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java

@ -15,10 +15,11 @@ import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil;
import it.tref.liferay.portos.bo.service.TerritorioLocalServiceUtil; import it.tref.liferay.portos.bo.service.TerritorioLocalServiceUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable; import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -26,6 +27,8 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSONDeserializer; import com.liferay.portal.kernel.json.JSONDeserializer;
@ -35,7 +38,10 @@ import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.HttpMethods; import com.liferay.portal.kernel.servlet.HttpMethods;
import com.liferay.portal.kernel.util.ContentTypes; import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portal.kernel.util.MapUtil; import com.liferay.portal.kernel.util.MapUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.Company;
import com.liferay.portal.util.PortalUtil;
public abstract class Command { public abstract class Command {
@ -52,19 +58,21 @@ public abstract class Command {
protected Map<String, Serializable> parameters = null; protected Map<String, Serializable> parameters = null;
protected Sportello sportello = null; protected Sportello sportello = null;
private String verb; private final String verb;
private List<String> methods; private final List<String> methods;
private String description; private final String description;
private AccessToken accessToken; private AccessToken accessToken;
private long companyId = 0L;
private static final String[] defaultMethods = { HttpMethods.POST }; private static final List<String> DEFAULT_METHODS = Arrays.asList(HttpMethods.GET, HttpMethods.POST);
private static final JSONDeserializer<Map<String, Serializable>> deserializer = JSONFactoryUtil private static final JSONDeserializer<Map<String, Serializable>> deserializer = JSONFactoryUtil
.createJSONDeserializer(); .createJSONDeserializer();
private static final List<String> BLACKLIST = Arrays.asList("password", "token", "username");
public Command(String description, String... methods) { public Command(String description, String... methods) {
this.verb = getCommandVerb(); this.verb = getCommandVerb();
this.methods = Arrays.asList(methods.length > 0 ? methods : defaultMethods); this.methods = methods.length > 0 ? Arrays.asList(methods) : DEFAULT_METHODS;
this.description = description; this.description = description;
} }
@ -93,10 +101,22 @@ public abstract class Command {
protected Map<String, Serializable> readParameters(HttpServletRequest request) throws IOException { protected Map<String, Serializable> readParameters(HttpServletRequest request) throws IOException {
parameters = new HashMap<>(); parameters = new HashMap<>();
String input = StringPool.BLANK;
if (request.getMethod().equals(HttpMethods.POST)) { if (request.getMethod().equals(HttpMethods.POST)) {
input = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
}
Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
if (!BLACKLIST.contains(name)) {
parameters.put(name, request.getParameter(name));
}
}
if (request.getMethod().equals(HttpMethods.POST) && !input.isEmpty()) {
try { try {
parameters = deserializer.deserialize(new InputStreamReader(request.getInputStream())); parameters.putAll(deserializer.deserialize(input));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
} }
} }
String token = request.getHeader(Parameters.X_AUTH_TOKEN); String token = request.getHeader(Parameters.X_AUTH_TOKEN);
@ -135,7 +155,7 @@ public abstract class Command {
} else { } else {
try { try {
try { try {
accessToken = new AccessToken(token); accessToken = new AccessToken(getCompanyId(request), token);
sportello = SportelloLocalServiceUtil.getSportello(accessToken.getSportelloId()); sportello = SportelloLocalServiceUtil.getSportello(accessToken.getSportelloId());
} catch (InvalidTokenException e) { } catch (InvalidTokenException e) {
Response.write(response, Status.INVALID_TOKEN); Response.write(response, Status.INVALID_TOKEN);
@ -153,6 +173,19 @@ public abstract class Command {
return false; return false;
} }
protected long getCompanyId(HttpServletRequest request) throws PortalException, SystemException {
if (0 == companyId) {
Company company = PortalUtil.getCompany(request);
if (Validator.isNull(company)) {
companyId = PortalUtil.getDefaultCompanyId();
} else {
companyId = company.getCompanyId();
}
}
return companyId;
}
protected Sportello getSportello() { protected Sportello getSportello() {
if (null == sportello) { if (null == sportello) {
@ -196,7 +229,7 @@ public abstract class Command {
} }
} catch (PortalException | SystemException e) { } catch (PortalException | SystemException e) {
additionalInfo.add("Errore del server durante il caricamento dell'istanza"); additionalInfo.add("Errore del server durante il caricamento dell'istanza");
Response.write(response, Status.INVALID_INPUT, additionalInfo); Response.write(response, Status.SERVER_ERROR, additionalInfo);
return null; return null;
} }
return intPratica; return intPratica;

30
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/CommandList.java

@ -11,11 +11,11 @@ import it.mwg.sicilia.sue.api.v1.command.impl.ListAttachments;
import it.mwg.sicilia.sue.api.v1.command.impl.ListFields; import it.mwg.sicilia.sue.api.v1.command.impl.ListFields;
import it.mwg.sicilia.sue.api.v1.command.impl.ListValues; import it.mwg.sicilia.sue.api.v1.command.impl.ListValues;
import it.mwg.sicilia.sue.api.v1.command.impl.Login; import it.mwg.sicilia.sue.api.v1.command.impl.Login;
import it.mwg.sicilia.sue.api.v1.command.impl.Manual;
import it.mwg.sicilia.sue.api.v1.command.impl.ManualHtml; import it.mwg.sicilia.sue.api.v1.command.impl.ManualHtml;
import it.mwg.sicilia.sue.api.v1.command.impl.Nop; import it.mwg.sicilia.sue.api.v1.command.impl.Nop;
import it.mwg.sicilia.sue.api.v1.command.impl.SetFields; import it.mwg.sicilia.sue.api.v1.command.impl.SetFields;
import it.mwg.sicilia.sue.api.v1.command.impl.UploadAttachment; import it.mwg.sicilia.sue.api.v1.command.impl.UploadAttachment;
import it.mwg.sicilia.sue.api.v1.command.impl.VerifyApplication;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -33,37 +33,31 @@ public class CommandList {
private static final Set<String> verbs = new TreeSet<>(); private static final Set<String> verbs = new TreeSet<>();
static { static {
// Manuali // Manuali
addCommand(new Manual("Restituisce la documentazione dell'API generata automaticamente", HttpMethods.GET, addCommand(new ManualHtml("Restituisce la documentazione dell'API generata automaticamente in versione HTML"));
HttpMethods.POST));
addCommand(new ManualHtml("Restituisce la documentazione dell'API generata automaticamente in versione HTML",
HttpMethods.GET, HttpMethods.POST));
// Login // Login
addCommand(new Login("Esegue l'accesso con nome email e password e restituisce un token di accesso")); addCommand(new Login("Esegue l'accesso con nome email e password e restituisce un token di accesso",
// Elenchi
addCommand(new ListApplications("Elenco delle istanze presentabili sul portale", HttpMethods.GET,
HttpMethods.POST));
addCommand(new ListAttachments("Elenco dei documenti riconosciuti dal portale", HttpMethods.GET,
HttpMethods.POST));
addCommand(new ListFields("Elenco dei dati dell'istanza accettati dal portale", HttpMethods.GET,
HttpMethods.POST)); HttpMethods.POST));
// Elenchi
addCommand(new ListApplications("Elenco delle istanze presentabili sul portale"));
addCommand(new ListAttachments("Elenco dei documenti riconosciuti dal portale"));
addCommand(new ListFields("Elenco dei dati dell'istanza accettati dal portale"));
addCommand(new ListValues("Elenca i valori ammissibili per un campo a selezione obbligata")); addCommand(new ListValues("Elenca i valori ammissibili per un campo a selezione obbligata"));
// Istanze // Istanze
addCommand(new AddApplication( addCommand(new AddApplication(
"Crea una nuova istanza di endoprocedimento, crea l'utente se non esiste ancora sul portale")); "Crea una nuova istanza di endoprocedimento, crea l'utente se non esiste ancora sul portale"));
addCommand(new GetApplications("Elenca le istanze in lavorazione da questo SUE", HttpMethods.GET, addCommand(new GetApplications("Elenca le istanze in lavorazione da questo SUE"));
HttpMethods.POST));
addCommand(new DeleteApplication("Elimina un'istanza")); addCommand(new DeleteApplication("Elimina un'istanza"));
addCommand(new VerifyApplication("Verifica la completezza dell'istanza"));
addCommand(new SetFields( addCommand(new SetFields(
"Imposta i valori dei dati dell'istanza, l'elenco dei campi valorizzabili è fornito dal comando " "Imposta i valori dei dati dell'istanza, l'elenco dei campi valorizzabili è fornito dal comando "
+ Command.getCommandVerb(ListFields.class))); + Command.getCommandVerb(ListFields.class)));
// Allegati // Allegati
addCommand(new UploadAttachment("Allega un documento all'istanza")); addCommand(new UploadAttachment("Allega un documento all'istanza", HttpMethods.POST));
addCommand(new GetAttachments("Elenca gli allegati dell'istanza")); addCommand(new GetAttachments("Elenca gli allegati dell'istanza"));
addCommand(new DeleteAttachment("Elimina un allegato")); addCommand(new DeleteAttachment("Elimina un allegato"));
// Altro // Altro
addCommand(new Nop("NOP verifica la connettività senza eseguire operazioni", HttpMethods.GET, HttpMethods.POST)); addCommand(new Nop("NOP verifica la connettività senza eseguire operazioni"));
addCommand(new GetSourceCode("Scarica il codice sorgente generato per il client", HttpMethods.GET, addCommand(new GetSourceCode("Scarica il codice sorgente generato per il client"));
HttpMethods.POST));
} }
private static void addCommand(Command command) { private static void addCommand(Command command) {

9
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetApplications.java

@ -25,6 +25,13 @@ import com.liferay.portal.kernel.dao.orm.QueryUtil;
public class GetApplications extends Command { public class GetApplications extends Command {
@SuppressWarnings("serial")
private static final List<Parameter> INPUT_PARAMETERS = new ArrayList<Parameter>() {
{
add(new Parameter(Parameters.CODE, TYPES.STRING, "Codice del tipo di istanza", false));
}
};
private static final List<Parameter> OUTPUT_PARAMETERS = new ArrayList<>(); private static final List<Parameter> OUTPUT_PARAMETERS = new ArrayList<>();
static { static {
OUTPUT_PARAMETERS.addAll(BASE_OUTPUT_PARAMETERS); OUTPUT_PARAMETERS.addAll(BASE_OUTPUT_PARAMETERS);
@ -62,7 +69,7 @@ public class GetApplications extends Command {
@Override @Override
public List<Parameter> getInputParameters() { public List<Parameter> getInputParameters() {
return EMPTY_PARAMETERS; return INPUT_PARAMETERS;
} }
@Override @Override

54
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetSourceCode.java

@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import com.liferay.portal.kernel.servlet.HttpHeaders; import com.liferay.portal.kernel.servlet.HttpHeaders;
import com.liferay.portal.kernel.servlet.HttpMethods;
import com.liferay.portal.kernel.servlet.ServletResponseUtil; import com.liferay.portal.kernel.servlet.ServletResponseUtil;
import com.liferay.portal.kernel.util.ContentTypes; import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.StringPool;
@ -68,7 +69,7 @@ public class GetSourceCode extends Command {
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { public void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
ServletContext servletContext = request.getServletContext(); ServletContext servletContext = request.getServletContext();
String regex = "(\\s*)\\/\\/\\{\\{([^}]*)\\}\\}\\/\\/(.*)"; String regex = "(\\s*)(.*?)\\/\\/\\{\\{([^}]*)\\}\\}\\/\\/(.*)";
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);
File sourcePath = new File(servletContext.getRealPath("/WEB-INF/src/resource/client/php")); File sourcePath = new File(servletContext.getRealPath("/WEB-INF/src/resource/client/php"));
URI sourceUri = sourcePath.toURI(); URI sourceUri = sourcePath.toURI();
@ -79,27 +80,30 @@ public class GetSourceCode extends Command {
for (String line = reader.readLine(); null != line; line = reader.readLine()) { for (String line = reader.readLine(); null != line; line = reader.readLine()) {
Matcher matcher = pattern.matcher(line); Matcher matcher = pattern.matcher(line);
if (matcher.matches()) { if (matcher.matches()) {
switch (matcher.group(2)) { switch (matcher.group(3)) {
case "CLIENT_FUNCTIONS": case "CLIENT_FUNCTIONS":
line = line.replaceAll(regex, getClientFunctions(matcher.group(1)) + "$3"); line = line.replaceAll(regex, getClientFunctions(matcher.group(1)) + "$4");
break; break;
case "COMMANDS": case "COMMANDS":
line = line.replaceAll(regex, getCommands(matcher.group(1)) + "$3"); line = line.replaceAll(regex, getCommands(matcher.group(1)) + "$4");
break;
case "ENDPOINT":
line = line.replace("//{{ENDPOINT}}//", ApiUtil.getBaseUrl(request));
break; break;
case "HELP_ARRAY": case "HELP_ARRAY":
line = line.replaceAll(regex, getHelpArray(matcher.group(1)) + "$3"); line = line.replaceAll(regex, getHelpArray(matcher.group(1)) + "$4");
break; break;
case "METHODS": case "METHODS":
line = line.replaceAll(regex, getMethods(matcher.group(1)) + "$3"); line = line.replaceAll(regex, getMethods(matcher.group(1)) + "$4");
break; break;
case "PARAMETERS": case "PARAMETERS":
line = line.replaceAll(regex, getParameters(matcher.group(1)) + "$3"); line = line.replaceAll(regex, getParameters(matcher.group(1)) + "$4");
break; break;
case "STATUSES": case "STATUSES":
line = line.replaceAll(regex, getStatuses(matcher.group(1)) + "$3"); line = line.replaceAll(regex, getStatuses(matcher.group(1)) + "$4");
break; break;
default: default:
System.out.println("################# Unknown match //{{" + matcher.group(2) + "}}//"); System.out.println("################# Unknown match //{{" + matcher.group(3) + "}}//");
} }
} }
output.append(line).append(StringPool.NEW_LINE); output.append(line).append(StringPool.NEW_LINE);
@ -133,7 +137,8 @@ public class GetSourceCode extends Command {
sb.append(prefix).append(INDENT).append("if (\\$argc < ").append(nRequired + 2).append(") {\n"); sb.append(prefix).append(INDENT).append("if (\\$argc < ").append(nRequired + 2).append(") {\n");
sb.append(prefix).append(INDENT).append(INDENT) sb.append(prefix).append(INDENT).append(INDENT)
.append("echo(\"Numero di argomenti insufficiente.\\\\n\\\\n\");\n"); .append("echo(\"Numero di argomenti insufficiente.\\\\n\\\\n\");\n");
sb.append(prefix).append(INDENT).append(INDENT).append("die(\\$api->getHelp(\\$argv[1]));\n"); sb.append(prefix).append(INDENT).append(INDENT)
.append("die(\\$api->getHelp(\\$argv[0], \\$argv[1]));\n");
sb.append(prefix).append(INDENT).append("}\n"); sb.append(prefix).append(INDENT).append("}\n");
} }
if (command.isSecure()) { if (command.isSecure()) {
@ -197,7 +202,7 @@ public class GetSourceCode extends Command {
if (!verb.equals("login")) { if (!verb.equals("login")) {
Command command = CommandList.get(verb); Command command = CommandList.get(verb);
sb.append(prefix).append(StringPool.APOSTROPHE).append(verb).append("' => [\n"); sb.append(prefix).append(StringPool.APOSTROPHE).append(verb).append("' => [\n");
sb.append(prefix).append(INDENT).append("\"Uso: php {\\$argv[0]} ").append(verb); sb.append(prefix).append(INDENT).append("\"Uso: php \\$application ").append(verb);
for (Parameter parameter : command.getInputParameters()) { for (Parameter parameter : command.getInputParameters()) {
if (parameter.isRequired()) { if (parameter.isRequired()) {
sb.append(" <").append(parameter.getName()).append(StringPool.GREATER_THAN); sb.append(" <").append(parameter.getName()).append(StringPool.GREATER_THAN);
@ -216,8 +221,7 @@ public class GetSourceCode extends Command {
boolean hasRequired = false; boolean hasRequired = false;
for (Parameter parameter : command.getInputParameters()) { for (Parameter parameter : command.getInputParameters()) {
if (parameter.isRequired()) { if (parameter.isRequired()) {
sb.append(prefix).append(INDENT).append("'**").append(parameter.getName()) sb.append(prefix).append(INDENT).append("'**").append(parameter.getName()).append(": ")
.append(": ")
.append(parameter.getDescription().replace(StringPool.APOSTROPHE, "\\\\'")) .append(parameter.getDescription().replace(StringPool.APOSTROPHE, "\\\\'"))
.append("',\n"); .append("',\n");
hasRequired = true; hasRequired = true;
@ -290,7 +294,13 @@ public class GetSourceCode extends Command {
} }
if (allRequired) { if (allRequired) {
sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase()) sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase())
.append(", [\n"); .append(StringPool.COMMA_AND_SPACE);
if (command.getMethods().size() > 1) {
sb.append("\\$this->config->getDefaultMethod() === 'POST'");
} else {
sb.append(command.getMethods().get(0).equals(HttpMethods.POST));
}
sb.append(", [\n");
for (Parameter parameter : parameters) { for (Parameter parameter : parameters) {
sb.append(prefix).append(INDENT).append(INDENT).append("Parameters::") sb.append(prefix).append(INDENT).append(INDENT).append("Parameters::")
.append(PARAMETER_NAMES.get(parameter.getName())).append(" => \\$") .append(PARAMETER_NAMES.get(parameter.getName())).append(" => \\$")
@ -322,14 +332,26 @@ public class GetSourceCode extends Command {
} }
} }
sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase()) sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase())
.append(", \\$data"); .append(StringPool.COMMA_AND_SPACE);
if (command.getMethods().size() > 1) {
sb.append("\\$this->config->getDefaultMethod() === 'POST'");
} else {
sb.append(command.getMethods().get(0).equals(HttpMethods.POST));
}
sb.append(", \\$data");
if (!command.isSecure()) { if (!command.isSecure()) {
sb.append(", false"); sb.append(", false");
} }
sb.append(");\n"); sb.append(");\n");
} }
} else { } else {
sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase()); sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase())
.append(StringPool.COMMA_AND_SPACE);
if (command.getMethods().size() > 1) {
sb.append("\\$this->config->getDefaultMethod() === 'POST'");
} else {
sb.append(command.getMethods().get(0).equals(HttpMethods.POST));
}
if (!command.isSecure()) { if (!command.isSecure()) {
sb.append(", null, false"); sb.append(", null, false");
} }

17
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Login.java

@ -48,14 +48,19 @@ public class Login extends Command {
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { public void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
readParameters(request); readParameters(request);
String userName = (String) parameters.get(Parameters.USERNAME); List<String> additionalInfo = new ArrayList<>();
String username = (String) parameters.get(Parameters.USERNAME);
if (null == username) {
additionalInfo.add("Parametro " + Parameters.USERNAME + " mancante");
}
String password = (String) parameters.get(Parameters.PASSWORD); String password = (String) parameters.get(Parameters.PASSWORD);
if ((null == userName) || (null == password)) { if (null == password) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST); additionalInfo.add("Parametro " + Parameters.PASSWORD + " mancante");
} else { }
if (additionalInfo.isEmpty()) {
Sportello sportello = null; Sportello sportello = null;
try { try {
sportello = SportelloLocalServiceUtil.findByUserName(userName); sportello = SportelloLocalServiceUtil.findByUserName(username);
} catch (NoSuchSportelloException | SystemException e) { } catch (NoSuchSportelloException | SystemException e) {
} }
if (Validator.isNull(sportello) || !sportello.checkPassword(password)) { if (Validator.isNull(sportello) || !sportello.checkPassword(password)) {
@ -67,6 +72,8 @@ public class Login extends Command {
result.put(Parameters.TOKEN, new AccessToken(sportello).getToken()); result.put(Parameters.TOKEN, new AccessToken(sportello).getToken());
Response.write(response, Status.OK, result); Response.write(response, Status.OK, result);
} }
} else {
Response.write(response, Status.INVALID_INPUT, additionalInfo);
} }
} }

114
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Manual.java

@ -2,11 +2,13 @@ package it.mwg.sicilia.sue.api.v1.command.impl;
import it.mwg.sicilia.sue.api.v1.Parameters; import it.mwg.sicilia.sue.api.v1.Parameters;
import it.mwg.sicilia.sue.api.v1.command.Command; import it.mwg.sicilia.sue.api.v1.command.Command;
import it.mwg.sicilia.sue.api.v1.command.CommandList;
import it.mwg.sicilia.sue.api.v1.parameter.Parameter; import it.mwg.sicilia.sue.api.v1.parameter.Parameter;
import it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES; import it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES;
import java.io.Serializable; import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -16,14 +18,10 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import com.liferay.portal.kernel.json.JSONFactoryUtil; import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONSerializer; import com.liferay.portal.kernel.json.JSONSerializer;
import com.liferay.portal.kernel.servlet.HttpMethods; import com.liferay.portal.kernel.servlet.HttpMethods;
import com.liferay.portal.kernel.servlet.ServletResponseUtil;
import com.liferay.portal.kernel.util.Base64; import com.liferay.portal.kernel.util.Base64;
import com.liferay.portal.kernel.util.Http;
import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.StringPool;
public class Manual extends Command { public class Manual extends Command {
@ -35,8 +33,6 @@ public class Manual extends Command {
} }
}; };
private static String baseUrl = null;
private static final JSONSerializer serializer = JSONFactoryUtil.createJSONSerializer(); private static final JSONSerializer serializer = JSONFactoryUtil.createJSONSerializer();
public Manual(String description, String... methods) { public Manual(String description, String... methods) {
@ -45,68 +41,14 @@ public class Manual extends Command {
@Override @Override
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { public void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
StringBuilder result = new StringBuilder();
Iterator<Command> commands = CommandList.getList().iterator();
while (commands.hasNext()) {
Command command = commands.next();
result.append("Comando: /").append(command.getVerb());
if (command.isSecure()) {
result.append(" [T]");
}
result.append(StringPool.NEW_LINE);
result.append(command.getDescription()).append(StringPool.NEW_LINE);
result.append("Metodi: ").append(StringUtils.join(command.getMethods(), StringPool.COMMA_AND_SPACE))
.append(StringPool.NEW_LINE);
result.append("Parametri:");
List<Parameter> parameters = command.getInputParameters();
if (parameters.isEmpty()) {
result.append(" Nessuno\n");
} else {
result.append(StringPool.NEW_LINE);
for (Parameter parameter : parameters) {
result.append(StringPool.TAB).append(parameter.getName());
if (parameter.isRequired()) {
result.append(StringPool.STAR);
}
result.append(" (").append(parameter.getType().toString()).append(") - ")
.append(parameter.getDescription()).append(StringPool.NEW_LINE);
}
}
parameters = command.getOutputParameters();
if (!parameters.isEmpty()) {
result.append("Restituisce:\n");
for (Parameter parameter : parameters) {
result.append(StringPool.TAB).append(parameter.getName()).append(" (")
.append(parameter.getType().toString()).append(") - ").append(parameter.getDescription())
.append(StringPool.NEW_LINE);
if (parameter.getType().equals(TYPES.ARRAY)) {
for (Parameter subParameter : parameter.getSubParameters()) {
result.append(StringPool.TAB).append(StringPool.TAB).append(subParameter.getName())
.append(" (").append(subParameter.getType().toString()).append(") - ")
.append(subParameter.getDescription()).append(StringPool.NEW_LINE);
}
}
}
}
result.append("Esempio:\n").append(getCurlExample(command, getBaseUrl(request), StringPool.TAB));
if (commands.hasNext()) {
result.append("================================================================================\n");
}
}
result.append("\nNote:\n[T] = Richiede token di autenticazione: header di richiesta \"")
.append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro \"").append(Parameters.TOKEN)
.append("\"\n * = Parametro obbligatorio\n");
setTextPlain(response);
ServletResponseUtil.write(response, result.toString());
} }
protected String getCurlExample(Command command, String baseUrl) { protected String getCurlExample(Command command, String method, String baseUrl) {
return getCurlExample(command, baseUrl, StringPool.BLANK); return getCurlExample(command, method, baseUrl, StringPool.BLANK);
} }
protected String getCurlExample(Command command, String baseUrl, String prefix) { protected String getCurlExample(Command command, String method, String baseUrl, String prefix) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(prefix).append("curl "); sb.append(prefix).append("curl ");
@ -114,11 +56,6 @@ public class Manual extends Command {
sb.append("--header \"").append(Parameters.X_AUTH_TOKEN).append(": $TOKEN\"").append(" \\\n") sb.append("--header \"").append(Parameters.X_AUTH_TOKEN).append(": $TOKEN\"").append(" \\\n")
.append(prefix).append(StringPool.TAB); .append(prefix).append(StringPool.TAB);
} }
if (command.getMethods().contains(HttpMethods.GET)) {
} else {
sb.append("--header \"Content-Type: application/json; charset=UTF-8\" \\\n").append(prefix)
.append(StringPool.TAB);
sb.append("--request POST \\\n").append(prefix).append(StringPool.TAB);
Map<String, Serializable> data = new LinkedHashMap<>(); Map<String, Serializable> data = new LinkedHashMap<>();
for (Parameter parameter : command.getInputParameters()) { for (Parameter parameter : command.getInputParameters()) {
if (parameter.getType().equals(TYPES.ARRAY)) { if (parameter.getType().equals(TYPES.ARRAY)) {
@ -135,12 +72,33 @@ public class Manual extends Command {
data.put(parameter.getName(), getParameterSampleValue(parameter)); data.put(parameter.getName(), getParameterSampleValue(parameter));
} }
} }
if (method.equals(HttpMethods.POST)) {
sb.append("--request POST \\\n").append(prefix).append(StringPool.TAB);
if (data.size() > 0) { if (data.size() > 0) {
sb.append("--header \"Content-Type: application/json; charset=UTF-8\" \\\n").append(prefix)
.append(StringPool.TAB);
sb.append("--data '").append(serializer.serializeDeep(data)).append("' \\\n").append(prefix) sb.append("--data '").append(serializer.serializeDeep(data)).append("' \\\n").append(prefix)
.append(StringPool.TAB); .append(StringPool.TAB);
} }
} }
sb.append(baseUrl).append(command.getVerb()).append(StringPool.NEW_LINE); sb.append(baseUrl).append(command.getVerb());
if (method.equals(HttpMethods.GET) && !data.isEmpty()) {
sb.append(StringPool.QUESTION);
Iterator<String> names = data.keySet().iterator();
while (names.hasNext()) {
String name = names.next();
sb.append(name).append(StringPool.EQUAL);
try {
sb.append(URLEncoder.encode(data.get(name).toString(), StandardCharsets.UTF_8.toString()));
} catch (UnsupportedEncodingException e) {
sb.append(data.get(name).toString());
}
if (names.hasNext()) {
sb.append(StringPool.AMPERSAND);
}
}
}
sb.append(StringPool.NEW_LINE);
return sb.toString(); return sb.toString();
} }
@ -170,22 +128,6 @@ public class Manual extends Command {
return ret; return ret;
} }
protected String getBaseUrl(HttpServletRequest request) {
if (null == baseUrl) {
StringBuilder sb = new StringBuilder();
sb.append(request.isSecure() ? Http.HTTPS_WITH_SLASH : Http.HTTP_WITH_SLASH);
sb.append(request.getServerName());
if ((request.isSecure() && (request.getServerPort() != Http.HTTPS_PORT))
|| (!request.isSecure() && (request.getServerPort() != Http.HTTP_PORT))) {
sb.append(StringPool.COLON).append(request.getServerPort());
}
sb.append(request.getContextPath()).append(request.getServletPath()).append(StringPool.FORWARD_SLASH);
baseUrl = sb.toString();
}
return baseUrl;
}
@Override @Override
public boolean isSecure() { public boolean isSecure() {
return false; return false;

61
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ManualHtml.java

@ -5,6 +5,7 @@ import it.mwg.sicilia.sue.api.v1.command.Command;
import it.mwg.sicilia.sue.api.v1.command.CommandList; import it.mwg.sicilia.sue.api.v1.command.CommandList;
import it.mwg.sicilia.sue.api.v1.parameter.Parameter; import it.mwg.sicilia.sue.api.v1.parameter.Parameter;
import it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES; import it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES;
import it.mwg.sicilia.sue.api.v1.util.ApiUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,13 +36,13 @@ public class ManualHtml extends Manual {
String cssFile = "/css/api/v1/api.css"; String cssFile = "/css/api/v1/api.css";
String bootstrapFile = "/css/bootstrap.css"; String bootstrapFile = "/css/bootstrap.css";
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
result.append("<!doctype html>").append("<meta charset=\"utf-8\">") result.append("<!doctype html><meta charset=\"utf-8\">")
.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">") .append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">")
.append("<head><title>Manual</title>").append("<link rel=\"stylesheet\" href=\"") .append("<head><title>Manual</title><link rel=\"stylesheet\" href=\"").append(request.getContextPath())
.append(request.getContextPath()).append(cssFile).append("?v=") .append(cssFile).append("?v=")
.append(new File(request.getServletContext().getRealPath(cssFile)).lastModified()).append("\">") .append(new File(request.getServletContext().getRealPath(cssFile)).lastModified()).append("\">")
.append("<link rel=\"stylesheet\" href=\"").append(request.getContextPath()).append(bootstrapFile) .append("<link rel=\"stylesheet\" href=\"").append(request.getContextPath()).append(bootstrapFile)
.append("\">").append("</head><body class=''>"); .append("\"></head><body class=''>");
result.append("<div class='container'>"); result.append("<div class='container'>");
result.append("<div class='row'>"); result.append("<div class='row'>");
result.append("<div class='col-12 pt-4'>"); result.append("<div class='col-12 pt-4'>");
@ -57,15 +58,15 @@ public class ManualHtml extends Manual {
result.append("</h2>"); result.append("</h2>");
result.append("<p class='description text-secondary mb-3'>").append(command.getDescription()) result.append("<p class='description text-secondary mb-3'>").append(command.getDescription())
.append(".</p>"); .append(".</p>");
for (String method : command.getMethods()) {
result.append("<div class='w-100 mb-2'>"); result.append("<div class='w-100 mb-2'>");
for (String cmd : command.getMethods()) { result.append("<span class='badge badge-success mr-2 py-1 px-2' data-type='")
result.append("<span class='badge badge-success mr-2 py-1 px-2' data-type='").append(cmd.toLowerCase()) .append(method.toLowerCase()).append("'>").append(method).append("</span>");
.append("'>").append(cmd).append("</span>");
}
result.append("</div>"); result.append("</div>");
result.append("<div class='d-flex w-100 mb-3'><pre class='container-fluid py-2'>"); result.append("<div class='d-flex w-100 mb-3'><pre class='container-fluid py-2'>");
result.append(getCurlExample(command, getBaseUrl(request))); result.append(getCurlExample(command, method, ApiUtil.getBaseUrl(request)));
result.append("</pre></div>"); result.append("</pre></div>");
}
List<Parameter> parameters = command.getInputParameters(); List<Parameter> parameters = command.getInputParameters();
result.append("<div class='w-100 mb-3 mt-4'>"); result.append("<div class='w-100 mb-3 mt-4'>");
result.append("<h4 class='w-100'>Parametri</h4>"); result.append("<h4 class='w-100'>Parametri</h4>");
@ -76,13 +77,13 @@ public class ManualHtml extends Manual {
result.append("<thead class='thead-light font-weight-bold'>"); result.append("<thead class='thead-light font-weight-bold'>");
result.append("<tr>"); result.append("<tr>");
result.append("<th>Campo</th>"); result.append("<th>Campo</th>");
result.append("<th>Obbligatorio</th>"); result.append("<th>Opzionale</th>");
result.append("<th>Tipo</th>"); result.append("<th>Tipo</th>");
result.append("<th>Descrizione</th>"); result.append("<th>Descrizione</th>");
result.append("</tr>"); result.append("</tr>");
result.append("</thead>"); result.append("</thead>");
result.append("<tbody>"); result.append("<tbody>");
result.append(printTableParameters(parameters, 0, false)); result.append(printTableParameters(parameters, 0));
result.append("</tbody>"); result.append("</tbody>");
result.append("</table>"); result.append("</table>");
} }
@ -103,7 +104,7 @@ public class ManualHtml extends Manual {
result.append("</tr>"); result.append("</tr>");
result.append("</thead>"); result.append("</thead>");
result.append("<tbody>"); result.append("<tbody>");
result.append(printTableParameters(parameters, 0, true)); result.append(printTableParameters(parameters, 0));
result.append("</tbody>"); result.append("</tbody>");
result.append("</table>"); result.append("</table>");
} }
@ -114,8 +115,9 @@ public class ManualHtml extends Manual {
result.append("<div class='row'>"); result.append("<div class='row'>");
result.append("<div class='col-12 pt-4'>"); result.append("<div class='col-12 pt-4'>");
result.append("<p>"); result.append("<p>");
result.append("<b>Note</b><br>[T] = Richiede token di autenticazione: header di richiesta \""); result.append("<b>Note</b><br/>[T] = Richiede token di autenticazione: header di richiesta \"");
result.append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro JSON \"").append(Parameters.TOKEN); result.append(Parameters.X_AUTH_TOKEN).append("\" oppure per il metodo POST parametro JSON \"")
.append(Parameters.TOKEN);
result.append("\"</p>"); result.append("\"</p>");
result.append("</div>"); result.append("</div>");
result.append("</div>"); result.append("</div>");
@ -125,33 +127,20 @@ public class ManualHtml extends Manual {
ServletResponseUtil.write(response, result.toString()); ServletResponseUtil.write(response, result.toString());
} }
private String printTableParameters(List<Parameter> parameters, int level, boolean output) { private String printTableParameters(List<Parameter> parameters, int level) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
for (Parameter parameter : parameters) { for (Parameter parameter : parameters) {
result.append("<tr>"); result.append("<tr><td style='padding-left:").append(0.75 + 2 * level).append("rem'>");
result.append("<td style='padding-left:").append(0.75 + 2 * level).append("rem'>") for (int i = 0; i < level; i++) {
.append(parameter.getName()).append("</td>"); result.append("&gt;");
result.append("<td>");
if (output) {
if (parameter.isRequired()) {
result.append("No");
} else {
result.append("Sì");
} }
} else { result.append(StringPool.SPACE).append(parameter.getName()).append("</td><td>")
if (parameter.isRequired()) { .append(parameter.isRequired() ? "No" : "Sì").append("</td><td>")
result.append("Sì"); .append(parameter.getType().toString()).append("</td><td>").append(parameter.getDescription())
} else { .append("</td></tr>");
result.append("No");
}
}
result.append("</td>");
result.append("<td>").append(parameter.getType().toString()).append("</td>");
result.append("<td>").append(parameter.getDescription()).append("</td>");
result.append("</tr>");
if (parameter.getType().equals(TYPES.ARRAY)) { if (parameter.getType().equals(TYPES.ARRAY)) {
result.append(printTableParameters(parameter.getSubParameters(), level + 1, output)); result.append(printTableParameters(parameter.getSubParameters(), level + 1));
} }
} }
return result.toString(); return result.toString();

62
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/VerifyApplication.java

@ -0,0 +1,62 @@
package it.mwg.sicilia.sue.api.v1.command.impl;
import it.mwg.sicilia.sue.api.v1.Parameters;
import it.mwg.sicilia.sue.api.v1.Response;
import it.mwg.sicilia.sue.api.v1.Status;
import it.mwg.sicilia.sue.api.v1.command.Command;
import it.mwg.sicilia.sue.api.v1.parameter.Parameter;
import it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES;
import it.tref.liferay.portos.bo.model.IntPratica;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.kernel.util.Validator;
public class VerifyApplication extends Command {
@SuppressWarnings("serial")
private static final List<Parameter> INPUT_PARAMETERS = new ArrayList<Parameter>() {
{
add(new Parameter(Parameters.APPLICATION_ID, TYPES.INT, "Id dell'istanza"));
}
};
@SuppressWarnings("serial")
private static final List<Parameter> OUTPUT_PARAMETERS = new ArrayList<Parameter>() {
{
addAll(BASE_OUTPUT_PARAMETERS);
add(new Parameter(Parameters.ADDITIONAL_INFO, TYPES.STRING,
"Eventuali informazioni aggiuntive sull'operazione o sugli errori incontrati", false));
}
};
public VerifyApplication(String description, String... methods) {
super(description, methods);
}
@Override
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (verifyAccessToken(request, response)) {
IntPratica intPratica = getSecureIntPratica(response);
if (Validator.isNotNull(intPratica)) {
Response.write(response, Status.OK);
}
}
}
@Override
public List<Parameter> getInputParameters() {
return INPUT_PARAMETERS;
}
@Override
public List<Parameter> getOutputParameters() {
return OUTPUT_PARAMETERS;
}
}

17
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/ApiUtil.java

@ -5,10 +5,14 @@ import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfReader;
import com.liferay.portal.kernel.util.Http;
import com.liferay.portal.kernel.util.PropsUtil; import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.Validator;
public class ApiUtil { public class ApiUtil {
@ -34,6 +38,19 @@ public class ApiUtil {
return Validator.isNotNull(PropsUtil.get("mwg.test.display")); return Validator.isNotNull(PropsUtil.get("mwg.test.display"));
} }
public static String getBaseUrl(HttpServletRequest request) {
StringBuilder sb = new StringBuilder();
sb.append(request.isSecure() ? Http.HTTPS_WITH_SLASH : Http.HTTP_WITH_SLASH);
sb.append(request.getServerName());
if ((request.isSecure() && (request.getServerPort() != Http.HTTPS_PORT))
|| (!request.isSecure() && (request.getServerPort() != Http.HTTP_PORT))) {
sb.append(StringPool.COLON).append(request.getServerPort());
}
sb.append(request.getContextPath()).append(request.getServletPath()).append(StringPool.FORWARD_SLASH);
return sb.toString();
}
public static String underscoreToCamelCase(String underscore) { public static String underscoreToCamelCase(String underscore) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

1
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/startup/Startup.java

@ -29,7 +29,6 @@ public class Startup extends SimpleAction {
String secret = null; String secret = null;
try { try {
secret = ApiSettingLocalServiceUtil.get(companyId, ApiConstants.API_SECRET); secret = ApiSettingLocalServiceUtil.get(companyId, ApiConstants.API_SECRET);
_log.info("apiSetting = " + secret);
if (Validator.isNull(secret)) { if (Validator.isNull(secret)) {
SecureRandom rnd = new SecureRandom(); SecureRandom rnd = new SecureRandom();
byte[] bytes = new byte[32]; byte[] bytes = new byte[32];

3
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/README.txt

@ -1,5 +1,6 @@
Prima di operare aggiornare il file SueApi/v1/config/api.json con i corretti Prima di operare aggiornare il file SueApi/v1/config/api.json con i corretti
parametri di accesso. parametri di accesso, oppure utilizzare il comando:
php client.php username password
Compatibile con php 7.1+ Compatibile con php 7.1+

29
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/functions.php

@ -1,5 +1,7 @@
<?php <?php
use SueApi\v1\Client;
function parseCommandLine() function parseCommandLine()
{ {
global $argc, $argv; global $argc, $argv;
@ -20,3 +22,30 @@ function parseCommandLine()
define('DEBUG', $debug); define('DEBUG', $debug);
$argv = array_values($argv); $argv = array_values($argv);
} }
function help(Client $api, string $command = '')
{
echo "set_login: Salva le credenziali per l'accesso\n";
echo "set_default: Imposta il metodo predefinito per le richieste (GET o POST)\n";
echo $api->getHelp($command);
echo "\nDigitare help <comando> per maggiori informazioni sul comando.\n";
echo "L'opzione --debug visualizza a schermo le comunicazioni con il server.\n";
echo " Es.: php client.php nop --debug\n";
}
function helpSetLogin(string $program)
{
echo "Uso: php $program set_login <username> <password>\n";
echo "Salva le credenziali per l'accesso\n\n";
echo "**username: Nome utente\n";
echo "**password: Password\n\n";
echo "** = parametro obbligatorio\n";
}
function helpSetMethod(string $program)
{
echo "Uso: php $program set_method <method>\n";
echo " Imposta il metodo predefinito per le richieste (GET o POST)\n\n";
echo "**method: Il metodo predefinito (GET o POST)\n";
echo "** = parametro obbligatorio\n";
}

38
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Client.php

@ -16,7 +16,7 @@ class Client
public function login(?string $username = null, ?string $password = null) public function login(?string $username = null, ?string $password = null)
{ {
$response = $this->exec(Commands::LOGIN, [ $response = $this->exec(Commands::LOGIN, true, [
Parameters::USERNAME => $username ?? $this->config->getUsername(), Parameters::USERNAME => $username ?? $this->config->getUsername(),
Parameters::PASSWORD => $password ?? $this->config->getPassword(), Parameters::PASSWORD => $password ?? $this->config->getPassword(),
]); ]);
@ -33,20 +33,25 @@ class Client
$this->config->save(); $this->config->save();
} }
public function setMethod(string $method)
{
$this->config->setDefaultMethod(strtoupper($method));
$this->config->save();
}
//{{METHODS}}// //{{METHODS}}//
public static function getHelp(string $command = '') public static function getHelp(string $application, string $command = '')
{ {
global $argv;
$help = [ $help = [
//{{HELP_ARRAY}}// //{{HELP_ARRAY}}//
][$command] ?? ["Nessun aiuto per $command"]; ][$command] ?? ["Nessun aiuto per $command"];
return implode("\n", $help) . "\n"; return implode("\n", $help) . "\n";
} }
private function exec(string $command, ?array $payload = null, bool $secure = true) private function exec(string $command, bool $post = true, ?array $payload = null, bool $secure = true)
{ {
$data = $this->curlExec($command, $payload, $secure); $data = $this->curlExec($command, $post, $payload, $secure);
if (is_array($data)) { if (is_array($data)) {
if (!isset($data[Parameters::STATUS_CODE])) { if (!isset($data[Parameters::STATUS_CODE])) {
die("Risposta del server non corretta.\n$" . json_encode($data) . "\n"); die("Risposta del server non corretta.\n$" . json_encode($data) . "\n");
@ -59,22 +64,26 @@ class Client
return $data; return $data;
} }
private function curlExec(string $command, ?array $payload = null, bool $secure = true) private function curlExec(string $command, bool $post = true, ?array $payload = null, bool $secure = true)
{ {
$url = "{$this->config->getEndpoint()}/$command"; $url = "{$this->config->getEndpoint()}$command";
$post = (null !== $payload); $curl = curl_init();
$curl = curl_init($url);
if ($post) { if ($post) {
$json = json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
curl_setopt_array($curl, [ curl_setopt_array($curl, [
CURLOPT_HTTPHEADER => ['Content-Type:application/json; charset=UTF-8'], CURLOPT_HTTPHEADER => ['Content-Type:application/json; charset=UTF-8'],
CURLOPT_POST => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $json,
]); ]);
if (null !== $payload) {
$json = json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
}
if (DEBUG) { if (DEBUG) {
echo "DEBUG: POST $url > $json\n"; echo "DEBUG: POST $url" . (isset($json) ? " > $json" : '') . "\n";
} }
} else { } else {
if (null != $payload) {
$url .= '?' . http_build_query($payload);
}
if (DEBUG) { if (DEBUG) {
echo "DEBUG: GET $url\n"; echo "DEBUG: GET $url\n";
} }
@ -82,7 +91,10 @@ class Client
if ($secure) { if ($secure) {
curl_setopt($curl, CURLOPT_HTTPHEADER, [Parameters::X_AUTH_TOKEN . ': ' . $this->token]); curl_setopt($curl, CURLOPT_HTTPHEADER, [Parameters::X_AUTH_TOKEN . ': ' . $this->token]);
} }
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
]);
$data = curl_exec($curl); $data = curl_exec($curl);
if (200 !== ($sc = curl_getinfo($curl, CURLINFO_HTTP_CODE))) { if (200 !== ($sc = curl_getinfo($curl, CURLINFO_HTTP_CODE))) {
if ('' != ($error = curl_error($curl))) { if ('' != ($error = curl_error($curl))) {

18
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Config.php

@ -7,6 +7,7 @@ abstract class Config
protected $endpoint = null; protected $endpoint = null;
protected $username = null; protected $username = null;
protected $password = null; protected $password = null;
protected $defaultMethod = 'POST';
protected static $apiPath = null; protected static $apiPath = null;
protected static $basePath = null; protected static $basePath = null;
@ -19,11 +20,12 @@ abstract class Config
self::$configPath = self::$apiPath . 'config' . DIRECTORY_SEPARATOR; self::$configPath = self::$apiPath . 'config' . DIRECTORY_SEPARATOR;
} }
public function __construct(string $endpoint, string $username, string $password) public function __construct(string $endpoint, string $username, string $password, string $defaultMethod)
{ {
$this->endpoint = $endpoint; $this->endpoint = $endpoint;
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
$this->defaultMethod = $defaultMethod;
} }
public static function getConfigPath(string $configFile = ''): ?string public static function getConfigPath(string $configFile = ''): ?string
@ -38,7 +40,7 @@ abstract class Config
public function setEndpoint(string $endpoint): void public function setEndpoint(string $endpoint): void
{ {
$this->endpoint = $endpoint; $this->endpoint = rtrim($endpoint, '/') . '/';
} }
public function getUsername(): ?string public function getUsername(): ?string
@ -61,5 +63,17 @@ abstract class Config
$this->password = $password; $this->password = $password;
} }
public function getDefaultMethod(): string
{
return $this->defaultMethod;
}
public function setDefaultMethod(string $defaultMethod): void
{
if (in_array($defaultMethod, ['GET', 'POST'])) {
$this->defaultMethod = $defaultMethod;
}
}
abstract public function save(); abstract public function save();
} }

3
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/FileConfig.php

@ -10,7 +10,7 @@ class FileConfig extends Config
{ {
$this->fileName = $fileName; $this->fileName = $fileName;
$dati = json_decode(file_get_contents($this->getConfigPath($fileName))); $dati = json_decode(file_get_contents($this->getConfigPath($fileName)));
parent::__construct($dati->endpoint, $dati->username, $dati->password); parent::__construct($dati->endpoint, $dati->username, $dati->password, $dati->defaultMethod);
} }
public function save() public function save()
@ -19,6 +19,7 @@ class FileConfig extends Config
'endpoint' => $this->endpoint, 'endpoint' => $this->endpoint,
'username' => $this->username, 'username' => $this->username,
'password' => $this->password, 'password' => $this->password,
'defaultMethod' => $this->defaultMethod,
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
} }
} }

5
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/config/api.json

@ -1,5 +1,6 @@
{ {
"endpoint": "http://paesaggistica:8080/sicilia-sue-connector-portlet/api/v1", "endpoint": "//{{ENDPOINT}}//",
"username": "", "username": "",
"password": "" "password": "",
"defaultMethod": "POST"
} }

33
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/client.php

@ -12,38 +12,31 @@ switch ($argv[1] ?? '') {
case 'set_login': case 'set_login':
if ($argc < 4) { if ($argc < 4) {
echo ("Numero di argomenti insufficiente.\n\n"); echo ("Numero di argomenti insufficiente.\n\n");
echo "Uso: php {$argv[0]} {$argv[2]} <username> <password>\n"; helpSetLogin($argv[0]);
echo "Salva le credenziali per l'accesso\n\n";
echo "**username: Nome utente\n";
echo "**password: Password\n\n";
echo "** = parametro obbligatorio\n";
die(); die();
} }
$api->setLogin($argv[2], $argv[3]); $api->setLogin($argv[2], $argv[3]);
echo "Impostazioni salvate\n"; echo "Impostazioni salvate\n";
break; break;
case 'set_method':
if ($argc < 3) {
echo ("Numero di argomenti insufficiente.\n\n");
helpSetMethod($argv[0]);
die();
}
$api->setMethod($argv[2]);
echo "Impostazioni salvate\n";
break;
case 'help': case 'help':
switch ($argv[2] ?? '') { switch ($argv[2] ?? '') {
case 'set_login': case 'set_login':
echo "Uso: php {$argv[0]} {$argv[2]} <username> <password>\n"; helpSetLogin($argv[0]);
echo "Salva le credenziali per l'accesso\n\n";
echo "**username: Nome utente\n";
echo "**password: Password\n\n";
echo "** = parametro obbligatorio\n";
break; break;
default: default:
echo "set_login: Salva le credenziali per l'accesso\n"; help($api, $argv[2]);
echo $api->getHelp($argv[2] ?? '');
echo "\nDigitare help <comando> per maggiori informazioni sul comando.\n";
echo "L'opzione --debug visualizza a schermo le comunicazioni con il server.\n";
echo " Es.: php client.php nop --debug\n";
break; break;
} }
break; break;
default: default:
echo "set_login: Salva le credenziali per l'accesso\n"; help($api);
echo $api->getHelp();
echo "\nDigitare help <comando> per maggiori informazioni sul comando.\n";
echo "L'opzione --debug visualizza a schermo le comunicazioni con il server.\n";
echo " Es.: php client.php nop --debug\n";
} }

Caricamento…
Annulla
Salva