Skip to content

Commit

Permalink
Merge branch 'master' into java17-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yogyagamage authored Aug 26, 2022
2 parents 73c786c + 864ceec commit 9b65cca
Show file tree
Hide file tree
Showing 70 changed files with 265 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<parent>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.application.management</artifactId>
<version>1.1.26-SNAPSHOT</version>
<version>1.2.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.server.application.management.common</artifactId>
<version>1.1.26-SNAPSHOT</version>
<version>1.2.6-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.wso2.carbon.identity.oauth.common.GrantType;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
import org.wso2.carbon.identity.oauth2.device.constants.Constants;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -47,6 +48,8 @@ private ApplicationManagementConstants() {
public static final String DEFAULT_CERTIFICATE_ALIAS = "wso2carbon";
public static final String ADVANCED_CONFIGURATIONS = "advancedConfigurations";
public static final String TEMPLATE_ID = "templateId";
public static final String CLIENT_ID = "clientId";
public static final String ISSUER = "issuer";

public static final String NON_EXISTING_USER_CODE = "30007 - ";

Expand All @@ -59,7 +62,7 @@ public enum ErrorMessage {
UNSUPPORTED_FILTER_ATTRIBUTE("60004",
"Filtering using the attempted attribute is not supported.",
"Filtering cannot be done with the '%s' attribute. " +
"Filtering is only supported with the 'name', and the 'clientID' attributes."),
"Filtering is only supported with the 'name', and the 'clientId' attributes."),
INVALID_FILTER_FORMAT("60004",
"Invalid format user for filtering.",
"Filter needs to be in the format <attribute>+<operation>+<value>. Eg: name+eq+john"),
Expand Down Expand Up @@ -175,6 +178,8 @@ public String toString() {
OAUTH_GRANT_TYPE_NAMES.put("urn:ietf:params:oauth:grant-type:saml1-bearer", "SAML1");
OAUTH_GRANT_TYPE_NAMES.put(GrantType.SAML20_BEARER.toString(), "SAML2");
OAUTH_GRANT_TYPE_NAMES.put(OAuthConstants.GrantTypes.IWA_NTLM, "IWA-NTLM");
OAUTH_GRANT_TYPE_NAMES.put("organization_switch", "Organization Switch");
OAUTH_GRANT_TYPE_NAMES.put(Constants.DEVICE_FLOW_GRANT_TYPE, "Device Code");
}

public static Map<String, String> getOAuthGrantTypeNames() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
<parent>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.application.management</artifactId>
<version>1.1.26-SNAPSHOT</version>
<version>1.2.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<name>WSO2 Identity Server - Applications Rest API</name>
<description>WSO2 Identity Server - Applications Rest API</description>
<artifactId>org.wso2.carbon.identity.api.server.application.management.v1</artifactId>
<version>1.1.26-SNAPSHOT</version>
<version>1.2.6-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class ApplicationListItem {
private String description;
private String image;
private String accessUrl;
private String inboundKey;

@XmlType(name="AccessEnum")
@XmlEnum(String.class)
Expand Down Expand Up @@ -73,6 +72,8 @@ public static AccessEnum fromValue(String value) {
private AccessEnum access = AccessEnum.READ;
private String self;
private AdvancedApplicationConfiguration advancedConfigurations;
private String clientId;
private String issuer;
private String templateId;

/**
Expand Down Expand Up @@ -165,23 +166,6 @@ public void setAccessUrl(String accessUrl) {
this.accessUrl = accessUrl;
}

public ApplicationListItem inboundKey(String inboundKey) {

this.inboundKey = inboundKey;
return this;
}

@ApiModelProperty(example = "sampleRandomString", value = "")
@JsonProperty("inboundKey")
@Valid
public String getInboundKey() {
return inboundKey;
}

public void setInboundKey(String inboundKey) {
this.inboundKey = inboundKey;
}

/**
**/
public ApplicationListItem access(AccessEnum access) {
Expand Down Expand Up @@ -236,6 +220,44 @@ public void setAdvancedConfigurations(AdvancedApplicationConfiguration advancedC
this.advancedConfigurations = advancedConfigurations;
}

/**
**/
public ApplicationListItem clientId(String clientId) {

this.clientId = clientId;
return this;
}

@ApiModelProperty(example = "SmrrDNXRYf1lMmDlnleeHTuXx_Ea", value = "")
@JsonProperty("clientId")
@Valid
public String getClientId() {
return clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

/**
**/
public ApplicationListItem issuer(String issuer) {

this.issuer = issuer;
return this;
}

@ApiModelProperty(example = "http://idp.example.com/metadata.php", value = "")
@JsonProperty("issuer")
@Valid
public String getIssuer() {
return issuer;
}

public void setIssuer(String issuer) {
this.issuer = issuer;
}

/**
**/
public ApplicationListItem templateId(String templateId) {
Expand Down Expand Up @@ -271,7 +293,8 @@ public boolean equals(java.lang.Object o) {
Objects.equals(this.description, applicationListItem.description) &&
Objects.equals(this.image, applicationListItem.image) &&
Objects.equals(this.accessUrl, applicationListItem.accessUrl) &&
Objects.equals(this.inboundKey, applicationListItem.inboundKey) &&
Objects.equals(this.clientId, applicationListItem.clientId) &&
Objects.equals(this.issuer, applicationListItem.issuer) &&
Objects.equals(this.access, applicationListItem.access) &&
Objects.equals(this.self, applicationListItem.self) &&
Objects.equals(this.advancedConfigurations, applicationListItem.advancedConfigurations) &&
Expand All @@ -281,7 +304,7 @@ public boolean equals(java.lang.Object o) {
@Override
public int hashCode() {

return Objects.hash(id, name, description, image, accessUrl, inboundKey, access, self,
return Objects.hash(id, name, description, image, accessUrl, clientId, issuer, access, self,
advancedConfigurations, templateId);
}

Expand All @@ -296,7 +319,8 @@ public String toString() {
sb.append(" description: ").append(toIndentedString(description)).append("\n");
sb.append(" image: ").append(toIndentedString(image)).append("\n");
sb.append(" accessUrl: ").append(toIndentedString(accessUrl)).append("\n");
sb.append(" inboundKey: ").append(toIndentedString(inboundKey)).append("\n");
sb.append(" clientId: ").append(toIndentedString(clientId)).append("\n");
sb.append(" issuer: ").append(toIndentedString(issuer)).append("\n");
sb.append(" access: ").append(toIndentedString(access)).append("\n");
sb.append(" self: ").append(toIndentedString(self)).append("\n");
sb.append(" advancedConfigurations: ").append(toIndentedString(advancedConfigurations)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class ApplicationResponseModel {
private String description;
private String imageUrl;
private String accessUrl;
private String clientId;
private String issuer;
private String templateId;
private Boolean isManagementApp;
private ClaimConfiguration claimConfiguration;
Expand Down Expand Up @@ -177,6 +179,42 @@ public void setAccessUrl(String accessUrl) {
this.accessUrl = accessUrl;
}

/**
**/
public ApplicationResponseModel clientId(String clientId) {

this.clientId = clientId;
return this;
}

@ApiModelProperty(example = "SmrrDNXRYf1lMmDlnleeHTuXx_Ea", value = "")
@JsonProperty("clientId")
@Valid
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}

/**
**/
public ApplicationResponseModel issuer(String issuer) {

this.issuer = issuer;
return this;
}

@ApiModelProperty(example = "http://idp.example.com/metadata.php", value = "")
@JsonProperty("issuer")
@Valid
public String getIssuer() {
return issuer;
}
public void setIssuer(String issuer) {
this.issuer = issuer;
}

/**
**/
public ApplicationResponseModel templateId(String templateId) {
Expand Down Expand Up @@ -344,6 +382,8 @@ public boolean equals(java.lang.Object o) {
Objects.equals(this.description, applicationResponseModel.description) &&
Objects.equals(this.imageUrl, applicationResponseModel.imageUrl) &&
Objects.equals(this.accessUrl, applicationResponseModel.accessUrl) &&
Objects.equals(this.clientId, applicationResponseModel.clientId) &&
Objects.equals(this.issuer, applicationResponseModel.issuer) &&
Objects.equals(this.templateId, applicationResponseModel.templateId) &&
Objects.equals(this.isManagementApp, applicationResponseModel.isManagementApp) &&
Objects.equals(this.claimConfiguration, applicationResponseModel.claimConfiguration) &&
Expand All @@ -356,7 +396,7 @@ public boolean equals(java.lang.Object o) {

@Override
public int hashCode() {
return Objects.hash(id, name, description, imageUrl, accessUrl, templateId, isManagementApp, claimConfiguration, inboundProtocols, authenticationSequence, advancedConfigurations, provisioningConfigurations, access);
return Objects.hash(id, name, description, imageUrl, accessUrl, clientId, issuer, templateId, isManagementApp, claimConfiguration, inboundProtocols, authenticationSequence, advancedConfigurations, provisioningConfigurations, access);
}

@Override
Expand All @@ -370,6 +410,8 @@ public String toString() {
sb.append(" description: ").append(toIndentedString(description)).append("\n");
sb.append(" imageUrl: ").append(toIndentedString(imageUrl)).append("\n");
sb.append(" accessUrl: ").append(toIndentedString(accessUrl)).append("\n");
sb.append(" clientId: ").append(toIndentedString(clientId)).append("\n");
sb.append(" issuer: ").append(toIndentedString(issuer)).append("\n");
sb.append(" templateId: ").append(toIndentedString(templateId)).append("\n");
sb.append(" isManagementApp: ").append(toIndentedString(isManagementApp)).append("\n");
sb.append(" claimConfiguration: ").append(toIndentedString(claimConfiguration)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@

import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ADVANCED_CONFIGURATIONS;
import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.APPLICATION_MANAGEMENT_PATH_COMPONENT;
import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.CLIENT_ID;
import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.APPLICATION_CREATION_WITH_TEMPLATES_NOT_IMPLEMENTED;
import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ERROR_APPLICATION_LIMIT_REACHED;
import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ERROR_PROCESSING_REQUEST;
import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.INBOUND_NOT_CONFIGURED;
import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ISSUER;
import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.TEMPLATE_ID;
import static org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils.buildBadRequestError;
import static org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils.buildNotImplementedError;
Expand Down Expand Up @@ -156,13 +158,14 @@ public class ServerApplicationManagementService {

// Allowed filter attributes mapped to real field names.
private static final Map<String, String> SEARCH_SUPPORTED_FIELD_MAP = new HashMap<>();
private static final List<String> SUPPORTED_REQUIRED_ATTRIBUTES = new ArrayList<>();
private static final int DEFAULT_OFFSET = 0;

// Filter related constants.
private static final String FILTER_STARTS_WITH = "sw";
private static final String FILTER_ENDS_WITH = "ew";
private static final String FILTER_EQUALS = "eq";
private static final String FILTER_CONTAINS = "co";
private static final int DEFAULT_OFFSET = 0;

// WS-Trust related constants.
private static final String WS_TRUST_TEMPLATE_ID = "061a3de4-8c08-4878-84a6-24245f11bf0e";
Expand All @@ -171,7 +174,12 @@ public class ServerApplicationManagementService {

static {
SEARCH_SUPPORTED_FIELD_MAP.put("name", "SP_APP.APP_NAME");
SEARCH_SUPPORTED_FIELD_MAP.put("clientID", "SP_INBOUND_AUTH.INBOUND_AUTH_KEY");
SEARCH_SUPPORTED_FIELD_MAP.put("clientId", "SP_INBOUND_AUTH.INBOUND_AUTH_KEY");

SUPPORTED_REQUIRED_ATTRIBUTES.add(ADVANCED_CONFIGURATIONS);
SUPPORTED_REQUIRED_ATTRIBUTES.add(CLIENT_ID);
SUPPORTED_REQUIRED_ATTRIBUTES.add(TEMPLATE_ID);
SUPPORTED_REQUIRED_ATTRIBUTES.add(ISSUER);
}

private static final Set<String> SEARCH_SUPPORTED_ATTRIBUTES = SEARCH_SUPPORTED_FIELD_MAP.keySet();
Expand All @@ -188,6 +196,8 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
limit = validateAndGetLimit(limit);
offset = validateAndGetOffset(offset);

boolean isFilterContainsClientIdAttribute = false;

// Get the filter tree and validate it before sending the filter to the backend.
if (StringUtils.isNotBlank(filter)) {
try {
Expand All @@ -199,6 +209,10 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
throw buildClientError(ErrorMessage.UNSUPPORTED_FILTER_ATTRIBUTE, expressionNode
.getAttributeValue());
}

if (expressionNode.getAttributeValue().equals(CLIENT_ID)) {
isFilterContainsClientIdAttribute = true;
}
} else if (rootNode instanceof OperationNode) {
// Currently, supports only filters with one AND/OR operation.
// Have to recursively traverse the filter tree to support more than one operation.
Expand All @@ -209,6 +223,7 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
if (operationNode.getOperation().equals("not")) {
throw buildClientError(ErrorMessage.INVALID_FILTER_FORMAT);
}

if (leftNode instanceof ExpressionNode && rightNode instanceof ExpressionNode) {
ExpressionNode expressionLeftNode = (ExpressionNode) leftNode;
ExpressionNode expressionRightNode = (ExpressionNode) rightNode;
Expand All @@ -220,6 +235,11 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
throw buildClientError(ErrorMessage.UNSUPPORTED_FILTER_ATTRIBUTE, expressionRightNode
.getAttributeValue());
}

if (expressionLeftNode.getAttributeValue().equals(CLIENT_ID) ||
expressionRightNode.getAttributeValue().equals(CLIENT_ID)) {
isFilterContainsClientIdAttribute = true;
}
} else {
throw buildClientError(ErrorMessage.INVALID_FILTER_FORMAT);
}
Expand All @@ -240,13 +260,20 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
.getApplicationBasicInfo(tenantDomain, username, filter, offset, limit);
int resultsInCurrentPage = filteredAppList.length;

List<String> requestedAttributeList = null;
List<String> requestedAttributeList = new ArrayList<>();
if (StringUtils.isNotEmpty(requiredAttributes)) {
requestedAttributeList = Arrays.asList(requiredAttributes.split(","));
requestedAttributeList = new ArrayList<>(Arrays.asList(requiredAttributes.split(",")));
validateRequiredAttributes(requestedAttributeList);
}

// Add clientId as a required attribute when there's clientId as a filter param.
if (!requestedAttributeList.contains(CLIENT_ID) && !StringUtils.isBlank(filter) &&
!filter.equals("*") && isFilterContainsClientIdAttribute) {
requestedAttributeList.add(CLIENT_ID);
}

if (CollectionUtils.isNotEmpty(requestedAttributeList)) {
List<ServiceProvider> serviceProviderList = getSpWithRequiredAttributes(filteredAppList,
List<ServiceProvider> serviceProviderList = getSpWithRequiredAttributes(filteredAppList,
requestedAttributeList);

return new ApplicationListResponse()
Expand Down Expand Up @@ -283,10 +310,7 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
private void validateRequiredAttributes(List<String> requestedAttributeList) {

for (String attribute: requestedAttributeList) {
/* 'attributes' requested in get application list only supports advancedConfigurations and templateId.
* The advancedConfigurations is supported as metadata of the application is essential in certain cases and
* templateId is supported to add filtering on listing page. */
if (!(attribute.equals(ADVANCED_CONFIGURATIONS) || attribute.equals(TEMPLATE_ID))) {
if (!(SUPPORTED_REQUIRED_ATTRIBUTES.contains(attribute))) {
ErrorMessage errorEnum = ErrorMessage.NON_EXISTING_REQ_ATTRIBUTES;
throw Utils.buildBadRequestError(errorEnum.getCode(), errorEnum.getDescription());
}
Expand Down Expand Up @@ -1089,6 +1113,12 @@ private List<ApplicationListItem> getApplicationListItems(List<ServiceProvider>
if (requiredAttributes.stream().noneMatch(attribute -> attribute.equals(ADVANCED_CONFIGURATIONS))) {
applicationResponseModel.advancedConfigurations(null);
}
if (requiredAttributes.stream().noneMatch(attribute -> attribute.equals(CLIENT_ID))) {
applicationResponseModel.clientId(null);
}
if (requiredAttributes.stream().noneMatch(attribute -> attribute.equals(ISSUER))) {
applicationResponseModel.issuer(null);
}
applicationListItems.add(new ApplicationInfoWithRequiredPropsToApiModel().apply(applicationResponseModel));
}
return applicationListItems;
Expand Down
Loading

0 comments on commit 9b65cca

Please sign in to comment.