Skip to content

Commit

Permalink
[Spring Cleanup] Remove spring dependency in client authn filter
Browse files Browse the repository at this point in the history
  • Loading branch information
lashinijay committed Nov 22, 2024
1 parent 1eb13c1 commit 2969d83
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 42 deletions.
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;
}
}

0 comments on commit 2969d83

Please sign in to comment.