diff --git a/open-banking-accelerator/accelerators/ob-is/carbon-home/repository/resources/conf/templates/repository/conf/open-banking.xml.j2 b/open-banking-accelerator/accelerators/ob-is/carbon-home/repository/resources/conf/templates/repository/conf/open-banking.xml.j2
index a635b51e..eae3cf02 100644
--- a/open-banking-accelerator/accelerators/ob-is/carbon-home/repository/resources/conf/templates/repository/conf/open-banking.xml.j2
+++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/repository/resources/conf/templates/repository/conf/open-banking.xml.j2
@@ -152,6 +152,47 @@
{% endif %}
+
+
+ {% if open_banking.identity.ciba.auth_web_link.redirect_endpoint is defined %}
+ {{open_banking.identity.ciba.auth_web_link.redirect_endpoint}}
+ {% else %}
+ ${carbon.protocol}://${carbon.host}:${carbon.management.port}/authenticationendpoint/ciba.jsp
+ {% endif %}
+
+ {% if open_banking.identity.ciba.auth_web_link.allowed_auth_url_parameters is defined %}
+ {% for value in open_banking.identity.ciba.auth_web_link.allowed_auth_url_parameters %}
+ {{value}}
+ {% endfor %}
+ {% else %}
+ client_id
+ scope
+ response_type
+ nonce
+ redirect_uri
+ binding_message
+ {% endif %}
+
+ {% if open_banking.identity.ciba.auth_web_link.notification_provider is defined %}
+ {{open_banking.identity.ciba.auth_web_link.notification_provider}}
+ {% else %}
+ com.wso2.openbanking.accelerator.consent.extensions.ciba.authenticator.weblink.notification.provider.SMSNotificationProvider
+ {% endif %}
+
+
+ {% if open_banking.identity.ciba.auth_web_link.sms_notification.sms_url is defined %}
+ {{open_banking.identity.ciba.auth_web_link.sms_notification.sms_url}}
+ {% else %}
+ ${carbon.protocol}://${carbon.host}:${carbon.management.port}/sample/sms
+ {% endif %}
+
+ {% for header in open_banking.identity.ciba.auth_web_link.sms_notification.header %}
+
+ {% endfor %}
+
+
+
+
{% if open_banking.identity.authentication_webapp.servlet_extension is defined %}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBARequestObjectValidationExtension.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBARequestObjectValidationExtension.java
index 7b0251dc..c66a2c59 100644
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBARequestObjectValidationExtension.java
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBARequestObjectValidationExtension.java
@@ -18,9 +18,15 @@
package com.wso2.openbanking.accelerator.ciba;
+import com.wso2.openbanking.accelerator.common.constant.OpenBankingConstants;
+import com.wso2.openbanking.accelerator.common.exception.ConsentManagementException;
import com.wso2.openbanking.accelerator.common.util.Generated;
+import com.wso2.openbanking.accelerator.consent.mgt.dao.models.DetailedConsentResource;
+import com.wso2.openbanking.accelerator.identity.internal.IdentityExtensionsDataHolder;
import net.minidev.json.JSONObject;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.oauth2.RequestObjectException;
import org.wso2.carbon.identity.oauth2.model.OAuth2Parameters;
import org.wso2.carbon.identity.openidconnect.CIBARequestObjectValidatorImpl;
@@ -34,6 +40,8 @@
*/
public class OBCIBARequestObjectValidationExtension extends CIBARequestObjectValidatorImpl {
+ private static final Log log = LogFactory.getLog(OBCIBARequestObjectValidationExtension.class);
+
/**
* Validations related to clientId, response type, exp, redirect URL, mandatory params,
* issuer, audience are done. Called after signature validation.
@@ -56,10 +64,32 @@ public boolean validateRequestObject(RequestObject initialRequestObject, OAuth2P
if (StringUtils.isEmpty(intent.getAsString(CIBAConstants.VALUE_TAG))) {
throw new RequestObjectException(CIBAConstants.INVALID_REQUEST, CIBAConstants.EMPTY_CONTENT_ERROR);
}
-
+ if (!isAuthorizableConsent(intent.getAsString("value"))) {
+ throw new RequestObjectException(OAuth2ErrorCodes.INVALID_REQUEST,
+ "Consent is not in authorizable state");
+ }
return validateIAMConstraints(initialRequestObject, oAuth2Parameters);
}
+ private boolean isAuthorizableConsent(String consentId) throws RequestObjectException {
+ try {
+ DetailedConsentResource detailedConsent = IdentityExtensionsDataHolder.getInstance()
+ .getConsentCoreService().getDetailedConsent(consentId);
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Consent status for consent_id %s is %s",
+ detailedConsent.getConsentID(), detailedConsent.getCurrentStatus()));
+ }
+ return OpenBankingConstants.AWAITING_AUTHORISATION_STATUS.equalsIgnoreCase(
+ detailedConsent.getCurrentStatus()) ||
+ OpenBankingConstants.AWAITING_FURTHER_AUTHORISATION_STATUS
+ .equalsIgnoreCase(detailedConsent.getCurrentStatus());
+ } catch (ConsentManagementException e) {
+ log.error("Error occurred while fetching consent_id", e);
+ throw new RequestObjectException(OAuth2ErrorCodes.INVALID_REQUEST,
+ "Error occurred while fetching consent_id", e);
+ }
+ }
+
/**
* Validate IAM related logic.
* @param requestObject
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBARequestObjectValidationExtensionTest.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBARequestObjectValidationExtensionTest.java
index 74133c1a..e3cabab2 100644
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBARequestObjectValidationExtensionTest.java
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBARequestObjectValidationExtensionTest.java
@@ -19,26 +19,53 @@
package com.wso2.openbanking.accelerator.ciba;
import com.nimbusds.jwt.JWTClaimsSet;
+import com.wso2.openbanking.accelerator.common.exception.ConsentManagementException;
+import com.wso2.openbanking.accelerator.consent.mgt.dao.models.DetailedConsentResource;
+import com.wso2.openbanking.accelerator.consent.mgt.service.impl.ConsentCoreServiceImpl;
+import com.wso2.openbanking.accelerator.identity.internal.IdentityExtensionsDataHolder;
import net.minidev.json.JSONObject;
import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.testng.PowerMockTestCase;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.wso2.carbon.identity.oauth2.RequestObjectException;
import org.wso2.carbon.identity.oauth2.model.OAuth2Parameters;
import org.wso2.carbon.identity.openidconnect.model.RequestObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Test class for OBCIBARequestObjectValidationExtension.
*/
@PowerMockIgnore("jdk.internal.reflect.*")
-@PrepareForTest({JWTClaimsSet.class, OAuth2Parameters.class, RequestObject.class, JSONObject.class})
+@PrepareForTest({JWTClaimsSet.class, OAuth2Parameters.class, RequestObject.class, JSONObject.class,
+ IdentityExtensionsDataHolder.class})
public class OBCIBARequestObjectValidationExtensionTest extends PowerMockTestCase {
private final String dummyString = "dummyString";
+ private static ConsentCoreServiceImpl consentCoreServiceMock;
+
+ @BeforeClass
+ public void initTest() {
+
+ consentCoreServiceMock = PowerMockito.mock(ConsentCoreServiceImpl.class);
+ }
+
+ @BeforeMethod
+ private void mockStaticClasses() throws ConsentManagementException {
+
+ PowerMockito.mockStatic(IdentityExtensionsDataHolder.class);
+ IdentityExtensionsDataHolder mock = PowerMockito.mock(IdentityExtensionsDataHolder.class);
+ PowerMockito.when(IdentityExtensionsDataHolder.getInstance()).thenReturn(mock);
+ PowerMockito.when(IdentityExtensionsDataHolder.getInstance().getConsentCoreService())
+ .thenReturn(consentCoreServiceMock);
+ }
@Test(expectedExceptions = RequestObjectException.class, description = "Empty intent key")
public void validateRequestObjectInvalidIntentKeyTest() throws Exception {
@@ -61,6 +88,30 @@ public void validateRequestObjectInvalidIntentKeyTest() throws Exception {
}
+ @Test(expectedExceptions = RequestObjectException.class, description = "Consent is not in authorizable state")
+ public void validateRequestObjectInvalidConsentIdTest() throws Exception {
+
+ OBCIBARequestObjectValidationExtensionMock obcibaRequestObjectValidationExtensionMock =
+ new OBCIBARequestObjectValidationExtensionMock();
+
+ JSONObject intent = mock(JSONObject.class);
+
+ RequestObject requestObject = mock(RequestObject.class);
+ OAuth2Parameters oAuth2Parameters = mock(OAuth2Parameters.class);
+ JWTClaimsSet claimsSet = Mockito.mock(JWTClaimsSet.class);
+
+ Mockito.when(requestObject.getClaimsSet()).thenReturn(claimsSet);
+ Mockito.when(claimsSet.getJSONObjectClaim(Mockito.anyString())).thenReturn(intent);
+ when(intent.getAsString("value")).thenReturn(dummyString);
+
+ DetailedConsentResource consentResourceMock = mock(DetailedConsentResource.class);
+ doReturn("authorised").when(consentResourceMock).getCurrentStatus();
+ doReturn(consentResourceMock).when(consentCoreServiceMock).getDetailedConsent(anyString());
+
+ obcibaRequestObjectValidationExtensionMock.validateRequestObject(requestObject, oAuth2Parameters);
+
+ }
+
@Test(description = "success scenario")
public void validateRequestObjectValidObjectTest() throws Exception {
@@ -78,6 +129,10 @@ public void validateRequestObjectValidObjectTest() throws Exception {
when(intent.getAsString("value")).thenReturn(dummyString);
+ DetailedConsentResource consentResourceMock = mock(DetailedConsentResource.class);
+ doReturn("awaitingAuthorisation").when(consentResourceMock).getCurrentStatus();
+ doReturn(consentResourceMock).when(consentCoreServiceMock).getDetailedConsent(anyString());
+
obcibaRequestObjectValidationExtensionMock.validateRequestObject(requestObject, oAuth2Parameters);
}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/config/OpenBankingConfigParser.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/config/OpenBankingConfigParser.java
index 9debdae1..511e3d90 100644
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/config/OpenBankingConfigParser.java
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/config/OpenBankingConfigParser.java
@@ -1489,4 +1489,97 @@ public boolean isNbfClaimMandatory() {
getConfigElementFromKey(OpenBankingConstants.MANDATE_NBF_CLAIM)).trim());
}
+ /**
+ * Method to get the CIBA authentication redirect endpoint configuration.
+ *
+ * @return ciba redirect endpoint
+ */
+ public String getCibaAuthenticationRedirectEndpoint() {
+ return getConfigElementFromKey(OpenBankingConstants.CIBA_AUTHENTICATION_REDIRECT_ENDPOINT) == null ?
+ "" : ((String) getConfigElementFromKey(
+ OpenBankingConstants.CIBA_AUTHENTICATION_REDIRECT_ENDPOINT)).trim();
+ }
+
+ /**
+ * Method to get the CIBA web link allowed parameters.
+ *
+ * @return list of allowed parameters
+ */
+ public List getCibaWebLinkAllowedParams() {
+
+ List allowedParamsList = new ArrayList<>();
+ Object configElementFromKey = getConfigElementFromKey(OpenBankingConstants.CIBA_WEB_LINK_ALLOWED_PARAMETERS);
+ if (configElementFromKey instanceof List) {
+ allowedParamsList = (List) configElementFromKey;
+ } else {
+ allowedParamsList.add(configElementFromKey.toString());
+ }
+ return allowedParamsList;
+ }
+
+ /**
+ * Method to get the CIBA notification Provider
+ *
+ * @return CIBA notification Provider
+ */
+ public String getCibaWebLinkNotificationProvider() {
+
+ return getConfigElementFromKey(OpenBankingConstants.CIBA_NOTIFICATION_PROVIDER) == null ?
+ "" : ((String) getConfigElementFromKey(OpenBankingConstants.CIBA_NOTIFICATION_PROVIDER)).trim();
+ }
+
+ /**
+ * Method to get the CIBA SMS notification service URL
+ *
+ * @return sms service URL
+ */
+ public String getCibaWebLinkSMSNotificationServiceURL() {
+
+ return getConfigElementFromKey(OpenBankingConstants.CIBA_WEB_LINK_NOTIFICATION_SMS_SERVICE_URL) == null ?
+ "" : ((String) getConfigElementFromKey(
+ OpenBankingConstants.CIBA_WEB_LINK_NOTIFICATION_SMS_SERVICE_URL)).trim();
+ }
+
+ /**
+ * Method to get the CIBA web link SMS notification request headers
+ *
+ * @return A map of header name and values
+ */
+ public Map getCibaWebLinkSMSNotificationRequestHeaders() {
+
+ Map headersMap = new HashMap<>();
+ OMElement identityElement = rootElement.getFirstChildWithName(
+ new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.IDENTITY_CONFIG_TAG));
+
+ if (identityElement != null) {
+ OMElement cibaElement = identityElement.getFirstChildWithName(
+ new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.CIBA_CONFIG_TAG));
+
+ if (cibaElement != null) {
+ OMElement authWebLinkElement = cibaElement.getFirstChildWithName(
+ new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.AUTH_WEB_LINK_CONFIG_TAG));
+
+ if (authWebLinkElement != null) {
+ OMElement smsElement = authWebLinkElement.getFirstChildWithName(
+ new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.SMS_CONFIG_TAG));
+
+ if (smsElement != null) {
+ OMElement headersElement = smsElement.getFirstChildWithName(
+ new QName(OpenBankingConstants.OB_CONFIG_QNAME,
+ OpenBankingConstants.HEADERS_CONFIG_TAG));
+ if (headersElement != null) {
+ Iterator headerElements = headersElement.getChildElements();
+ while (headerElements.hasNext()) {
+ OMElement headerElement = (OMElement) headerElements.next();
+ String headerName = headerElement.getAttributeValue(new QName("name"));
+ String headerValue = headerElement.getAttributeValue(new QName("value"));
+ headersMap.put(headerName, headerValue);
+ }
+ }
+ }
+ }
+ }
+ }
+ return headersMap;
+ }
}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/constant/OpenBankingConstants.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/constant/OpenBankingConstants.java
index 6cf4d04a..952589a2 100644
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/constant/OpenBankingConstants.java
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/constant/OpenBankingConstants.java
@@ -270,5 +270,33 @@ public class OpenBankingConstants {
public static final String DOT_SEPARATOR = ".";
public static final String MANDATE_NBF_CLAIM = "Identity.RequestObject.MandateNBF";
+ // CIBA Constants
+ public static final String CIBA_AUTHENTICATION_REDIRECT_ENDPOINT =
+ "Identity.CIBA.AuthWebLink.AuthenticationRedirectEndpoint";
+ public static final String CIBA_WEB_LINK_ALLOWED_PARAMETERS =
+ "Identity.CIBA.AuthWebLink.AllowedAuthURLParams.Value";
+ public static final String CIBA_NOTIFICATION_PROVIDER = "Identity.CIBA.AuthWebLink.NotificationProvider";
+ public static final String AUTH_REQ_ID = "auth_req_id";
+ public static final String CIBA_WEB_AUTH_LINK_PARAM = "ciba_web_auth_link";
+ public static final String CIBA_AUTH_CODE_RESPONSE_TYPE = "cibaAuthCode";
+
+ // CIBA SMS Constants
+ public static final String CIBA_WEB_LINK_NOTIFICATION_SMS_SERVICE_URL =
+ "Identity.CIBA.AuthWebLink.SMS.SMSUrl";
+ public static final String IDENTITY_CONFIG_TAG = "Identity";
+ public static final String CIBA_CONFIG_TAG = "CIBA";
+ public static final String AUTH_WEB_LINK_CONFIG_TAG = "AuthWebLink";
+ public static final String SMS_CONFIG_TAG = "SMS";
+ public static final String HEADERS_CONFIG_TAG = "Headers";
+
+ // Accelerator default consent statuses
+ public static final String AUTHORISED_STATUS = "authorised";
+ public static final String REJECTED_STATUS = "rejected";
+ public static final String AWAITING_AUTHORISATION_STATUS = "awaitingAuthorisation";
+ public static final String AWAITING_FURTHER_AUTHORISATION_STATUS = "awaitingFurtherAuthorisation";
+ public static final String CREATED_AUTHORISATION_RESOURCE_STATE = "created";
+ public static final String MULTI_AUTH_AUTHORISATION_TYPE = "multi-authorization";
+ public static final String CARBON_SUPER_TENANT_DOMAIN = "@carbon.super";
+
}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/util/CarbonUtils.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/util/CarbonUtils.java
index d25f6461..a8bedac3 100644
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/util/CarbonUtils.java
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/util/CarbonUtils.java
@@ -71,7 +71,7 @@ public static String getCarbonHome() {
@Generated(message = "Ignoring because ServerConfiguration cannot be mocked")
public static String getCarbonPort() {
- int offset = Integer.parseInt(ServerConfiguration.getInstance().getFirstProperty("Offset"));
+ int offset = Integer.parseInt(ServerConfiguration.getInstance().getFirstProperty("Ports.Offset"));
return String.valueOf(9443 + offset);
}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/test/java/com/wso2/openbanking/accelerator/common/test/OBConfigParserTests.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/test/java/com/wso2/openbanking/accelerator/common/test/OBConfigParserTests.java
index cba3464d..ddb56045 100644
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/test/java/com/wso2/openbanking/accelerator/common/test/OBConfigParserTests.java
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/test/java/com/wso2/openbanking/accelerator/common/test/OBConfigParserTests.java
@@ -476,4 +476,32 @@ public void testNbfClaimMandatory() {
boolean nbfClaimMandatory = openBankingConfigParser.isNbfClaimMandatory();
Assert.assertTrue(nbfClaimMandatory);
}
+
+ @Test(priority = 37)
+ public void testCibaWebLinkConfigs() {
+ String dummyConfigFile = absolutePathForTestResources + "/open-banking.xml";
+ OpenBankingConfigParser openBankingConfigParser = OpenBankingConfigParser.getInstance(dummyConfigFile);
+
+ List cibaWebLinkAllowedParams = openBankingConfigParser.getCibaWebLinkAllowedParams();
+ Assert.assertEquals(cibaWebLinkAllowedParams.size(), 6);
+ Assert.assertEquals(cibaWebLinkAllowedParams.get(0), "client_id");
+ Assert.assertEquals(openBankingConfigParser.getCibaWebLinkNotificationProvider(),
+ "com.wso2.openbanking.accelerator.consent.extensions.ciba.authenticator.weblink." +
+ "notification.provider.SMSNotificationProvider");
+ Assert.assertEquals(openBankingConfigParser.getCibaAuthenticationRedirectEndpoint(),
+ "https://localhost:9446/authenticationendpoint/ciba.jsp");
+ }
+
+ @Test(priority = 38)
+ public void testCibaWebLinkSMSConfigs() {
+ String dummyConfigFile = absolutePathForTestResources + "/open-banking.xml";
+ OpenBankingConfigParser openBankingConfigParser = OpenBankingConfigParser.getInstance(dummyConfigFile);
+
+ String cibaWebLinkAllowedParams = openBankingConfigParser.getCibaWebLinkSMSNotificationServiceURL();
+ Assert.assertEquals(cibaWebLinkAllowedParams, "https://localhost:9446/sample/sms");
+ Map headerMap = openBankingConfigParser.getCibaWebLinkSMSNotificationRequestHeaders();
+ Assert.assertEquals(headerMap.get("Authorization"), "abc");
+ Assert.assertEquals(headerMap.get("Accept"), "application/json");
+ }
+
}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/test/resources/open-banking.xml b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/test/resources/open-banking.xml
index 3d50008b..ec7fba9c 100644
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/test/resources/open-banking.xml
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/test/resources/open-banking.xml
@@ -45,6 +45,27 @@
sampleServletExtension
+
+
+ https://localhost:9446/authenticationendpoint/ciba.jsp
+
+ client_id
+ scope
+ response_type
+ nonce
+ redirect_uri
+ binding_message
+
+ com.wso2.openbanking.accelerator.consent.extensions.ciba.authenticator.weblink.notification.provider.SMSNotificationProvider
+
+ https://localhost:9446/sample/sms
+
+
+
+
+
+
+
sampleCIBAServletExtension
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandler.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandler.java
new file mode 100644
index 00000000..2b72cd22
--- /dev/null
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandler.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.wso2.openbanking.accelerator.identity.auth.extensions.response.handler;
+
+import com.wso2.openbanking.accelerator.common.config.OpenBankingConfigParser;
+import com.wso2.openbanking.accelerator.common.constant.OpenBankingConstants;
+import com.wso2.openbanking.accelerator.common.exception.ConsentManagementException;
+import com.wso2.openbanking.accelerator.identity.internal.IdentityExtensionsDataHolder;
+import org.apache.commons.lang3.StringUtils;
+import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
+import org.wso2.carbon.identity.oauth.ciba.dao.CibaDAOFactory;
+import org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException;
+import org.wso2.carbon.identity.oauth.ciba.handlers.CibaResponseTypeHandler;
+import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
+import org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext;
+import org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO;
+import org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO;
+
+import java.util.ArrayList;
+
+/**
+ * Handles authorize requests with CibaAuthCode as response type.
+ */
+public class OBCibaResponseTypeHandler extends CibaResponseTypeHandler {
+
+ @Override
+ public OAuth2AuthorizeRespDTO issue(OAuthAuthzReqMessageContext oauthAuthzMsgCtx) throws IdentityOAuth2Exception {
+
+ OAuth2AuthorizeReqDTO authorizationReqDTO = oauthAuthzMsgCtx.getAuthorizationReqDTO();
+ try {
+ // Assigning authenticated user for the request that to be persisted.
+ AuthenticatedUser cibaAuthenticatedUser = authorizationReqDTO.getUser();
+ // Assigning the authentication status that to be persisted.
+
+ ArrayList consentIds = IdentityExtensionsDataHolder.getInstance().getConsentCoreService()
+ .getConsentIdByConsentAttributeNameAndValue(OpenBankingConstants.AUTH_REQ_ID,
+ authorizationReqDTO.getNonce());
+
+ if (!consentIds.isEmpty()) {
+ if (IdentityExtensionsDataHolder.getInstance().getConsentCoreService().getDetailedConsent(
+ consentIds.get(0)).getCurrentStatus().equals(OpenBankingConstants.AUTHORISED_STATUS)) {
+ // Update successful authentication.
+ String authCodeKey = CibaDAOFactory.getInstance().getCibaAuthMgtDAO()
+ .getCibaAuthCodeKey(authorizationReqDTO.getNonce());
+ CibaDAOFactory.getInstance().getCibaAuthMgtDAO()
+ .persistAuthenticationSuccess(authCodeKey, cibaAuthenticatedUser);
+ }
+ }
+ String callbackURL = OpenBankingConfigParser.getInstance().getCibaAuthenticationRedirectEndpoint();
+ if (StringUtils.isNotEmpty(callbackURL)) {
+ OAuth2AuthorizeRespDTO respDTO = new OAuth2AuthorizeRespDTO();
+ respDTO.setCallbackURI(callbackURL);
+ return respDTO;
+ } else {
+ throw new IdentityOAuth2Exception("Error occurred while retrieving CIBA redirect endpoint.");
+ }
+ } catch (CibaCoreException e) {
+ throw new IdentityOAuth2Exception("Error occurred in persisting authenticated user and authentication " +
+ "status for the request made by client: " + authorizationReqDTO.getConsumerKey(), e);
+ } catch (ConsentManagementException e) {
+ throw new IdentityOAuth2Exception("Error occurred in retrieving auth_req_id ", e);
+ }
+ }
+}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/validator/OBCibaResponseTypeValidator.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/validator/OBCibaResponseTypeValidator.java
new file mode 100644
index 00000000..d41a98f5
--- /dev/null
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/validator/OBCibaResponseTypeValidator.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package com.wso2.openbanking.accelerator.identity.auth.extensions.response.validator;
+
+import com.wso2.openbanking.accelerator.common.util.Generated;
+import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
+import org.wso2.carbon.identity.oauth.ciba.handlers.CibaResponseTypeValidator;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Validates authorize responses with cibaAuthCode as response type.
+ */
+@Generated(message = "Ignoring since method do not contain a logic")
+public class OBCibaResponseTypeValidator extends CibaResponseTypeValidator {
+
+ @Override
+ @Generated(message = "Ignoring since method do not contain a logic")
+ public void validateContentType(HttpServletRequest request) throws OAuthProblemException {
+ // Overriding content type validation
+ // This is for browser flow with cibaAuthCode response type. (Web-Auth link scenario)
+ }
+
+}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/test/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandlerTest.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/test/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandlerTest.java
new file mode 100644
index 00000000..50815ea6
--- /dev/null
+++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/test/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandlerTest.java
@@ -0,0 +1,196 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.wso2.openbanking.accelerator.identity.auth.extensions.response.handler;
+
+import com.wso2.openbanking.accelerator.common.config.OpenBankingConfigParser;
+import com.wso2.openbanking.accelerator.common.exception.ConsentManagementException;
+import com.wso2.openbanking.accelerator.consent.mgt.dao.models.DetailedConsentResource;
+import com.wso2.openbanking.accelerator.consent.mgt.service.impl.ConsentCoreServiceImpl;
+import com.wso2.openbanking.accelerator.identity.internal.IdentityExtensionsDataHolder;
+import org.mockito.Mock;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.testng.PowerMockTestCase;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
+import org.wso2.carbon.identity.oauth.ciba.dao.CibaDAOFactory;
+import org.wso2.carbon.identity.oauth.ciba.dao.CibaMgtDAO;
+import org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException;
+import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
+import org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext;
+import org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO;
+
+import java.util.ArrayList;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+
+@PowerMockIgnore("jdk.internal.reflect.*")
+@PrepareForTest({OpenBankingConfigParser.class, IdentityExtensionsDataHolder.class, CibaDAOFactory.class})
+public class OBCibaResponseTypeHandlerTest extends PowerMockTestCase {
+
+ @Mock
+ ConsentCoreServiceImpl consentCoreServiceMock;
+ @Mock
+ OpenBankingConfigParser openBankingConfigParser;
+
+ @Mock
+ CibaDAOFactory cibaDAOFactory;
+
+ @BeforeMethod
+ private void mockStaticClasses() throws ConsentManagementException {
+
+ PowerMockito.mockStatic(IdentityExtensionsDataHolder.class);
+ IdentityExtensionsDataHolder mock = PowerMockito.mock(IdentityExtensionsDataHolder.class);
+ PowerMockito.when(IdentityExtensionsDataHolder.getInstance()).thenReturn(mock);
+ PowerMockito.when(IdentityExtensionsDataHolder.getInstance().getConsentCoreService())
+ .thenReturn(consentCoreServiceMock);
+
+ PowerMockito.mockStatic(OpenBankingConfigParser.class);
+ openBankingConfigParser = PowerMockito.mock(OpenBankingConfigParser.class);
+ PowerMockito.when(OpenBankingConfigParser.getInstance())
+ .thenReturn(openBankingConfigParser);
+
+ PowerMockito.mockStatic(CibaDAOFactory.class);
+ cibaDAOFactory = PowerMockito.mock(CibaDAOFactory.class);
+ PowerMockito.when(CibaDAOFactory.getInstance())
+ .thenReturn(cibaDAOFactory);
+ }
+
+ @Test()
+ public void obCibaResponseTypeHandlerSuccessTest() throws Exception {
+
+ PowerMockito.when(OpenBankingConfigParser.getInstance().getCibaAuthenticationRedirectEndpoint())
+ .thenReturn("testURL");
+ OBCibaResponseTypeHandler obCibaResponseTypeHandler = new OBCibaResponseTypeHandler();
+ OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext = mock(OAuthAuthzReqMessageContext.class);
+ AuthenticatedUser cibaAuthenticatedUser = mock(AuthenticatedUser.class);
+ OAuth2AuthorizeReqDTO authorizationReqDTO = mock(OAuth2AuthorizeReqDTO.class);
+ doReturn(authorizationReqDTO).when(oAuthAuthzReqMessageContext).getAuthorizationReqDTO();
+ doReturn(cibaAuthenticatedUser).when(authorizationReqDTO).getUser();
+ obCibaResponseTypeHandler.issue(oAuthAuthzReqMessageContext);
+
+ }
+
+ @Test()
+ public void obCibaResponseTypeHandlerValidConsentIdTest() throws Exception {
+
+ PowerMockito.when(OpenBankingConfigParser.getInstance().getCibaAuthenticationRedirectEndpoint())
+ .thenReturn("testURL");
+ OBCibaResponseTypeHandler obCibaResponseTypeHandler = new OBCibaResponseTypeHandler();
+ OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext = mock(OAuthAuthzReqMessageContext.class);
+ AuthenticatedUser cibaAuthenticatedUser = mock(AuthenticatedUser.class);
+ OAuth2AuthorizeReqDTO authorizationReqDTO = mock(OAuth2AuthorizeReqDTO.class);
+ doReturn(authorizationReqDTO).when(oAuthAuthzReqMessageContext).getAuthorizationReqDTO();
+ doReturn(cibaAuthenticatedUser).when(authorizationReqDTO).getUser();
+ ArrayList