Skip to content

Commit 4b40ede

Browse files
Merge pull request #2228 from rmsamitha/master
Introduce proxy support for backend oauth security
2 parents 4d18c6b + ee30ffb commit 4b40ede

File tree

11 files changed

+365
-51
lines changed

11 files changed

+365
-51
lines changed

modules/core/src/main/java/org/apache/synapse/endpoints/OAuthConfiguredHTTPEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public void send(MessageContext synCtx) {
6464

6565
} catch (AuthException e) {
6666
handleError(synCtx,
67-
"Could not generate access token for oauth configured http endpoint " + this.getName(), e);
67+
"Could not generate access token for oauth configured http endpoint " + this.getName() + ".", e);
6868
} catch (AxisFault axisFault) {
6969
handleError(synCtx,
70-
"Error cloning the message context for oauth configured http endpoint " + this.getName(),
70+
"Error cloning the message context for oauth configured http endpoint " + this.getName() + ".",
7171
axisFault);
7272
}
7373
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com/).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.apache.synapse.endpoints;
20+
21+
/**
22+
* This class represents a model for proxy configurations which is used for the OAuth authentication of endpoints
23+
*/
24+
public class ProxyConfigs {
25+
private String proxyHost;
26+
private String proxyPort;
27+
private String proxyUsername;
28+
private String proxyPassword;
29+
private String proxyProtocol;
30+
private boolean proxyEnabled;
31+
32+
public void setProxyEnabled(boolean proxyEnabled) {
33+
this.proxyEnabled = proxyEnabled;
34+
}
35+
36+
public void setProxyHost(String proxyHost) {
37+
this.proxyHost = proxyHost;
38+
}
39+
40+
public void setProxyPort(String proxyPort) {
41+
this.proxyPort = proxyPort;
42+
}
43+
44+
public void setProxyUsername(String proxyUsername) {
45+
this.proxyUsername = proxyUsername;
46+
}
47+
48+
public void setProxyPassword(String proxyPassword) {
49+
this.proxyPassword = proxyPassword;
50+
}
51+
52+
public void setProxyProtocol(String proxyProtocol) {
53+
this.proxyProtocol = proxyProtocol;
54+
}
55+
56+
public boolean isProxyEnabled() {
57+
return proxyEnabled;
58+
}
59+
60+
public String getProxyHost() {
61+
return proxyHost;
62+
}
63+
64+
public String getProxyPort() {
65+
return proxyPort;
66+
}
67+
68+
public String getProxyUsername() {
69+
return proxyUsername;
70+
}
71+
72+
public String getProxyPassword() {
73+
return proxyPassword;
74+
}
75+
76+
public String getProxyProtocol() {
77+
return proxyProtocol;
78+
}
79+
}
80+
81+

modules/core/src/main/java/org/apache/synapse/endpoints/auth/AuthConstants.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,12 @@ public class AuthConstants {
8787
public static final String BASIC_AUTH_USERNAME = "username";
8888
public static final String BASIC_AUTH_PASSWORD = "password";
8989

90+
public static final String PROXY_CONFIGS = "proxyConfigs";
91+
public static final String PROXY_HOST = "proxyHost";
92+
public static final String PROXY_PORT = "proxyPort";
93+
public static final String PROXY_USERNAME = "proxyUsername";
94+
public static final String PROXY_PASSWORD = "proxyPassword";
95+
public static final String OAUTH_PROXY_PROTOCOL = "proxyProtocol";
96+
97+
public static final String HTTPS_PROTOCOL = "https";
9098
}

modules/core/src/main/java/org/apache/synapse/endpoints/auth/oauth/AuthorizationCodeHandler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.commons.lang.StringUtils;
2424
import org.apache.synapse.MessageContext;
2525
import org.apache.synapse.SynapseConstants;
26+
import org.apache.synapse.endpoints.ProxyConfigs;
2627
import org.apache.synapse.endpoints.auth.AuthConstants;
2728
import org.apache.synapse.endpoints.auth.AuthException;
2829

@@ -35,13 +36,12 @@ public class AuthorizationCodeHandler extends OAuthHandler {
3536

3637
private final String refreshToken;
3738

38-
public AuthorizationCodeHandler(String tokenApiUrl, String clientId, String clientSecret,
39-
String refreshToken, String authMode, int connectionTimeout,
40-
int connectionRequestTimeout, int socketTimeout,
41-
TokenCacheProvider tokenCacheProvider) {
39+
public AuthorizationCodeHandler(String tokenApiUrl, String clientId, String clientSecret, String refreshToken,
40+
String authMode, int connectionTimeout, int connectionRequestTimeout, int socketTimeout,
41+
TokenCacheProvider tokenCacheProvider, ProxyConfigs proxyConfigs) {
4242

43-
super(tokenApiUrl, clientId, clientSecret, authMode, connectionTimeout, connectionRequestTimeout,
44-
socketTimeout, tokenCacheProvider);
43+
super(tokenApiUrl, clientId, clientSecret, authMode, connectionTimeout, connectionRequestTimeout, socketTimeout,
44+
tokenCacheProvider,proxyConfigs);
4545
this.refreshToken = refreshToken;
4646
}
4747

modules/core/src/main/java/org/apache/synapse/endpoints/auth/oauth/ClientCredentialsHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.commons.lang.StringUtils;
2424
import org.apache.synapse.MessageContext;
2525
import org.apache.synapse.SynapseConstants;
26+
import org.apache.synapse.endpoints.ProxyConfigs;
2627
import org.apache.synapse.endpoints.auth.AuthConstants;
2728
import org.apache.synapse.endpoints.auth.AuthException;
2829

@@ -34,11 +35,11 @@
3435
public class ClientCredentialsHandler extends OAuthHandler {
3536

3637
public ClientCredentialsHandler(String tokenApiUrl, String clientId, String clientSecret, String authMode,
37-
int connectionTimeout, int connectionRequestTimeout, int socketTimeout,
38-
TokenCacheProvider tokenCacheProvider) {
38+
int connectionTimeout, int connectionRequestTimeout, int socketTimeout,
39+
TokenCacheProvider tokenCacheProvider, ProxyConfigs proxyConfigs) {
3940

4041
super(tokenApiUrl, clientId, clientSecret, authMode, connectionTimeout, connectionRequestTimeout, socketTimeout,
41-
tokenCacheProvider);
42+
tokenCacheProvider, proxyConfigs);
4243
}
4344

4445
@Override

0 commit comments

Comments
 (0)