Skip to content

Commit 6535143

Browse files
authored
Merge branch 'master' into feature/gxobservability-testing-and-docs
2 parents a872ee0 + 0270694 commit 6535143

File tree

51 files changed

+712
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+712
-296
lines changed

common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<dependency>
3434
<groupId>org.apache.commons</groupId>
3535
<artifactId>commons-lang3</artifactId>
36-
<version>3.17.0</version>
36+
<version>3.18.0</version>
3737
</dependency>
3838
<dependency>
3939
<groupId>commons-io</groupId>

common/src/main/java/com/genexus/ApplicationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public boolean checkIfResourceExist(String path)
132132
if (isSpringBootApp())
133133
return new ClassPathResource(path).exists();
134134
else
135-
return new File(path).exists();
135+
return new File(path).exists() || getClass().getClassLoader().getResource(path) != null;
136136
}
137137

138138
public void setEJBEngine(boolean isEJBEngine)

common/src/main/java/com/genexus/CommonUtil.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3490,4 +3490,69 @@ public static String Sanitize(String input, HashMap<Character, Character> whiteL
34903490
}
34913491
return sanitizedInput.toString();
34923492
}
3493+
3494+
3495+
public static boolean isKnownContentType(String type)
3496+
{
3497+
if (type != null)
3498+
{
3499+
for (int i = 0; i < contentTypes.length; i++)
3500+
{
3501+
if (contentTypes[i].length >= 2)
3502+
{
3503+
if (type.equalsIgnoreCase(contentTypes[i][1]))
3504+
return true;
3505+
}
3506+
}
3507+
}
3508+
return false;
3509+
}
3510+
3511+
public static String getContentFromExt( String extension)
3512+
{
3513+
if (extension != null)
3514+
{
3515+
extension = extension.toLowerCase();
3516+
for (int i = 0; i < contentTypes.length; i++) {
3517+
if (contentTypes[i][0].equals(extension.trim()))
3518+
return contentTypes[i][1];
3519+
}
3520+
}
3521+
return null;
3522+
}
3523+
3524+
private static final String contentTypes[][] = {
3525+
{"txt" , "text/plain"},
3526+
{"rtx" , "text/richtext"},
3527+
{"htm" , "text/html"},
3528+
{"html" , "text/html"},
3529+
{"xml" , "text/xml"},
3530+
{"aif" , "audio/x-aiff"},
3531+
{"au" , "audio/basic"},
3532+
{"wav" , "audio/wav"},
3533+
{"bmp" , "image/bmp"},
3534+
{"gif" , "image/gif"},
3535+
{"jpe" , "image/jpeg"},
3536+
{"jpeg" , "image/jpeg"},
3537+
{"jpg" , "image/jpeg"},
3538+
{"jfif" , "image/pjpeg"},
3539+
{"tif" , "image/tiff"},
3540+
{"tiff" , "image/tiff"},
3541+
{"png" , "image/x-png"},
3542+
{"3gp" , "video/3gpp"},
3543+
{"3g2" , "video/3gpp2"},
3544+
{"mpg" , "video/mpeg"},
3545+
{"mpeg" , "video/mpeg"},
3546+
{"mov" , "video/quicktime"},
3547+
{"qt" , "video/quicktime"},
3548+
{"avi" , "video/x-msvideo"},
3549+
{"exe" , "application/octet-stream"},
3550+
{"dll" , "application/x-msdownload"},
3551+
{"ps" , "application/postscript"},
3552+
{"pdf" , "application/pdf"},
3553+
{"svg" , "image/svg+xml"},
3554+
{"tgz" , "application/x-compressed"},
3555+
{"zip" , "application/x-zip-compressed"},
3556+
{"gz" , "application/x-gzip"}
3557+
};
34933558
}

