Skip to content

Commit be2070a

Browse files
Add logic to check RAR is enabled
1 parent f523061 commit be2070a

File tree

6 files changed

+90
-85
lines changed

6 files changed

+90
-85
lines changed

components/org.wso2.carbon.identity.discovery/src/main/java/org/wso2/carbon/identity/discovery/builders/ProviderConfigBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public OIDProviderConfigResponse buildOIDProviderConfig(OIDProviderRequest reque
157157
final Set<String> authorizationDetailTypes = AuthorizationDetailsProcessorFactory.getInstance()
158158
.getSupportedAuthorizationDetailTypes();
159159
if (authorizationDetailTypes != null && !authorizationDetailTypes.isEmpty()) {
160-
//final int size = supportedTypes.size();
161-
providerConfig.setAuthorizationDetailsTypesSupported(authorizationDetailTypes.toArray(String[]::new));
160+
providerConfig
161+
.setAuthorizationDetailsTypesSupported(authorizationDetailTypes.stream().toArray(String[]::new));
162162
}
163163
return providerConfig;
164164
}

components/org.wso2.carbon.identity.oauth.rar/src/main/java/org/wso2/carbon/identity/oauth2/rar/dao/AuthorizationDetailsDAOImpl.java

+3-41
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import java.util.HashSet;
3131
import java.util.Set;
3232

