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

Revert "[Spring Cleanup] Remove spring dependency in client authn filter" #2651

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<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,6 +30,7 @@
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 @@ -50,6 +51,7 @@ 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 @@ -58,6 +60,16 @@ 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 @@ -70,8 +82,8 @@ public void handleMessage(Message message) {
HttpServletRequest request = ((HttpServletRequest) message.get(HTTP_REQUEST));
if (canHandle(message)) {
try {
OAuthClientAuthnContext oAuthClientAuthnContext = OAuthClientAuthnServiceFactory
.getOAuthClientAuthnService().authenticateClient(request, bodyContentParams);
OAuthClientAuthnContext oAuthClientAuthnContext = oAuthClientAuthnService
.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-2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* WSO2 Inc. 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,29 +18,37 @@

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 class to get OAuthClientAuthnService OSGI service.
* 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.
*/
public class OAuthClientAuthnServiceFactory {
public class OAuthClientAuthnServiceFactory extends AbstractFactoryBean<OAuthClientAuthnService> {

private static final OAuthClientAuthnService SERVICE;
public OAuthClientAuthnService oAuthClientAuthnService;

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

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

SERVICE = oAuthClientAuthnService;
return OAuthClientAuthnService.class;
}

public static OAuthClientAuthnService getOAuthClientAuthnService() {

return SERVICE;
@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;
}
}
}
Loading