Skip to content

Commit 4baaf73

Browse files
Merge remote-tracking branch 'origin/4.17'
Signed-off-by: Rohit Yadav <[email protected]>
2 parents 731a83b + 7a3e97d commit 4baaf73

File tree

20 files changed

+4639
-601
lines changed

20 files changed

+4639
-601
lines changed

api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,8 @@ public void setResourceIconResponse(ResourceIconResponse icon) {
253253
public void setIpv6Routes(Set<Ipv6RouteResponse> ipv6Routes) {
254254
this.ipv6Routes = ipv6Routes;
255255
}
256+
257+
public Set<Ipv6RouteResponse> getIpv6Routes() {
258+
return ipv6Routes;
259+
}
256260
}

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ cloudstack (4.18.0.0) unstable; urgency=low
44

55
-- the Apache CloudStack project <[email protected]> Tue, 31 May 2022 14:33:47 -0300
66

7+
cloudstack (4.17.0.1) unstable; urgency=low
8+
9+
* Update the version to 4.17.0.1
10+
11+
-- the Apache CloudStack project <[email protected]> Fri, 15 Jul 2022 18:18:39 +0530
12+
713
cloudstack (4.17.0.0) unstable; urgency=low
814

915
* Update the version to 4.17.0.0

engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public NetUtils.InternetProtocol getNetworkOfferingInternetProtocol(long offerin
279279
}
280280

