Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API structure was changed to obtain Access Token Audiences in GET response #391

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9e0f77e
API structure was changed to obtain Access Token Audiences in GET res…
gershom96 Sep 7, 2022
9a88550
Added correct headers
gershom96 Sep 7, 2022
2d76505
Updated pom to point to the right identitiy-inbound-auth-oauth versio…
gershom96 Sep 8, 2022
846ec31
Reverted header
gershom96 Sep 8, 2022
324fc23
Changed header
gershom96 Sep 8, 2022
af6b257
Carried out some suggestions
gershom96 Sep 8, 2022
5980db8
Fixed header issues
gershom96 Sep 9, 2022
9c5c09b
Changed header files
gershom96 Sep 12, 2022
3be794a
Merge branch 'master' of https://github.com/wso2/identity-api-server
gershom96 Oct 28, 2022
31d038d
Merge branch 'wso2:master' into master
gershom96 Oct 28, 2022
1be3762
Addressed issues raised in review
gershom96 Oct 31, 2022
46772f6
Merge branch 'master' of github.com:gershom96/identity-api-server
gershom96 Oct 31, 2022
b02544a
Merge branch 'wso2:master' into master
gershom96 Jan 4, 2023
b95f20c
Adding an Error Response if the API request body contains audience in…
gershom96 Jan 7, 2023
d7dea03
Handling access token audience values in API requests when legacy aud…
gershom96 Jan 31, 2023
3973ca8
Bumped oauth version
gershom96 Feb 2, 2023
d66d3ae
Merged from upstream and resolved conflicts
gershom96 Jun 16, 2023
013e86d
Updated APIs to remove functionality to support Legacy Audience behav…
gershom96 Jul 11, 2023
1dea844
Resolved pom file
gershom96 Jul 11, 2023
0c41e0f
API changes to accomadata curent audience separation implementation
gershom96 Jul 26, 2023
149dd8c
Fixed merge conflict
gershom96 Jul 26, 2023
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
Expand Up @@ -22,6 +22,8 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.*;


