Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -188,6 +189,33 @@ public static Builder authorizationCode() {
return new Builder(AuthorizationGrantType.AUTHORIZATION_CODE);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
OAuth2AuthorizationRequest that = (OAuth2AuthorizationRequest) obj;

return Objects.equals(this.authorizationUri, that.authorizationUri)
&& Objects.equals(this.authorizationGrantType, that.authorizationGrantType)
&& Objects.equals(this.responseType, that.responseType) && Objects.equals(this.clientId, that.clientId)
&& Objects.equals(this.redirectUri, that.redirectUri) && Objects.equals(this.scopes, that.scopes)
&& Objects.equals(this.state, that.state)
&& Objects.equals(this.additionalParameters, that.additionalParameters)
&& Objects.equals(this.authorizationRequestUri, that.authorizationRequestUri)
&& Objects.equals(this.attributes, that.attributes);
}

@Override
public int hashCode() {
return Objects.hash(this.authorizationUri, this.clientId, this.authorizationGrantType, this.responseType,
this.redirectUri, this.scopes, this.state, this.additionalParameters, this.authorizationRequestUri,
this.attributes);
}

/**
* Returns a new {@link Builder}, initialized with the values from the provided
* {@code authorizationRequest}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,27 @@ public void buildWhenAdditionalParametersContainsNullThenAuthorizationRequestUri
+ "item1=null&item2=value2");
}

@Test
public void equalsWhenAllFieldsEqualEqualsThenTrue() {
OAuth2AuthorizationRequest authorizationRequest1 = TestOAuth2AuthorizationRequests.allFields().build();

OAuth2AuthorizationRequest authorizationRequest2 = TestOAuth2AuthorizationRequests.allFields().build();

assertThat(authorizationRequest1).isNotSameAs(authorizationRequest2);
assertThat(authorizationRequest1).isEqualTo(authorizationRequest2);
}

@Test
public void hashCodeWhenAllFieldsEqualThenHashCodesAreEqual() {
OAuth2AuthorizationRequest authorizationRequest1 = TestOAuth2AuthorizationRequests.allFields().build();

OAuth2AuthorizationRequest authorizationRequest2 = TestOAuth2AuthorizationRequests.allFields().build();

int authorizationRequest1HashCode = authorizationRequest1.hashCode();
int authorizationRequest2HashCode = authorizationRequest2.hashCode();

assertThat(authorizationRequest1).isNotSameAs(authorizationRequest2);
assertThat(authorizationRequest1HashCode).isEqualTo(authorizationRequest2HashCode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ public static OAuth2AuthorizationRequest.Builder oidcRequest() {
return request().scope("openid");
}

public static OAuth2AuthorizationRequest.Builder allFields() {
// @formatter:off
return request()
.authorizationRequestUri("https://example.com")
.additionalParameters(Map.of("someAdditionalParameterKey", "someAdditionalParameterValue"))
.parameters((parametersMap) ->
parametersMap.put("someParameterKey", "someParameterValue"))
.scope("someScope");
// @formatter:on
}

}