common/src/main/java/com/genexus/GXExternalCollection.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,14 @@ public <E> ArrayList<E> getExternalInstance() {
120120
public void setExternalInstance(ArrayList<?> data)
121121
{
122122
try {
123-
clear();
124-
for (Object item : data) {
125-
T obj = elementsType.getConstructor(new Class[]{}).newInstance();
126-
obj.getClass().getMethod("setExternalInstance", item.getClass()).invoke(obj, item);
127-
super.add(obj);
128-
vectorExternal.add(item);
123+
if (elementsType != null) {
124+
clear();
125+
for (Object item : data) {
126+
T obj = elementsType.getConstructor(new Class[]{}).newInstance();
127+
obj.getClass().getMethod("setExternalInstance", item.getClass()).invoke(obj, item);
128+
super.add(obj);
129+
vectorExternal.add(item);
130+
}
129131
}
130132
}
131133
catch(Exception ex)

common/src/main/java/com/genexus/util/GXFileInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public GXFileInfo(File file, boolean isDirectory){
2828
this.isDirectory = isDirectory;
2929
}
3030
public String getPath(){
31-
if (fileSource.isFile()){
31+
if (fileSource.isFile() || !exists()){
3232
String absoluteName = getAbsolutePath();
3333
if (!absoluteName.equals(""))
3434
return new File(absoluteName).getParent();

common/src/main/java/com/genexus/xml/GXXMLSerializable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ private void collectionFromJSONArray(JSONArray jsonArray, GXSimpleCollection gxC
497497
}
498498

499499
// cache of methods for classes, inpruve perfomance, becuase each intance get all methods each time called.
500-
private static transient ConcurrentHashMap<String, ConcurrentHashMap<String, Method>> classesCacheMethods = new ConcurrentHashMap<>();
500+
public static transient ConcurrentHashMap<String, ConcurrentHashMap<String, Method>> classesCacheMethods = new ConcurrentHashMap<>();
501501
// cache of methods names, inpruve perfomance.
502502
private static transient ConcurrentHashMap<String, String> toLowerCacheMethods = new ConcurrentHashMap<>();
503503

common/src/main/java/com/genexus/xml/XMLReader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,11 @@ public void open(String url)
785785
else
786786
{
787787
File xmlFile = new File(url);
788-
fileInputStream = new FileInputStream(xmlFile);
788+
if (xmlFile.exists())
789+
fileInputStream = new FileInputStream(xmlFile);
790+
else {
791+
fileInputStream = getClass().getClassLoader().getResourceAsStream(url);
792+
}
789793
}
790794
inputSource = new XMLInputSource(null, url, null, fileInputStream, null);
791795
if (documentEncoding.length() > 0)

gamsaml20/src/main/java/com/genexus/saml20/PostBinding.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public class PostBinding extends Binding {
1515
private static final Logger logger = LogManager.getLogger(PostBinding.class);
1616

1717
private Document xmlDoc;
18+
private Document verifiedDoc;
1819

1920
public PostBinding() {
2021
logger.trace("PostBinding constructor");
21-
xmlDoc = null;
2222
}
2323
// EXTERNAL OBJECT PUBLIC METHODS - BEGIN
2424

@@ -42,27 +42,34 @@ public static String logout(SamlParms parms, String relayState) {
4242
}
4343

4444
public boolean verifySignatures(SamlParms parms) {
45-
return DSig.validateSignatures(this.xmlDoc, parms.getTrustCertPath(), parms.getTrustCertAlias(), parms.getTrustCertPass());
45+
String verified = DSig.validateSignatures(this.xmlDoc, parms.getTrustCertPath(), parms.getTrustCertAlias(), parms.getTrustCertPass());
46+
if(verified.isEmpty()){
47+
return false;
48+
}else {
49+
this.verifiedDoc = SamlAssertionUtils.loadDocument(verified);
50+
logger.debug(MessageFormat.format("verifySignatures - sanitized xmlDoc {0}", Encoding.documentToString(this.xmlDoc)));
51+
return true;
52+
}
4653
}
4754

4855
public String getLoginAssertions() {
4956
logger.trace("getLoginAssertions");
50-
return SamlAssertionUtils.getLoginInfo(this.xmlDoc);
57+
return SamlAssertionUtils.getLoginInfo(this.verifiedDoc);
5158
}
5259

5360
public String getLogoutAssertions() {
5461
logger.trace("getLogoutAssertions");
55-
return SamlAssertionUtils.getLogoutInfo(this.xmlDoc);
62+
return SamlAssertionUtils.getLogoutInfo(this.verifiedDoc);
5663
}
5764

5865
public String getLoginAttribute(String name) {
5966
logger.trace("getLoginAttribute");
60-
return SamlAssertionUtils.getLoginAttribute(this.xmlDoc, name).trim();
67+
return SamlAssertionUtils.getLoginAttribute(this.verifiedDoc, name).trim();
6168
}
6269

6370
public String getRoles(String name) {
6471
logger.debug("getRoles");
65-
return SamlAssertionUtils.getRoles(this.xmlDoc, name);
72+
return SamlAssertionUtils.getRoles(this.verifiedDoc, name);
6673
}
6774

6875
public boolean isLogout(){

gamsaml20/src/main/java/com/genexus/saml20/utils/DSig.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.apache.xml.security.utils.Constants;
77
import org.w3c.dom.Document;
88
import org.w3c.dom.Element;
9+
import org.w3c.dom.Node;
910
import org.w3c.dom.NodeList;
1011

1112
import javax.xml.xpath.XPath;
@@ -22,40 +23,44 @@ public class DSig {
2223

2324
private static final Logger logger = LogManager.getLogger(DSig.class);
2425

25-
public static boolean validateSignatures(Document xmlDoc, String certPath, String certAlias, String certPassword) {
26+
public static String validateSignatures(Document xmlDoc, String certPath, String certAlias, String certPassword) {
2627
logger.trace("validateSignatures");
28+
List<Element> assertions = new ArrayList<Element>();
2729
X509Certificate cert = Keys.loadCertificate(certPath, certAlias, certPassword);
2830

2931
NodeList nodes = findElementsByPath(xmlDoc, "//*[@ID]");
3032

3133
NodeList signatures = xmlDoc.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE);
3234
//check the message is signed - security measure
3335
if(signatures.getLength() == 0){
34-
return false;
36+
return "";
3537
}
3638
for (int i = 0; i < signatures.getLength(); i++) {
3739
Element signedElement = findNodeById(nodes, getSignatureID((Element) signatures.item(i)));
40+
assertions.add(signedElement);
3841
if (signedElement == null) {
39-
return false;
42+
return "";
4043
}
4144
signedElement.setIdAttribute("ID", true);
4245
try {
4346
XMLSignature signature = new XMLSignature((Element) signatures.item(i), "");
4447
//verifies the signature algorithm is one expected - security meassure
4548
if (!verifySignatureAlgorithm((Element) signatures.item(i))) {
46-
return false;
49+
return "";
4750
}
4851
if (!signature.checkSignatureValue(cert)) {
49-
return false;
52+
return "";
5053
}
5154
} catch (Exception e) {
5255
logger.error("validateSignatures", e);
53-
return false;
56+
return "";
5457
}
5558
}
56-
return true;
59+
return SamlAssertionUtils.isLogout(xmlDoc) ? SamlAssertionUtils.buildXmlLogout(assertions) : SamlAssertionUtils.buildXmlLogin(assertions, xmlDoc);
5760
}
5861

62+
63+
5964
private static boolean verifySignatureAlgorithm(Element elem) {
6065
logger.trace("verifySignatureAlgorithm");
6166
NodeList signatureMethod = elem.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATUREMETHOD);

gamsaml20/src/main/java/com/genexus/saml20/utils/Encoding.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import org.apache.logging.log4j.Logger;
55
import org.bouncycastle.util.encoders.Base64;
66
import org.w3c.dom.Document;
7+
import org.w3c.dom.Element;
78

9+
import javax.xml.transform.OutputKeys;
810
import javax.xml.transform.Transformer;
911
import javax.xml.transform.TransformerFactory;
1012
import javax.xml.transform.dom.DOMSource;
@@ -74,6 +76,24 @@ public static String documentToString(Document doc) {
7476
}
7577
}
7678

79+
public static String elementToString(Element element) {
80+
try {
81+
TransformerFactory tf = TransformerFactory.newInstance();
82+
Transformer transformer = tf.newTransformer();
83+
84+
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
85+
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
86+
87+
StringWriter writer = new StringWriter();
88+
transformer.transform(new DOMSource(element), new StreamResult(writer));
89+
90+
return writer.toString();
91+
} catch (Exception e) {
92+
logger.error("elementToString", e);
93+
return null;
94+
}
95+
}
96+
7797
public static byte[] decodeParameter(String parm) {
7898
logger.trace("decodeParameter");
7999
try {

0 commit comments

Comments
 (0)