|
20 | 20 |
|
21 | 21 | import org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException; |
22 | 22 | import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; |
| 23 | +import org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig; |
| 24 | +import org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig; |
23 | 25 | import org.wso2.carbon.identity.application.common.model.ServiceProvider; |
24 | 26 | import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil; |
25 | 27 | import org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener; |
| 28 | +import org.wso2.carbon.identity.core.util.IdentityTenantUtil; |
26 | 29 | import org.wso2.carbon.identity.oauth.Error; |
27 | 30 | import org.wso2.identity.apps.common.internal.AppsCommonDataHolder; |
28 | 31 |
|
| 32 | +import java.util.Arrays; |
| 33 | +import java.util.Optional; |
29 | 34 | import java.util.Set; |
30 | 35 |
|
| 36 | +import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.OAUTH2; |
| 37 | + |
31 | 38 | /** |
32 | 39 | * App portal application management listener. |
33 | 40 | */ |
@@ -64,7 +71,18 @@ public boolean isEnable() { |
64 | 71 | public boolean doPreUpdateApplication(ServiceProvider serviceProvider, String tenantDomain, String userName) |
65 | 72 | throws IdentityApplicationManagementException { |
66 | 73 |
|
67 | | - if (!isEnable() || IdentityApplicationManagementUtil.getAllowUpdateSystemApplicationThreadLocal()) { |
| 74 | + if (!isEnable()) { |
| 75 | + return true; |
| 76 | + } |
| 77 | + |
| 78 | + Optional<String> clientId = getOAuth2ClientId(serviceProvider); |
| 79 | + if (clientId.isPresent() && IdentityTenantUtil.isSystemApplication(tenantDomain, clientId.get()) && |
| 80 | + serviceProvider.isEnhancedOrganizationAuthenticationEnabled()) { |
| 81 | + throw new IdentityApplicationManagementClientException(Error.INVALID_UPDATE.getErrorCode(), |
| 82 | + "Enabling enhanced organization authentication is not allowed for system applications."); |
| 83 | + } |
| 84 | + |
| 85 | + if (IdentityApplicationManagementUtil.getAllowUpdateSystemApplicationThreadLocal()) { |
68 | 86 | return true; |
69 | 87 | } |
70 | 88 |
|
@@ -93,6 +111,17 @@ public boolean doPreDeleteApplication(String applicationName, String tenantDomai |
93 | 111 | "Deletion of system applications are not allowed. Application name: " + applicationName); |
94 | 112 | } |
95 | 113 |
|
| 114 | + private Optional<String> getOAuth2ClientId(ServiceProvider serviceProvider) { |
| 115 | + |
| 116 | + return Optional.ofNullable(serviceProvider.getInboundAuthenticationConfig()) |
| 117 | + .map(InboundAuthenticationConfig::getInboundAuthenticationRequestConfigs) |
| 118 | + .map(Arrays::stream) |
| 119 | + .flatMap(stream -> stream |
| 120 | + .filter(cfg -> OAUTH2.equals(cfg.getInboundAuthType())) |
| 121 | + .findFirst()) |
| 122 | + .map(InboundAuthenticationRequestConfig::getInboundAuthKey); |
| 123 | + } |
| 124 | + |
96 | 125 | private ServiceProvider getApplicationByResourceId(String resourceId, String tenantDomain) |
97 | 126 | throws IdentityApplicationManagementException { |
98 | 127 |
|
|
0 commit comments