Skip to content

Commit

Permalink
[ELY-1745] checkNotNullParam in the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
lvydra committed Feb 2, 2024
1 parent 78c91be commit ae791a6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
Expand Up @@ -1376,7 +1376,7 @@ public InactiveState(SecurityIdentity capturedIdentity, MechanismConfigurationSe
public InactiveState(SecurityIdentity capturedIdentity, MechanismConfigurationSelector mechanismConfigurationSelector,
MechanismInformation mechanismInformation, IdentityCredentials privateCredentials, IdentityCredentials publicCredentials, Attributes runtimeAttributes) {
this.capturedIdentity = capturedIdentity;
this.mechanismConfigurationSelector = mechanismConfigurationSelector;
this.mechanismConfigurationSelector = checkNotNullParam("mechanismConfigurationSelector", mechanismConfigurationSelector);
this.mechanismInformation = checkNotNullParam("mechanismInformation", mechanismInformation);
this.privateCredentials = privateCredentials;
this.publicCredentials = publicCredentials;
Expand Down Expand Up @@ -1492,9 +1492,6 @@ private void transition() {
}

private InitialState selectMechanismConfiguration() {
if (mechanismConfigurationSelector == null) {
throw log.mechanismConfigurationSelectorNotDefined();
}
MechanismConfiguration mechanismConfiguration = mechanismConfigurationSelector.selectConfiguration(mechanismInformation);
if (mechanismConfiguration == null) {
throw log.unableToSelectMechanismConfiguration(mechanismInformation.getMechanismType(),
Expand Down
Expand Up @@ -108,9 +108,6 @@ IllegalStateException unableToSelectMechanismConfiguration(String mechanismType,
@Message(id = 1120, value = "Too late to set mechanism information as authentication has already begun.")
IllegalStateException tooLateToSetMechanismInformation();

@Message(id = 1121, value = "MechanismConfigurationSelector is not defined.")
IllegalStateException mechanismConfigurationSelectorNotDefined();

@Message(id = 1124, value = "The security realm does not support updating a credential")
UnsupportedOperationException credentialUpdateNotSupportedByRealm();

Expand Down
Expand Up @@ -34,13 +34,12 @@ public class AvailableRealmsCallbackTest {
@Test
public void testNullMechanismConfigurationSelector() {
SecurityDomain securityDomain = SecurityDomain.builder().build();
ServerAuthenticationContext sac = securityDomain.createNewAuthenticationContext(null);

try {
sac.setAuthenticationName("user");
ServerAuthenticationContext sac = securityDomain.createNewAuthenticationContext(null);
fail("The exception should be thrown.");
} catch (Exception e) {
String expectedMessage = "MechanismConfigurationSelector is not defined.";
String expectedMessage = "Parameter 'mechanismConfigurationSelector' may not be null";
String actualMessage = e.getMessage();

assertTrue(actualMessage.contains(expectedMessage));
Expand Down

0 comments on commit ae791a6

Please sign in to comment.