Skip to content

Commit

Permalink
updated the authconfigs from basicauth to basic and bearertoken to be…
Browse files Browse the repository at this point in the history
…arer
  • Loading branch information
Sachin-Mamoru committed Jul 18, 2024
1 parent ca31e7c commit a870cb2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
* This class is used to create the authentication configurations based on the authentication type.
* The supported authentication types are:
* 1. ClientCredential
* 2. BearerToken
* 2. Bearer
* 3. ApiKey
* 4. BasicAuth
* 4. Basic
*/
public class AuthConfigFactory {

Expand All @@ -48,11 +48,11 @@ public static AuthConfig getAuthConfig(AuthConfigModel authConfigModel,
clientCredentialAuthConfig.setAuthenticationContext(authenticationContext);
clientCredentialAuthConfig.setAsyncReturn(asyncReturn);
return clientCredentialAuthConfig;
case "bearertoken":
return new BearerTokenAuthConfig();
case "bearer":
return new BearerAuthConfig();
case "apikey":
return new ApiKeyAuthConfig();
case "basicauth":
case "basic":
return new BasicAuthConfig();
default:
throw new IllegalArgumentException("Unsupported authentication type: " + authConfigModel.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* This class is used to configure the bearer token authentication.
* The bearer token is added to the request header.
*/
public class BearerTokenAuthConfig implements AuthConfig {
public class BearerAuthConfig implements AuthConfig {
private String token;

public void setToken(String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public class HTTPGetFunctionImplTest extends JsSequenceHandlerAbstractTest {

private static final String TEST_SP_CONFIG = "http-get-test-sp.xml";
private static final String TEST_HEADERS = "http-get-test-headers.xml";
private static final String TEST_AUTH_CONFIG_WITH_BASICAUTH = "http-get-test-auth-config-with-basicauth.xml";
private static final String TEST_AUTH_CONFIG_WITH_BASIC = "http-get-test-auth-config-with-basic.xml";
private static final String TEST_AUTH_CONFIG_WITH_APIKEY = "http-get-test-auth-config-with-apikey.xml";
private static final String TEST_AUTH_CONFIG_WITH_BEARERTOKEN = "http-get-test-auth-config-with-bearertoken.xml";
private static final String TEST_AUTH_CONFIG_WITH_BEARER = "http-get-test-auth-config-with-bearer.xml";
private static final String TEST_AUTH_CONFIG_WITH_CLIENTCREDENTIAL = "http-get-test-auth-config-with" +
"-clientcredential.xml";
private static final String TENANT_DOMAIN = "carbon.super";
Expand Down Expand Up @@ -166,18 +166,18 @@ public void testHttpGetMethodWithHeaders() throws JsTestException {
}

/**
* Test httpGet method with basicauth auth config.
* Test httpGet method with basic auth config.
* Check if the auth config is applied to the request.
*
* @throws JsTestException
*/
@Test
public void testHttpGetMethodWithBasicAuthAuthConfig() throws JsTestException {

String result = executeHttpGetFunction("dummy-get-with-basicauth-auth-config", TEST_AUTH_CONFIG_WITH_BASICAUTH);
String result = executeHttpGetFunction("dummy-get-with-basic-auth-config", TEST_AUTH_CONFIG_WITH_BASIC);

assertEquals(result, SUCCESS,
"The http get request was not successful with basicauth auth config. Result from request: " +
"The http get request was not successful with basic auth config. Result from request: " +
result);
}

Expand All @@ -198,18 +198,18 @@ public void testHttpGetMethodWithApiKeyAuthAuthConfig() throws JsTestException {
}

/**
* Test httpGet method with bearertoken auth config.
* Test httpGet method with bearer auth config.
* Check if the auth config is applied to the request.
*
* @throws JsTestException
*/
@Test
public void testHttpGetMethodWithBearerTokenAuthConfig() throws JsTestException {
public void testHttpGetMethodWithBearerAuthConfig() throws JsTestException {

String result = executeHttpGetFunction("dummy-get-with-bearertoken-auth-config", TEST_AUTH_CONFIG_WITH_BEARERTOKEN);
String result = executeHttpGetFunction("dummy-get-with-bearer-auth-config", TEST_AUTH_CONFIG_WITH_BEARER);

assertEquals(result, SUCCESS,
"The http get request was not successful with bearertoken auth config. Result from request: " +
"The http get request was not successful with bearer auth config. Result from request: " +
result);
}

Expand Down Expand Up @@ -305,12 +305,12 @@ private String getFormattedScript(String script, String path) {
return String.format(script, getRequestUrl("dummy-get"));
case "dummy-get-with-headers":
return String.format(script, getRequestUrl("dummy-get-with-headers"));
case "dummy-get-with-basicauth-auth-config":
return String.format(script, getRequestUrl("dummy-get-with-basicauth-auth-config"));
case "dummy-get-with-basic-auth-config":
return String.format(script, getRequestUrl("dummy-get-with-basic-auth-config"));
case "dummy-get-with-apikey-auth-config":
return String.format(script, getRequestUrl("dummy-get-with-apikey-auth-config"));
case "dummy-get-with-bearertoken-auth-config":
return String.format(script, getRequestUrl("dummy-get-with-bearertoken-auth-config"));
case "dummy-get-with-bearer-auth-config":
return String.format(script, getRequestUrl("dummy-get-with-bearer-auth-config"));
case "dummy-get-with-clientcredential-auth-config":
return String.format(script, getRequestUrl("dummy-get-with-clientcredential-auth-config"),
getRequestUrl("dummy-token-endpoint"));
Expand Down Expand Up @@ -370,15 +370,15 @@ public Map<String, String> dummyGetWithHeaders(@HeaderParam(AUTHORIZATION) Strin
}

/**
* Dummy endpoint to test the http get function with basicauth auth config.
* Dummy endpoint to test the http get function with basic auth config.
*
* @param authorization Authorization header value.
* @return Response.
*/
@GET
@Path("/dummy-get-with-basicauth-auth-config")
@Path("/dummy-get-with-basic-auth-config")
@Produces("application/json")
public Map<String, String> dummyGetWithBasicAuthAuthConfig(@HeaderParam(AUTHORIZATION) String authorization) {
public Map<String, String> dummyGetWithBasicAuthConfig(@HeaderParam(AUTHORIZATION) String authorization) {

Map<String, String> response = new HashMap<>();
if (authorization != null) {
Expand Down Expand Up @@ -410,15 +410,15 @@ public Map<String, String> dummyGetWithApiKeyAuthConfig(@HeaderParam(API_KEY_HEA
}

/**
* Dummy endpoint to test the http get function with bearertoken auth config.
* Dummy endpoint to test the http get function with bearer auth config.
*
* @param authorization authorization header value.
* @return Response.
*/
@GET
@Path("/dummy-get-with-bearertoken-auth-config")
@Path("/dummy-get-with-bearer-auth-config")
@Produces("application/json")
public Map<String, String> dummyGetWithBearerTokenAuthConfig(@HeaderParam(AUTHORIZATION) String authorization) {
public Map<String, String> dummyGetWithBearerAuthConfig(@HeaderParam(AUTHORIZATION) String authorization) {

Map<String, String> response = new HashMap<>();
if (authorization.startsWith("Bearer")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public class HTTPPostFunctionImplTest extends JsSequenceHandlerAbstractTest {
private static final String TEST_SP_CONFIG = "http-post-test-sp.xml";
private static final String TEST_HEADERS = "http-post-test-headers.xml";
private static final String TEST_AUTH_CONFIG_WITH_APIKEY = "http-post-test-auth-config-with-apikey.xml";
private static final String TEST_AUTH_CONFIG_WITH_BEARERTOKEN = "http-post-test-auth-config-with-bearertoken.xml";
private static final String TEST_AUTH_CONFIG_WITH_BASICAUTH = "http-post-test-auth-config-with-basicauth.xml";
private static final String TEST_AUTH_CONFIG_WITH_BEARER = "http-post-test-auth-config-with-bearer.xml";
private static final String TEST_AUTH_CONFIG_WITH_BASIC = "http-post-test-auth-config-with-basic.xml";
private static final String TEST_AUTH_CONFIG_WITH_CLIENTCREDENTIAL = "http-post-test-auth-config-with-clientcredential.xml";
private static final String TENANT_DOMAIN = "carbon.super";
private static final String STATUS = "status";
Expand Down Expand Up @@ -162,19 +162,19 @@ public void testHttpPostWithHeaders() throws JsTestException {
}

/**
* Test httpPost method with basicauth auth config.
* Test httpPost method with basic auth config.
* Check if the auth config is applied to the request.
*
* @throws JsTestException
*/
@Test
public void testHttpPostMethodWithBasicAuthAuthConfig() throws JsTestException {

String result = executeHttpPostFunction("dummy-post-with-basicauth-auth-config",
TEST_AUTH_CONFIG_WITH_BASICAUTH);
String result = executeHttpPostFunction("dummy-post-with-basic-auth-config",
TEST_AUTH_CONFIG_WITH_BASIC);

assertEquals(result, SUCCESS,
"The http post request was not successful with basicauth auth config. Result from request: " +
"The http post request was not successful with basic auth config. Result from request: " +
result);
}

Expand All @@ -195,19 +195,19 @@ public void testHttpPostMethodWithApiKeyAuthAuthConfig() throws JsTestException
}

/**
* Test httpPost method with bearertoken auth config.
* Test httpPost method with bearer auth config.
* Check if the auth config is applied to the request.
*
* @throws JsTestException
*/
@Test
public void testHttpPostMethodWithBearerTokenAuthConfig() throws JsTestException {
public void testHttpPostMethodWithBearerAuthConfig() throws JsTestException {

String result = executeHttpPostFunction("dummy-post-with-bearertoken-auth-config",
TEST_AUTH_CONFIG_WITH_BEARERTOKEN);
String result = executeHttpPostFunction("dummy-post-with-bearer-auth-config",
TEST_AUTH_CONFIG_WITH_BEARER);

assertEquals(result, SUCCESS,
"The http post request was not successful with bearertoken auth config. Result from request: " +
"The http post request was not successful with bearer auth config. Result from request: " +
result);
}

Expand Down Expand Up @@ -308,12 +308,12 @@ private String getFormattedScript(String script, String path) {
return String.format(script, getRequestUrl("dummy-post"));
case "dummy-post-with-headers":
return String.format(script, getRequestUrl("dummy-post-with-headers"));
case "dummy-post-with-basicauth-auth-config":
return String.format(script, getRequestUrl("dummy-post-with-basicauth-auth-config"));
case "dummy-post-with-basic-auth-config":
return String.format(script, getRequestUrl("dummy-post-with-basic-auth-config"));
case "dummy-post-with-apikey-auth-config":
return String.format(script, getRequestUrl("dummy-post-with-apikey-auth-config"));
case "dummy-post-with-bearertoken-auth-config":
return String.format(script, getRequestUrl("dummy-post-with-bearertoken-auth-config"));
case "dummy-post-with-bearer-auth-config":
return String.format(script, getRequestUrl("dummy-post-with-bearer-auth-config"));
case "dummy-post-with-clientcredential-auth-config":
return String.format(script, getRequestUrl("dummy-post-with-clientcredential-auth-config"),
getRequestUrl("dummy-token-endpoint"));
Expand Down Expand Up @@ -386,13 +386,13 @@ public Map<String, String> dummyPostWithHeaders(@HeaderParam(AUTHORIZATION) Stri
}

/**
* Dummy endpoint to test the http post function with basicauth auth config.
* Dummy endpoint to test the http post function with basic auth config.
*
* @param authorization Authorization header value.
* @return Response.
*/
@POST
@Path("/dummy-post-with-basicauth-auth-config")
@Path("/dummy-post-with-basic-auth-config")
@Produces("application/json")
public Map<String, String> dummyPostWithBasicAuthAuthConfig(@HeaderParam(AUTHORIZATION) String authorization, Map<String, String> data) {

Expand Down Expand Up @@ -426,15 +426,15 @@ public Map<String, String> dummyPostWithApiKeyAuthConfig(@HeaderParam(API_KEY_HE
}

/**
* Dummy endpoint to test the http post function with bearertoken auth config.
* Dummy endpoint to test the http post function with bearer auth config.
*
* @param authorization authorization header value.
* @return Response.
*/
@POST
@Path("/dummy-post-with-bearertoken-auth-config")
@Path("/dummy-post-with-bearer-auth-config")
@Produces("application/json")
public Map<String, String> dummyPostWithBearerTokenAuthConfig(@HeaderParam(AUTHORIZATION) String authorization, Map<String, String> data) {
public Map<String, String> dummyPostWithBearerAuthConfig(@HeaderParam(AUTHORIZATION) String authorization, Map<String, String> data) {

Map<String, String> response = new HashMap<>();
if (data.containsKey(EMAIL) && authorization.startsWith("Bearer")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function onLoginRequest(context) {
"Accept": "application/json"
},
{
"type": "basicauth",
"type": "basic",
"properties": {
"username": "admin",
"password": "admin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function onLoginRequest(context) {
"Accept": "application/json"
},
{
"type": "bearertoken",
"type": "bearer",
"properties": {
"token": "test-token",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function onLoginRequest(context) {
"Accept": "application/json"
},
{
"type": "basicauth",
"type": "basic",
"properties": {
"username": "admin",
"password": "admin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function onLoginRequest(context) {
"Accept": "application/json"
},
{
"type": "bearertoken",
"type": "bearer",
"properties": {
"token": "test-token",
}
Expand Down

0 comments on commit a870cb2

Please sign in to comment.