Skip to content

Commit

Permalink
Fix review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Nov 30, 2023
1 parent 3c7650f commit 86e01ec
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
package org.wso2.carbon.identity.oauth;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
Expand All @@ -42,6 +43,7 @@

import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.OAUTH2;
Expand All @@ -53,6 +55,7 @@
*/
public class OauthInboundAuthConfigHandler implements ApplicationInboundAuthConfigHandler {

private static final Log log = LogFactory.getLog(OauthInboundAuthConfigHandler.class);
private static final String TENANT_NAME_FROM_CONTEXT = "TenantNameFromContext";

@Override
Expand Down Expand Up @@ -124,8 +127,7 @@ public InboundAuthenticationRequestConfig handleConfigUpdate(

// First we identify whether this is a insert or update.
try {
String currentClientId = InboundFunctions.getInboundAuthKey(application,
FrameworkConstants.StandardInboundProtocols.OAUTH2);
Optional<String> optionalInboundAuthKey = InboundFunctions.getInboundAuthKey(application, OAUTH2);

// Retrieve the existing CORS origins for the application.
existingCORSOrigins = OAuthComponentServiceHolder.getInstance().getCorsManagementService()
Expand All @@ -137,10 +139,10 @@ public InboundAuthenticationRequestConfig handleConfigUpdate(
OAuthComponentServiceHolder.getInstance().getCorsManagementService().setCORSOrigins(
application.getApplicationResourceId(), corsOrigins, tenantDomain);

if (currentClientId != null) {
if (optionalInboundAuthKey.isPresent()) {
// Update an existing application.
OAuthConsumerAppDTO oauthApp = OAuth2ServiceComponentHolder.getInstance().getOAuthAdminService()
.getOAuthApplicationData(currentClientId);
.getOAuthApplicationData(optionalInboundAuthKey.get());

if (!StringUtils.equals(oauthApp.getOauthConsumerKey(), consumerAppDTO.getOauthConsumerKey())) {
throw new IdentityOAuthClientException("Invalid ClientID provided for update.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@

package org.wso2.carbon.identity.oauth.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.axis2.databinding.annotation.IgnoreNullElement;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.mgt.inbound.dto.InboundProtocolConfigurationDTO;

import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlTransient;

/**
* OAuth consumer app dto.
*/
Expand Down Expand Up @@ -71,7 +75,15 @@ public class OAuthConsumerAppDTO implements InboundProtocolConfigurationDTO {
private String jwksURI;
private boolean fapiConformanceEnabled;
// CORS orgin related properties. This will be used by the CORS management service
@IgnoreNullElement
@XmlTransient
@JsonIgnore
private List<String> allowedOrigins = null;

// This will be used to store data for audit logs. This will not be persisted in the database.
@IgnoreNullElement
@XmlTransient
@JsonIgnore
private Map<String, Object> auditLogData;

public String getJwksURI() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.oauth;

import org.apache.axis2.context.ConfigurationContext;
Expand Down Expand Up @@ -43,7 +61,7 @@
import static org.powermock.api.mockito.PowerMockito.when;

@PrepareForTest({ OAuth2ServiceComponentHolder.class, OAuthComponentServiceHolder.class, PrivilegedCarbonContext.class})
public class OAuthProtocolManagementServiceTest extends PowerMockTestCase {
public class OAuthInboundAuthConfigHandlerTest extends PowerMockTestCase {

@Mock
private OAuthAdminServiceImpl oAuthAdminService;
Expand Down Expand Up @@ -75,7 +93,6 @@ public void setUp() throws Exception {
System.setProperty("carbon.home",
System.getProperty("user.dir") + File.separator + "src" + File.separator + "test"
+ File.separator + "resources");

initConfigsAndRealm();
}

Expand Down

0 comments on commit 86e01ec

Please sign in to comment.