Skip to content

Commit

Permalink
Added: managing API_BEARER_AUTH_HANDLE_TOS_ACCEPTANCE_IN_IDP feature …
Browse files Browse the repository at this point in the history
…flag in RegisterOIDCUserCommand
  • Loading branch information
GPortas committed Dec 11, 2024
1 parent f9283e8 commit fac0dc3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ private String getValueOrDefault(String oidcValue, String dtoValue) {
private void validateUserFields(CommandContext ctxt, boolean provideMissingClaimsEnabled) throws InvalidFieldsCommandException {
Map<String, String> fieldErrors = new HashMap<>();

validateTermsAccepted(fieldErrors);
if (!FeatureFlags.API_BEARER_AUTH_HANDLE_TOS_ACCEPTANCE_IN_IDP.enabled()) {
validateTermsAccepted(fieldErrors);
}

validateField(fieldErrors, FIELD_EMAIL_ADDRESS, userDTO.getEmailAddress(), ctxt, provideMissingClaimsEnabled);
validateField(fieldErrors, FIELD_USERNAME, userDTO.getUsername(), ctxt, provideMissingClaimsEnabled);
validateField(fieldErrors, FIELD_FIRST_NAME, userDTO.getFirstName(), ctxt, provideMissingClaimsEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import edu.harvard.iq.dataverse.harvest.client.HarvestingClient;
import edu.harvard.iq.dataverse.license.License;
import edu.harvard.iq.dataverse.license.LicenseServiceBean;
import edu.harvard.iq.dataverse.settings.FeatureFlags;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.workflow.Workflow;
Expand Down Expand Up @@ -1107,13 +1108,18 @@ private void validate(String objectName, JsonObject jobject, String fieldName, V

public UserDTO parseUserDTO(JsonObject jobj) throws JsonParseException {
UserDTO userDTO = new UserDTO();

userDTO.setUsername(jobj.getString("username", null));
userDTO.setEmailAddress(jobj.getString("emailAddress", null));
userDTO.setFirstName(jobj.getString("firstName", null));
userDTO.setLastName(jobj.getString("lastName", null));
userDTO.setTermsAccepted(getMandatoryBoolean(jobj, "termsAccepted"));
userDTO.setAffiliation(jobj.getString("affiliation", null));
userDTO.setPosition(jobj.getString("position", null));

if (!FeatureFlags.API_BEARER_AUTH_HANDLE_TOS_ACCEPTANCE_IN_IDP.enabled()) {
userDTO.setTermsAccepted(getMandatoryBoolean(jobj, "termsAccepted"));
}

return userDTO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static edu.harvard.iq.dataverse.mocks.MocksFactory.makeRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.*;

@LocalJvmSettings
Expand Down Expand Up @@ -350,4 +351,21 @@ void execute_happyPath_withoutAffiliationAndPosition_blankClaimInProviderProvide
eq(true)
);
}

@Test
@JvmSetting(key = JvmSettings.FEATURE_FLAG, value = "true", varArgs = "api-bearer-auth-handle-tos-acceptance-in-idp")
void execute_doNotThrowUnacceptedTermsError_unacceptedTermsInUserDTOAndAllClaimsInProvider_handleTosAcceptanceInIdpFeatureFlagEnabled() throws AuthorizationException {
testUserDTO.setTermsAccepted(false);
testUserDTO.setEmailAddress(null);
testUserDTO.setUsername(null);
testUserDTO.setFirstName(null);
testUserDTO.setLastName(null);

when(authServiceStub.verifyOIDCBearerTokenAndGetOAuth2UserRecord(TEST_BEARER_TOKEN)).thenReturn(oAuth2UserRecordStub);

when(oAuth2UserRecordStub.getUsername()).thenReturn(TEST_USERNAME);
when(oAuth2UserRecordStub.getDisplayInfo()).thenReturn(TEST_VALID_DISPLAY_INFO);

assertDoesNotThrow(() -> sut.execute(contextStub));
}
}

0 comments on commit fac0dc3

Please sign in to comment.