|
getSupportedTokenBindingsMetaData() {
return OAuthComponentServiceHolder.getInstance().getTokenBindingMetaDataDTOs();
}
+ /**
+ * Get the authorization code validity period property value from identity.xml file.
+ *
+ * @return authorization code validity period property value
+ */
+ public long getAuthorizationCodeValidityPeriod() {
+
+ return OAuthServerConfiguration.getInstance().getAuthorizationCodeValidityPeriodInSeconds();
+ }
+
public OAuthTokenExpiryTimeDTO getTokenExpiryTimes() {
OAuthTokenExpiryTimeDTO tokenExpiryTime = new OAuthTokenExpiryTimeDTO();
@@ -1246,38 +1259,51 @@ AuthenticatedUser buildAuthenticatedUser(String tenantAwareUser, String tenantDo
return user;
}
+ void validateAuthorizationCodeValidityPeriodConfiguration(OAuthConsumerAppDTO oAuthConsumerAppDTO) {
+
+ if (oAuthConsumerAppDTO.getAuthorizationCodeValidityPeriod() == 0) {
+ oAuthConsumerAppDTO.setAuthorizationCodeValidityPeriod(
+ OAuthServerConfiguration.getInstance().getAuthorizationCodeValidityPeriodInSeconds());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Invalid value '0' set for authorization code validity period in ServiceProvider: "
+ + oAuthConsumerAppDTO.getApplicationName() + ". Defaulting to expiry value: "
+ + oAuthConsumerAppDTO.getAuthorizationCodeValidityPeriod() + " seconds.");
+ }
+ }
+ }
+
void validateTokenExpiryConfigurations(OAuthConsumerAppDTO oAuthConsumerAppDTO) {
if (oAuthConsumerAppDTO.getUserAccessTokenExpiryTime() == 0) {
oAuthConsumerAppDTO.setUserAccessTokenExpiryTime(
OAuthServerConfiguration.getInstance().getUserAccessTokenValidityPeriodInSeconds());
- logOnInvalidConfig(oAuthConsumerAppDTO.getApplicationName(), "user access token",
+ logOnInvalidTokenExpiryConfig(oAuthConsumerAppDTO.getApplicationName(), "user access token",
oAuthConsumerAppDTO.getUserAccessTokenExpiryTime());
}
if (oAuthConsumerAppDTO.getApplicationAccessTokenExpiryTime() == 0) {
oAuthConsumerAppDTO.setApplicationAccessTokenExpiryTime(
OAuthServerConfiguration.getInstance().getApplicationAccessTokenValidityPeriodInSeconds());
- logOnInvalidConfig(oAuthConsumerAppDTO.getApplicationName(), "application access token",
+ logOnInvalidTokenExpiryConfig(oAuthConsumerAppDTO.getApplicationName(), "application access token",
oAuthConsumerAppDTO.getApplicationAccessTokenExpiryTime());
}
if (oAuthConsumerAppDTO.getRefreshTokenExpiryTime() == 0) {
oAuthConsumerAppDTO.setRefreshTokenExpiryTime(
OAuthServerConfiguration.getInstance().getRefreshTokenValidityPeriodInSeconds());
- logOnInvalidConfig(oAuthConsumerAppDTO.getApplicationName(), "refresh token",
+ logOnInvalidTokenExpiryConfig(oAuthConsumerAppDTO.getApplicationName(), "refresh token",
oAuthConsumerAppDTO.getRefreshTokenExpiryTime());
}
if (oAuthConsumerAppDTO.getIdTokenExpiryTime() == 0) {
oAuthConsumerAppDTO.setIdTokenExpiryTime(
OAuthServerConfiguration.getInstance().getOpenIDConnectIDTokenExpiryTimeInSeconds());
- logOnInvalidConfig(oAuthConsumerAppDTO.getApplicationName(), "id token",
+ logOnInvalidTokenExpiryConfig(oAuthConsumerAppDTO.getApplicationName(), "id token",
oAuthConsumerAppDTO.getIdTokenExpiryTime());
}
}
- void logOnInvalidConfig(String appName, String tokenType, long defaultValue) {
+ void logOnInvalidTokenExpiryConfig(String appName, String tokenType, long defaultValue) {
if (LOG.isDebugEnabled()) {
LOG.debug("Invalid expiry time value '0' set for token type: " + tokenType + " in ServiceProvider: " +
diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthUtil.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthUtil.java
index ce9eb5287c6..f53404ddb1f 100644
--- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthUtil.java
+++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthUtil.java
@@ -309,6 +309,7 @@ public static OAuthConsumerAppDTO buildConsumerAppDTO(OAuthAppDO appDO) {
dto.setState(appDO.getState());
dto.setPkceMandatory(appDO.isPkceMandatory());
dto.setPkceSupportPlain(appDO.isPkceSupportPlain());
+ dto.setAuthorizationCodeValidityPeriod(appDO.getAuthorizationCodeValidityPeriod());
dto.setUserAccessTokenExpiryTime(appDO.getUserAccessTokenExpiryTime());
dto.setApplicationAccessTokenExpiryTime(appDO.getApplicationAccessTokenExpiryTime());
dto.setRefreshTokenExpiryTime(appDO.getRefreshTokenExpiryTime());
diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDAO.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDAO.java
index 2d2f07f9512..3e4cf6f473d 100644
--- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDAO.java
+++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDAO.java
@@ -61,6 +61,7 @@
import java.util.Set;
import static org.wso2.carbon.identity.oauth.OAuthUtil.handleError;
+import static org.wso2.carbon.identity.oauth.common.OAuthConstants.AUTHORIZATION_CODE_VALIDITY_PERIOD;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OIDCConfigProperties.BACK_CHANNEL_LOGOUT_URL;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OIDCConfigProperties.BYPASS_CLIENT_CREDENTIALS;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OIDCConfigProperties.FRONT_CHANNEL_LOGOUT_URL;
@@ -613,6 +614,10 @@ private void addOrUpdateOIDCSpProperty(OAuthAppDO oauthAppDO,
addOrUpdateOIDCSpProperty(preprocessedClientId, spTenantId, spOIDCProperties, TOKEN_BINDING_TYPE,
oauthAppDO.getTokenBindingType(), prepStatementForPropertyAdd, preparedStatementForPropertyUpdate);
+ addOrUpdateOIDCSpProperty(preprocessedClientId, spTenantId, spOIDCProperties,
+ AUTHORIZATION_CODE_VALIDITY_PERIOD, String.valueOf(oauthAppDO.getAuthorizationCodeValidityPeriod()),
+ prepStatementForPropertyAdd, preparedStatementForPropertyUpdate);
+
// Execute batched add/update/delete.
prepStatementForPropertyAdd.executeBatch();
preparedStatementForPropertyUpdate.executeBatch();
@@ -1050,6 +1055,10 @@ private void addServiceProviderOIDCProperties(Connection connection,
addToBatchForOIDCPropertyAdd(processedClientId, spTenantId, prepStmtAddOIDCProperty, TOKEN_BINDING_TYPE,
consumerAppDO.getTokenBindingType());
+ addToBatchForOIDCPropertyAdd(processedClientId, spTenantId, prepStmtAddOIDCProperty,
+ AUTHORIZATION_CODE_VALIDITY_PERIOD,
+ String.valueOf(consumerAppDO.getAuthorizationCodeValidityPeriod()));
+
prepStmtAddOIDCProperty.executeBatch();
}
}
@@ -1136,6 +1145,17 @@ private void setSpOIDCProperties(Map> spOIDCProperties, OAu
String renewRefreshToken = getFirstPropertyValue(spOIDCProperties, RENEW_REFRESH_TOKEN);
oauthApp.setRenewRefreshTokenEnabled(renewRefreshToken);
+ long authorizationCodeValidityPeriod;
+ String authorizationCodeValidityPeriodProperty = getFirstPropertyValue(spOIDCProperties,
+ AUTHORIZATION_CODE_VALIDITY_PERIOD);
+ if (StringUtils.isNotBlank(authorizationCodeValidityPeriodProperty)) {
+ authorizationCodeValidityPeriod = Long.parseLong(authorizationCodeValidityPeriodProperty);
+ } else {
+ authorizationCodeValidityPeriod = OAuthServerConfiguration.getInstance()
+ .getAuthorizationCodeValidityPeriodInSeconds();
+ }
+ oauthApp.setAuthorizationCodeValidityPeriod(authorizationCodeValidityPeriod);
+
}
private String getFirstPropertyValue(Map> propertyMap, String key) {
diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDO.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDO.java
index 7b6e63c894b..c601f140397 100644
--- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDO.java
+++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDO.java
@@ -51,6 +51,7 @@ public class OAuthAppDO implements Serializable {
private boolean pkceSupportPlain;
private boolean pkceMandatory;
private String state;
+ private long authorizationCodeValidityPeriod;
private long userAccessTokenExpiryTime;
private long applicationAccessTokenExpiryTime;
private long refreshTokenExpiryTime;
@@ -185,6 +186,16 @@ public String getState() {
return state;
}
+ public long getAuthorizationCodeValidityPeriod() {
+
+ return authorizationCodeValidityPeriod;
+ }
+
+ public void setAuthorizationCodeValidityPeriod(long authorizationCodeValidityPeriod) {
+
+ this.authorizationCodeValidityPeriod = authorizationCodeValidityPeriod;
+ }
+
public long getUserAccessTokenExpiryTime() {
return userAccessTokenExpiryTime;
}
diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/OAuthConsumerAppDTO.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/OAuthConsumerAppDTO.java
index 9ea61dcaa2f..c0e874221bb 100644
--- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/OAuthConsumerAppDTO.java
+++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/OAuthConsumerAppDTO.java
@@ -34,6 +34,7 @@ public class OAuthConsumerAppDTO {
private boolean pkceSupportPlain;
private boolean pkceMandatory;
private String state;
+ private long authorizationCodeValidityPeriod;
private long userAccessTokenExpiryTime;
private long applicationAccessTokenExpiryTime;
private long refreshTokenExpiryTime;
@@ -51,6 +52,16 @@ public class OAuthConsumerAppDTO {
private String tokenType;
private String tokenBindingType;
+ public long getAuthorizationCodeValidityPeriod() {
+
+ return authorizationCodeValidityPeriod;
+ }
+
+ public void setAuthorizationCodeValidityPeriod(long authorizationCodeValidityPeriod) {
+
+ this.authorizationCodeValidityPeriod = authorizationCodeValidityPeriod;
+ }
+
public long getUserAccessTokenExpiryTime() {
return userAccessTokenExpiryTime;
}
|