33-
import static org.wso2.carbon.identity.api.resource.mgt.util.AuthorizationDetailsTypesUtil.isRichAuthorizationRequestsDisabled;
34-
3533
/**
3634
* Implements the {@link AuthorizationDetailsDAO} interface to manage rich authorization requests.
3735
*
@@ -47,10 +45,6 @@ public class AuthorizationDetailsDAOImpl implements AuthorizationDetailsDAO {
4745
public int[] addUserConsentedAuthorizationDetails(final Set<AuthorizationDetailsConsentDTO> consentDTOs)
4846
throws SQLException {
4947

50-
if (isRichAuthorizationRequestsDisabled()) {
51-
return new int[0];
52-
}
53-
5448
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
5549
PreparedStatement ps =
5650
connection.prepareStatement(SQLQueries.ADD_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS)) {
@@ -75,10 +69,6 @@ public int[] addUserConsentedAuthorizationDetails(final Set<AuthorizationDetails
7569
public int[] updateUserConsentedAuthorizationDetails(final Set<AuthorizationDetailsConsentDTO> consentDTOs)
7670
throws SQLException {
7771

78-
if (isRichAuthorizationRequestsDisabled()) {
79-
return new int[0];
80-
}
81-
8272
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
8373
PreparedStatement ps =
8474
connection.prepareStatement(SQLQueries.UPDATE_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS)) {
@@ -104,11 +94,6 @@ public Set<AuthorizationDetailsConsentDTO> getUserConsentedAuthorizationDetails(
10494
final int tenantId)
10595
throws SQLException {
10696

107-
final Set<AuthorizationDetailsConsentDTO> authorizationDetailsConsentDTOs = new HashSet<>();
108-
if (isRichAuthorizationRequestsDisabled()) {
109-
return authorizationDetailsConsentDTOs;
110-
}
111-
11297
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
11398
final PreparedStatement ps =
11499
connection.prepareStatement(SQLQueries.GET_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS)) {
@@ -117,6 +102,7 @@ public Set<AuthorizationDetailsConsentDTO> getUserConsentedAuthorizationDetails(
117102
ps.setInt(2, tenantId);
118103
try (ResultSet rs = ps.executeQuery()) {
119104

105+
final Set<AuthorizationDetailsConsentDTO> authorizationDetailsConsentDTOs = new HashSet<>();
120106
while (rs.next()) {
121107
final String id = rs.getString(1);
122108
final String typeId = rs.getString(2);
@@ -138,10 +124,6 @@ public Set<AuthorizationDetailsConsentDTO> getUserConsentedAuthorizationDetails(
138124
public int deleteUserConsentedAuthorizationDetails(final String consentId, final int tenantId)
139125
throws SQLException {
140126

141-
if (isRichAuthorizationRequestsDisabled()) {
142-
return -1;
143-
}
144-
145127
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
146128
final PreparedStatement ps =
147129
connection.prepareStatement(SQLQueries.DELETE_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS)) {
@@ -159,10 +141,6 @@ public int deleteUserConsentedAuthorizationDetails(final String consentId, final
159141
public int[] addAccessTokenAuthorizationDetails(final Set<AuthorizationDetailsTokenDTO> tokenDTOs)
160142
throws SQLException {
161143

162-
if (isRichAuthorizationRequestsDisabled()) {
163-
return new int[0];
164-
}
165-
166144
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
167145
final PreparedStatement ps =
168146
connection.prepareStatement(SQLQueries.ADD_OAUTH2_ACCESS_TOKEN_AUTHORIZATION_DETAILS)) {
@@ -187,11 +165,6 @@ public Set<AuthorizationDetailsTokenDTO> getAccessTokenAuthorizationDetails(fina
187165
final int tenantId)
188166
throws SQLException {
189167

190-
final Set<AuthorizationDetailsTokenDTO> authorizationDetailsTokenDTO = new HashSet<>();
191-
if (isRichAuthorizationRequestsDisabled()) {
192-
return authorizationDetailsTokenDTO;
193-
}
194-
195168
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
196169
final PreparedStatement ps =
197170
connection.prepareStatement(SQLQueries.GET_OAUTH2_ACCESS_TOKEN_AUTHORIZATION_DETAILS)) {
@@ -200,6 +173,7 @@ public Set<AuthorizationDetailsTokenDTO> getAccessTokenAuthorizationDetails(fina
200173
ps.setInt(2, tenantId);
201174
try (ResultSet rs = ps.executeQuery()) {
202175

176+
final Set<AuthorizationDetailsTokenDTO> authorizationDetailsTokenDTO = new HashSet<>();
203177
while (rs.next()) {
204178
final String id = rs.getString(1);
205179
final String typeId = rs.getString(2);
@@ -220,10 +194,6 @@ public Set<AuthorizationDetailsTokenDTO> getAccessTokenAuthorizationDetails(fina
220194
public int deleteAccessTokenAuthorizationDetails(final String accessTokenId, final int tenantId)
221195
throws SQLException {
222196

223-
if (isRichAuthorizationRequestsDisabled()) {
224-
return -1;
225-
}
226-
227197
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
228198
final PreparedStatement ps =
229199
connection.prepareStatement(SQLQueries.DELETE_OAUTH2_ACCESS_TOKEN_AUTHORIZATION_DETAILS)) {
@@ -241,10 +211,6 @@ public int deleteAccessTokenAuthorizationDetails(final String accessTokenId, fin
241211
public int[] addOAuth2CodeAuthorizationDetails(final Set<AuthorizationDetailsCodeDTO> authorizationDetailsCodeDTOs)
242212
throws SQLException {
243213

244-
if (isRichAuthorizationRequestsDisabled()) {
245-
return new int[0];
246-
}
247-
248214
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
249215
final PreparedStatement ps =
250216
connection.prepareStatement(SQLQueries.ADD_OAUTH2_CODE_AUTHORIZATION_DETAILS)) {
@@ -268,11 +234,6 @@ public int[] addOAuth2CodeAuthorizationDetails(final Set<AuthorizationDetailsCod
268234
public Set<AuthorizationDetailsCodeDTO> getOAuth2CodeAuthorizationDetails(final String authorizationCode,
269235
final int tenantId) throws SQLException {
270236

271-
final Set<AuthorizationDetailsCodeDTO> authorizationDetailsCodeDTOs = new HashSet<>();
272-
if (isRichAuthorizationRequestsDisabled()) {
273-
return authorizationDetailsCodeDTOs;
274-
}
275-
276237
try (final Connection connection = IdentityDatabaseUtil.getDBConnection(false);
277238
final PreparedStatement ps =
278239
connection.prepareStatement(SQLQueries.GET_OAUTH2_CODE_AUTHORIZATION_DETAILS_BY_CODE)) {
@@ -281,6 +242,7 @@ public Set<AuthorizationDetailsCodeDTO> getOAuth2CodeAuthorizationDetails(final
281242
ps.setInt(2, tenantId);
282243
try (ResultSet rs = ps.executeQuery()) {
283244

245+
final Set<AuthorizationDetailsCodeDTO> authorizationDetailsCodeDTOs = new HashSet<>();
284246
while (rs.next()) {
285247
final String codeId = rs.getString(1);
286248
final String typeId = rs.getString(2);

components/org.wso2.carbon.identity.oauth.rar/src/test/java/org/wso2/carbon/identity/oauth2/rar/dao/AuthorizationDetailsDAOImplTest.java

-30
Original file line numberDiff line numberDiff line change
@@ -265,36 +265,6 @@ public void shouldReturnNull_whenUserIdOrAppIdInvalid() throws SQLException {
265265
assertNull(this.uut.getConsentIdByUserIdAndAppId("invalid_user_id", "invalid_app_id", TEST_TENANT_ID));
266266
}
267267

268-
@Test
269-
public void testUserConsentedAuthorizationDetailsWhenFeatureIsDisabled() throws SQLException {
270-
271-
this.mockAuthorizationDetailsTypesUtil(false);
272-
273-
assertEquals(0, this.uut.addUserConsentedAuthorizationDetails(Collections.emptySet()).length);
274-
assertEquals(0, this.uut.updateUserConsentedAuthorizationDetails(Collections.emptySet()).length);
275-
assertEquals(0, this.uut.getUserConsentedAuthorizationDetails(TEST_CONSENT_ID, TEST_TENANT_ID).size());
276-
assertEquals(-1, this.uut.deleteUserConsentedAuthorizationDetails(TEST_CONSENT_ID, TEST_TENANT_ID));
277-
}
278-
279-
@Test
280-
public void testAccessTokenAuthorizationDetailsWhenFeatureIsDisabled() throws SQLException {
281-
282-
this.mockAuthorizationDetailsTypesUtil(false);
283-
284-
assertEquals(0, uut.addAccessTokenAuthorizationDetails(Collections.emptySet()).length);
285-
assertEquals(0, this.uut.getAccessTokenAuthorizationDetails(TEST_TOKEN_ID, TEST_TENANT_ID).size());
286-
assertEquals(-1, this.uut.deleteAccessTokenAuthorizationDetails(TEST_TOKEN_ID, TEST_TENANT_ID));
287-
}
288-
289-
@Test
290-
public void testOAuth2CodeAuthorizationDetailsWhenFeatureIsDisabled() throws SQLException {
291-
292-
this.mockAuthorizationDetailsTypesUtil(false);
293-
294-
assertEquals(0, uut.addOAuth2CodeAuthorizationDetails(Collections.emptySet()).length);
295-
assertEquals(0, this.uut.getOAuth2CodeAuthorizationDetails(TEST_AUTHORIZATION_CODE, TEST_TENANT_ID).size());
296-
}
297-
298268
private void mockAuthorizationDetailsTypesUtil(boolean isRichAuthorizationRequestsEnabled) {
299269

300270
this.authorizationDetailsTypesUtilMock

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/dao/OAuthTokenPersistenceFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public OAuthUserConsentedScopesDAO getOAuthUserConsentedScopesDAO() {
116116
* Retrieves the DAO for authorization details.
117117
* <p>
118118
* This method returns an {@link AuthorizationDetailsDAO} singleton instance that provides access to the
119-
* {@link org.wso2.carbon.identity.oauth2.rar.common.model.AuthorizationDetails} data. This DAO is used to interact
119+
* {@link org.wso2.carbon.identity.oauth2.rar.model.AuthorizationDetails} data. This DAO is used to interact
120120
* with the underlying data store to fetch and manipulate authorization information.
121121
*</p>
122122
* @return the {@link AuthorizationDetailsDAO} instance that provides access to authorization details data.

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/rar/AuthorizationDetailsService.java

+35-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
2424
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
25+
import org.wso2.carbon.identity.api.resource.mgt.util.AuthorizationDetailsTypesUtil;
2526
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
2627
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
2728
import org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext;
@@ -68,6 +69,7 @@ public class AuthorizationDetailsService {
6869
private static final Log log = LogFactory.getLog(AuthorizationDetailsService.class);
6970
private final AuthorizationDetailsDAO authorizationDetailsDAO;
7071
private final AuthorizationDetailsProcessorFactory authorizationDetailsProcessorFactory;
72+
private final boolean isRichAuthorizationRequestsDisabled;
7173

7274
/**
7375
* Default constructor that initializes the service with the default {@link AuthorizationDetailsDAO} and
@@ -81,7 +83,8 @@ public AuthorizationDetailsService() {
8183

8284
this(
8385
AuthorizationDetailsProcessorFactory.getInstance(),
84-
OAuthTokenPersistenceFactory.getInstance().getAuthorizationDetailsDAO()
86+
OAuthTokenPersistenceFactory.getInstance().getAuthorizationDetailsDAO(),
87+
AuthorizationDetailsTypesUtil.isRichAuthorizationRequestsEnabled()
8588
);
8689
}
8790

@@ -93,12 +96,14 @@ public AuthorizationDetailsService() {
9396
* handling authorization details persistence. Must not be {@code null}.
9497
*/
9598
public AuthorizationDetailsService(final AuthorizationDetailsProcessorFactory authorizationDetailsProcessorFactory,
96-
final AuthorizationDetailsDAO authorizationDetailsDAO) {
99+
final AuthorizationDetailsDAO authorizationDetailsDAO,
100+
final boolean isRichAuthorizationRequestsEnabled) {
97101

98102
this.authorizationDetailsDAO =
99103
Objects.requireNonNull(authorizationDetailsDAO, "AuthorizationDetailsDAO must not be null");
100104
this.authorizationDetailsProcessorFactory = Objects.requireNonNull(authorizationDetailsProcessorFactory,
101105
"AuthorizationDetailsProviderFactory must not be null");
106+
this.isRichAuthorizationRequestsDisabled = !isRichAuthorizationRequestsEnabled;
102107
}
103108

