├── README.md ├── .travis.yml ├── .github ├── ISSUE_TEMPLATE │ └── config.yml └── workflows │ └── pr-builder.yml ├── codecov.yml ├── .gitignore ├── issue_template.md ├── components ├── org.wso2.carbon.identity.conditional.auth.functions.common │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── common │ │ ├── model │ │ ├── JsUtils.java │ │ ├── graaljs │ │ │ └── JsGraalUtils.java │ │ ├── nashorn │ │ │ └── JsNashornUtils.java │ │ ├── openjdk │ │ │ └── nashorn │ │ │ │ └── JsOpenJdkNashornUtils.java │ │ └── JsUtilsProvider.java │ │ ├── auth │ │ ├── Credentials.java │ │ ├── AuthenticationManager.java │ │ ├── AuthenticationFactory.java │ │ ├── BasicAuthenticationManager.java │ │ ├── BasicUserPrincipal.java │ │ └── UsernamePasswordCredentials.java │ │ └── internal │ │ ├── FunctionsDataHolder.java │ │ └── FunctionsServiceComponent.java ├── org.wso2.carbon.identity.conditional.auth.functions.elk │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── queries │ │ │ │ └── risk_profile_query.json │ │ └── java │ │ │ └── org │ │ │ └── wso2 │ │ │ └── carbon │ │ │ └── identity │ │ │ └── conditional │ │ │ └── auth │ │ │ └── functions │ │ │ └── elk │ │ │ ├── CallElasticFunction.java │ │ │ └── internal │ │ │ └── ElasticFunctionsServiceHolder.java │ │ └── test │ │ └── resources │ │ └── testng.xml ├── org.wso2.carbon.identity.conditional.auth.functions.jwt.decode │ └── src │ │ ├── test │ │ └── resources │ │ │ └── testng.xml │ │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── jwt │ │ └── decode │ │ ├── JwtDecode.java │ │ └── internal │ │ └── JwtDecodeServiceHolder.java ├── org.wso2.carbon.identity.conditional.auth.functions.choreo │ └── src │ │ ├── test │ │ └── resources │ │ │ ├── org │ │ │ └── wso2 │ │ │ │ └── carbon │ │ │ │ └── identity │ │ │ │ └── conditional │ │ │ │ └── auth │ │ │ │ └── functions │ │ │ │ └── choreo │ │ │ │ └── choreo-payload.json │ │ │ └── testng.xml │ │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── choreo │ │ ├── cache │ │ └── ChoreoAccessTokenCache.java │ │ ├── CallChoreoFunction.java │ │ └── listener │ │ └── ChoreoAxis2ConfigurationContextObserver.java ├── org.wso2.carbon.identity.conditional.auth.functions.http │ └── src │ │ ├── test │ │ └── resources │ │ │ ├── org │ │ │ └── wso2 │ │ │ │ └── carbon │ │ │ │ └── identity │ │ │ │ └── conditional │ │ │ │ └── auth │ │ │ │ └── functions │ │ │ │ └── http │ │ │ │ ├── http-get-response.json │ │ │ │ └── http-post-payload.json │ │ │ └── testng.xml │ │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── http │ │ ├── HTTPGetFunction.java │ │ ├── util │ │ ├── AuthConfig.java │ │ ├── HTTPConstants.java │ │ ├── AuthConfigModel.java │ │ ├── BearerAuthConfig.java │ │ ├── ApiKeyAuthConfig.java │ │ ├── BasicAuthConfig.java │ │ └── HttpUtil.java │ │ ├── HTTPPostFunction.java │ │ ├── GetCookieFunction.java │ │ ├── cache │ │ └── APIAccessTokenCache.java │ │ ├── SetCookieFunction.java │ │ └── internal │ │ └── HTTPFunctionsServiceHolder.java ├── org.wso2.carbon.identity.conditional.auth.functions.analytics │ └── src │ │ ├── test │ │ └── resources │ │ │ ├── org │ │ │ └── wso2 │ │ │ │ └── carbon │ │ │ │ └── identity │ │ │ │ └── conditional │ │ │ │ └── auth │ │ │ │ └── functions │ │ │ │ └── analytics │ │ │ │ └── analytics-payload.json │ │ │ └── testng.xml │ │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── analytics │ │ ├── PublishToAnalyticsFunction.java │ │ ├── CallAnalyticsFunction.java │ │ ├── listener │ │ └── AnalyticsAxis2ConfigurationContextObserver.java │ │ └── internal │ │ └── AnalyticsFunctionsServiceHolder.java ├── org.wso2.carbon.identity.conditional.auth.functions.utils │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── wso2 │ │ │ └── carbon │ │ │ └── identity │ │ │ └── conditional │ │ │ └── auth │ │ │ └── functions │ │ │ └── utils │ │ │ ├── GetMaskedValueFunction.java │ │ │ ├── FilterAuthenticatorsFunction.java │ │ │ ├── GetMaskedValueFunctionImpl.java │ │ │ ├── ResolveMultiAttributeLoginIdentifierFunction.java │ │ │ ├── internal │ │ │ └── UtilsFunctionServiceHolder.java │ │ │ ├── ResolveMultiAttributeLoginIdentifierFunctionImpl.java │ │ │ └── FilterAuthenticatorsFunctionImpl.java │ │ └── test │ │ └── resources │ │ ├── testng.xml │ │ ├── dbscripts │ │ └── h2.sql │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── utils │ │ └── get-masked-value-sp.xml ├── org.wso2.carbon.identity.conditional.auth.functions.user │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── wso2 │ │ │ └── carbon │ │ │ └── identity │ │ │ └── conditional │ │ │ └── auth │ │ │ └── functions │ │ │ └── user │ │ │ ├── PromptIdentifierFunction.java │ │ │ ├── exception │ │ │ ├── UserSessionRetrievalException.java │ │ │ └── UserSessionTerminationException.java │ │ │ ├── MicrosoftEmailVerificationFunction.java │ │ │ ├── RemoveAssociatedLocalUserFunction.java │ │ │ ├── GetAssociatedLocalUserFunction.java │ │ │ ├── UpdateUserPasswordFunction.java │ │ │ ├── model │ │ │ ├── JsUserAgent.java │ │ │ ├── JsApplication.java │ │ │ ├── JsUserSession.java │ │ │ ├── JsWrapperFactory.java │ │ │ ├── JsWrapperBaseFactory.java │ │ │ ├── JsGraalWrapperFactory.java │ │ │ ├── nashorn │ │ │ │ ├── JsNashornApplication.java │ │ │ │ └── JsNashornUserAgent.java │ │ │ ├── openjdk │ │ │ │ └── nashorn │ │ │ │ │ ├── JsOpenJdkNashornApplication.java │ │ │ │ │ └── JsOpenJdkNashornUserAgent.java │ │ │ ├── JsOpenJdkNashornWrapperFactory.java │ │ │ └── graaljs │ │ │ │ └── JsGraalApplication.java │ │ │ ├── GetUserSessionsFunction.java │ │ │ ├── CheckSessionExistenceFunction.java │ │ │ ├── GetAuthenticatedApplicationsFunction.java │ │ │ ├── GetAuthenticatedApplicationsV2Function.java │ │ │ ├── TerminateUserSession.java │ │ │ ├── AssignUserRolesV2Function.java │ │ │ ├── RemoveUserRolesV2Function.java │ │ │ ├── AssignUserRolesFunction.java │ │ │ ├── RemoveUserRolesFunction.java │ │ │ ├── IsMemberOfAnyOfGroupsFunction.java │ │ │ ├── HasAnyOfTheRolesV2Function.java │ │ │ ├── HasRoleFunction.java │ │ │ ├── HasAnyOfTheRolesFunction.java │ │ │ ├── SetAccountAssociationToLocalUser.java │ │ │ ├── IsAnyOfTheRolesAssignedToUserFunction.java │ │ │ └── GetAuthenticatedApplicationsV2FunctionImpl.java │ │ └── test │ │ └── resources │ │ └── dbscripts │ │ └── h2.sql ├── org.wso2.carbon.identity.conditional.auth.functions.test.utils │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── test │ │ └── utils │ │ ├── api │ │ └── SubjectCallback.java │ │ └── sequence │ │ ├── ResponseValidator.java │ │ └── JsTestException.java ├── org.wso2.carbon.identity.conditional.auth.functions.session │ └── src │ │ ├── test │ │ ├── resources │ │ │ └── testng.xml │ │ └── java │ │ │ └── org │ │ │ └── wso2 │ │ │ └── carbon │ │ │ └── identity │ │ │ └── conditional │ │ │ └── auth │ │ │ └── functions │ │ │ └── session │ │ │ └── test │ │ │ ├── TestUtils.java │ │ │ └── SessionModelTest.java │ │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── session │ │ ├── exception │ │ └── SessionValidationException.java │ │ ├── function │ │ ├── ExecuteActionFunction.java │ │ ├── GetUserSessionDataFunction.java │ │ └── IsWithinSessionLimitFunction.java │ │ └── model │ │ └── Session.java ├── org.wso2.carbon.identity.conditional.auth.functions.user.store │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── identity │ │ └── conditional │ │ └── auth │ │ └── functions │ │ └── user │ │ └── store │ │ ├── GetUserWithClaimValues.java │ │ ├── GetUserWithClaimValuesV2Function.java │ │ ├── GetUserWithClaimValuesV2FunctionImpl.java │ │ ├── GetUsersWithClaimValuesFunctionImpl.java │ │ ├── internal │ │ └── UserStoreFunctionsServiceHolder.java │ │ └── GetUsersWithClaimValuesFunction.java └── org.wso2.carbon.identity.conditional.auth.functions.notification │ └── src │ ├── test │ └── resources │ │ ├── testng.xml │ │ └── dbscripts │ │ └── h2.sql │ └── main │ └── java │ └── org │ └── wso2 │ └── carbon │ └── identity │ └── conditional │ └── auth │ └── functions │ └── notification │ ├── SendEmailFunction.java │ └── internal │ └── NotificationFunctionServiceHolder.java └── pull_request_template.md /README.md: -------------------------------------------------------------------------------- 1 | # identity-conditional-auth-functions -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk8 4 | cache: 5 | directories: 6 | - .autoconf 7 | - $HOME/.m2 8 | script: mvn clean install 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Report an issue 4 | url: https://github.com/wso2/product-is/issues/new/choose 5 | about: Issue creation for this component is done in the product-is repo. Click "Open" to continue. 6 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | require_ci_to_pass: yes 3 | notify: 4 | wait_for_ci: yes 5 | max_report_age: false 6 | 7 | coverage: 8 | status: 9 | project: off 10 | patch: off 11 | 12 | flag_management: 13 | default_rules: 14 | carryforward: true 15 | individual_flags: 16 | - name: unit 17 | statuses: 18 | - type: project 19 | target: auto 20 | threshold: null 21 | - type: patch 22 | target: 80% 23 | threshold: 40% 24 | 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .classpath 3 | .settings 4 | .project 5 | *.iml 6 | *.iws 7 | *.ipr 8 | .idea 9 | .DS_Store 10 | 11 | # Mobile Tools for Java (J2ME) 12 | .mtj.tmp/ 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | 23 | # Log file 24 | *.log 25 | 26 | # BlueJ files 27 | *.ctxt 28 | 29 | 30 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 31 | hs_err_pid* 32 | 33 | # Ignore everything in this directory 34 | target -------------------------------------------------------------------------------- /issue_template.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | 4 | **Suggested Labels:** 5 | 6 | 7 | **Suggested Assignees:** 8 | 9 | 10 | **Affected Product Version:** 11 | 12 | **OS, DB, other environment details and versions:** 13 | 14 | **Steps to reproduce:** 15 | 16 | 17 | **Related Issues:** 18 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/model/JsUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.model; 20 | 21 | public interface JsUtils { 22 | 23 | boolean isArray(Object obj); 24 | } 25 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/main/resources/queries/risk_profile_query.json: -------------------------------------------------------------------------------- 1 | { 2 | "query": { 3 | "bool": { 4 | "must": [ 5 | { 6 | "match": { 7 | "username.keyword": "[ES_QUERY_PARAM_USERNAME]" 8 | } 9 | } 10 | ], 11 | "filter": [ 12 | { 13 | "range": { 14 | "@timestamp": { 15 | "gte": "now-[ES_QUERY_PARAM_DURATION]" 16 | } 17 | } 18 | } 19 | ] 20 | } 21 | }, 22 | "aggs": { 23 | "risk_score": { 24 | "scripted_metric": { 25 | "init_script": "state.sum = [];", 26 | "map_script": "[ES_QUERY_PARAM_LOGIC]", 27 | "combine_script": "int sum = 0; for (t in state.sum) { sum += t } return sum", 28 | "reduce_script": "int sum = 0; for (a in states) { sum += a } return sum > [ES_QUERY_PARAM_THRESHOLD] ? 1 : 0" 29 | } 30 | } 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.jwt.decode/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/test/resources/org/wso2/carbon/identity/conditional/auth/functions/choreo/choreo-payload.json: -------------------------------------------------------------------------------- 1 | { 2 | "stringKey": "stringValue", 3 | "numberKey": 123, 4 | "booleanKey": true, 5 | "arrayKey": [ 6 | "arrayString", 7 | 456, 8 | false, 9 | { 10 | "nestedObjectInArrayKey": "nestedObjectValue", 11 | "nestedArrayInArrayKey": ["nestedArrayValue1", "nestedArrayValue2"] 12 | } 13 | ], 14 | "objectKey": { 15 | "objectStringKey": "objectStringValue", 16 | "objectNumberKey": 789, 17 | "objectBooleanKey": false, 18 | "nestedObjectKey": { 19 | "nestedObjectStringKey": "nestedObjectStringValue", 20 | "nestedObjectArrayKey": [ 21 | "nestedArrayValue1", 22 | 101112, 23 | true 24 | ] 25 | }, 26 | "arrayOfObjectsKey": [ 27 | { 28 | "arrayOfObjectsStringKey": "arrayOfObjectsStringValue1", 29 | "arrayOfObjectsNumberKey": 131415, 30 | "arrayOfObjectsBooleanKey": true 31 | }, 32 | { 33 | "arrayOfObjectsStringKey": "arrayOfObjectsStringValue2", 34 | "arrayOfObjectsNumberKey": 161718, 35 | "arrayOfObjectsBooleanKey": false 36 | } 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/resources/org/wso2/carbon/identity/conditional/auth/functions/http/http-get-response.json: -------------------------------------------------------------------------------- 1 | { 2 | "stringKey": "stringValue", 3 | "numberKey": 123, 4 | "booleanKey": true, 5 | "arrayKey": [ 6 | "arrayString", 7 | 456, 8 | false, 9 | { 10 | "nestedObjectInArrayKey": "nestedObjectValue", 11 | "nestedArrayInArrayKey": ["nestedArrayValue1", "nestedArrayValue2"] 12 | } 13 | ], 14 | "objectKey": { 15 | "objectStringKey": "objectStringValue", 16 | "objectNumberKey": 789, 17 | "objectBooleanKey": false, 18 | "nestedObjectKey": { 19 | "nestedObjectStringKey": "nestedObjectStringValue", 20 | "nestedObjectArrayKey": [ 21 | "nestedArrayValue1", 22 | 101112, 23 | true 24 | ] 25 | }, 26 | "arrayOfObjectsKey": [ 27 | { 28 | "arrayOfObjectsStringKey": "arrayOfObjectsStringValue1", 29 | "arrayOfObjectsNumberKey": 131415, 30 | "arrayOfObjectsBooleanKey": true 31 | }, 32 | { 33 | "arrayOfObjectsStringKey": "arrayOfObjectsStringValue2", 34 | "arrayOfObjectsNumberKey": 161718, 35 | "arrayOfObjectsBooleanKey": false 36 | } 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/resources/org/wso2/carbon/identity/conditional/auth/functions/http/http-post-payload.json: -------------------------------------------------------------------------------- 1 | { 2 | "stringKey": "stringValue", 3 | "numberKey": 123, 4 | "booleanKey": true, 5 | "arrayKey": [ 6 | "arrayString", 7 | 456, 8 | false, 9 | { 10 | "nestedObjectInArrayKey": "nestedObjectValue", 11 | "nestedArrayInArrayKey": ["nestedArrayValue1", "nestedArrayValue2"] 12 | } 13 | ], 14 | "objectKey": { 15 | "objectStringKey": "objectStringValue", 16 | "objectNumberKey": 789, 17 | "objectBooleanKey": false, 18 | "nestedObjectKey": { 19 | "nestedObjectStringKey": "nestedObjectStringValue", 20 | "nestedObjectArrayKey": [ 21 | "nestedArrayValue1", 22 | 101112, 23 | true 24 | ] 25 | }, 26 | "arrayOfObjectsKey": [ 27 | { 28 | "arrayOfObjectsStringKey": "arrayOfObjectsStringValue1", 29 | "arrayOfObjectsNumberKey": 131415, 30 | "arrayOfObjectsBooleanKey": true 31 | }, 32 | { 33 | "arrayOfObjectsStringKey": "arrayOfObjectsStringValue2", 34 | "arrayOfObjectsNumberKey": 161718, 35 | "arrayOfObjectsBooleanKey": false 36 | } 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/test/resources/org/wso2/carbon/identity/conditional/auth/functions/analytics/analytics-payload.json: -------------------------------------------------------------------------------- 1 | { 2 | "stringKey": "stringValue", 3 | "numberKey": 123, 4 | "booleanKey": true, 5 | "arrayKey": [ 6 | "arrayString", 7 | 456, 8 | false, 9 | { 10 | "nestedObjectInArrayKey": "nestedObjectValue", 11 | "nestedArrayInArrayKey": ["nestedArrayValue1", "nestedArrayValue2"] 12 | } 13 | ], 14 | "objectKey": { 15 | "objectStringKey": "objectStringValue", 16 | "objectNumberKey": 789, 17 | "objectBooleanKey": false, 18 | "nestedObjectKey": { 19 | "nestedObjectStringKey": "nestedObjectStringValue", 20 | "nestedObjectArrayKey": [ 21 | "nestedArrayValue1", 22 | 101112, 23 | true 24 | ] 25 | }, 26 | "arrayOfObjectsKey": [ 27 | { 28 | "arrayOfObjectsStringKey": "arrayOfObjectsStringValue1", 29 | "arrayOfObjectsNumberKey": 131415, 30 | "arrayOfObjectsBooleanKey": true 31 | }, 32 | { 33 | "arrayOfObjectsStringKey": "arrayOfObjectsStringValue2", 34 | "arrayOfObjectsNumberKey": 161718, 35 | "arrayOfObjectsBooleanKey": false 36 | } 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/model/graaljs/JsGraalUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.model.graaljs; 20 | 21 | import org.wso2.carbon.identity.conditional.auth.functions.common.model.JsUtils; 22 | 23 | import java.util.List; 24 | 25 | public class JsGraalUtils implements JsUtils { 26 | 27 | @Override 28 | public boolean isArray(Object obj) { 29 | 30 | return obj instanceof List; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/utils/GetMaskedValueFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.utils; 20 | 21 | /** 22 | * Function to mask the given value. 23 | */ 24 | @FunctionalInterface 25 | public interface GetMaskedValueFunction { 26 | 27 | /** 28 | * Masks the given value. 29 | * 30 | * @param value The value to be masked. 31 | * @return The masked value. 32 | */ 33 | String getMaskedValue(String value); 34 | } 35 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/PromptIdentifierFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | /** 22 | * Function to prompt for user identifier. 23 | */ 24 | @FunctionalInterface 25 | public interface PromptIdentifierFunction { 26 | 27 | /** 28 | * Prompt for user identifier. 29 | * 30 | * @param step step number 31 | * @param parameters parameters 32 | */ 33 | void promptIdentifier(int step, Object... parameters); 34 | } 35 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/exception/UserSessionRetrievalException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.exception; 20 | 21 | import org.wso2.carbon.identity.base.IdentityException; 22 | 23 | /** 24 | * Exception occurred while retrieving user sessions. 25 | */ 26 | public class UserSessionRetrievalException extends IdentityException { 27 | 28 | public UserSessionRetrievalException(String message, Throwable cause) { 29 | 30 | super(message, cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/exception/UserSessionTerminationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.exception; 20 | 21 | import org.wso2.carbon.identity.base.IdentityException; 22 | 23 | /** 24 | * Exception occurred while terminating user sessions. 25 | */ 26 | public class UserSessionTerminationException extends IdentityException { 27 | 28 | public UserSessionTerminationException(String message, Throwable cause) { 29 | 30 | super(message, cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.test.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/test/utils/api/SubjectCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.test.utils.api; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; 23 | 24 | import java.io.Serializable; 25 | 26 | public interface SubjectCallback extends Serializable { 27 | 28 | AuthenticatedUser getAuthenticatedUser(AuthenticationContext context); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/utils/FilterAuthenticatorsFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.utils; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * Function to exclude a defined authenticator from the provided options list. 26 | */ 27 | @FunctionalInterface 28 | public interface FilterAuthenticatorsFunction { 29 | 30 | Map> filterAuthenticators(List> authenticatorOptions, 31 | String excludeAuthenticator); 32 | } 33 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/auth/Credentials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.auth; 20 | 21 | import java.security.Principal; 22 | 23 | /** 24 | * User credentials 25 | */ 26 | public interface Credentials { 27 | 28 | /** 29 | * Get the user principal of this credential. 30 | * 31 | * @return principal 32 | */ 33 | Principal getUserPrincipal(); 34 | 35 | /** 36 | * Get the password of this credential. 37 | * 38 | * @return password 39 | */ 40 | String getPassword(); 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/utils/GetMaskedValueFunctionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.utils; 20 | 21 | import org.graalvm.polyglot.HostAccess; 22 | import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils; 23 | 24 | /** 25 | * Implementation of {@link GetMaskedValueFunction}. 26 | */ 27 | public class GetMaskedValueFunctionImpl implements GetMaskedValueFunction { 28 | 29 | @Override 30 | @HostAccess.Export 31 | public String getMaskedValue(String value) { 32 | 33 | return LoggerUtils.getMaskedContent(value); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.session/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/elk/CallElasticFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.elk; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * Function to call http endpoints. Function will send get to the given endpoint reference. 25 | */ 26 | @FunctionalInterface 27 | public interface CallElasticFunction { 28 | 29 | /** 30 | * ELK Risk Score Analysis 31 | * 32 | * @param params Parameters for ELK analytics query. 33 | * @param eventHandlers Event handlers. 34 | */ 35 | void callElastic(Map params, Map eventHandlers); 36 | } 37 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/model/nashorn/JsNashornUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.model.nashorn; 20 | 21 | import jdk.nashorn.api.scripting.ScriptObjectMirror; 22 | import org.wso2.carbon.identity.conditional.auth.functions.common.model.JsUtils; 23 | 24 | import java.util.List; 25 | 26 | public class JsNashornUtils implements JsUtils { 27 | 28 | @Override 29 | public boolean isArray(Object obj) { 30 | 31 | if (obj instanceof ScriptObjectMirror) { 32 | return ((ScriptObjectMirror) obj).isArray(); 33 | } 34 | return obj instanceof List; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPGetFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.http; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * Function to call http endpoints. Function will send get to the given endpoint reference. 25 | */ 26 | @FunctionalInterface 27 | public interface HTTPGetFunction { 28 | 29 | /** 30 | * POST data to the given endpoint. 31 | * 32 | * @param endpointURL Endpoint url. 33 | * @param params Parameters. 34 | * 1. headers headers (optional). 35 | * 2. eventHandlers event handlers. 36 | */ 37 | void httpGet(String endpointURL, Object... params); 38 | } 39 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user.store/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/store/GetUserWithClaimValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.store; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; 23 | 24 | import java.util.Map; 25 | 26 | @FunctionalInterface 27 | public interface GetUserWithClaimValues { 28 | 29 | JsAuthenticatedUser getUniqueUserWithClaimValues(Map claimMap, Object... parameters) throws 30 | FrameworkException; 31 | } 32 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/MicrosoftEmailVerificationFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | 23 | @FunctionalInterface 24 | public interface MicrosoftEmailVerificationFunction { 25 | 26 | /** 27 | * Function to check whether the email from Microsoft is verified. 28 | * 29 | * @param context Authentication context. 30 | * @return True if the email is verified. 31 | */ 32 | boolean checkMicrosoftEmailVerification(JsAuthenticationContext context); 33 | } 34 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/model/openjdk/nashorn/JsOpenJdkNashornUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.model.openjdk.nashorn; 20 | 21 | import org.openjdk.nashorn.api.scripting.ScriptObjectMirror; 22 | import org.wso2.carbon.identity.conditional.auth.functions.common.model.JsUtils; 23 | 24 | import java.util.List; 25 | 26 | public class JsOpenJdkNashornUtils implements JsUtils { 27 | 28 | @Override 29 | public boolean isArray(Object obj) { 30 | 31 | if (obj instanceof ScriptObjectMirror) { 32 | return ((ScriptObjectMirror) obj).isArray(); 33 | } 34 | return obj instanceof List; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/RemoveAssociatedLocalUserFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | /** 24 | * Function to remove association with the local user for a federated user. 25 | */ 26 | @FunctionalInterface 27 | public interface RemoveAssociatedLocalUserFunction { 28 | 29 | /** 30 | * Remove association to the local user with federated user. 31 | * 32 | * @param federatedUser Federated user. 33 | */ 34 | boolean removeAssociatedLocalUser(JsAuthenticatedUser federatedUser); 35 | } 36 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/GetAssociatedLocalUserFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | /** 24 | * Function to get associated local user of the federated user. 25 | */ 26 | @FunctionalInterface 27 | public interface GetAssociatedLocalUserFunction { 28 | 29 | /** 30 | * Get associated local user of a federated user. 31 | * 32 | * @param federatedUser federated user 33 | */ 34 | JsAuthenticatedUser getAssociatedLocalUser(JsAuthenticatedUser federatedUser); 35 | } 36 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/util/AuthConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.http.util; 19 | 20 | import org.apache.http.client.methods.HttpUriRequest; 21 | 22 | /** 23 | * Interface for the authentication configurations. 24 | */ 25 | public interface AuthConfig { 26 | 27 | /** 28 | * Apply the authentication configurations to the request. 29 | * 30 | * @param request HttpUriRequest 31 | * @param authConfigModel Authentication configuration model 32 | * @return HttpUriRequest 33 | * @throws Exception 34 | */ 35 | HttpUriRequest applyAuth(HttpUriRequest request, AuthConfigModel authConfigModel) throws Exception; 36 | } 37 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/util/HTTPConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | 20 | package org.wso2.carbon.identity.conditional.auth.functions.http.util; 21 | 22 | /** 23 | * Set of the constants used in the cookie related functions. 24 | */ 25 | public class HTTPConstants { 26 | 27 | public static final String SIGN = "sign"; 28 | public static final String ENCRYPT = "encrypt"; 29 | public static final String VALIDATE_SIGN = "validateSignature"; 30 | public static final String DECRYPT = "decrypt"; 31 | public static final String VALUE = "value"; 32 | public static final String SIGNATURE = "signature"; 33 | public static final String KEY_STORE_CONTEXT = "cookie"; 34 | } 35 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/auth/AuthenticationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.auth; 20 | 21 | import org.apache.http.Header; 22 | import org.apache.http.HttpRequest; 23 | 24 | /** 25 | * Authentication manager. 26 | */ 27 | public interface AuthenticationManager { 28 | 29 | /** 30 | * Create Authorization header with provided credentials. 31 | * 32 | * @param credentials Credentials to use for Authorization header. 33 | * @param request HTTP request. 34 | * 35 | * @return Authorization header 36 | */ 37 | Header authenticate( 38 | final Credentials credentials, 39 | final HttpRequest request); 40 | } 41 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/utils/ResolveMultiAttributeLoginIdentifierFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.utils; 20 | 21 | /** 22 | * Function to resolve username from the multi attribute login identifier. 23 | */ 24 | @FunctionalInterface 25 | public interface ResolveMultiAttributeLoginIdentifierFunction { 26 | 27 | /** 28 | * Resolves username from the provided login identifier when multi attribute login is enabled. 29 | * 30 | * @param loginIdentifier The user provided login identifier. 31 | * @param tenantDomain The tenant domain. 32 | * @return The resolved username. 33 | */ 34 | String resolveMultiAttributeLoginIdentifier(String loginIdentifier, String tenantDomain); 35 | } 36 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/auth/AuthenticationFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.auth; 20 | 21 | /** 22 | * Factory to get authentication manager. 23 | */ 24 | public class AuthenticationFactory { 25 | 26 | /** 27 | * Get the authentication manager 28 | * @param authType authentication type. 29 | * @return Authentication manager. 30 | */ 31 | public AuthenticationManager getAuthenticationManager(String authType){ 32 | if ("Basic".equalsIgnoreCase(authType)) { 33 | return new BasicAuthenticationManager(); 34 | } else { 35 | throw new IllegalArgumentException("Unsupported Authentication type."); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.test.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/test/utils/sequence/ResponseValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence; 20 | 21 | import org.graalvm.polyglot.HostAccess; 22 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsParameters; 23 | 24 | /** 25 | * Function to validate HTTP response. 26 | */ 27 | @FunctionalInterface 28 | public interface ResponseValidator { 29 | 30 | /** 31 | * Validate the HTTP response. 32 | * 33 | * @param response Response parameters. 34 | * @return Whether the response is valid. 35 | */ 36 | @HostAccess.Export 37 | boolean validateResponse(JsParameters response) throws JsTestException; 38 | } 39 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPPostFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.http; 20 | 21 | import java.util.Map; 22 | import java.util.function.Consumer; 23 | 24 | /** 25 | * Function to call http endpoints. Function will post to the given endpoint reference with payload data as a json. 26 | */ 27 | @FunctionalInterface 28 | public interface HTTPPostFunction { 29 | 30 | /** 31 | * POST data to the given endpoint. 32 | * 33 | * @param endpointURL Endpoint url. 34 | * @param params parameters. 35 | * 1. payloadData payload data. 36 | * 2. headers headers (optional). 37 | * 3. eventHandlers event handlers. 38 | */ 39 | void httpPost(String endpointURL, Object... params); 40 | } 41 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.notification/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/UpdateUserPasswordFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | /** 24 | * Function to update user password. 25 | */ 26 | @FunctionalInterface 27 | public interface UpdateUserPasswordFunction { 28 | 29 | /** 30 | * Update user password. 31 | * 32 | * @param user Authenticated user. 33 | * @param parameters Parameters. It is mandatory to provide the new password as the first parameter. 34 | * Then an optional map of event handlers can be provided. 35 | */ 36 | void updateUserPassword(JsAuthenticatedUser user, Object... parameters); 37 | } 38 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/GetCookieFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | 20 | package org.wso2.carbon.identity.conditional.auth.functions.http; 21 | 22 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsServletRequest; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Function definition for getcookie value from the context request. 28 | */ 29 | @FunctionalInterface 30 | public interface GetCookieFunction { 31 | 32 | /** 33 | * Retrieve cookie value for the respective name from the request object. 34 | * 35 | * @param request request object 36 | * @param params value mandatory and properties optional 37 | * @return cookieValue 38 | */ 39 | String getCookieValue(JsServletRequest request, Object... params); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.session/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/session/exception/SessionValidationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | package org.wso2.carbon.identity.conditional.auth.functions.session.exception; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException; 22 | 23 | /** 24 | * Exception class for indicating the exceptions in session count validation process. 25 | */ 26 | public class SessionValidationException extends AuthenticationFailedException { 27 | 28 | private static final long serialVersionUID = -476728056175361072L; 29 | 30 | /** 31 | * Constructor for exception class. 32 | * 33 | * @param message exception message 34 | */ 35 | public SessionValidationException(String message) { 36 | 37 | super(message); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/PublishToAnalyticsFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.analytics; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * Function to publish events to analytics engine. 27 | */ 28 | @FunctionalInterface 29 | public interface PublishToAnalyticsFunction { 30 | 31 | /** 32 | * Publish data to analytics engine. 33 | * 34 | * @param metadata Metadata to call the endpoint. 35 | * @param payloadData payload data. 36 | */ 37 | void publishToAnalytics(Map metadata, Map payloadData, 38 | JsAuthenticationContext context); 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/CallAnalyticsFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.analytics; 20 | 21 | import java.util.Map; 22 | import java.util.function.Consumer; 23 | 24 | /** 25 | * Function to publish events to analytics engine and get the output event synchronously. 26 | */ 27 | @FunctionalInterface 28 | public interface CallAnalyticsFunction { 29 | 30 | /** 31 | * Publish data to analytics engine and get the decision. 32 | * 33 | * @param metadata Metadata to call the endpoint. 34 | * @param payloadData payload data. 35 | * @param eventHandlers event handlers. 36 | */ 37 | void callAnalytics(Map metadata, Map payloadData, 38 | Map eventHandlers); 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.jwt.decode/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/jwt/decode/JwtDecode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.jwt.decode; 19 | 20 | import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; 21 | 22 | @FunctionalInterface 23 | public interface JwtDecode { 24 | 25 | /** 26 | * @param clientAssertion jwt assertion 27 | * @param parameterName parameter to be retrieved from jwt 28 | * @param isParameterInBody whether parameter to be retrieved is in jwt body 29 | * @return String representation of the decoded value of the parameter 30 | * @throws FrameworkException 31 | */ 32 | Object getValueFromDecodedAssertion(String clientAssertion, String parameterName, boolean isParameterInBody) 33 | throws FrameworkException; 34 | } 35 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/JsUserAgent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.AbstractJSObjectWrapper; 22 | import org.wso2.carbon.identity.core.model.UserAgent; 23 | 24 | /** 25 | * Javascript wrapper for Java level UserAgent. 26 | * This provides controlled access to UserSession object via provided javascript native syntax. 27 | * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime 28 | * AuthenticatedUser. 29 | * 30 | * @see UserAgent 31 | */ 32 | public abstract class JsUserAgent extends AbstractJSObjectWrapper { 33 | 34 | public JsUserAgent(UserAgent wrapped) { 35 | super(wrapped); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/cache/APIAccessTokenCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.http.cache; 19 | 20 | import org.wso2.carbon.identity.core.cache.BaseCache; 21 | 22 | /** 23 | * The cache implementation which stores the access tokens received from API. 24 | */ 25 | public class APIAccessTokenCache extends BaseCache { 26 | 27 | private static final String ACCESS_TOKEN_CACHE_NAME = "APIAccessTokenCache"; 28 | 29 | private APIAccessTokenCache() { 30 | 31 | super(ACCESS_TOKEN_CACHE_NAME); 32 | } 33 | 34 | private static class AccessTokenCacheHolder { 35 | static final APIAccessTokenCache INSTANCE = new APIAccessTokenCache(); 36 | } 37 | 38 | public static APIAccessTokenCache getInstance() { 39 | return AccessTokenCacheHolder.INSTANCE; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.session/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/session/test/TestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | package org.wso2.carbon.identity.conditional.auth.functions.session.test; 20 | 21 | import org.apache.commons.lang.RandomStringUtils; 22 | 23 | import java.util.Random; 24 | 25 | /** 26 | * Contains utility methods for Test classes 27 | */ 28 | public class TestUtils { 29 | 30 | //Method for generating random string for testing purposes 31 | public static String getRandomString(int size, boolean useLetters, boolean useNumbers) { 32 | return RandomStringUtils.random(size, useLetters, useNumbers); 33 | } 34 | //method for generating random integer in a given range for testing methods 35 | public static int getRandomInt(int start, int end) { 36 | Random rand = new Random(); 37 | return rand.nextInt(end) + start; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/SetCookieFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | 20 | package org.wso2.carbon.identity.conditional.auth.functions.http; 21 | 22 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsServletResponse; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Function definition for add cookie to the context response. 28 | */ 29 | @FunctionalInterface 30 | public interface SetCookieFunction { 31 | 32 | /** 33 | * Set the cookie in the response. 34 | * 35 | * @param response response object 36 | * @param name name of the cookie 37 | * @param params value of the cookie mandatory and optional parameter of cookie with two additional parameters 38 | * encrypt and sign. 39 | */ 40 | void setCookie(JsServletResponse response, String name, Object... params); 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/GetUserSessionsFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsUserSession; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Function to get the active sessions for a given user. 28 | */ 29 | @FunctionalInterface 30 | public interface GetUserSessionsFunction { 31 | 32 | /** 33 | * Get active sessions for a given user. 34 | * 35 | * @param user Authenticated user. 36 | * @return a list of active sessionIds if there are any. Returns an empty list when there are no active sessions. 37 | */ 38 | List getUserSessions(JsAuthenticatedUser user); 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/CheckSessionExistenceFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | 23 | /** 24 | * Function to check if the user in the authentication context has at least one authenticator authenticated for the 25 | * give step. 26 | */ 27 | @FunctionalInterface 28 | public interface CheckSessionExistenceFunction { 29 | 30 | /** 31 | * Check if the user in the authentication context is authenticated for the give step. 32 | * 33 | * @param step step number 34 | * @param context authentication context 35 | * @return if the user is already authenticated for the step. 36 | */ 37 | boolean checkSessionExistence(int step, JsAuthenticationContext context); 38 | } 39 | -------------------------------------------------------------------------------- /.github/workflows/pr-builder.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build the project on pull requests with tests 2 | # Uses: 3 | # OS: ubuntu-latest 4 | # JDK: Adopt JDK 11 5 | 6 | name: PR Builder 7 | 8 | on: 9 | pull_request: 10 | branches: [main, master] 11 | workflow_dispatch: 12 | 13 | env: 14 | MAVEN_OPTS: -Xmx4g -Xms1g 15 | 16 | jobs: 17 | build: 18 | runs-on: ubuntu-latest 19 | 20 | env: 21 | JAVA_TOOL_OPTIONS: "-Djdk.util.zip.disableZip64ExtraFieldValidation=true -Djdk.nio.zipfs.allowDotZipEntry=true" 22 | 23 | steps: 24 | - uses: actions/checkout@v2 25 | - name: Set up Adopt JDK 11 26 | uses: actions/setup-java@v2 27 | with: 28 | java-version: "11" 29 | distribution: "adopt" 30 | - name: Cache local Maven repository 31 | id: cache-maven-m2 32 | uses: actions/cache@v4 33 | env: 34 | cache-name: cache-m2 35 | with: 36 | path: ~/.m2/repository 37 | key: ${{ runner.os }}-maven-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }} 38 | restore-keys: | 39 | ${{ runner.os }}-maven-${{ env.cache-name }}- 40 | ${{ runner.os }}-maven- 41 | ${{ runner.os }}- 42 | - name: Build with Maven 43 | run: mvn clean install -U -B 44 | - name: Delete SNAPSHOT artifacts 45 | run: find ~/.m2/repository/ -name "*-SNAPSHOT" -type d -print -prune -exec rm -r {} + 46 | - name: Generate coverage report 47 | run: mvn test jacoco:report 48 | - name: Upload coverage reports to Codecov 49 | uses: codecov/codecov-action@v4 50 | with: 51 | token: ${{ secrets.CODECOV_TOKEN }} 52 | flags: unit 53 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/util/AuthConfigModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.http.util; 19 | 20 | import java.util.Map; 21 | 22 | /** 23 | * Model class for the authentication configuration. 24 | */ 25 | public class AuthConfigModel { 26 | String type; 27 | private Map properties; 28 | 29 | public AuthConfigModel(String type, Map properties) { 30 | this.type = type; 31 | this.properties = properties; 32 | } 33 | 34 | public void setType(String type) { 35 | this.type = type; 36 | } 37 | 38 | public void setProperties(Map properties) { 39 | this.properties = properties; 40 | } 41 | 42 | public String getType() { 43 | return type; 44 | } 45 | 46 | public Map getProperties() { 47 | return properties; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.test.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/test/utils/sequence/JsTestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence; 20 | 21 | /** 22 | * Exception thrown from the Javascript based test. 23 | */ 24 | public class JsTestException extends Exception { 25 | 26 | public JsTestException() { 27 | 28 | } 29 | 30 | public JsTestException(String message) { 31 | 32 | super(message); 33 | } 34 | 35 | public JsTestException(String message, Throwable cause) { 36 | 37 | super(message, cause); 38 | } 39 | 40 | public JsTestException(Throwable cause) { 41 | 42 | super(cause); 43 | } 44 | 45 | public JsTestException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 46 | 47 | super(message, cause, enableSuppression, writableStackTrace); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/GetAuthenticatedApplicationsFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Function definition for retrieving authenticated applications. 28 | */ 29 | @FunctionalInterface 30 | public interface GetAuthenticatedApplicationsFunction { 31 | 32 | /** 33 | * Retrieve the already authenticated applications for a given session. 34 | * 35 | * @param context context object. 36 | * @return List of already authenticated applications of the given session. 37 | */ 38 | List getAuthenticatedApplications(JsAuthenticationContext context); 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/GetAuthenticatedApplicationsV2Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsApplication; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Function definition for retrieving authenticated applications. 28 | */ 29 | @FunctionalInterface 30 | public interface GetAuthenticatedApplicationsV2Function { 31 | 32 | /** 33 | * Retrieve the already authenticated applications for a given session. 34 | * 35 | * @param context context object. 36 | * @return List of already authenticated applications of the given session. 37 | */ 38 | List getAuthenticatedApplications(JsAuthenticationContext context); 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/cache/ChoreoAccessTokenCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.choreo.cache; 19 | 20 | import org.wso2.carbon.identity.core.cache.BaseCache; 21 | 22 | /** 23 | * The cache implementation which stores the access tokens received from Choreo. 24 | */ 25 | public class ChoreoAccessTokenCache extends BaseCache { 26 | 27 | private static final String ACCESS_TOKEN_CACHE_NAME = "ChoreoAccessTokenCache"; 28 | 29 | private ChoreoAccessTokenCache() { 30 | 31 | super(ACCESS_TOKEN_CACHE_NAME); 32 | } 33 | 34 | private static class AccessTokenCacheHolder { 35 | static final ChoreoAccessTokenCache INSTANCE = new ChoreoAccessTokenCache(); 36 | } 37 | 38 | public static ChoreoAccessTokenCache getInstance() { 39 | return AccessTokenCacheHolder.INSTANCE; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user.store/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/store/GetUserWithClaimValuesV2Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.store; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 23 | import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; 24 | 25 | import java.util.Map; 26 | 27 | @FunctionalInterface 28 | public interface GetUserWithClaimValuesV2Function { 29 | 30 | JsAuthenticatedUser getUniqueUserWithClaimValues(Map claimMap, 31 | JsAuthenticationContext authenticationContext, 32 | String... parameters) throws FrameworkException; 33 | } 34 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/TerminateUserSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | /** 24 | * Function to terminate a session of user. 25 | */ 26 | @FunctionalInterface 27 | public interface TerminateUserSession { 28 | 29 | /** 30 | * Terminate the active sessions of a given user with the given sessionId. 31 | * 32 | * @param user Authenticated user. Ideally from a given step. 33 | * @param sessionId SessionId of the session that needs to be killed. 34 | * @return true if the terminate operation was successful. false if the operation failed. 35 | */ 36 | boolean terminateUserSession(JsAuthenticatedUser user, String sessionId); 37 | } 38 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/JsApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.AbstractJSObjectWrapper; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 23 | 24 | /** 25 | * Javascript wrapper for Java level Application. 26 | * This provides controlled access to UserSession object via provided javascript native syntax. 27 | * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime 28 | * AuthenticatedUser. 29 | * 30 | * @see Application 31 | */ 32 | public abstract class JsApplication extends AbstractJSObjectWrapper { 33 | 34 | public JsApplication(Application wrappedApplication) { 35 | 36 | super(wrappedApplication); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/internal/FunctionsDataHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.internal; 20 | 21 | import org.wso2.carbon.identity.governance.IdentityGovernanceService; 22 | 23 | /** 24 | * Data holder. 25 | */ 26 | public class FunctionsDataHolder { 27 | 28 | private static FunctionsDataHolder instance = new FunctionsDataHolder(); 29 | private IdentityGovernanceService identityGovernanceService; 30 | 31 | public static FunctionsDataHolder getInstance() { 32 | 33 | return instance; 34 | } 35 | 36 | public IdentityGovernanceService getIdentityGovernanceService() { 37 | 38 | return identityGovernanceService; 39 | } 40 | 41 | public void setIdentityGovernanceService(IdentityGovernanceService identityGovernanceService) { 42 | 43 | this.identityGovernanceService = identityGovernanceService; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.session/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/session/function/ExecuteActionFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | package org.wso2.carbon.identity.conditional.auth.functions.session.function; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * Function definition for verify some defined requirement is fulfilled. 27 | * 28 | * @deprecated 29 | */ 30 | @FunctionalInterface 31 | @Deprecated 32 | public interface ExecuteActionFunction { 33 | 34 | /** 35 | * This method will contain the implementation of execute action. 36 | * 37 | * @param context AuthenticationContext passed from Javascript 38 | * @param map parameter map 39 | * @return boolean value indicating the success or failure state of process 40 | */ 41 | boolean execute(JsAuthenticationContext context, Map map); 42 | } 43 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/AssignUserRolesV2Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Function to update given roles(v2) for a given user. 27 | * The purpose is to perform role(v2) assigning during dynamic authentication. 28 | */ 29 | @FunctionalInterface 30 | public interface AssignUserRolesV2Function { 31 | 32 | /** 33 | * Add roles for a given user 34 | * 35 | * @param context authentication context 36 | * @param roleListToAssign Roles to be assigned. 37 | * @return true If the role assigning is successfully completed. false for any other case. 38 | */ 39 | boolean assignUserRolesV2(JsAuthenticationContext context, List roleListToAssign); 40 | } 41 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/RemoveUserRolesV2Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Function to remove given roles(v2) for a given user. 27 | * The purpose is to perform role(v2) removing during dynamic authentication. 28 | */ 29 | @FunctionalInterface 30 | public interface RemoveUserRolesV2Function { 31 | 32 | /** 33 | * Remove roles for a given user 34 | * 35 | * @param context authentication context 36 | * @param roleListToRemove Roles to be removed. 37 | * @return true If the role removal is successfully completed. false for any other case. 38 | */ 39 | boolean removeUserRolesV2(JsAuthenticationContext context, List roleListToRemove); 40 | } 41 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/AssignUserRolesFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Function to update given roles for a given user. 27 | * The purpose is to perform role assigning during dynamic authentication. 28 | */ 29 | @FunctionalInterface 30 | public interface AssignUserRolesFunction { 31 | 32 | /** 33 | * Add roles for a given user 34 | * 35 | * @param user Authenticated user. 36 | * @param assigningRoles Roles to be assigned. 37 | * @return true If the role assigning is successfully completed. false for any other case. 38 | */ 39 | boolean assignUserRoles(JsAuthenticatedUser user, List assigningRoles); 40 | } 41 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.jwt.decode/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/jwt/decode/internal/JwtDecodeServiceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.jwt.decode.internal; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry; 22 | 23 | public class JwtDecodeServiceHolder { 24 | 25 | private static JwtDecodeServiceHolder instance = new JwtDecodeServiceHolder(); 26 | 27 | private JsFunctionRegistry jsFunctionRegistry; 28 | 29 | private JwtDecodeServiceHolder() { 30 | 31 | } 32 | 33 | public static JwtDecodeServiceHolder getInstance() { 34 | 35 | return instance; 36 | } 37 | 38 | public JsFunctionRegistry getJsFunctionRegistry() { 39 | 40 | return jsFunctionRegistry; 41 | } 42 | 43 | public void setJsFunctionRegistry(JsFunctionRegistry jsFunctionRegistry) { 44 | 45 | this.jsFunctionRegistry = jsFunctionRegistry; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/RemoveUserRolesFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Function to remove given roles from the a given user. 27 | * The purpose is to perform role removing during dynamic authentication. 28 | */ 29 | @FunctionalInterface 30 | public interface RemoveUserRolesFunction { 31 | 32 | /** 33 | * Remove roles for a given user 34 | * 35 | * @param user Authenticated user. 36 | * @param removingRoles Roles to be removed. 37 | * @return true If the role assigning is successfully completed. false for any other case. 38 | */ 39 | boolean removeUserRoles(JsAuthenticatedUser user, List removingRoles); 40 | } 41 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.notification/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/notification/SendEmailFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.notification; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | import java.util.Map; 24 | 25 | @FunctionalInterface 26 | public interface SendEmailFunction { 27 | 28 | /** 29 | * Send an email to the given user using a provided template. 30 | * @param user The user object to whom the mail is send 31 | * @param templateId The email template id, Which is configured under email templates. 32 | * @param paramMap Placeholder value map 33 | * @return true if the email is successfully queued to be sent. false If the mail 34 | * couldn't be queued due to any error. 35 | */ 36 | boolean sendMail(JsAuthenticatedUser user, String templateId, Map paramMap); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/IsMemberOfAnyOfGroupsFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Function to check if the given user is a member in at least one of the given groups. 27 | * The purpose is to perform dynamic authentication selection based on user groups. 28 | */ 29 | @FunctionalInterface 30 | public interface IsMemberOfAnyOfGroupsFunction { 31 | 32 | /** 33 | * Checks if the given user is a member in one of the given group names. 34 | * 35 | * @param user Authenticated user. 36 | * @param groupNames Groups to be checked. 37 | * @return True if the user is a member in at least one of the given groups. 38 | */ 39 | boolean isMemberOfAnyOfGroups(JsAuthenticatedUser user, List groupNames); 40 | } 41 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/utils/internal/UtilsFunctionServiceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.utils.internal; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry; 22 | 23 | /** 24 | * Class to hold services discovered via OSGI on this component. 25 | */ 26 | public class UtilsFunctionServiceHolder { 27 | 28 | private static UtilsFunctionServiceHolder instance = new UtilsFunctionServiceHolder(); 29 | 30 | private JsFunctionRegistry jsFunctionRegistry; 31 | 32 | public static UtilsFunctionServiceHolder getInstance() { 33 | 34 | return instance; 35 | } 36 | private UtilsFunctionServiceHolder(){ 37 | } 38 | 39 | public JsFunctionRegistry getJsFunctionRegistry() { 40 | 41 | return jsFunctionRegistry; 42 | } 43 | 44 | public void setJsFunctionRegistry(JsFunctionRegistry jsFunctionRegistry) { 45 | 46 | this.jsFunctionRegistry = jsFunctionRegistry; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasAnyOfTheRolesV2Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Function to check if the given user has at least one of the given roles(v2). 27 | * The purpose is to perform dynamic authentication selection based on user role(v2). 28 | */ 29 | @FunctionalInterface 30 | public interface HasAnyOfTheRolesV2Function { 31 | 32 | /** 33 | * Check if the user in the authentication context has any of the given roles. 34 | * 35 | * @param context authentication context 36 | * @param roleNames Role to be checked 37 | * @return true if the user has at least one of the given roles. false for any other 38 | * case. 39 | */ 40 | boolean hasAnyOfTheRolesV2(JsAuthenticationContext context, List roleNames); 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasRoleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | /** 24 | * Function to check if the given user has the given role. 25 | * The purpose is to perform dynamic authentication selection based on user role. 26 | * 27 | * @deprecated Use {@link HasAnyOfTheRolesFunction} instead 28 | */ 29 | @FunctionalInterface 30 | @Deprecated 31 | public interface HasRoleFunction { 32 | 33 | /** 34 | * Checks if the given user has the given roleName 35 | * 36 | * @param user Authenticated user. Ideally from a given step. 37 | * @param roleName Role to be checked 38 | * @return true if the user has the given role. false for any other case. 39 | */ 40 | boolean hasRole(JsAuthenticatedUser user, String roleName); 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasAnyOfTheRolesFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Function to check if the given user has at least one of the given roles. 27 | * The purpose is to perform dynamic authentication selection based on user role. 28 | */ 29 | @FunctionalInterface 30 | public interface HasAnyOfTheRolesFunction { 31 | 32 | /** 33 | * Checks if the given user has the given roleName 34 | * 35 | * @param user Authenticated user. Ideally from a given step. 36 | * @param roleNames Role to be checked 37 | * @return true if the user has at least one of the given roles. false for any other 38 | * case. 39 | */ 40 | boolean hasAnyOfTheRoles(JsAuthenticatedUser user, List roleNames); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/util/BearerAuthConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.http.util; 19 | 20 | import org.apache.http.client.methods.HttpUriRequest; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Implementation of the {@link AuthConfig} 26 | * This class is used to configure the bearer token authentication. 27 | * The bearer token is added to the request header. 28 | */ 29 | public class BearerAuthConfig implements AuthConfig { 30 | private String token; 31 | 32 | public void setToken(String token) { 33 | this.token = token; 34 | } 35 | 36 | public String getToken() { 37 | return token; 38 | } 39 | 40 | @Override 41 | public HttpUriRequest applyAuth(HttpUriRequest request, AuthConfigModel authConfigModel) { 42 | 43 | Map properties = authConfigModel.getProperties(); 44 | setToken(properties.get("token").toString()); 45 | request.setHeader("Authorization", "Bearer " + getToken()); 46 | return request; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/SetAccountAssociationToLocalUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.user; 19 | 20 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 21 | 22 | /** 23 | * Function to set associate local user to federated user. 24 | */ 25 | @FunctionalInterface 26 | public interface SetAccountAssociationToLocalUser { 27 | 28 | /** 29 | * Set association to the local user with federated user. 30 | * 31 | * @param federatedUser Federated user. 32 | * @param username Local user's username. 33 | * @param tenantDomain Tenant domain of the local user. 34 | * @param userStoreDomainName Userstore domain of the local user. 35 | * @return Whether the association is successful or not. 36 | */ 37 | boolean doAssociationWithLocalUser(JsAuthenticatedUser federatedUser, String username, String tenantDomain, 38 | String userStoreDomainName); 39 | } 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/IsAnyOfTheRolesAssignedToUserFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Function to check whether the specified user belongs to any of the specified roles. 27 | * Roles are directly retrieved from database without checking in the cache first. 28 | */ 29 | @FunctionalInterface 30 | public interface IsAnyOfTheRolesAssignedToUserFunction { 31 | 32 | /** 33 | * Checks if the given user has the given roleName 34 | * 35 | * @param user Authenticated user. Ideally from a given step. 36 | * @param roleNames Role to be checked 37 | * @return true if the user has at least one of the given roles. false for any other 38 | * case. 39 | */ 40 | boolean IsAnyOfTheRolesAssignedToUser(JsAuthenticatedUser user, List roleNames); 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/JsUserSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.AbstractJSObjectWrapper; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.UserSession; 23 | import org.wso2.carbon.identity.core.model.UserAgent; 24 | 25 | import java.util.stream.Collectors; 26 | 27 | /** 28 | * Javascript wrapper for Java level UserSession. 29 | * This provides controlled access to UserSession object via provided javascript native syntax. 30 | * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime 31 | * AuthenticatedUser. 32 | * 33 | * @see UserSession 34 | */ 35 | public abstract class JsUserSession extends AbstractJSObjectWrapper { 36 | 37 | private UserAgent userAgent; 38 | 39 | public JsUserSession(UserSession wrappedUserSession) { 40 | 41 | super(wrappedUserSession); 42 | userAgent = new UserAgent(wrappedUserSession.getUserAgent()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/CallChoreoFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.choreo; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * Function to send HTTP requests to the Choreo and get the response synchronously. 25 | */ 26 | @FunctionalInterface 27 | public interface CallChoreoFunction { 28 | 29 | /** 30 | * Sends data to Choreo and get the response from the Choreo service. 31 | * The payload and the return value from the Choreo are both JSON structure, which needs to be the contract between 32 | * the service and authentication script 33 | * 34 | * @param connectionMetaData Metadata to call the endpoint. This connectionMetaData map consists with connection url 35 | * (connectionMetaData.url) and api-key (connectionMetaData.apikey) 36 | * @param payloadData payload data. 37 | * @param eventHandlers event handlers. 38 | */ 39 | void callChoreo(Map connectionMetaData, Map payloadData, 40 | Map eventHandlers); 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.session/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/session/function/GetUserSessionDataFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | package org.wso2.carbon.identity.conditional.auth.functions.session.function; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; 23 | import org.wso2.carbon.identity.conditional.auth.functions.session.model.Session; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * Function definition for retrieving data. 29 | * 30 | * @deprecated 31 | */ 32 | @FunctionalInterface 33 | @Deprecated 34 | public interface GetUserSessionDataFunction { 35 | 36 | /** 37 | * This function will contain the implementation for retrieving data. 38 | * 39 | * @param context AuthenticationContext object passed from Javascript 40 | * @param map parameter map 41 | * @return Map of sessionID and sessions 42 | * @throws FrameworkException 43 | */ 44 | Map getData(JsAuthenticationContext context, Map map) throws 45 | FrameworkException; 46 | } 47 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.session/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/session/function/IsWithinSessionLimitFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | package org.wso2.carbon.identity.conditional.auth.functions.session.function; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 22 | import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Function definition for verify some defined requirement is fulfilled. 28 | * 29 | * @deprecated 30 | */ 31 | @FunctionalInterface 32 | @Deprecated 33 | public interface IsWithinSessionLimitFunction { 34 | 35 | /** 36 | * Method to validate user session a given the authentication context and set of required attributes. 37 | * 38 | * @param context Authentication context 39 | * @param map Hash map of attributes required for validation 40 | * @return boolean value indicating the validation success/failure 41 | * @throws FrameworkException when exception occurred in session retrieving method 42 | */ 43 | boolean validate(JsAuthenticationContext context, Map map) 44 | throws FrameworkException; 45 | } 46 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/GetAuthenticatedApplicationsV2FunctionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user; 20 | 21 | import org.graalvm.polyglot.HostAccess; 22 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 23 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsApplication; 24 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsWrapperFactoryProvider; 25 | 26 | import java.util.List; 27 | import java.util.stream.Collectors; 28 | 29 | /** 30 | * Function for retrieving javascript authenticated applications for a given session. 31 | */ 32 | public class GetAuthenticatedApplicationsV2FunctionImpl implements GetAuthenticatedApplicationsV2Function { 33 | 34 | @Override 35 | @HostAccess.Export 36 | public List getAuthenticatedApplications(JsAuthenticationContext context) { 37 | 38 | return new GetAuthenticatedAppsFuncImp().getAuthenticatedApplications(context) 39 | .stream() 40 | .map(app -> JsWrapperFactoryProvider.getInstance().getWrapperFactory().createJsApplication(app)) 41 | .collect(Collectors.toList()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user.store/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/store/GetUserWithClaimValuesV2FunctionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.store; 20 | 21 | import org.graalvm.polyglot.HostAccess; 22 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 23 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 24 | import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; 25 | 26 | import java.util.Map; 27 | 28 | /** 29 | * Implementation of GetUserWithClaimValuesV2Function. This will return a user given a set of claim values. 30 | */ 31 | public class GetUserWithClaimValuesV2FunctionImpl implements GetUserWithClaimValuesV2Function { 32 | 33 | @Override 34 | @HostAccess.Export 35 | public JsAuthenticatedUser getUniqueUserWithClaimValues(Map claimMap, 36 | JsAuthenticationContext authenticationContext, 37 | String... parameters) throws FrameworkException { 38 | 39 | return new UserStoreFunctions().getUniqueUserWithClaimValues(claimMap, authenticationContext, parameters); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/JsWrapperFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 23 | import org.wso2.carbon.identity.application.authentication.framework.model.UserSession; 24 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.nashorn.JsNashornApplication; 25 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.nashorn.JsNashornUserSession; 26 | 27 | /** 28 | * Factory to create a Javascript Object Wrappers for Nashorn execution. 29 | */ 30 | public class JsWrapperFactory implements JsWrapperBaseFactory { 31 | 32 | @Override 33 | public JsUserSession createJsUserSession(UserSession userSession) { 34 | return new JsNashornUserSession(userSession); 35 | } 36 | 37 | public JsApplication createJsApplication(Application application) { 38 | return new JsNashornApplication(application); 39 | } 40 | 41 | public SerializableJsFunction createJsSerializableFunction(String source, boolean isFunction) { 42 | 43 | return new SerializableJsFunction(source, isFunction); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user.store/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/store/GetUsersWithClaimValuesFunctionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.store; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | import org.graalvm.polyglot.HostAccess; 24 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 25 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 26 | import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; 27 | 28 | /** 29 | * Implementation of GetUsersWithClaimValuesFunction interface. This returns a list of users with provided claim values. 30 | */ 31 | public class GetUsersWithClaimValuesFunctionImpl implements GetUsersWithClaimValuesFunction { 32 | 33 | @Override 34 | @HostAccess.Export 35 | public List getUsersWithClaimValues(Map claimMap, 36 | JsAuthenticationContext authenticationContext, 37 | String... parameters) throws FrameworkException { 38 | 39 | return new UserStoreFunctions().getUsersWithClaimValues(claimMap, authenticationContext, parameters); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user.store/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/store/internal/UserStoreFunctionsServiceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.store.internal; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry; 22 | import org.wso2.carbon.user.core.service.RealmService; 23 | 24 | public class UserStoreFunctionsServiceHolder { 25 | 26 | private static UserStoreFunctionsServiceHolder instance = new UserStoreFunctionsServiceHolder(); 27 | 28 | private RealmService realmService; 29 | private JsFunctionRegistry jsFunctionRegistry; 30 | 31 | private UserStoreFunctionsServiceHolder() { 32 | 33 | } 34 | 35 | public static UserStoreFunctionsServiceHolder getInstance() { 36 | 37 | return instance; 38 | } 39 | 40 | public RealmService getRealmService() { 41 | 42 | return realmService; 43 | } 44 | 45 | public void setRealmService(RealmService realmService) { 46 | 47 | this.realmService = realmService; 48 | } 49 | 50 | public JsFunctionRegistry getJsFunctionRegistry() { 51 | 52 | return jsFunctionRegistry; 53 | } 54 | 55 | public void setJsFunctionRegistry(JsFunctionRegistry jsFunctionRegistry) { 56 | 57 | this.jsFunctionRegistry = jsFunctionRegistry; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/resources/dbscripts/h2.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_DIALECT ( 2 | ID INTEGER NOT NULL AUTO_INCREMENT, 3 | DIALECT_URI VARCHAR (255) NOT NULL, 4 | TENANT_ID INTEGER NOT NULL, 5 | PRIMARY KEY (ID), 6 | CONSTRAINT DIALECT_URI_CONSTRAINT UNIQUE (DIALECT_URI, TENANT_ID) 7 | ); 8 | 9 | CREATE TABLE IF NOT EXISTS IDN_CLAIM ( 10 | ID INTEGER NOT NULL AUTO_INCREMENT, 11 | DIALECT_ID INTEGER NOT NULL, 12 | CLAIM_URI VARCHAR (255) NOT NULL, 13 | TENANT_ID INTEGER NOT NULL, 14 | PRIMARY KEY (ID), 15 | FOREIGN KEY (DIALECT_ID) REFERENCES IDN_CLAIM_DIALECT(ID) ON DELETE CASCADE, 16 | CONSTRAINT CLAIM_URI_CONSTRAINT UNIQUE (DIALECT_ID, CLAIM_URI, TENANT_ID) 17 | ); 18 | 19 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_MAPPED_ATTRIBUTE ( 20 | ID INTEGER NOT NULL AUTO_INCREMENT, 21 | LOCAL_CLAIM_ID INTEGER, 22 | USER_STORE_DOMAIN_NAME VARCHAR (255) NOT NULL, 23 | ATTRIBUTE_NAME VARCHAR (255) NOT NULL, 24 | TENANT_ID INTEGER NOT NULL, 25 | PRIMARY KEY (ID), 26 | FOREIGN KEY (LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 27 | CONSTRAINT USER_STORE_DOMAIN_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, USER_STORE_DOMAIN_NAME, TENANT_ID) 28 | ); 29 | 30 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_PROPERTY ( 31 | ID INTEGER NOT NULL AUTO_INCREMENT, 32 | LOCAL_CLAIM_ID INTEGER, 33 | PROPERTY_NAME VARCHAR (255) NOT NULL, 34 | PROPERTY_VALUE VARCHAR (255) NOT NULL, 35 | TENANT_ID INTEGER NOT NULL, 36 | PRIMARY KEY (ID), 37 | FOREIGN KEY (LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 38 | CONSTRAINT PROPERTY_NAME_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, PROPERTY_NAME, TENANT_ID) 39 | ); 40 | 41 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_MAPPING ( 42 | ID INTEGER NOT NULL AUTO_INCREMENT, 43 | EXT_CLAIM_ID INTEGER NOT NULL, 44 | MAPPED_LOCAL_CLAIM_ID INTEGER NOT NULL, 45 | TENANT_ID INTEGER NOT NULL, 46 | PRIMARY KEY (ID), 47 | FOREIGN KEY (EXT_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 48 | FOREIGN KEY (MAPPED_LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 49 | CONSTRAINT EXT_TO_LOC_MAPPING_CONSTRN UNIQUE (EXT_CLAIM_ID, TENANT_ID), 50 | ); 51 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.notification/src/test/resources/dbscripts/h2.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_DIALECT ( 2 | ID INTEGER NOT NULL AUTO_INCREMENT, 3 | DIALECT_URI VARCHAR (255) NOT NULL, 4 | TENANT_ID INTEGER NOT NULL, 5 | PRIMARY KEY (ID), 6 | CONSTRAINT DIALECT_URI_CONSTRAINT UNIQUE (DIALECT_URI, TENANT_ID) 7 | ); 8 | 9 | CREATE TABLE IF NOT EXISTS IDN_CLAIM ( 10 | ID INTEGER NOT NULL AUTO_INCREMENT, 11 | DIALECT_ID INTEGER NOT NULL, 12 | CLAIM_URI VARCHAR (255) NOT NULL, 13 | TENANT_ID INTEGER NOT NULL, 14 | PRIMARY KEY (ID), 15 | FOREIGN KEY (DIALECT_ID) REFERENCES IDN_CLAIM_DIALECT(ID) ON DELETE CASCADE, 16 | CONSTRAINT CLAIM_URI_CONSTRAINT UNIQUE (DIALECT_ID, CLAIM_URI, TENANT_ID) 17 | ); 18 | 19 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_MAPPED_ATTRIBUTE ( 20 | ID INTEGER NOT NULL AUTO_INCREMENT, 21 | LOCAL_CLAIM_ID INTEGER, 22 | USER_STORE_DOMAIN_NAME VARCHAR (255) NOT NULL, 23 | ATTRIBUTE_NAME VARCHAR (255) NOT NULL, 24 | TENANT_ID INTEGER NOT NULL, 25 | PRIMARY KEY (ID), 26 | FOREIGN KEY (LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 27 | CONSTRAINT USER_STORE_DOMAIN_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, USER_STORE_DOMAIN_NAME, TENANT_ID) 28 | ); 29 | 30 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_PROPERTY ( 31 | ID INTEGER NOT NULL AUTO_INCREMENT, 32 | LOCAL_CLAIM_ID INTEGER, 33 | PROPERTY_NAME VARCHAR (255) NOT NULL, 34 | PROPERTY_VALUE VARCHAR (255) NOT NULL, 35 | TENANT_ID INTEGER NOT NULL, 36 | PRIMARY KEY (ID), 37 | FOREIGN KEY (LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 38 | CONSTRAINT PROPERTY_NAME_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, PROPERTY_NAME, TENANT_ID) 39 | ); 40 | 41 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_MAPPING ( 42 | ID INTEGER NOT NULL AUTO_INCREMENT, 43 | EXT_CLAIM_ID INTEGER NOT NULL, 44 | MAPPED_LOCAL_CLAIM_ID INTEGER NOT NULL, 45 | TENANT_ID INTEGER NOT NULL, 46 | PRIMARY KEY (ID), 47 | FOREIGN KEY (EXT_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 48 | FOREIGN KEY (MAPPED_LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 49 | CONSTRAINT EXT_TO_LOC_MAPPING_CONSTRN UNIQUE (EXT_CLAIM_ID, TENANT_ID), 50 | ); 51 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/auth/BasicAuthenticationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.auth; 20 | 21 | import org.apache.http.Header; 22 | import org.apache.http.HttpRequest; 23 | import org.apache.http.auth.AUTH; 24 | import org.apache.http.message.BufferedHeader; 25 | import org.apache.http.util.CharArrayBuffer; 26 | 27 | import java.util.Base64; 28 | 29 | /** 30 | * Basic authentication manager. 31 | */ 32 | public class BasicAuthenticationManager implements AuthenticationManager { 33 | 34 | @Override 35 | public Header authenticate( 36 | final Credentials credentials, 37 | final HttpRequest request) { 38 | 39 | final StringBuilder tmp = new StringBuilder(); 40 | tmp.append(credentials.getUserPrincipal().getName()); 41 | tmp.append(":"); 42 | tmp.append((credentials.getPassword() == null) ? "" : credentials.getPassword()); 43 | 44 | final byte[] base64password = Base64.getEncoder().encode(tmp.toString().getBytes()); 45 | 46 | final CharArrayBuffer buffer = new CharArrayBuffer(32); 47 | 48 | //TODO handle proxy 49 | buffer.append(AUTH.WWW_AUTH_RESP); 50 | 51 | buffer.append(": Basic "); 52 | buffer.append(base64password, 0, base64password.length); 53 | 54 | return new BufferedHeader(buffer); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user.store/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/store/GetUsersWithClaimValuesFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.store; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; 22 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; 23 | import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | /** 29 | * Function to retrieve a list of users with provided claim values. 30 | */ 31 | @FunctionalInterface 32 | public interface GetUsersWithClaimValuesFunction { 33 | 34 | /** 35 | * Get a list of users who have the claim values as provided in the adaptive script. 36 | * 37 | * @param claimMap Map of claims and its values. 38 | * @param authenticationContext Authentication context object 39 | * @param parameters Additional parameters provided from the adaptive script. 40 | */ 41 | List getUsersWithClaimValues(Map claimMap, 42 | JsAuthenticationContext authenticationContext, 43 | String... parameters) throws FrameworkException; 44 | } 45 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/internal/HTTPFunctionsServiceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.http.internal; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry; 22 | import org.wso2.carbon.security.keystore.service.IdentityKeyStoreGenerator; 23 | 24 | public class HTTPFunctionsServiceHolder { 25 | 26 | private static HTTPFunctionsServiceHolder instance = new HTTPFunctionsServiceHolder(); 27 | 28 | private JsFunctionRegistry jsFunctionRegistry; 29 | private IdentityKeyStoreGenerator identityKeyStoreGenerator; 30 | 31 | public static HTTPFunctionsServiceHolder getInstance() { 32 | 33 | return instance; 34 | } 35 | 36 | private HTTPFunctionsServiceHolder() { 37 | 38 | } 39 | 40 | public JsFunctionRegistry getJsFunctionRegistry() { 41 | 42 | return jsFunctionRegistry; 43 | } 44 | 45 | public void setJsFunctionRegistry(JsFunctionRegistry jsFunctionRegistry) { 46 | 47 | this.jsFunctionRegistry = jsFunctionRegistry; 48 | } 49 | 50 | public IdentityKeyStoreGenerator getIdentityKeyStoreGenerator() { 51 | 52 | return identityKeyStoreGenerator; 53 | } 54 | 55 | public void setIdentityKeyStoreGenerator(IdentityKeyStoreGenerator identityKeyStoreGenerator) { 56 | 57 | this.identityKeyStoreGenerator = identityKeyStoreGenerator; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/listener/AnalyticsAxis2ConfigurationContextObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.analytics.listener; 19 | 20 | import org.apache.axis2.context.ConfigurationContext; 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.context.PrivilegedCarbonContext; 24 | import org.wso2.carbon.identity.conditional.auth.functions.analytics.ClientManager; 25 | import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * This class is responsible for closing the http client used for the tenant when the tenant is unloaded. 31 | */ 32 | public class AnalyticsAxis2ConfigurationContextObserver extends 33 | AbstractAxis2ConfigurationContextObserver { 34 | 35 | private static final Log log = LogFactory.getLog( 36 | AnalyticsAxis2ConfigurationContextObserver.class); 37 | 38 | public void terminatingConfigurationContext(ConfigurationContext configContext) { 39 | 40 | int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); 41 | try { 42 | ClientManager.getInstance().closeClient(tenantId); 43 | } catch (IOException e) { 44 | log.error("Error while closing http client for tenant: " + tenantId, e); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/JsWrapperBaseFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.GenericSerializableJsFunction; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 23 | import org.wso2.carbon.identity.application.authentication.framework.model.UserSession; 24 | 25 | /** 26 | * Interface to create Js Wrapper objects. 27 | */ 28 | public interface JsWrapperBaseFactory { 29 | 30 | /** 31 | * Creates a JavaScript Proxy for User session. 32 | * @param userSession - Represent User session Subject 33 | * @return Proxy for User Session 34 | */ 35 | JsUserSession createJsUserSession(UserSession userSession); 36 | 37 | /** 38 | * Creates a JavaScript Proxy for Application. 39 | * @param application - Represent Application Subject 40 | * @return Proxy for Application 41 | */ 42 | JsApplication createJsApplication(Application application); 43 | 44 | /** 45 | * Creates a Serializable Javascript function. 46 | * 47 | * @param source - Source of the function 48 | * @param isFunction - Is the source a function 49 | * @return Serializable Javascript function 50 | */ 51 | GenericSerializableJsFunction createJsSerializableFunction(String source, boolean isFunction); 52 | } 53 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/listener/ChoreoAxis2ConfigurationContextObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.choreo.listener; 20 | 21 | import org.apache.axis2.context.ConfigurationContext; 22 | import org.apache.commons.logging.Log; 23 | import org.apache.commons.logging.LogFactory; 24 | import org.wso2.carbon.context.PrivilegedCarbonContext; 25 | import org.wso2.carbon.identity.conditional.auth.functions.choreo.internal.ChoreoFunctionServiceHolder; 26 | import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * This class is responsible for closing the http client used for the tenant when the tenant is unloaded. 32 | */ 33 | public class ChoreoAxis2ConfigurationContextObserver extends AbstractAxis2ConfigurationContextObserver { 34 | 35 | private static final Log LOG = LogFactory.getLog( 36 | ChoreoAxis2ConfigurationContextObserver.class); 37 | 38 | public void terminatingConfigurationContext(ConfigurationContext configContext) { 39 | 40 | int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); 41 | try { 42 | ChoreoFunctionServiceHolder.getInstance().getClientManager().closeClient(tenantId); 43 | } catch (IOException e) { 44 | LOG.error("Error while closing http client for tenant: " + tenantId, e); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/JsGraalWrapperFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.GraalSerializableJsFunction; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 23 | import org.wso2.carbon.identity.application.authentication.framework.model.UserSession; 24 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.graaljs.JsGraalApplication; 25 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.graaljs.JsGraalUserSession; 26 | 27 | /** 28 | * Factory to create a Javascript Object Wrappers for GraalJS execution. 29 | * Since Nashorn is deprecated in JDK 11 and onwards. We are introducing GraalJS engine. 30 | */ 31 | public class JsGraalWrapperFactory implements JsWrapperBaseFactory { 32 | 33 | @Override 34 | public JsUserSession createJsUserSession(UserSession userSession) { 35 | 36 | return new JsGraalUserSession(userSession); 37 | } 38 | 39 | @Override 40 | public JsApplication createJsApplication(Application application) { 41 | 42 | return new JsGraalApplication(application); 43 | } 44 | 45 | public GraalSerializableJsFunction createJsSerializableFunction(String source, boolean isFunction) { 46 | 47 | return new GraalSerializableJsFunction(source, isFunction); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/nashorn/JsNashornApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model.nashorn; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.AbstractJsObject; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 23 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsApplication; 24 | 25 | /** 26 | * Javascript wrapper for Java level Application. 27 | * This provides controlled access to UserSession object via provided javascript native syntax. 28 | * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime 29 | * AuthenticatedUser. 30 | * 31 | * @see Application 32 | */ 33 | public class JsNashornApplication extends JsApplication implements AbstractJsObject { 34 | 35 | public JsNashornApplication(Application wrappedApplication) { 36 | 37 | super(wrappedApplication); 38 | } 39 | 40 | @Override 41 | public Object getMember(String name) { 42 | 43 | switch (name) { 44 | case "subject": 45 | return getWrapped().getSubject(); 46 | case "appName": 47 | return getWrapped().getAppName(); 48 | case "appId": 49 | return getWrapped().getAppId(); 50 | default: 51 | return super.getMember(name); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.session/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/session/test/SessionModelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | package org.wso2.carbon.identity.conditional.auth.functions.session.test; 20 | 21 | import org.testng.Assert; 22 | import org.testng.annotations.Test; 23 | import org.wso2.carbon.identity.conditional.auth.functions.session.model.Session; 24 | 25 | /** 26 | * Contains methods for testing Session Model class methods. 27 | */ 28 | public class SessionModelTest { 29 | 30 | //Test for model object's toJSONObject function 31 | @Test 32 | public void testGetJSONObject() { 33 | 34 | String sessionId = TestUtils.getRandomString(10, true, true); 35 | String timeStamp = TestUtils.getRandomString(10, false, true); 36 | String userAgent = TestUtils.getRandomString(10, true, true); 37 | String ipAddress = TestUtils.getRandomString(8, true, true); 38 | String serviceProvider = TestUtils.getRandomString(8, true, false); 39 | Session session = new Session(sessionId, timeStamp, userAgent, ipAddress, serviceProvider); 40 | String actual = "{" + 41 | "\"ipAddress\":\"" + ipAddress + "\"" + 42 | ",\"serviceProvider\":\"" + serviceProvider + "\"," + 43 | "\"userAgent\":\"" + userAgent + "\"," + 44 | "\"sessionID\":\"" + sessionId + "\"," + 45 | "\"timestamp\":\"" + timeStamp + "\"" + 46 | "}"; 47 | Assert.assertEquals(actual, session.toJSONObject().toString()); 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/nashorn/JsNashornUserAgent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model.nashorn; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.AbstractJsObject; 22 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsUserAgent; 23 | import org.wso2.carbon.identity.core.model.UserAgent; 24 | 25 | /** 26 | * Javascript wrapper for Java level UserAgent. 27 | * This provides controlled access to UserSession object via provided javascript native syntax. 28 | * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime 29 | * AuthenticatedUser. 30 | * 31 | * @see UserAgent 32 | */ 33 | public class JsNashornUserAgent extends JsUserAgent implements AbstractJsObject { 34 | 35 | public JsNashornUserAgent(UserAgent wrappedUserAgent) { 36 | 37 | super(wrappedUserAgent); 38 | } 39 | 40 | @Override 41 | public Object getMember(String name) { 42 | 43 | switch (name) { 44 | case "rawString": 45 | return getWrapped().getRawString(); 46 | case "browser": 47 | return getWrapped().getBrowser(); 48 | case "platform": 49 | return getWrapped().getPlatform(); 50 | case "device": 51 | return getWrapped().getDevice(); 52 | default: 53 | return super.getMember(name); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/openjdk/nashorn/JsOpenJdkNashornApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model.openjdk.nashorn; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.openjdk.nashorn.AbstractOpenJdkNashornJsObject; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 23 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsApplication; 24 | 25 | /** 26 | * Javascript wrapper for Java level Application. 27 | * This provides controlled access to UserSession object via provided javascript native syntax. 28 | * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime 29 | * AuthenticatedUser. 30 | * 31 | * @see Application 32 | */ 33 | public class JsOpenJdkNashornApplication extends JsApplication implements AbstractOpenJdkNashornJsObject { 34 | 35 | public JsOpenJdkNashornApplication(Application wrappedApplication) { 36 | 37 | super(wrappedApplication); 38 | } 39 | 40 | @Override 41 | public Object getMember(String name) { 42 | 43 | switch (name) { 44 | case "subject": 45 | return getWrapped().getSubject(); 46 | case "appName": 47 | return getWrapped().getAppName(); 48 | case "appId": 49 | return getWrapped().getAppId(); 50 | default: 51 | return super.getMember(name); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/util/ApiKeyAuthConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.http.util; 19 | 20 | import org.apache.http.client.methods.HttpUriRequest; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Implementation of the {@link AuthConfig} 26 | * This class is used to configure the API key authentication. 27 | * The API key is added to the request header. 28 | */ 29 | public class ApiKeyAuthConfig implements AuthConfig { 30 | private String headerName = "X-API-KEY"; // Default header name 31 | private String apiKey; 32 | private static final String HEADER_NAME_VARIABLE_NAME = "headerName"; 33 | private static final String API_KEY_VARIABLE_NAME = "apiKey"; 34 | 35 | public void setHeaderName(String headerName) { 36 | this.headerName = headerName; 37 | } 38 | 39 | public void setApiKey(String apiKey) { 40 | this.apiKey = apiKey; 41 | } 42 | 43 | public String getHeaderName() { 44 | return headerName; 45 | } 46 | 47 | public String getApiKey() { 48 | return apiKey; 49 | } 50 | 51 | @Override 52 | public HttpUriRequest applyAuth(HttpUriRequest request, AuthConfigModel authConfigModel) { 53 | 54 | Map properties = authConfigModel.getProperties(); 55 | setApiKey(properties.get(API_KEY_VARIABLE_NAME).toString()); 56 | setHeaderName(properties.get(HEADER_NAME_VARIABLE_NAME).toString()); 57 | request.addHeader(getHeaderName(), getApiKey()); 58 | return request; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/JsOpenJdkNashornWrapperFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.openjdk.nashorn.OpenJdkNashornSerializableJsFunction; 22 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 23 | import org.wso2.carbon.identity.application.authentication.framework.model.UserSession; 24 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.openjdk.nashorn.JsOpenJdkNashornApplication; 25 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.openjdk.nashorn.JsOpenJdkNashornUserSession; 26 | 27 | /** 28 | * Factory to create a Javascript Object Wrappers for OpenJDk.Nashorn execution. 29 | * Since Nashorn is deprecated in JDK 11 and onwards. We are introducing OpenJDK Nashorn engine. 30 | */ 31 | public class JsOpenJdkNashornWrapperFactory implements JsWrapperBaseFactory { 32 | 33 | @Override 34 | public JsUserSession createJsUserSession(UserSession userSession) { 35 | 36 | return new JsOpenJdkNashornUserSession(userSession); 37 | } 38 | 39 | @Override 40 | public JsApplication createJsApplication(Application application) { 41 | 42 | return new JsOpenJdkNashornApplication(application); 43 | } 44 | 45 | public OpenJdkNashornSerializableJsFunction createJsSerializableFunction(String source, boolean isFunction) { 46 | 47 | return new OpenJdkNashornSerializableJsFunction(source, isFunction); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/auth/BasicUserPrincipal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.auth; 20 | 21 | import org.apache.http.util.LangUtils; 22 | 23 | import java.io.Serializable; 24 | import java.security.Principal; 25 | 26 | /** 27 | * Basic user principal implementation. 28 | */ 29 | public class BasicUserPrincipal implements Principal, Serializable { 30 | 31 | private static final long serialVersionUID = 2521442859755178103L; 32 | private final String username; 33 | 34 | public BasicUserPrincipal(String username) { 35 | this.username = username; 36 | } 37 | 38 | public String getName() { 39 | return this.username; 40 | } 41 | 42 | public int hashCode() { 43 | int hash = LangUtils.HASH_SEED; 44 | hash = LangUtils.hashCode(hash, this.username); 45 | return hash; 46 | } 47 | 48 | public boolean equals(Object o) { 49 | if (this == o) { 50 | return true; 51 | } 52 | if (o instanceof BasicUserPrincipal) { 53 | final BasicUserPrincipal that = (BasicUserPrincipal) o; 54 | if (LangUtils.equals(this.username, that.username)) { 55 | return true; 56 | } 57 | } 58 | return false; 59 | } 60 | 61 | public String toString() { 62 | StringBuilder buffer = new StringBuilder(); 63 | buffer.append("[principal: "); 64 | buffer.append(this.username); 65 | buffer.append("]"); 66 | return buffer.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/openjdk/nashorn/JsOpenJdkNashornUserAgent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model.openjdk.nashorn; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.openjdk.nashorn.AbstractOpenJdkNashornJsObject; 22 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsUserAgent; 23 | import org.wso2.carbon.identity.core.model.UserAgent; 24 | 25 | /** 26 | * Javascript wrapper for Java level UserAgent. 27 | * This provides controlled access to UserSession object via provided javascript native syntax. 28 | * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime 29 | * AuthenticatedUser. 30 | * 31 | * @see UserAgent 32 | */ 33 | public class JsOpenJdkNashornUserAgent extends JsUserAgent implements AbstractOpenJdkNashornJsObject { 34 | 35 | public JsOpenJdkNashornUserAgent(UserAgent wrappedUserAgent) { 36 | 37 | super(wrappedUserAgent); 38 | } 39 | 40 | @Override 41 | public Object getMember(String name) { 42 | 43 | switch (name) { 44 | case "rawString": 45 | return getWrapped().getRawString(); 46 | case "browser": 47 | return getWrapped().getBrowser(); 48 | case "platform": 49 | return getWrapped().getPlatform(); 50 | case "device": 51 | return getWrapped().getDevice(); 52 | default: 53 | return super.getMember(name); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/auth/UsernamePasswordCredentials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.auth; 20 | 21 | import org.apache.http.util.LangUtils; 22 | 23 | import java.security.Principal; 24 | 25 | /** 26 | * Username password credential implementation. 27 | */ 28 | public class UsernamePasswordCredentials implements Credentials { 29 | private final BasicUserPrincipal principal; 30 | private final String password; 31 | 32 | public UsernamePasswordCredentials(String userName, String password) { 33 | 34 | this.principal = new BasicUserPrincipal(userName); 35 | this.password = password; 36 | } 37 | 38 | public Principal getUserPrincipal() { 39 | return this.principal; 40 | } 41 | 42 | public String getUserName() { 43 | return this.principal.getName(); 44 | } 45 | 46 | public String getPassword() { 47 | return this.password; 48 | } 49 | 50 | public int hashCode() { 51 | return this.principal.hashCode(); 52 | } 53 | 54 | public boolean equals(Object o) { 55 | if (this == o) { 56 | return true; 57 | } else { 58 | if (o instanceof UsernamePasswordCredentials) { 59 | UsernamePasswordCredentials that = (UsernamePasswordCredentials)o; 60 | return LangUtils.equals(this.principal, that.principal); 61 | } 62 | 63 | return false; 64 | } 65 | } 66 | 67 | public String toString() { 68 | return this.principal.toString(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/utils/ResolveMultiAttributeLoginIdentifierFunctionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-2025, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.utils; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.graalvm.polyglot.HostAccess; 24 | import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; 25 | import org.wso2.carbon.identity.core.util.IdentityTenantUtil; 26 | import org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult; 27 | 28 | /** 29 | * Function to resolve user from multi attribute login identifier. 30 | */ 31 | public class ResolveMultiAttributeLoginIdentifierFunctionImpl implements ResolveMultiAttributeLoginIdentifierFunction { 32 | 33 | private static final Log log = LogFactory.getLog(ResolveMultiAttributeLoginIdentifierFunctionImpl.class); 34 | 35 | @Override 36 | @HostAccess.Export 37 | public String resolveMultiAttributeLoginIdentifier(String loginIdentifier, String tenantDomain) { 38 | 39 | if (!IdentityTenantUtil.resolveTenantDomain().equals(tenantDomain)) { 40 | log.debug("Cross-tenant multi attribute login identifier lookup is not allowed."); 41 | return null; 42 | } 43 | ResolvedUserResult resolvedUserResult = FrameworkUtils.processMultiAttributeLoginIdentification( 44 | loginIdentifier, tenantDomain); 45 | 46 | if (resolvedUserResult != null && 47 | ResolvedUserResult.UserResolvedStatus.SUCCESS.equals(resolvedUserResult.getResolvedStatus())) { 48 | return resolvedUserResult.getUser().getPreferredUsername(); 49 | } 50 | return null; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/internal/AnalyticsFunctionsServiceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.analytics.internal; 20 | 21 | import org.wso2.carbon.base.api.ServerConfigurationService; 22 | import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry; 23 | 24 | import java.security.KeyStore; 25 | 26 | public class AnalyticsFunctionsServiceHolder { 27 | 28 | private static AnalyticsFunctionsServiceHolder instance = new AnalyticsFunctionsServiceHolder(); 29 | 30 | private JsFunctionRegistry jsFunctionRegistry; 31 | private ServerConfigurationService serverConfigurationService; 32 | private KeyStore trustStore; 33 | 34 | public KeyStore getTrustStore() { 35 | 36 | return trustStore; 37 | } 38 | 39 | public void setTrustStore(KeyStore trustStore) { 40 | 41 | this.trustStore = trustStore; 42 | } 43 | 44 | public ServerConfigurationService getServerConfigurationService() { 45 | 46 | return serverConfigurationService; 47 | } 48 | 49 | public void setServerConfigurationService(ServerConfigurationService serverConfigurationService) { 50 | 51 | this.serverConfigurationService = serverConfigurationService; 52 | } 53 | 54 | public static AnalyticsFunctionsServiceHolder getInstance() { 55 | 56 | return instance; 57 | } 58 | 59 | private AnalyticsFunctionsServiceHolder(){ 60 | 61 | } 62 | 63 | public JsFunctionRegistry getJsFunctionRegistry() { 64 | 65 | return jsFunctionRegistry; 66 | } 67 | 68 | public void setJsFunctionRegistry(JsFunctionRegistry jsFunctionRegistry) { 69 | 70 | this.jsFunctionRegistry = jsFunctionRegistry; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/util/BasicAuthConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.http.util; 19 | 20 | import org.apache.http.client.methods.HttpUriRequest; 21 | 22 | import java.nio.charset.StandardCharsets; 23 | import java.util.Base64; 24 | import java.util.Map; 25 | 26 | /** 27 | * Implementation of the {@link AuthConfig} 28 | * This class is used to configure the basic authentication. 29 | * The username and password are added to the request header. 30 | */ 31 | public class BasicAuthConfig implements AuthConfig { 32 | private String username; 33 | private String password; 34 | private static final String USERNAME_VARIABLE_NAME = "username"; 35 | private static final String PASSWORD_VARIABLE_NAME = "password"; 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public void setPassword(String password) { 42 | this.password = password; 43 | } 44 | 45 | public String getUsername() { 46 | return username; 47 | } 48 | 49 | public String getPassword() { 50 | return password; 51 | } 52 | 53 | @Override 54 | public HttpUriRequest applyAuth(HttpUriRequest request, AuthConfigModel authConfigModel) { 55 | 56 | Map properties = authConfigModel.getProperties(); 57 | setUsername(properties.get(USERNAME_VARIABLE_NAME).toString()); 58 | setPassword(properties.get(PASSWORD_VARIABLE_NAME).toString()); 59 | String auth = getUsername() + ":" + getPassword(); 60 | String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8)); 61 | request.addHeader("Authorization", "Basic " + encodedAuth); 62 | 63 | return request; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.notification/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/notification/internal/NotificationFunctionServiceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.notification.internal; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry; 22 | import org.wso2.carbon.identity.event.services.IdentityEventService; 23 | import org.wso2.carbon.user.core.service.RealmService; 24 | 25 | public class NotificationFunctionServiceHolder { 26 | 27 | private static NotificationFunctionServiceHolder instance = new NotificationFunctionServiceHolder(); 28 | 29 | private RealmService realmService; 30 | private JsFunctionRegistry jsFunctionRegistry; 31 | private IdentityEventService identityEventService; 32 | 33 | public static NotificationFunctionServiceHolder getInstance() { 34 | 35 | return instance; 36 | } 37 | 38 | private NotificationFunctionServiceHolder(){ 39 | } 40 | 41 | public RealmService getRealmService() { 42 | 43 | return realmService; 44 | } 45 | 46 | public void setRealmService(RealmService realmService) { 47 | 48 | this.realmService = realmService; 49 | } 50 | 51 | public JsFunctionRegistry getJsFunctionRegistry() { 52 | 53 | return jsFunctionRegistry; 54 | } 55 | 56 | public void setJsFunctionRegistry(JsFunctionRegistry jsFunctionRegistry) { 57 | 58 | this.jsFunctionRegistry = jsFunctionRegistry; 59 | } 60 | 61 | public IdentityEventService getIdentityEventService() { 62 | 63 | return identityEventService; 64 | } 65 | 66 | public void setIdentityEventService(IdentityEventService identityEventService) { 67 | 68 | this.identityEventService = identityEventService; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/resources/org/wso2/carbon/identity/conditional/auth/functions/utils/get-masked-value-sp.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 1 20 | default 21 | Default Service Provider 22 | 23 | 24 | 25 | 1 26 | 27 | 28 | BasicMockAuthenticator 29 | basicauth 30 | true 31 | 32 | 33 | true 34 | true 35 | 36 | 37 | 51 | flow 52 | 53 | 54 | true 55 | 56 | 57 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.http/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/http/util/HttpUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 org.wso2.carbon.identity.conditional.auth.functions.http.util; 19 | 20 | import org.apache.http.client.methods.HttpUriRequest; 21 | import org.wso2.carbon.identity.conditional.auth.functions.common.utils.Constants; 22 | 23 | /** 24 | * Utility class for HTTP related operations. 25 | */ 26 | public class HttpUtil { 27 | 28 | /** 29 | * Get the invoke API Action ID based on the HTTP method. 30 | * 31 | * @param request HttpUriRequest 32 | * @return String 33 | */ 34 | public static String getInvokeApiActionId(HttpUriRequest request) { 35 | 36 | String invokeApi; 37 | 38 | if (request.getMethod().equals(Constants.GET)) { 39 | invokeApi = Constants.LogConstants.ActionIDs.INVOKE_API_HTTP_GET; 40 | } else if (request.getMethod().equals(Constants.POST)) { 41 | invokeApi = Constants.LogConstants.ActionIDs.INVOKE_API_HTTP_POST; 42 | } else { 43 | invokeApi = "invoke-api"; 44 | } 45 | 46 | return invokeApi; 47 | } 48 | 49 | /** 50 | * Get the request token Action ID based on the HTTP method. 51 | * 52 | * @param request HttpUriRequest 53 | * @return String 54 | */ 55 | public static String getRequestTokenActionId(HttpUriRequest request) { 56 | String requestToken; 57 | if (request.getMethod().equals(Constants.GET)) { 58 | requestToken = Constants.LogConstants.ActionIDs.REQUEST_TOKEN_HTTP_GET; 59 | } else if (request.getMethod().equals(Constants.POST)) { 60 | requestToken = Constants.LogConstants.ActionIDs.REQUEST_TOKEN_HTTP_POST; 61 | } else { 62 | requestToken = "request-token"; 63 | } 64 | return requestToken; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/resources/dbscripts/h2.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_DIALECT ( 2 | ID INTEGER NOT NULL AUTO_INCREMENT, 3 | DIALECT_URI VARCHAR (255) NOT NULL, 4 | TENANT_ID INTEGER NOT NULL, 5 | PRIMARY KEY (ID), 6 | CONSTRAINT DIALECT_URI_CONSTRAINT UNIQUE (DIALECT_URI, TENANT_ID) 7 | ); 8 | 9 | CREATE TABLE IF NOT EXISTS IDN_CLAIM ( 10 | ID INTEGER NOT NULL AUTO_INCREMENT, 11 | DIALECT_ID INTEGER NOT NULL, 12 | CLAIM_URI VARCHAR (255) NOT NULL, 13 | TENANT_ID INTEGER NOT NULL, 14 | PRIMARY KEY (ID), 15 | FOREIGN KEY (DIALECT_ID) REFERENCES IDN_CLAIM_DIALECT(ID) ON DELETE CASCADE, 16 | CONSTRAINT CLAIM_URI_CONSTRAINT UNIQUE (DIALECT_ID, CLAIM_URI, TENANT_ID) 17 | ); 18 | 19 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_MAPPED_ATTRIBUTE ( 20 | ID INTEGER NOT NULL AUTO_INCREMENT, 21 | LOCAL_CLAIM_ID INTEGER, 22 | USER_STORE_DOMAIN_NAME VARCHAR (255) NOT NULL, 23 | ATTRIBUTE_NAME VARCHAR (255) NOT NULL, 24 | TENANT_ID INTEGER NOT NULL, 25 | PRIMARY KEY (ID), 26 | FOREIGN KEY (LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 27 | CONSTRAINT USER_STORE_DOMAIN_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, USER_STORE_DOMAIN_NAME, TENANT_ID) 28 | ); 29 | 30 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_PROPERTY ( 31 | ID INTEGER NOT NULL AUTO_INCREMENT, 32 | LOCAL_CLAIM_ID INTEGER, 33 | PROPERTY_NAME VARCHAR (255) NOT NULL, 34 | PROPERTY_VALUE VARCHAR (255) NOT NULL, 35 | TENANT_ID INTEGER NOT NULL, 36 | PRIMARY KEY (ID), 37 | FOREIGN KEY (LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 38 | CONSTRAINT PROPERTY_NAME_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, PROPERTY_NAME, TENANT_ID) 39 | ); 40 | 41 | CREATE TABLE IF NOT EXISTS IDN_CLAIM_MAPPING ( 42 | ID INTEGER NOT NULL AUTO_INCREMENT, 43 | EXT_CLAIM_ID INTEGER NOT NULL, 44 | MAPPED_LOCAL_CLAIM_ID INTEGER NOT NULL, 45 | TENANT_ID INTEGER NOT NULL, 46 | PRIMARY KEY (ID), 47 | FOREIGN KEY (EXT_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 48 | FOREIGN KEY (MAPPED_LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID) ON DELETE CASCADE, 49 | CONSTRAINT EXT_TO_LOC_MAPPING_CONSTRN UNIQUE (EXT_CLAIM_ID, TENANT_ID), 50 | ); 51 | 52 | CREATE TABLE IF NOT EXISTS IDN_AUTH_WAIT_STATUS ( 53 | ID INTEGER AUTO_INCREMENT NOT NULL, 54 | TENANT_ID INTEGER NOT NULL, 55 | LONG_WAIT_KEY VARCHAR(255) NOT NULL, 56 | WAIT_STATUS CHAR(1) NOT NULL DEFAULT '1', 57 | TIME_CREATED TIMESTAMP DEFAULT 0, 58 | EXPIRE_TIME TIMESTAMP DEFAULT 0, 59 | PRIMARY KEY (ID), 60 | CONSTRAINT IDN_AUTH_WAIT_STATUS_KEY UNIQUE (LONG_WAIT_KEY) 61 | ); 62 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/elk/internal/ElasticFunctionsServiceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | 20 | package org.wso2.carbon.identity.conditional.auth.functions.elk.internal; 21 | 22 | import org.wso2.carbon.base.api.ServerConfigurationService; 23 | import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry; 24 | 25 | import java.security.KeyStore; 26 | 27 | /** 28 | * Class to hold services discovered via OSGI on this component. 29 | */ 30 | public class ElasticFunctionsServiceHolder { 31 | 32 | private static final ElasticFunctionsServiceHolder instance = new ElasticFunctionsServiceHolder(); 33 | 34 | private JsFunctionRegistry jsFunctionRegistry; 35 | private ServerConfigurationService serverConfigurationService; 36 | private KeyStore trustStore; 37 | 38 | public KeyStore getTrustStore() { 39 | 40 | return trustStore; 41 | } 42 | 43 | public void setTrustStore(KeyStore trustStore) { 44 | 45 | this.trustStore = trustStore; 46 | } 47 | 48 | public ServerConfigurationService getServerConfigurationService() { 49 | 50 | return serverConfigurationService; 51 | } 52 | 53 | public void setServerConfigurationService(ServerConfigurationService serverConfigurationService) { 54 | 55 | this.serverConfigurationService = serverConfigurationService; 56 | } 57 | 58 | public static ElasticFunctionsServiceHolder getInstance() { 59 | 60 | return instance; 61 | } 62 | 63 | private ElasticFunctionsServiceHolder() { 64 | 65 | } 66 | 67 | public JsFunctionRegistry getJsFunctionRegistry() { 68 | 69 | return jsFunctionRegistry; 70 | } 71 | 72 | public void setJsFunctionRegistry(JsFunctionRegistry jsFunctionRegistry) { 73 | 74 | this.jsFunctionRegistry = jsFunctionRegistry; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/model/JsUtilsProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.model; 20 | 21 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGenericGraphBuilderFactory; 22 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalGraphBuilderFactory; 23 | import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.openjdk.nashorn.JsOpenJdkNashornGraphBuilderFactory; 24 | import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; 25 | import org.wso2.carbon.identity.conditional.auth.functions.common.model.graaljs.JsGraalUtils; 26 | import org.wso2.carbon.identity.conditional.auth.functions.common.model.nashorn.JsNashornUtils; 27 | import org.wso2.carbon.identity.conditional.auth.functions.common.model.openjdk.nashorn.JsOpenJdkNashornUtils; 28 | 29 | public class JsUtilsProvider { 30 | 31 | private static final JsUtilsProvider jsUtilsProvider = new JsUtilsProvider(); 32 | 33 | private final JsUtils jsUtils; 34 | 35 | private JsUtilsProvider() { 36 | 37 | JsGenericGraphBuilderFactory jsGraphBuilderFactory = 38 | FrameworkUtils.createJsGenericGraphBuilderFactoryFromConfig(); 39 | if (jsGraphBuilderFactory instanceof JsOpenJdkNashornGraphBuilderFactory) { 40 | jsUtils = new JsOpenJdkNashornUtils(); 41 | } else if (jsGraphBuilderFactory instanceof JsGraalGraphBuilderFactory) { 42 | jsUtils = new JsGraalUtils(); 43 | } else { 44 | jsUtils = new JsNashornUtils(); 45 | } 46 | } 47 | 48 | public static JsUtilsProvider getInstance() { 49 | 50 | return jsUtilsProvider; 51 | } 52 | 53 | public JsUtils getJsUtils() { 54 | 55 | return jsUtils; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.common/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/common/internal/FunctionsServiceComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.common.internal; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.osgi.service.component.annotations.Component; 24 | import org.osgi.service.component.annotations.Reference; 25 | import org.osgi.service.component.annotations.ReferenceCardinality; 26 | import org.osgi.service.component.annotations.ReferencePolicy; 27 | import org.wso2.carbon.identity.governance.IdentityGovernanceService; 28 | 29 | @Component( 30 | name = "identity.conditional.auth.functions.common", 31 | immediate = true 32 | ) 33 | public class FunctionsServiceComponent { 34 | 35 | private static final Log LOG = LogFactory.getLog(FunctionsServiceComponent.class); 36 | 37 | @Reference( 38 | name = "identity.governance.service", 39 | service = IdentityGovernanceService.class, 40 | cardinality = ReferenceCardinality.MANDATORY, 41 | policy = ReferencePolicy.DYNAMIC, 42 | unbind = "unsetIdentityGovernanceService" 43 | ) 44 | protected void setIdentityGovernanceService(IdentityGovernanceService identityGovernanceService) { 45 | 46 | if (LOG.isDebugEnabled()) { 47 | LOG.debug("Identity Governance service is set form functions"); 48 | } 49 | FunctionsDataHolder.getInstance().setIdentityGovernanceService(identityGovernanceService); 50 | } 51 | 52 | protected void unsetIdentityGovernanceService(IdentityGovernanceService identityGovernanceService) { 53 | 54 | if (LOG.isDebugEnabled()) { 55 | LOG.debug("Identity Governance service is unset from functions"); 56 | } 57 | FunctionsDataHolder.getInstance().setIdentityGovernanceService(null); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/utils/FilterAuthenticatorsFunctionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.utils; 20 | 21 | import org.apache.commons.lang.StringUtils; 22 | import org.graalvm.polyglot.HostAccess; 23 | import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | /** 29 | * Implementation of the {@link FilterAuthenticatorsFunction}. 30 | */ 31 | public class FilterAuthenticatorsFunctionImpl implements FilterAuthenticatorsFunction { 32 | @Override 33 | @HostAccess.Export 34 | public Map> filterAuthenticators(List> authenticatorOptions, 35 | String excludeAuthenticator) { 36 | 37 | Map> result = new HashMap<>(); 38 | int index = 0; 39 | 40 | if (authenticatorOptions != null) { 41 | for (Map option : authenticatorOptions) { 42 | String idp = option.get(FrameworkConstants.JSAttributes.IDP); 43 | String authenticator = option.get(FrameworkConstants.JSAttributes.AUTHENTICATOR); 44 | 45 | if (!StringUtils.equals(excludeAuthenticator, authenticator)) { 46 | Map idpMap = new HashMap<>(); 47 | if (FrameworkConstants.LOCAL_IDP_NAME.equals(idp)) { 48 | idpMap.put(FrameworkConstants.JSAttributes.AUTHENTICATOR, authenticator); 49 | } else { 50 | idpMap.put(FrameworkConstants.JSAttributes.IDP, idp); 51 | } 52 | result.put(String.valueOf(index++), idpMap); 53 | } 54 | } 55 | } 56 | return result; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.user/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/user/model/graaljs/JsGraalApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | 19 | package org.wso2.carbon.identity.conditional.auth.functions.user.model.graaljs; 20 | 21 | import org.graalvm.polyglot.Value; 22 | import org.graalvm.polyglot.proxy.ProxyArray; 23 | import org.graalvm.polyglot.proxy.ProxyObject; 24 | import org.wso2.carbon.identity.application.authentication.framework.model.Application; 25 | import org.wso2.carbon.identity.conditional.auth.functions.user.model.JsApplication; 26 | 27 | /** 28 | * Javascript wrapper for Java level Application. 29 | * This provides controlled access to UserSession object via provided javascript native syntax. 30 | * Also, it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime 31 | * AuthenticatedUser. 32 | * 33 | * @see Application 34 | */ 35 | public class JsGraalApplication extends JsApplication implements ProxyObject { 36 | 37 | public JsGraalApplication(Application wrappedApplication) { 38 | 39 | super(wrappedApplication); 40 | } 41 | 42 | @Override 43 | public Object getMemberKeys() { 44 | 45 | return ProxyArray.fromArray("subject", "appName", "appId"); 46 | } 47 | 48 | @Override 49 | public boolean hasMember(String key) { 50 | 51 | return "subject".equals(key) || "appName".equals(key) || "appId".equals(key); 52 | } 53 | 54 | @Override 55 | public Object getMember(String name) { 56 | 57 | switch (name) { 58 | case "subject": 59 | return getWrapped().getSubject(); 60 | case "appName": 61 | return getWrapped().getAppName(); 62 | case "appId": 63 | return getWrapped().getAppId(); 64 | default: 65 | return super.getMember(name); 66 | } 67 | } 68 | 69 | @Override 70 | public void putMember(String key, Value value) { 71 | 72 | // read-only object. 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Purpose 2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc. 3 | 4 | ## Goals 5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above 6 | 7 | ## Approach 8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here. 9 | 10 | ## User stories 11 | > Summary of user stories addressed by this change> 12 | 13 | ## Release note 14 | > Brief description of the new feature or bug fix as it will appear in the release notes 15 | 16 | ## Documentation 17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact 18 | 19 | ## Training 20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable 21 | 22 | ## Certification 23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why. 24 | 25 | ## Marketing 26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable 27 | 28 | ## Automation tests 29 | - Unit tests 30 | > Code coverage information 31 | - Integration tests 32 | > Details about the test cases and coverage 33 | 34 | ## Security checks 35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no 36 | - Ran FindSecurityBugs plugin and verified report? yes/no 37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no 38 | 39 | ## Samples 40 | > Provide high-level details about the samples related to this feature 41 | 42 | ## Related PRs 43 | > List any other related PRs 44 | 45 | ## Migrations (if applicable) 46 | > Describe migration steps and platforms on which migration has been tested 47 | 48 | ## Test environment 49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested 50 | 51 | ## Learning 52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem. -------------------------------------------------------------------------------- /components/org.wso2.carbon.identity.conditional.auth.functions.session/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/session/model/Session.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * 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 | */ 19 | package org.wso2.carbon.identity.conditional.auth.functions.session.model; 20 | 21 | import org.json.JSONObject; 22 | 23 | import java.io.Serializable; 24 | 25 | /** 26 | * Model class to store details about a active sessions of user. 27 | */ 28 | public class Session implements Serializable { 29 | 30 | private String sessionId; 31 | private String timeStamp; 32 | private String userAgent; 33 | private String ipAddress; 34 | private String serviceProvider; 35 | 36 | /** 37 | * Constructor of the model class. 38 | * 39 | * @param sessionId ID of the session 40 | * @param startTimeStamp Timestamp representing the creation time of session 41 | * @param userAgent user agent for the session 42 | * @param ipAddress ip address of the user 43 | * @param serviceProvider service provider of the session 44 | */ 45 | public Session(String sessionId, String startTimeStamp, String userAgent, String ipAddress, String serviceProvider) { 46 | 47 | this.sessionId = sessionId; 48 | this.timeStamp = startTimeStamp; 49 | this.userAgent = userAgent; 50 | this.ipAddress = ipAddress; 51 | this.serviceProvider = serviceProvider; 52 | } 53 | public String getSessionId() { 54 | return sessionId; 55 | } 56 | /** 57 | * Method for retrieving session details as a JSON Object. 58 | * 59 | * @return A JSON Object with session details 60 | */ 61 | public JSONObject toJSONObject() { 62 | 63 | JSONObject jsonObject = new JSONObject(); 64 | jsonObject.put("sessionID", sessionId); 65 | jsonObject.put("timestamp", timeStamp); 66 | jsonObject.put("userAgent", userAgent); 67 | jsonObject.put("ipAddress", ipAddress); 68 | jsonObject.put("serviceProvider", serviceProvider); 69 | return jsonObject; 70 | } 71 | } 72 | --------------------------------------------------------------------------------