281281
@Override
282-
public NetUtils.InternetProtocol getNetworkOfferingInternetProtocol(long offeringId,NetUtils.InternetProtocol defaultProtocol) {
282+
public NetUtils.InternetProtocol getNetworkOfferingInternetProtocol(long offeringId, NetUtils.InternetProtocol defaultProtocol) {
283283
NetUtils.InternetProtocol protocol = getNetworkOfferingInternetProtocol(offeringId);
284284
if (protocol == null) {
285285
return defaultProtocol;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.offerings.dao;
19+
20+
import org.junit.Assert;
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
import org.mockito.InjectMocks;
24+
import org.mockito.Mock;
25+
import org.mockito.Mockito;
26+
import org.mockito.MockitoAnnotations;
27+
28+
import com.cloud.offering.NetworkOffering;
29+
import com.cloud.utils.net.NetUtils;
30+
31+
public class NetworkOfferingDaoImplTest {
32+
@Mock
33+
NetworkOfferingDetailsDao detailsDao;
34+
35+
@InjectMocks
36+
NetworkOfferingDaoImpl networkOfferingDao = new NetworkOfferingDaoImpl();
37+
38+
final long offeringId = 1L;
39+
40+
@Before
41+
public void setup() {
42+
MockitoAnnotations.initMocks(this);
43+
}
44+
45+
@Test
46+
public void testGetNetworkOfferingInternetProtocol() {
47+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn(null);
48+
NetUtils.InternetProtocol protocol = networkOfferingDao.getNetworkOfferingInternetProtocol(offeringId);
49+
Assert.assertNull(protocol);
50+
51+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn("IPv4");
52+
protocol = networkOfferingDao.getNetworkOfferingInternetProtocol(offeringId);
53+
Assert.assertEquals(NetUtils.InternetProtocol.IPv4, protocol);
54+
55+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn("IPv6");
56+
protocol = networkOfferingDao.getNetworkOfferingInternetProtocol(offeringId);
57+
Assert.assertEquals(NetUtils.InternetProtocol.IPv6, protocol);
58+
59+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn("DualStack");
60+
protocol = networkOfferingDao.getNetworkOfferingInternetProtocol(offeringId);
61+
Assert.assertEquals(NetUtils.InternetProtocol.DualStack, protocol);
62+
}
63+
64+
@Test
65+
public void testGetNetworkOfferingInternetProtocolWithDefault() {
66+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn(null);
67+
NetUtils.InternetProtocol protocol = networkOfferingDao.getNetworkOfferingInternetProtocol(offeringId, NetUtils.InternetProtocol.IPv4);
68+
Assert.assertEquals(NetUtils.InternetProtocol.IPv4, protocol);
69+
70+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn("IPv6");
71+
protocol = networkOfferingDao.getNetworkOfferingInternetProtocol(offeringId, NetUtils.InternetProtocol.IPv4);
72+
Assert.assertEquals(NetUtils.InternetProtocol.IPv6, protocol);
73+
}
74+
75+
@Test
76+
public void testIsIpv6Supported() {
77+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn("");
78+
boolean result = networkOfferingDao.isIpv6Supported(offeringId);
79+
Assert.assertFalse(result);
80+
81+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn("IPv4");
82+
result = networkOfferingDao.isIpv6Supported(offeringId);
83+
Assert.assertFalse(result);
84+
85+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn("IPv6");
86+
result = networkOfferingDao.isIpv6Supported(offeringId);
87+
Assert.assertTrue(result);
88+
89+
Mockito.when(detailsDao.getDetail(offeringId, NetworkOffering.Detail.internetProtocol)).thenReturn("DualStack");
90+
result = networkOfferingDao.isIpv6Supported(offeringId);
91+
Assert.assertTrue(result);
92+
}
93+
}

plugins/user-authenticators/saml2/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<dependency>
3232
<groupId>org.opensaml</groupId>
3333
<artifactId>opensaml</artifactId>
34+
<version>${cs.opensaml.version}</version>
3435
</dependency>
3536
<dependency>
3637
<groupId>org.apache.cloudstack</groupId>

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.cloudstack.api.response.SAMLMetaDataResponse;
3131
import org.apache.cloudstack.saml.SAML2AuthManager;
3232
import org.apache.cloudstack.saml.SAMLProviderMetadata;
33+
import org.apache.cloudstack.utils.security.ParserUtils;
3334
import org.apache.log4j.Logger;
3435
import org.opensaml.Configuration;
3536
import org.opensaml.DefaultBootstrap;
@@ -239,7 +240,7 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
239240

240241
StringWriter stringWriter = new StringWriter();
241242
try {
242-
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
243+
DocumentBuilderFactory factory = ParserUtils.getSaferDocumentBuilderFactory();
243244
DocumentBuilder builder = factory.newDocumentBuilder();
244245
Document document = builder.newDocument();
245246
Marshaller out = Configuration.getMarshallerFactory().getMarshaller(spEntityDescriptor);

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
import org.opensaml.saml2.metadata.provider.MetadataProviderException;
7979
import org.opensaml.xml.ConfigurationException;
8080
import org.opensaml.xml.XMLObject;
81-
import org.opensaml.xml.parse.BasicParserPool;
8281
import org.opensaml.xml.security.credential.UsageType;
8382
import org.opensaml.xml.security.keyinfo.KeyInfoHelper;
8483
import org.springframework.stereotype.Component;
@@ -389,7 +388,7 @@ private boolean setup() {
389388
}
390389
}
391390
_idpMetaDataProvider.setRequireValidMetadata(true);
392-
_idpMetaDataProvider.setParserPool(new BasicParserPool());
391+
_idpMetaDataProvider.setParserPool(SAMLUtils.getSaferParserPool());
393392
_idpMetaDataProvider.initialize();
394393
_timer.scheduleAtFixedRate(new MetadataRefreshTask(), 0, _refreshInterval * 1000);
395394

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAMLUtils.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@
4242
import java.security.spec.InvalidKeySpecException;
4343
import java.security.spec.PKCS8EncodedKeySpec;
4444
import java.security.spec.X509EncodedKeySpec;
45+
import java.util.HashMap;
4546
import java.util.List;
47+
import java.util.Map;
4648
import java.util.zip.Deflater;
4749
import java.util.zip.DeflaterOutputStream;
4850

4951
import javax.servlet.http.Cookie;
5052
import javax.servlet.http.HttpServletResponse;
53+
import javax.xml.XMLConstants;
5154
import javax.xml.parsers.DocumentBuilder;
5255
import javax.xml.parsers.DocumentBuilderFactory;
5356
import javax.xml.parsers.ParserConfigurationException;
@@ -56,6 +59,7 @@
5659
import org.apache.cloudstack.api.ApiConstants;
5760
import org.apache.cloudstack.api.response.LoginCmdResponse;
5861
import org.apache.cloudstack.utils.security.CertUtils;
62+
import org.apache.cloudstack.utils.security.ParserUtils;
5963
import org.apache.log4j.Logger;
6064
import org.bouncycastle.operator.OperatorCreationException;
6165
import org.joda.time.DateTime;
@@ -88,6 +92,7 @@
8892
import org.opensaml.xml.io.Unmarshaller;
8993
import org.opensaml.xml.io.UnmarshallerFactory;
9094
import org.opensaml.xml.io.UnmarshallingException;
95+
import org.opensaml.xml.parse.BasicParserPool;
9196
import org.opensaml.xml.signature.SignatureConstants;
9297
import org.opensaml.xml.util.Base64;
9398
import org.opensaml.xml.util.XMLHelper;
@@ -231,7 +236,7 @@ public static String encodeSAMLRequest(XMLObject authnRequest)
231236
public static Response decodeSAMLResponse(String responseMessage)
232237
throws ConfigurationException, ParserConfigurationException,
233238
SAXException, IOException, UnmarshallingException {
234-
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
239+
DocumentBuilderFactory documentBuilderFactory = ParserUtils.getSaferDocumentBuilderFactory();
235240
documentBuilderFactory.setNamespaceAware(true);
236241
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
237242
byte[] base64DecodedResponse = Base64.decode(responseMessage);
@@ -365,4 +370,19 @@ public static X509Certificate generateRandomX509Certificate(KeyPair keyPair) thr
365370
"CN=ApacheCloudStack", "CN=ApacheCloudStack",
366371
3, "SHA256WithRSA");
367372
}
373+
374+
public static BasicParserPool getSaferParserPool() {
375+
final Map<String, Boolean> features = new HashMap<>();
376+
features.put(XMLConstants.FEATURE_SECURE_PROCESSING, true);
377+
features.put("http://apache.org/xml/features/disallow-doctype-decl", true);
378+
features.put("http://xml.org/sax/features/external-general-entities", false);
379+
features.put("http://xml.org/sax/features/external-parameter-entities", false);
380+
features.put("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
381+
final BasicParserPool parserPool = new BasicParserPool();
382+
parserPool.setXincludeAware(false);
383+
parserPool.setIgnoreComments(true);
384+
parserPool.setExpandEntityReferences(false);
385+
parserPool.setBuilderFeatures(features);
386+
return parserPool;
387+
}
368388
}

0 commit comments

Comments
 (0)