Expand All @@ -33,6 +35,8 @@
public class AccessTokenConfiguration {

private String type;
private List<String> audience = null;

private Long userAccessTokenExpiryInSeconds;
private Long applicationAccessTokenExpiryInSeconds;
private String bindingType = "None";
Expand All @@ -59,6 +63,32 @@ public void setType(String type) {

/**
**/
public AccessTokenConfiguration audience(List<String> audience) {

this.audience = audience;
return this;
}

@ApiModelProperty(example = "[\"http://idp.xyz.com\"]", value = "")
@JsonProperty("audience")
@Valid
public List<String> getAudience() {
return audience;
}
public void setAudience(List<String> audience) {
this.audience = audience;
}

public AccessTokenConfiguration addAudienceItem(String audienceItem) {
if (this.audience == null) {
this.audience = new ArrayList<>();
}
this.audience.add(audienceItem);
return this;
}

/**
**/
public AccessTokenConfiguration userAccessTokenExpiryInSeconds(Long userAccessTokenExpiryInSeconds) {

this.userAccessTokenExpiryInSeconds = userAccessTokenExpiryInSeconds;
Expand Down Expand Up @@ -163,6 +193,7 @@ public boolean equals(java.lang.Object o) {
}
AccessTokenConfiguration accessTokenConfiguration = (AccessTokenConfiguration) o;
return Objects.equals(this.type, accessTokenConfiguration.type) &&
Objects.equals(this.audience, accessTokenConfiguration.audience) &&
Objects.equals(this.userAccessTokenExpiryInSeconds, accessTokenConfiguration.userAccessTokenExpiryInSeconds) &&
Objects.equals(this.applicationAccessTokenExpiryInSeconds, accessTokenConfiguration.applicationAccessTokenExpiryInSeconds) &&
Objects.equals(this.bindingType, accessTokenConfiguration.bindingType) &&
Expand All @@ -172,7 +203,7 @@ public boolean equals(java.lang.Object o) {

@Override
public int hashCode() {
return Objects.hash(type, userAccessTokenExpiryInSeconds, applicationAccessTokenExpiryInSeconds, bindingType, revokeTokensWhenIDPSessionTerminated, validateTokenBinding);
return Objects.hash(type, audience, userAccessTokenExpiryInSeconds, applicationAccessTokenExpiryInSeconds, bindingType, revokeTokensWhenIDPSessionTerminated, validateTokenBinding);
}

@Override
Expand All @@ -182,6 +213,7 @@ public String toString() {
sb.append("class AccessTokenConfiguration {\n");

sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" audience: ").append(toIndentedString(audience)).append("\n");
sb.append(" userAccessTokenExpiryInSeconds: ").append(toIndentedString(userAccessTokenExpiryInSeconds)).append("\n");
sb.append(" applicationAccessTokenExpiryInSeconds: ").append(toIndentedString(applicationAccessTokenExpiryInSeconds)).append("\n");
sb.append(" bindingType: ").append(toIndentedString(bindingType)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2019, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
gershom96 marked this conversation as resolved.
Show resolved Hide resolved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
gershom96 marked this conversation as resolved.
Show resolved Hide resolved

package org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.oauth2;

import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -88,7 +89,7 @@ private void updateIdTokenConfiguration(OAuthConsumerAppDTO consumerAppDTO, IdTo

if (idToken != null) {
setIfNotNull(idToken.getExpiryInSeconds(), consumerAppDTO::setIdTokenExpiryTime);
consumerAppDTO.setAudiences(Optional.ofNullable(idToken.getAudience())
consumerAppDTO.setIdTokenAudiences(Optional.ofNullable(idToken.getAudience())
gershom96 marked this conversation as resolved.
Show resolved Hide resolved
.map(audiences -> audiences.toArray(new String[0]))
.orElse(new String[0])
);
Expand Down Expand Up @@ -131,6 +132,10 @@ private void updateAccessTokenConfiguration(OAuthConsumerAppDTO consumerAppDTO,
if (accessToken != null) {
consumerAppDTO.setTokenType(accessToken.getType());
consumerAppDTO.setUserAccessTokenExpiryTime(accessToken.getUserAccessTokenExpiryInSeconds());
consumerAppDTO.setAccessTokenAudiences(Optional.ofNullable(accessToken.getAudience())
.map(audiences -> audiences.toArray(new String[0]))
.orElse(new String[0])
);
consumerAppDTO.setApplicationAccessTokenExpiryTime(accessToken.getApplicationAccessTokenExpiryInSeconds());
consumerAppDTO.setTokenBindingType(accessToken.getBindingType());
if (accessToken.getRevokeTokensWhenIDPSessionTerminated() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2019, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.oauth2;

import org.apache.commons.lang.StringUtils;
Expand All @@ -24,6 +27,7 @@
import org.wso2.carbon.identity.api.server.application.management.v1.OpenIDConnectConfiguration;
import org.wso2.carbon.identity.api.server.application.management.v1.RefreshTokenConfiguration;
import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.identity.oauth2.internal.OAuth2ServiceComponentHolder;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -78,14 +82,20 @@ private OAuth2PKCEConfiguration buildPKCEConfiguration(OAuthConsumerAppDTO oAuth

private AccessTokenConfiguration buildTokenConfiguration(OAuthConsumerAppDTO oAuthConsumerAppDTO) {

return new AccessTokenConfiguration()
AccessTokenConfiguration accessTokenConfiguration = new AccessTokenConfiguration()
.type(oAuthConsumerAppDTO.getTokenType())
.userAccessTokenExpiryInSeconds(oAuthConsumerAppDTO.getUserAccessTokenExpiryTime())
.applicationAccessTokenExpiryInSeconds(oAuthConsumerAppDTO.getApplicationAccessTokenExpiryTime())
.bindingType(oAuthConsumerAppDTO.getTokenBindingType())
.revokeTokensWhenIDPSessionTerminated(oAuthConsumerAppDTO
.isTokenRevocationWithIDPSessionTerminationEnabled())
.validateTokenBinding(oAuthConsumerAppDTO.isTokenBindingValidationEnabled());

if (!OAuth2ServiceComponentHolder.isLegacyAudienceEnabled()) {
accessTokenConfiguration.audience(getAccessTokenAudiences(oAuthConsumerAppDTO.getAccessTokenAudiences()));
}

return accessTokenConfiguration;
}

private RefreshTokenConfiguration buildRefreshTokenConfiguration(OAuthConsumerAppDTO oAuthConsumerAppDTO) {
Expand All @@ -99,17 +109,18 @@ private IdTokenConfiguration buildIdTokenConfiguration(OAuthConsumerAppDTO oAuth

return new IdTokenConfiguration()
.expiryInSeconds(oAuthConsumerAppDTO.getIdTokenExpiryTime())
.audience(getAudiences(oAuthConsumerAppDTO))
.audience(getIdTokenAudiences(oAuthConsumerAppDTO.getIdTokenAudiences()))
.encryption(buildIdTokenEncryptionConfiguration(oAuthConsumerAppDTO));
}

private List<String> getAudiences(OAuthConsumerAppDTO oAuthConsumerAppDTO) {
private List<String> getIdTokenAudiences(String[] audiences) {

if (oAuthConsumerAppDTO.getAudiences() == null) {
return Collections.emptyList();
} else {
return Arrays.asList(oAuthConsumerAppDTO.getAudiences());
}
return (audiences == null) ? Collections.emptyList() : Arrays.asList(audiences);
}

private List<String> getAccessTokenAudiences(String[] audiences) {

return (audiences == null) ? Collections.emptyList() : Arrays.asList(audiences);
}
gershom96 marked this conversation as resolved.
Show resolved Hide resolved

private IdTokenEncryptionConfiguration buildIdTokenEncryptionConfiguration(OAuthConsumerAppDTO appDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.wso2.carbon.identity.oauth.IdentityOAuthClientException;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.identity.oauth2.internal.OAuth2ServiceComponentHolder;

import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -89,6 +90,13 @@ public static InboundAuthenticationRequestConfig putOAuthInbound(ServiceProvider
throw buildBadRequestError("Invalid ClientSecret provided for update.");
}

if (OAuth2ServiceComponentHolder.isLegacyAudienceEnabled()) {
if (oidcConfigModel.getAccessToken().getAudience() != null) {
throw buildBadRequestError("Cannot set audiences for access token if legacy audiences " +
"are enabled.");
}
}

OAuthConsumerAppDTO appToUpdate = new ApiModelToOAuthConsumerApp().apply(application
.getApplicationName(), oidcConfigModel);
ApplicationManagementServiceHolder.getOAuthAdminService().updateConsumerApplication(appToUpdate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,12 @@ components:
type:
type: string
example: JWT
audience:
type: array
example:
- 'http://idp.xyz.com'
items:
type: string
userAccessTokenExpiryInSeconds:
type: integer
format: int64
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
<identity.workflow.impl.bps.version>5.2.0</identity.workflow.impl.bps.version>
<maven.checkstyleplugin.excludes>**/gen/**/*</maven.checkstyleplugin.excludes>
<identity.event.handler.version>1.4.4</identity.event.handler.version>
<identity.inbound.oauth2.version>6.11.51</identity.inbound.oauth2.version>
<identity.inbound.oauth2.version>6.11.90</identity.inbound.oauth2.version>
<identity.inbound.saml2.version>5.11.16</identity.inbound.saml2.version>
<commons.beanutils.version>1.9.4</commons.beanutils.version>
<mavan.findbugsplugin.exclude.file>findbugs-exclude-filter.xml</mavan.findbugsplugin.exclude.file>
Expand Down
Loading