104109
/**
@@ -116,7 +121,7 @@ public void storeOrUpdateUserConsentedAuthorizationDetails(
116121
final AuthorizationDetails userConsentedAuthorizationDetails)
117122
throws OAuthSystemException {
118123

119-
if (!isRichAuthorizationRequest(oAuth2Parameters)) {
124+
if (this.isRichAuthorizationRequestsDisabled || !isRichAuthorizationRequest(oAuth2Parameters)) {
120125
log.debug("Request is not a rich authorization request. Skipping storage of authorization details.");
121126
return;
122127
}
@@ -185,7 +190,7 @@ public void deleteUserConsentedAuthorizationDetails(final AuthenticatedUser auth
185190
final String clientId, final OAuth2Parameters oAuth2Parameters)
186191
throws OAuthSystemException {
187192

188-
if (!isRichAuthorizationRequest(oAuth2Parameters)) {
193+
if (this.isRichAuthorizationRequestsDisabled || !isRichAuthorizationRequest(oAuth2Parameters)) {
189194
log.debug("Request is not a rich authorization request. Skipping deletion of authorization details.");
190195
return;
191196
}
@@ -239,7 +244,7 @@ public boolean isUserAlreadyConsentedForAuthorizationDetails(final Authenticated
239244
final OAuth2Parameters oAuth2Parameters)
240245
throws IdentityOAuth2Exception {
241246

242-
if (!isRichAuthorizationRequest(oAuth2Parameters)) {
247+
if (this.isRichAuthorizationRequestsDisabled || !isRichAuthorizationRequest(oAuth2Parameters)) {
243248
return true;
244249
}
245250

@@ -250,7 +255,7 @@ public AuthorizationDetails getConsentRequiredAuthorizationDetails(final Authent
250255
final OAuth2Parameters oAuth2Parameters)
251256
throws IdentityOAuth2Exception {
252257

253-
if (!isRichAuthorizationRequest(oAuth2Parameters)) {
258+
if (this.isRichAuthorizationRequestsDisabled || !isRichAuthorizationRequest(oAuth2Parameters)) {
254259
log.debug("Request is not a rich authorization request. Skipping the authorization details retrieval.");
255260
return new AuthorizationDetails();
256261
}
@@ -368,6 +373,11 @@ public AuthorizationDetails getUserConsentedAuthorizationDetails(
368373
public AuthorizationDetails getUserConsentedAuthorizationDetails(final String consentId, final int tenantId)
369374
throws IdentityOAuth2Exception {
370375

376+
if (this.isRichAuthorizationRequestsDisabled) {
377+
log.debug("Rich authorization requests is disabled. Skip retrieving consented authorization details.");
378+
return new AuthorizationDetails();
379+
}
380+
371381
try {
372382
final Set<AuthorizationDetail> consentedAuthorizationDetails = new HashSet<>();
373383
this.authorizationDetailsDAO.getUserConsentedAuthorizationDetails(consentId, tenantId)
@@ -413,6 +423,10 @@ private Optional<String> getConsentId(final AuthenticatedUser authenticatedUser,
413423
public Optional<String> getConsentIdByUserIdAndAppId(final String userId, final String appId, final int tenantId)
414424
throws IdentityOAuth2Exception {
415425

426+
if (this.isRichAuthorizationRequestsDisabled) {
427+
log.debug("Rich authorization requests is disabled. Skip retrieving consents.");
428+
return Optional.empty();
429+
}
416430
try {
417431
return Optional
418432
.ofNullable(this.authorizationDetailsDAO.getConsentIdByUserIdAndAppId(userId, appId, tenantId));
@@ -434,6 +448,10 @@ public Optional<String> getConsentIdByUserIdAndAppId(final String userId, final
434448
public AuthorizationDetails getAccessTokenAuthorizationDetails(final String accessTokenId, final int tenantId)
435449
throws IdentityOAuth2Exception {
436450

451+
if (this.isRichAuthorizationRequestsDisabled) {
452+
log.debug("Rich authorization requests is disabled. Skip retrieving token authorization details.");
453+
return new AuthorizationDetails();
454+
}
437455
try {
438456
final Set<AuthorizationDetailsTokenDTO> authorizationDetailsTokenDTOs =
439457
this.authorizationDetailsDAO.getAccessTokenAuthorizationDetails(accessTokenId, tenantId);
@@ -482,10 +500,10 @@ public void storeAccessTokenAuthorizationDetails(final AccessTokenDO accessToken
482500
final AuthorizationDetails authorizationDetails)
483501
throws IdentityOAuth2Exception {
484502

485-
if (AuthorizationDetailsUtils.isEmpty(authorizationDetails)) {
503+
if (this.isRichAuthorizationRequestsDisabled || AuthorizationDetailsUtils.isEmpty(authorizationDetails)) {
504+
log.debug("Request is not a rich authorization request. Skipping storage of token authorization details.");
486505
return;
487506
}
488-
489507
try {
490508
final AuthorizationDetails trimmedAuthorizationDetails = AuthorizationDetailsUtils
491509
.getTrimmedAuthorizationDetails(authorizationDetails);
@@ -542,6 +560,10 @@ public void storeOrReplaceAccessTokenAuthorizationDetails(
542560
public void deleteAccessTokenAuthorizationDetails(final String accessTokenId, final int tenantId)
543561
throws IdentityOAuth2Exception {
544562

563+
if (this.isRichAuthorizationRequestsDisabled) {
564+
log.debug("Rich authorization requests is disabled. Skip persisting token authorization details.");
565+
return;
566+
}
545567
try {
546568
int result = this.authorizationDetailsDAO.deleteAccessTokenAuthorizationDetails(accessTokenId, tenantId);
547569
if (result > 0 && log.isDebugEnabled()) {
@@ -604,7 +626,7 @@ public void storeAuthorizationCodeAuthorizationDetails(
604626
final AuthzCodeDO authzCodeDO, final OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext)
605627
throws IdentityOAuth2Exception {
606628

607-
if (!isRichAuthorizationRequest(oAuthAuthzReqMessageContext)) {
629+
if (this.isRichAuthorizationRequestsDisabled || !isRichAuthorizationRequest(oAuthAuthzReqMessageContext)) {
608630
log.debug("Request is not a rich authorization request. Skipping storage of code authorization details.");
609631
return;
610632
}
@@ -641,6 +663,10 @@ public void storeAuthorizationCodeAuthorizationDetails(
641663
public AuthorizationDetails getAuthorizationCodeAuthorizationDetails(final String code, final int tenantId)
642664
throws IdentityOAuth2Exception {
643665

666+
if (this.isRichAuthorizationRequestsDisabled) {
667+
log.debug("Rich authorization requests is disabled. Skip retrieving code authorization details.");
668+
return new AuthorizationDetails();
669+
}
644670
try {
645671
final Set<AuthorizationDetailsCodeDTO> authorizationDetailsCodeDTOs =
646672
this.authorizationDetailsDAO.getOAuth2CodeAuthorizationDetails(code, tenantId);

0 commit comments

Comments
 (0)