Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spring Cleanup] Refactor oauth2 webapp to remove Spring Framework Dependency #2675

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.base</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void handleMessage(Message message) {
// Attestation validation should be performed only if API-based authentication is enabled.
if (serviceProvider.isAPIBasedAuthenticationEnabled()) {
// Validate the attestation header and obtain client attestation context
clientAttestationContext = ClientAttestationServiceHolder.getInstance()
clientAttestationContext = ClientAttestationServiceHolder
.getClientAttestationService().validateAttestation(attestationHeader,
serviceProvider.getApplicationResourceId(),
IdentityTenantUtil.resolveTenantDomain());
Expand Down Expand Up @@ -265,7 +265,7 @@ private ServiceProvider getServiceProvider(String clientId, String tenantDomain)

ServiceProvider serviceProvider;
try {
serviceProvider = ClientAttestationServiceHolder.getInstance().getApplicationManagementService()
serviceProvider = ClientAttestationServiceHolder.getApplicationManagementService()
.getServiceProviderByClientId(clientId, OAUTH2, tenantDomain);
} catch (IdentityApplicationManagementClientException e) {
throw new WebApplicationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.wso2.carbon.identity.client.attestation.filter;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.client.attestation.mgt.services.ClientAttestationService;

Expand All @@ -29,62 +30,44 @@
*/
public class ClientAttestationServiceHolder {

// Singleton instance
private static ClientAttestationServiceHolder instance = new ClientAttestationServiceHolder();

// Service instances
private ClientAttestationService clientAttestationService;
private ApplicationManagementService applicationManagementService;
// Private constructor to enforce Singleton pattern
private ClientAttestationServiceHolder() {}

/**
* Returns the singleton instance of the ClientAttestationServiceHolder.
*
* @return The singleton instance.
*/
public static ClientAttestationServiceHolder getInstance() {
private static class ClientAttestationHolder {

return instance;
static final ClientAttestationService SERVICE = (ClientAttestationService)
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(ClientAttestationService.class, null);
}

/**
* Gets the instance of the Client Attestation Service.
*
* @return The Client Attestation Service instance.
*/
public ClientAttestationService getClientAttestationService() {
private static class ApplicationManagementHolder {

return ClientAttestationServiceHolder.getInstance().clientAttestationService;
static final ApplicationManagementService SERVICE = (ApplicationManagementService)
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(ApplicationManagementService.class, null);
}

/**
* Sets the instance of the Client Attestation Service.
* Gets the instance of the Client Attestation Service.
*
* @param clientAttestationService The Client Attestation Service instance to set.
* @return The Client Attestation Service instance.
*/
public void setClientAttestationService(ClientAttestationService clientAttestationService) {
public static ClientAttestationService getClientAttestationService() {

ClientAttestationServiceHolder.getInstance().clientAttestationService = clientAttestationService;
if (ClientAttestationHolder.SERVICE == null) {
throw new IllegalStateException("ClientAttestationService is not available from OSGI context.");
}
return ClientAttestationHolder.SERVICE;
}

/**
* Gets the instance of the Application Management Service.
*
* @return The Application Management Service instance.
*/
public ApplicationManagementService getApplicationManagementService() {

return ClientAttestationServiceHolder.getInstance().applicationManagementService;
}

/**
* Sets the instance of the Application Management Service.
*
* @param applicationManagementService The Application Management Service instance to set.
*/
public void setApplicationManagementService(ApplicationManagementService applicationManagementService) {
public static ApplicationManagementService getApplicationManagementService() {

ClientAttestationServiceHolder.getInstance().applicationManagementService = applicationManagementService;
if (ApplicationManagementHolder.SERVICE == null) {
throw new IllegalStateException("ApplicationManagementService is not available from OSGI context.");
}
return ApplicationManagementHolder.SERVICE;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.wso2.carbon.identity.oauth.common.OAuth2ErrorCodes;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
import org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext;
import org.wso2.carbon.identity.oauth2.client.authentication.OAuthClientAuthnService;

import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -51,7 +50,6 @@ public class OAuthClientAuthenticatorProxy extends AbstractPhaseInterceptor<Mess
private static final String HTTP_REQUEST = "HTTP.REQUEST";
private static final List<String> PROXY_ENDPOINT_LIST = Arrays.asList("/oauth2/token", "/oauth2/revoke",
"/oauth2/device_authorize", "/oauth2/ciba", "/oauth2/par", "/oauth2/authorize");
private OAuthClientAuthnService oAuthClientAuthnService;
private static final String SLASH = "/";

public OAuthClientAuthenticatorProxy() {
Expand All @@ -60,16 +58,6 @@ public OAuthClientAuthenticatorProxy() {
super(Phase.PRE_INVOKE);
}

public OAuthClientAuthnService getOAuthClientAuthnService() {

return oAuthClientAuthnService;
}

public void setOAuthClientAuthnService(OAuthClientAuthnService oAuthClientAuthnService) {

this.oAuthClientAuthnService = oAuthClientAuthnService;
}

/**
* Handles the incoming JAX-RS message for the purpose of OAuth2 client authentication.
*
Expand All @@ -82,8 +70,8 @@ public void handleMessage(Message message) {
HttpServletRequest request = ((HttpServletRequest) message.get(HTTP_REQUEST));
if (canHandle(message)) {
try {
OAuthClientAuthnContext oAuthClientAuthnContext = oAuthClientAuthnService
.authenticateClient(request, bodyContentParams);
OAuthClientAuthnContext oAuthClientAuthnContext = OAuthClientAuthnServiceFactory
.getOAuthClientAuthnService().authenticateClient(request, bodyContentParams);
if (!oAuthClientAuthnContext.isPreviousAuthenticatorEngaged()) {
/* If the previous authenticator is not engaged it means that either client authentication
flow failed or no supported authenticaiton mechanism was found.If the error details are already
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
Expand All @@ -18,37 +18,29 @@

package org.wso2.carbon.identity.oauth.client.authn.filter;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.oauth2.client.authentication.OAuthClientAuthnService;

/**
* Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to
* instantiate the OAuthClientAuthnService type of object inside the container.
* Factory class to get OAuthClientAuthnService OSGI service.
*/
public class OAuthClientAuthnServiceFactory extends AbstractFactoryBean<OAuthClientAuthnService> {
public class OAuthClientAuthnServiceFactory {

public OAuthClientAuthnService oAuthClientAuthnService;
private static final OAuthClientAuthnService SERVICE;

static {
OAuthClientAuthnService oAuthClientAuthnService = (OAuthClientAuthnService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(OAuthClientAuthnService.class, null);

@Override
public Class<OAuthClientAuthnService> getObjectType() {
if (oAuthClientAuthnService == null) {
throw new IllegalStateException("OAuthClientAuthnService is not available from OSGI context.");
}

return OAuthClientAuthnService.class;
SERVICE = oAuthClientAuthnService;
}

@Override
protected OAuthClientAuthnService createInstance() throws Exception {

if (this.oAuthClientAuthnService != null) {
return this.oAuthClientAuthnService;
} else {
OAuthClientAuthnService oAuthClientAuthnService = (OAuthClientAuthnService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(OAuthClientAuthnService.class, null);
if (oAuthClientAuthnService != null) {
this.oAuthClientAuthnService = oAuthClientAuthnService;
}
return oAuthClientAuthnService;
}
public static OAuthClientAuthnService getOAuthClientAuthnService() {

return SERVICE;
}
}
8 changes: 1 addition & 7 deletions components/org.wso2.carbon.identity.oauth.endpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@
<artifactId>org.wso2.carbon.identity.client.attestation.filter</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down Expand Up @@ -234,7 +229,6 @@
<artifactId>org.wso2.carbon.identity.oauth.extension</artifactId>
<scope>compile</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -331,7 +325,7 @@
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.48</minimum>
<minimum>0.47</minimum>
</limit>
</limits>
</rule>
Expand Down
Loading
Loading