Skip to content

Commit

Permalink
Merge pull request #157 from Sachin-Mamoru/feature-extend-http-functions
Browse files Browse the repository at this point in the history
[Feature] Enhance http adaptive auth functions with extended auth schemes and secret management
  • Loading branch information
Sachin-Mamoru authored Apr 16, 2024
2 parents ff1e73f + 0da007e commit bec2ea2
Show file tree
Hide file tree
Showing 19 changed files with 1,434 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.wso2.carbon.identity.conditional.auth.functions.common.utils.Constants.HTTP_CONNECTION_TIMEOUT;
import static org.wso2.carbon.identity.conditional.auth.functions.common.utils.Constants.HTTP_FUNCTION_ALLOWED_DOMAINS;
import static org.wso2.carbon.identity.conditional.auth.functions.common.utils.Constants.HTTP_READ_TIMEOUT;
import static org.wso2.carbon.identity.conditional.auth.functions.common.utils.Constants.HTTP_REQUEST_RETRY_COUNT;

public class ConfigProvider {

Expand All @@ -39,6 +40,7 @@ public class ConfigProvider {
private int connectionTimeout;
private int readTimeout;
private int connectionRequestTimeout;
private int requestRetryCount = 2;
private List<String> httpFunctionAllowedDomainList = new ArrayList<>();
private List<String> choreoDomainList = new ArrayList<>();
private final String choreoTokenEndpoint;
Expand All @@ -51,6 +53,7 @@ private ConfigProvider() {
String connectionTimeoutString = IdentityUtil.getProperty(HTTP_CONNECTION_TIMEOUT);
String readTimeoutString = IdentityUtil.getProperty(HTTP_READ_TIMEOUT);
String connectionRequestTimeoutString = IdentityUtil.getProperty(HTTP_CONNECTION_REQUEST_TIMEOUT);
String requestRetryCountString = IdentityUtil.getProperty(HTTP_REQUEST_RETRY_COUNT);
List<String> httpFunctionAllowedDomainList = IdentityUtil.getPropertyAsList(HTTP_FUNCTION_ALLOWED_DOMAINS);
List<String> choreoDomainList = IdentityUtil.getPropertyAsList(CHOREO_DOMAINS);

Expand Down Expand Up @@ -80,6 +83,15 @@ private ConfigProvider() {
LOG.error("Error while parsing connection request timeout : " + connectionTimeoutString, e);
}
}
if (requestRetryCountString != null) {
try {
requestRetryCount = Integer.parseInt
(requestRetryCountString);
} catch (NumberFormatException e) {
LOG.error("Error while parsing max request attempts for api endpoint timeout : " +
requestRetryCountString, e);
}
}

if (httpFunctionAllowedDomainList != null) {
this.httpFunctionAllowedDomainList = httpFunctionAllowedDomainList;
Expand Down Expand Up @@ -119,6 +131,11 @@ public int getConnectionRequestTimeout() {
return connectionRequestTimeout;
}

public int getRequestRetryCount() {

return requestRetryCount;
}

public List<String> getAllowedDomainsForHttpFunctions() {

return httpFunctionAllowedDomainList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Constants {

public static final String RECEIVER_URL = "AdaptiveAuth.EventPublisher.ReceiverURL";
public static final String HTTP_CONNECTION_TIMEOUT = "AdaptiveAuth.HTTPConnectionTimeout";
public static final String HTTP_REQUEST_RETRY_COUNT = "AdaptiveAuth.HTTPRequestRetryCount";
public static final String HTTP_READ_TIMEOUT = "AdaptiveAuth.HTTPReadTimeout";
public static final String HTTP_CONNECTION_REQUEST_TIMEOUT = "AdaptiveAuth.HTTPConnectionRequestTimeout";
public static final String AUTHENTICATION_ENABLED = "AdaptiveAuth.EventPublisher.BasicAuthentication.Enable";
Expand All @@ -46,4 +47,40 @@ public class Constants {
public static final String HTTP_FUNCTION_ALLOWED_DOMAINS = "AdaptiveAuth.HTTPFunctionAllowedDomains.Domain";
public static final String CHOREO_DOMAINS = "AdaptiveAuth.ChoreoDomains.Domain";
public static final String CHOREO_TOKEN_ENDPOINT = "AdaptiveAuth.ChoreoTokenEndpoint";

/**
* Define logging constants.
*/
public static class LogConstants {

public static final String ADAPTIVE_AUTH_SERVICE = "adaptive-auth-service";
public static final String FAILED = "FAILED";

/**
* Define action IDs for diagnostic logs.
*/
public static class ActionIDs {

public static final String RECEIVE_TOKEN = "receive-token";
public static final String RECEIVE_API_RESPONSE = "receive-api-response";
}

/**
* Define common and reusable Input keys for diagnostic logs.
*/
public static class InputKeys {

public static final String TOKEN_ENDPOINT = "token endpoint";
public static final String API = "external api";
}

/**
* Define common and reusable Configuration keys for diagnostic logs.
*/
public static class ConfigKeys {

public static final String SUPPORTED_GRANT_TYPES = "supported grant types";

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@
<artifactId>msf4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.central.log.mgt</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.crypto</groupId>
<artifactId>org.wso2.carbon.crypto.impl</artifactId>
Expand Down Expand Up @@ -176,10 +184,14 @@
org.wso2.carbon.identity.application.authentication.framework.config.model.graph;
version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.core.util; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.central.log.mgt.*; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.user.core; version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.user.core.service; version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.utils;version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.identity.conditional.auth.functions.common.utils,
com.nimbusds.jwt.*;version="${nimbusds.osgi.version.range}",
org.wso2.carbon.identity.conditional.auth.functions.common.auth,
org.wso2.carbon.identity.core.cache; version="${carbon.identity.package.import.version.range}",
</Import-Package>
</instructions>
</configuration>
Expand Down
Loading

0 comments on commit bec2ea2

Please sign in to comment.