forked from community/device-mgt-core
Add identity server service provider app integration See merge request entgra/carbon-device-mgt!849temp
commit
270904102d
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common;
|
||||
|
||||
public class Base64File {
|
||||
|
||||
private String name;
|
||||
private String base64String;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getBase64String() {
|
||||
return base64String;
|
||||
}
|
||||
|
||||
public void setBase64String(String base64String) {
|
||||
this.base64String = base64String;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class FileDataHolder {
|
||||
|
||||
private String name;
|
||||
private InputStream file;
|
||||
|
||||
public FileDataHolder(String name, InputStream file) {
|
||||
this.name = name;
|
||||
this.file = file;
|
||||
}
|
||||
public FileDataHolder() {
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public InputStream getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(InputStream file) {
|
||||
this.file = file;
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IdentityServerResponse {
|
||||
private int id;
|
||||
private String providerName;
|
||||
private String name;
|
||||
private String description;
|
||||
private String url;
|
||||
private String serviceProviderAppsUrl;
|
||||
private String username;
|
||||
private List<Map<String, String>> apiParamList;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getProviderName() {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
public void setProviderName(String providerName) {
|
||||
this.providerName = providerName;
|
||||
}
|
||||
|
||||
public String getServiceProviderAppsUrl() {
|
||||
return serviceProviderAppsUrl;
|
||||
}
|
||||
|
||||
public void setServiceProviderAppsUrl(String serviceProviderAppsUrl) {
|
||||
this.serviceProviderAppsUrl = serviceProviderAppsUrl;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getApiParamList() {
|
||||
return apiParamList;
|
||||
}
|
||||
|
||||
public void setApiParamList(Map<String, String> apiParams) {
|
||||
this.apiParamList = apiParams.entrySet().stream().map(param -> {
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put(param.getKey(), param.getValue());
|
||||
return paramMap;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common;
|
||||
|
||||
|
||||
import io.entgra.application.mgt.common.response.Application;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SPApplication {
|
||||
private String id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String image;
|
||||
private String accessUrl;
|
||||
private String access;
|
||||
private String self;
|
||||
private List<Application> existingApplications;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getAccessUrl() {
|
||||
return accessUrl;
|
||||
}
|
||||
|
||||
public void setAccessUrl(String accessUrl) {
|
||||
this.accessUrl = accessUrl;
|
||||
}
|
||||
|
||||
public String getAccess() {
|
||||
return access;
|
||||
}
|
||||
|
||||
public void setAccess(String access) {
|
||||
this.access = access;
|
||||
}
|
||||
|
||||
public String getSelf() {
|
||||
return self;
|
||||
}
|
||||
|
||||
public void setSelf(String self) {
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
public List<Application> getExistingApplications() {
|
||||
return existingApplications;
|
||||
}
|
||||
|
||||
public void setExistingApplications(List<Application> existingApplications) {
|
||||
this.existingApplications = existingApplications;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SPApplicationListResponse {
|
||||
private int totalResults;
|
||||
private int startIndex;
|
||||
private int count;
|
||||
private List<SPApplication> applications;
|
||||
|
||||
public int getTotalResults() {
|
||||
return totalResults;
|
||||
}
|
||||
|
||||
public void setTotalResults(int totalResults) {
|
||||
this.totalResults = totalResults;
|
||||
}
|
||||
|
||||
public int getStartIndex() {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
public void setStartIndex(int startIndex) {
|
||||
this.startIndex = startIndex;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public List<SPApplication> getApplications() {
|
||||
return applications;
|
||||
}
|
||||
|
||||
public void setApplications(List<SPApplication> applications) {
|
||||
this.applications = applications;
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common.dto;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class IdentityServerDTO {
|
||||
|
||||
private int id;
|
||||
private String providerName;
|
||||
private String name;
|
||||
private String description;
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
private Map<String, String> apiParams;
|
||||
|
||||
public IdentityServerDTO() {
|
||||
this.apiParams = new HashMap<>();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getProviderName() {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
public void setProviderName(String providerName) {
|
||||
this.providerName = providerName;
|
||||
}
|
||||
|
||||
public String constructApiParamsJsonString() {
|
||||
return new Gson().toJson(apiParams);
|
||||
}
|
||||
|
||||
public Set<String> getApiParamKeys() {
|
||||
return apiParams.keySet();
|
||||
}
|
||||
|
||||
public Map<String, String> getApiParams() {
|
||||
return apiParams;
|
||||
}
|
||||
|
||||
public void setApiParams(Map<String, String> apiParams) {
|
||||
this.apiParams = apiParams;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IdentityServiceProviderDTO {
|
||||
private String name;
|
||||
private List<String> requiredApiParams;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getRequiredApiParams() {
|
||||
return requiredApiParams;
|
||||
}
|
||||
|
||||
public void setRequiredApiParams(List<String> requiredApiParams) {
|
||||
this.requiredApiParams = requiredApiParams;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Exception that will be thrown if any error occurs while calling identity server services .
|
||||
*/
|
||||
public class IdentityServerManagementException extends ApplicationManagementException {
|
||||
|
||||
public IdentityServerManagementException(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
setMessage(message);
|
||||
}
|
||||
|
||||
public IdentityServerManagementException(String message) {
|
||||
super(message);
|
||||
setMessage(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.common.services;
|
||||
|
||||
import io.entgra.application.mgt.common.IdentityServerResponse;
|
||||
import io.entgra.application.mgt.common.SPApplicationListResponse;
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.dto.IdentityServiceProviderDTO;
|
||||
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
|
||||
import io.entgra.application.mgt.common.exception.RequestValidatingException;
|
||||
import io.entgra.application.mgt.common.response.Application;
|
||||
import java.util.List;
|
||||
|
||||
public interface SPApplicationManager {
|
||||
|
||||
/**
|
||||
* Removes consumer application from service provider
|
||||
*
|
||||
* @param identityServerId of the service provider
|
||||
* @param spUID uid of the service provider
|
||||
* @param appIds List of application ids to be removed
|
||||
* @throws ApplicationManagementException if errors while removing appIds from service provider
|
||||
*/
|
||||
void detachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Maps consumer applications to service provider
|
||||
*
|
||||
* @param identityServerId of the service provider
|
||||
* @param spUID uid of the service provider
|
||||
* @param appIds List of application ids to be mapped
|
||||
* @throws ApplicationManagementException if errors while mapping appIds to service provider
|
||||
*/
|
||||
void attachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identityServerId of the identity server that is to be retrieved
|
||||
* @return Identity server for the given ID
|
||||
* @throws ApplicationManagementException if error occurred while getting identity server
|
||||
*/
|
||||
IdentityServerResponse getIdentityServerResponse(int identityServerId) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Available identity servers
|
||||
* @throws ApplicationManagementException if error occurred while getting identity servers
|
||||
*/
|
||||
List<IdentityServerResponse> getIdentityServers() throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Create a new Identity Server
|
||||
*
|
||||
* @return {@link IdentityServerResponse}
|
||||
* @throws ApplicationManagementException if error occurred while getting identity servers
|
||||
*/
|
||||
IdentityServerResponse createIdentityServer(IdentityServerDTO identityServerDTO) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Update existing Identity Server
|
||||
*
|
||||
* @param id of the identity server to be updated
|
||||
* @param updateIdentityServerDTO identity server dto bean with updated fields
|
||||
* @throws ApplicationManagementException if error occurred while getting identity servers
|
||||
*/
|
||||
IdentityServerResponse updateIdentityServer(IdentityServerDTO updateIdentityServerDTO, int id) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Delete Identity Server
|
||||
*
|
||||
* @param id of the identity server to be deleted
|
||||
* @throws ApplicationManagementException if error occurred while getting identity servers
|
||||
*/
|
||||
void deleteIdentityServer(int id) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Check if Identity Server exists with the same name
|
||||
*
|
||||
* @param name of the identity server
|
||||
* @return if name already exists for identity server
|
||||
*/
|
||||
boolean isIdentityServerNameExist(String name) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Check if Identity Server exists with the same url
|
||||
*
|
||||
* @param url of the identity server
|
||||
* @return if url already exists for identity server
|
||||
*/
|
||||
boolean isIdentityServerUrlExist(String url) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Retrieve service provider apps from identity server
|
||||
*
|
||||
* @param identityServerId Id of the identity server
|
||||
* @return {@link SPApplicationListResponse}
|
||||
* @throws ApplicationManagementException if error while retrieving sp applications
|
||||
*/
|
||||
SPApplicationListResponse retrieveSPApplicationFromIdentityServer(int identityServerId, Integer offset, Integer limit)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identityServerId of the service provider
|
||||
* @param spUID uid of the service provider
|
||||
* @return Applications that are mapped to given service provider uid and identity server id
|
||||
* @throws ApplicationManagementException
|
||||
*/
|
||||
List<Application> getSPApplications(int identityServerId, String spUID) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* This method is responsible for creating a new application and mapping it the given service provider uid
|
||||
* and identity server id
|
||||
*
|
||||
* @param app Application wrapper of the application that should be created
|
||||
* @param identityServerId id of the identity server to which the created application should be mapped
|
||||
* @param spId uid of the service provder to which the created application should be mapped
|
||||
* @param <T> Application wrapper class which depends on application type (PUBLIC, ENTERPRISE & etc)
|
||||
* @param isPublished If the app should be added in PUBLISHED state instead of initial state
|
||||
* @return Application bean of the created application
|
||||
* @throws ApplicationManagementException if errors while creating and mapping the application
|
||||
* @throws RequestValidatingException if app contains any invalid payload
|
||||
*/
|
||||
<T> Application createSPApplication(T app, int identityServerId, String spId, boolean isPublished) throws ApplicationManagementException, RequestValidatingException;
|
||||
|
||||
/**
|
||||
* Validates application ids of the applications that should be attached
|
||||
*
|
||||
* @param appIds application ids to be validated
|
||||
* @throws ApplicationManagementException if invalid service provider, identity server Id or app Ids provided
|
||||
*/
|
||||
void validateAttachAppsRequest(int identityServerId, String serviceProviderId, List<Integer> appIds) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Validates application ids of the applications that should be detached
|
||||
*
|
||||
* @param identityServerId id of identity server
|
||||
* @param spId uid of service provider from which applications should be detached
|
||||
* @param appIds applications ids to be detached
|
||||
* @throws ApplicationManagementException
|
||||
*/
|
||||
void validateDetachAppsRequest(int identityServerId, String spId, List<Integer> appIds) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Get available identity service providers
|
||||
*
|
||||
* @return list of available service providers' names
|
||||
*/
|
||||
List<IdentityServiceProviderDTO> getIdentityServiceProviders() throws ApplicationManagementException;
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "IdentityServiceProvider")
|
||||
public class IdentityServiceProvider {
|
||||
private String providerName;
|
||||
private String providerClassName;
|
||||
private String serviceProvidersPageUri;
|
||||
|
||||
@XmlElement(name = "ProviderName")
|
||||
public String getProviderName() {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ProviderClassName")
|
||||
public String getProviderClassName() {
|
||||
return providerClassName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ServiceProvidersPageUri")
|
||||
public String getServiceProvidersPageUri() {
|
||||
return serviceProvidersPageUri;
|
||||
}
|
||||
|
||||
public void setProviderName(String providerName) {
|
||||
this.providerName = providerName;
|
||||
}
|
||||
|
||||
public void setServiceProvidersPageUri(String serviceProvidersPageUri) {
|
||||
this.serviceProvidersPageUri = serviceProvidersPageUri;
|
||||
}
|
||||
|
||||
public void setProviderClassName(String providerClassName) {
|
||||
this.providerClassName = providerClassName;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the Application Management Configuration.
|
||||
*/
|
||||
@XmlRootElement(name = "IdentityServiceProviderConfiguration")
|
||||
public class IdentityServiceProviderConfiguration {
|
||||
|
||||
private List<IdentityServiceProvider> identityServiceProviders;
|
||||
|
||||
@XmlElementWrapper(name = "IdentityServiceProviders")
|
||||
@XmlElement(name = "IdentityServiceProvider")
|
||||
public List<IdentityServiceProvider> getIdentityServiceProviders() {
|
||||
return identityServiceProviders;
|
||||
}
|
||||
|
||||
public IdentityServiceProvider getIdentityServerDetailByProviderName(String identityServiceProviderName) {
|
||||
for (IdentityServiceProvider identityServiceProvider : identityServiceProviders) {
|
||||
if (identityServiceProvider.getProviderName().equals(identityServiceProviderName)) {
|
||||
return identityServiceProvider;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setIdentityServiceProviders(List<IdentityServiceProvider> identityServiceProviders) {
|
||||
this.identityServiceProviders = identityServiceProviders;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,130 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.dao;
|
||||
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.dto.ApplicationDTO;
|
||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SPApplicationDAO {
|
||||
|
||||
/**
|
||||
* Use to check if an identity server exists with the same name
|
||||
*
|
||||
* @param name name of the identity server
|
||||
* @return if identity server with the given name exists
|
||||
*/
|
||||
boolean isExistingIdentityServerName(String name, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* Use to check if an identity server exists with the same url
|
||||
*
|
||||
* @param url name of the identity server
|
||||
* @return if identity server with the given url exists
|
||||
*/
|
||||
boolean isExistingIdentityServerUrl(String url, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update existing identity server in the database
|
||||
*
|
||||
* @param updatedIdentityServerDTO bean with the updated fields of the identity server
|
||||
*/
|
||||
void updateIdentityServer(IdentityServerDTO updatedIdentityServerDTO, int tenantId, int identityServerId)
|
||||
throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* Create new identity server in the database
|
||||
*
|
||||
* @param identityServerDTO DTO bean with the details of identity server to be created
|
||||
* @return id of the newly created identity server
|
||||
*/
|
||||
int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identityServerId Id of identity server in which the service provider is in
|
||||
* @param spUID Service provider uid of which the applications to be retrieved
|
||||
* @return the service provider applications for the given service provider
|
||||
* @throws ApplicationManagementDAOException if any db error occurred
|
||||
*/
|
||||
List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identityServerId Id of identity server in which the service provider is in
|
||||
* @param spUID Id of the service provider to which the application should be mapped
|
||||
* @param appId Id of the application that should be mapped
|
||||
* @return Primary key of the new service provider and application mapping entry
|
||||
* @throws ApplicationManagementDAOException if any db error occurred
|
||||
*/
|
||||
int attachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identityServerId Id of identity server in which the service provider is in
|
||||
* @param spUID Id of the service provider from which the application should be removed
|
||||
* @param appId Id of the application that should be removed
|
||||
* @throws ApplicationManagementDAOException if any db error occurred
|
||||
*/
|
||||
void detachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return All available identity servers
|
||||
* @throws ApplicationManagementDAOException if any db error occurred
|
||||
*/
|
||||
List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id Id of the Identity Server to be retrieved
|
||||
* @return Identity Server of the given id
|
||||
* @throws ApplicationManagementDAOException if any db error occurred
|
||||
*/
|
||||
IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* Verify whether application exist for given identity server id, service provider id and application id.
|
||||
* Because if an application does not exist for those, it should not be mapped
|
||||
*
|
||||
* @param appId Id of the application.
|
||||
* @param identityServerId Id of the identity server.
|
||||
* @param spUID UID of the service provider.
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
boolean isSPApplicationExist(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete application from all service providers if exists. When an application is deleted from the database
|
||||
* it shoulbe be deleted from mapping table as well
|
||||
*
|
||||
* @param applicationId Id of the application to be deleted
|
||||
* @throws ApplicationManagementDAOException if any db error occurred
|
||||
*/
|
||||
void deleteApplicationFromServiceProviders(int applicationId, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete identity server from db
|
||||
*
|
||||
* @param id of the identity server to be deleted
|
||||
* @throws ApplicationManagementDAOException if any db error occurred
|
||||
*/
|
||||
void deleteIdentityServer(int id, int tenantId) throws ApplicationManagementDAOException;
|
||||
}
|
@ -0,0 +1,486 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.dao.impl.application.spapplication;
|
||||
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.dto.ApplicationDTO;
|
||||
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.application.mgt.core.dao.SPApplicationDAO;
|
||||
import io.entgra.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import io.entgra.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
|
||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||
import io.entgra.application.mgt.core.util.DAOUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
|
||||
public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPApplicationDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
|
||||
@Override
|
||||
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setInt(1, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved available identity servers" );
|
||||
}
|
||||
return DAOUtil.loadIdentityServers(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE TENANT_ID = ? AND "
|
||||
+ "ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, id);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved available identity servers" );
|
||||
}
|
||||
return DAOUtil.loadIdentityServer(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (UnexpectedServerErrorException e) {
|
||||
String msg = "Found more than one identity server for id: " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExistingIdentityServerName(String name, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID AS ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE "
|
||||
+ "LOWER(NAME) = LOWER(?) AND "
|
||||
+ "TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, name);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check if identity server name: " + name +
|
||||
" already exist";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check if identity server with the name " + name +
|
||||
" already exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExistingIdentityServerUrl(String url, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID AS ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE "
|
||||
+ "LOWER(URL) = LOWER(?) AND "
|
||||
+ "TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, url);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check if identity server url: " + url +
|
||||
" already exist";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check if identity server with the url " + url +
|
||||
" already exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIdentityServer(IdentityServerDTO updatedIdentityServerDTO, int tenantId, int identityServerId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "UPDATE AP_IDENTITY_SERVER " +
|
||||
"SET ";
|
||||
if (updatedIdentityServerDTO.getName() != null) {
|
||||
sql += "NAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUrl() != null) {
|
||||
sql += "URL = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getProviderName() != null) {
|
||||
sql += "PROVIDER_NAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUsername() != null) {
|
||||
sql += "USERNAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getPassword() != null) {
|
||||
sql += "PASSWORD = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getDescription() != null) {
|
||||
sql += "DESCRIPTION = ?, ";
|
||||
}
|
||||
sql += "API_PARAMS = ? " +
|
||||
"WHERE ID = ? AND TENANT_ID = ?";
|
||||
|
||||
try {
|
||||
int index = 1;
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
if (updatedIdentityServerDTO.getName() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getName());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUrl() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getUrl());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getProviderName() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getProviderName());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUsername() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getUsername());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getPassword() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getPassword());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getDescription() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getDescription());
|
||||
}
|
||||
stmt.setString(index++, updatedIdentityServerDTO.constructApiParamsJsonString());
|
||||
stmt.setInt(index++, identityServerId);
|
||||
stmt.setInt(index, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to update identity server.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when executing SQL to update identity server. Executed query: " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to create an identity server");
|
||||
}
|
||||
String sql = "INSERT INTO AP_IDENTITY_SERVER "
|
||||
+ "(PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, identityServerDTO.getProviderName());
|
||||
stmt.setString(2, identityServerDTO.getName());
|
||||
stmt.setString(3, identityServerDTO.getDescription());
|
||||
stmt.setString(4, identityServerDTO.getUrl());
|
||||
stmt.setString(5, identityServerDTO.constructApiParamsJsonString());
|
||||
stmt.setString(6, identityServerDTO.getUsername());
|
||||
stmt.setString(7, identityServerDTO.getPassword());
|
||||
stmt.setInt(8, tenantId);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while creating identity server ";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an identity server ";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting identity server applications from the database");
|
||||
}
|
||||
String sql = "SELECT "
|
||||
+ "AP_APP.ID AS APP_ID, "
|
||||
+ "AP_APP.NAME AS APP_NAME, "
|
||||
+ "AP_APP.DESCRIPTION AS APP_DESCRIPTION, "
|
||||
+ "AP_APP.TYPE AS APP_TYPE, "
|
||||
+ "AP_APP.STATUS AS APP_STATUS, "
|
||||
+ "AP_APP.SUB_TYPE AS APP_SUB_TYPE, "
|
||||
+ "AP_APP.CURRENCY AS APP_CURRENCY, "
|
||||
+ "AP_APP.RATING AS APP_RATING, "
|
||||
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
|
||||
+ "AP_APP_RELEASE.ID AS RELEASE_ID, "
|
||||
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
|
||||
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
|
||||
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, "
|
||||
+ "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, "
|
||||
+ "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, "
|
||||
+ "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, "
|
||||
+ "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, "
|
||||
+ "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, "
|
||||
+ "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, "
|
||||
+ "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, "
|
||||
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
|
||||
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
|
||||
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
|
||||
+ "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, "
|
||||
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
|
||||
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
|
||||
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
|
||||
+ "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT "
|
||||
+ "FROM AP_APP "
|
||||
+ "LEFT JOIN AP_APP_RELEASE ON "
|
||||
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND "
|
||||
+ "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
|
||||
+ "INNER JOIN AP_IS_SP_APP_MAPPING as SP_APPS on SP_APPS.AP_APP_ID = AP_APP.ID "
|
||||
+ "WHERE "
|
||||
+ "SP_APPS.SP_UID = ? "
|
||||
+ "AND SP_APPS.IS_ID = ? "
|
||||
+ "AND AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, identityServerId);
|
||||
stmt.setInt(3, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved basic details of the identity server applications");
|
||||
}
|
||||
return DAOUtil.loadApplications(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to get identity server applications for application release";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while getting identity server applications while executing query. Executed query: " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSPApplicationExist(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP_ID AS ID "
|
||||
+ "FROM AP_IS_SP_APP_MAPPING SP_MAPPING "
|
||||
+ "WHERE "
|
||||
+ "SP_UID = ? AND AP_APP_ID = ? "
|
||||
+ "AND IS_ID = ? AND "
|
||||
+ "TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check whether the existence of "
|
||||
+ "sp application with id " + appId + " for service provider which has UID " + spUID;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check whether the existence of service provider application " +
|
||||
"with id " + appId + " for service provider which has UID " + spUID + ". executed query " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to map an application wit identity server:service provider");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("App ID : " + appId + " SP UID : " + spUID + " IS ID : " + identityServerId);
|
||||
}
|
||||
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING "
|
||||
+ "WHERE SP_UID = ? "
|
||||
+ "AND AP_APP_ID = ? "
|
||||
+ "AND IS_ID = ? "
|
||||
+ "AND TENANT_ID = ? ";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int attachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to map an application wit identity server:service provider");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("App ID : " + appId + " SP UID : " + spUID + " IS ID : " + identityServerId);
|
||||
}
|
||||
String sql = "INSERT INTO AP_IS_SP_APP_MAPPING "
|
||||
+ "(SP_UID, "
|
||||
+ "AP_APP_ID, "
|
||||
+ "IS_ID, TENANT_ID) "
|
||||
+ "VALUES (?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteApplicationFromServiceProviders(int applicationId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to delete application with the id: " + applicationId + " from service providers");
|
||||
}
|
||||
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING WHERE AP_APP_ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setInt(1, applicationId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + applicationId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ applicationId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteIdentityServer(int id, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to delete identity server with the id: " + id);
|
||||
}
|
||||
String sql = "DELETE FROM AP_IDENTITY_SERVER WHERE ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setInt(1, id);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to delete an identity server with the id " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to delete an identity server which has the id "
|
||||
+ id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,487 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.dao.impl.application.spapplication;
|
||||
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.dto.ApplicationDTO;
|
||||
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.application.mgt.core.dao.SPApplicationDAO;
|
||||
import io.entgra.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||
import io.entgra.application.mgt.core.util.DAOUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
|
||||
public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPApplicationDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(OracleSPApplicationDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setInt(1, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved available identity servers" );
|
||||
}
|
||||
return DAOUtil.loadIdentityServers(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE TENANT_ID = ? AND "
|
||||
+ "ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, id);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved available identity servers" );
|
||||
}
|
||||
return DAOUtil.loadIdentityServer(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (UnexpectedServerErrorException e) {
|
||||
String msg = "Found more than one identity server for id: " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExistingIdentityServerUrl(String url, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP.ID AS ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE "
|
||||
+ "LOWER(URL) = LOWER(?) AND "
|
||||
+ "AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, url);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check if identity server url: " + url +
|
||||
" already exist";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check if identity server with the url " + url +
|
||||
" already exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExistingIdentityServerName(String name, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP.ID AS ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE "
|
||||
+ "LOWER(NAME) = LOWER(?) AND "
|
||||
+ "AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, name);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check if identity server name: " + name +
|
||||
" already exist";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check if identity server with the name " + name +
|
||||
" already exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIdentityServer(IdentityServerDTO updatedIdentityServerDTO, int tenantId, int identityServerId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "UPDATE AP_IDENTITY_SERVER " +
|
||||
"SET ";
|
||||
if (updatedIdentityServerDTO.getName() != null) {
|
||||
sql += "NAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUrl() != null) {
|
||||
sql += "URL = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getProviderName() != null) {
|
||||
sql += "PROVIDER_NAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUsername() != null) {
|
||||
sql += "USERNAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getPassword() != null) {
|
||||
sql += "PASSWORD = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getDescription() != null) {
|
||||
sql += "DESCRIPTION = ?, ";
|
||||
}
|
||||
sql += "API_PARAMS = ? " +
|
||||
"WHERE ID = ? AND TENANT_ID = ?";
|
||||
|
||||
try {
|
||||
int index = 1;
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
if (updatedIdentityServerDTO.getName() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getName());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUrl() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getUrl());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getProviderName() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getProviderName());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUsername() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getUsername());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getPassword() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getPassword());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getDescription() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getDescription());
|
||||
}
|
||||
stmt.setString(index++, updatedIdentityServerDTO.constructApiParamsJsonString());
|
||||
stmt.setInt(index++, identityServerId);
|
||||
stmt.setInt(index, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to update identity server.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when executing SQL to update identity server. Executed query: " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to create an identity server");
|
||||
}
|
||||
String sql = "INSERT INTO AP_IDENTITY_SERVER "
|
||||
+ "(PROVIDER_NAME, "
|
||||
+ "NAME, "
|
||||
+ "DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, identityServerDTO.getProviderName());
|
||||
stmt.setString(2, identityServerDTO.getName());
|
||||
stmt.setString(3, identityServerDTO.getDescription());
|
||||
stmt.setString(4, identityServerDTO.getUrl());
|
||||
stmt.setString(5, identityServerDTO.constructApiParamsJsonString());
|
||||
stmt.setString(6, identityServerDTO.getUsername());
|
||||
stmt.setString(7, identityServerDTO.getPassword());
|
||||
stmt.setInt(8, tenantId);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while creating identity server ";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an identity server ";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting identity server applications from the database");
|
||||
}
|
||||
String sql = "SELECT "
|
||||
+ "AP_APP.ID AS APP_ID, "
|
||||
+ "AP_APP.NAME AS APP_NAME, "
|
||||
+ "AP_APP.DESCRIPTION AS APP_DESCRIPTION, "
|
||||
+ "AP_APP.TYPE AS APP_TYPE, "
|
||||
+ "AP_APP.STATUS AS APP_STATUS, "
|
||||
+ "AP_APP.SUB_TYPE AS APP_SUB_TYPE, "
|
||||
+ "AP_APP.CURRENCY AS APP_CURRENCY, "
|
||||
+ "AP_APP.RATING AS APP_RATING, "
|
||||
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
|
||||
+ "AP_APP_RELEASE.ID AS RELEASE_ID, "
|
||||
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
|
||||
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
|
||||
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, "
|
||||
+ "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, "
|
||||
+ "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, "
|
||||
+ "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, "
|
||||
+ "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, "
|
||||
+ "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, "
|
||||
+ "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, "
|
||||
+ "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, "
|
||||
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
|
||||
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
|
||||
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
|
||||
+ "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, "
|
||||
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
|
||||
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
|
||||
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
|
||||
+ "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT "
|
||||
+ "FROM AP_APP "
|
||||
+ "LEFT JOIN AP_APP_RELEASE ON "
|
||||
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND "
|
||||
+ "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
|
||||
+ "INNER JOIN AP_IS_SP_APP_MAPPING as SP_APPS on SP_APPS.AP_APP_ID = AP_APP.ID "
|
||||
+ "WHERE "
|
||||
+ "SP_APPS.SP_UID = ? "
|
||||
+ "AND SP_APPS.IS_ID = ? "
|
||||
+ "AND AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, identityServerId);
|
||||
stmt.setInt(3, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved basic details of the identity server applications");
|
||||
}
|
||||
return DAOUtil.loadApplications(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to get identity server applications for application release";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while getting identity server applications while executing query. Executed query: " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSPApplicationExist(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP_ID AS ID "
|
||||
+ "FROM AP_IS_SP_APP_MAPPING SP_MAPPING "
|
||||
+ "WHERE "
|
||||
+ "SP_UID = ? AND AP_APP_ID = ? "
|
||||
+ "AND IS_ID = ? AND "
|
||||
+ "TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check whether the existence of "
|
||||
+ "sp application with id " + appId + " for service provider which has UID " + spUID;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check whether the existence of service provider application " +
|
||||
"with id " + appId + " for service provider which has UID " + spUID + ". executed query " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to map an application wit identity server:service provider");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("App ID : " + appId + " SP UID : " + spUID + " IS ID : " + identityServerId);
|
||||
}
|
||||
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING "
|
||||
+ "WHERE SP_UID = ? "
|
||||
+ "AND AP_APP_ID = ? "
|
||||
+ "AND IS_ID = ? "
|
||||
+ "AND TENANT_ID = ? ";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int attachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to map an application wit identity server:service provider");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("App ID : " + appId + " SP UID : " + spUID + " IS ID : " + identityServerId);
|
||||
}
|
||||
String sql = "INSERT INTO AP_IS_SP_APP_MAPPING "
|
||||
+ "(SP_UID, "
|
||||
+ "AP_APP_ID, "
|
||||
+ "IS_ID, TENANT_ID) "
|
||||
+ "VALUES (?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteApplicationFromServiceProviders(int applicationId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to delete application with the id: " + applicationId + " from service providers");
|
||||
}
|
||||
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING WHERE AP_APP_ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setInt(1, applicationId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + applicationId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ applicationId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteIdentityServer(int id, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to delete identity server with the id: " + id);
|
||||
}
|
||||
String sql = "DELETE FROM AP_IDENTITY_SERVER WHERE ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setInt(1, id);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to delete an identity server with the id " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to delete an identity server which has the id "
|
||||
+ id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,487 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.dao.impl.application.spapplication;
|
||||
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.dto.ApplicationDTO;
|
||||
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.application.mgt.core.dao.SPApplicationDAO;
|
||||
import io.entgra.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||
import io.entgra.application.mgt.core.util.DAOUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
|
||||
public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements SPApplicationDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PostgreSQLSPApplicationDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setInt(1, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved available identity servers" );
|
||||
}
|
||||
return DAOUtil.loadIdentityServers(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE TENANT_ID = ? AND "
|
||||
+ "ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, id);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved available identity servers" );
|
||||
}
|
||||
return DAOUtil.loadIdentityServer(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (UnexpectedServerErrorException e) {
|
||||
String msg = "Found more than one identity server for id: " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExistingIdentityServerUrl(String url, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP.ID AS ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE "
|
||||
+ "LOWER(URL) = LOWER(?) AND "
|
||||
+ "AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, url);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check if identity server url: " + url +
|
||||
" already exist";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check if identity server with the url " + url +
|
||||
" already exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExistingIdentityServerName(String name, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP.ID AS ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE "
|
||||
+ "LOWER(NAME) = LOWER(?) AND "
|
||||
+ "AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, name);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check if identity server name: " + name +
|
||||
" already exist";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check if identity server with the name " + name +
|
||||
" already exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIdentityServer(IdentityServerDTO updatedIdentityServerDTO, int tenantId, int identityServerId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "UPDATE AP_IDENTITY_SERVER " +
|
||||
"SET ";
|
||||
if (updatedIdentityServerDTO.getName() != null) {
|
||||
sql += "NAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUrl() != null) {
|
||||
sql += "URL = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getProviderName() != null) {
|
||||
sql += "PROVIDER_NAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUsername() != null) {
|
||||
sql += "USERNAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getPassword() != null) {
|
||||
sql += "PASSWORD = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getDescription() != null) {
|
||||
sql += "DESCRIPTION = ?, ";
|
||||
}
|
||||
sql += "API_PARAMS = ? " +
|
||||
"WHERE ID = ? AND TENANT_ID = ?";
|
||||
|
||||
try {
|
||||
int index = 1;
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
if (updatedIdentityServerDTO.getName() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getName());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUrl() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getUrl());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getProviderName() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getProviderName());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUsername() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getUsername());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getPassword() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getPassword());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getDescription() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getDescription());
|
||||
}
|
||||
stmt.setString(index++, updatedIdentityServerDTO.constructApiParamsJsonString());
|
||||
stmt.setInt(index++, identityServerId);
|
||||
stmt.setInt(index, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to update identity server.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when executing SQL to update identity server. Executed query: " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to create an identity server");
|
||||
}
|
||||
String sql = "INSERT INTO AP_IDENTITY_SERVER "
|
||||
+ "(PROVIDER_NAME, "
|
||||
+ "NAME, "
|
||||
+ "DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, identityServerDTO.getProviderName());
|
||||
stmt.setString(2, identityServerDTO.getName());
|
||||
stmt.setString(3, identityServerDTO.getDescription());
|
||||
stmt.setString(4, identityServerDTO.getUrl());
|
||||
stmt.setString(5, identityServerDTO.constructApiParamsJsonString());
|
||||
stmt.setString(6, identityServerDTO.getUsername());
|
||||
stmt.setString(7, identityServerDTO.getPassword());
|
||||
stmt.setInt(8, tenantId);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while creating identity server ";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an identity server ";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting identity server applications from the database");
|
||||
}
|
||||
String sql = "SELECT "
|
||||
+ "AP_APP.ID AS APP_ID, "
|
||||
+ "AP_APP.NAME AS APP_NAME, "
|
||||
+ "AP_APP.DESCRIPTION AS APP_DESCRIPTION, "
|
||||
+ "AP_APP.TYPE AS APP_TYPE, "
|
||||
+ "AP_APP.STATUS AS APP_STATUS, "
|
||||
+ "AP_APP.SUB_TYPE AS APP_SUB_TYPE, "
|
||||
+ "AP_APP.CURRENCY AS APP_CURRENCY, "
|
||||
+ "AP_APP.RATING AS APP_RATING, "
|
||||
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
|
||||
+ "AP_APP_RELEASE.ID AS RELEASE_ID, "
|
||||
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
|
||||
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
|
||||
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, "
|
||||
+ "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, "
|
||||
+ "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, "
|
||||
+ "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, "
|
||||
+ "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, "
|
||||
+ "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, "
|
||||
+ "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, "
|
||||
+ "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, "
|
||||
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
|
||||
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
|
||||
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
|
||||
+ "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, "
|
||||
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
|
||||
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
|
||||
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
|
||||
+ "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT "
|
||||
+ "FROM AP_APP "
|
||||
+ "LEFT JOIN AP_APP_RELEASE ON "
|
||||
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND "
|
||||
+ "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
|
||||
+ "INNER JOIN AP_IS_SP_APP_MAPPING as SP_APPS on SP_APPS.AP_APP_ID = AP_APP.ID "
|
||||
+ "WHERE "
|
||||
+ "SP_APPS.SP_UID = ? "
|
||||
+ "AND SP_APPS.IS_ID = ? "
|
||||
+ "AND AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, identityServerId);
|
||||
stmt.setInt(3, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved basic details of the identity server applications");
|
||||
}
|
||||
return DAOUtil.loadApplications(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to get identity server applications for application release";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while getting identity server applications while executing query. Executed query: " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSPApplicationExist(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP_ID AS ID "
|
||||
+ "FROM AP_IS_SP_APP_MAPPING SP_MAPPING "
|
||||
+ "WHERE "
|
||||
+ "SP_UID = ? AND AP_APP_ID = ? "
|
||||
+ "AND IS_ID = ? AND "
|
||||
+ "TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check whether the existence of "
|
||||
+ "sp application with id " + appId + " for service provider which has UID " + spUID;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check whether the existence of service provider application " +
|
||||
"with id " + appId + " for service provider which has UID " + spUID + ". executed query " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to map an application wit identity server:service provider");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("App ID : " + appId + " SP UID : " + spUID + " IS ID : " + identityServerId);
|
||||
}
|
||||
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING "
|
||||
+ "WHERE SP_UID = ? "
|
||||
+ "AND AP_APP_ID = ? "
|
||||
+ "AND IS_ID = ? "
|
||||
+ "AND TENANT_ID = ? ";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int attachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to map an application wit identity server:service provider");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("App ID : " + appId + " SP UID : " + spUID + " IS ID : " + identityServerId);
|
||||
}
|
||||
String sql = "INSERT INTO AP_IS_SP_APP_MAPPING "
|
||||
+ "(SP_UID, "
|
||||
+ "AP_APP_ID, "
|
||||
+ "IS_ID, TENANT_ID) "
|
||||
+ "VALUES (?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteApplicationFromServiceProviders(int applicationId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to delete application with the id: " + applicationId + " from service providers");
|
||||
}
|
||||
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING WHERE AP_APP_ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setInt(1, applicationId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + applicationId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ applicationId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteIdentityServer(int id, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to delete identity server with the id: " + id);
|
||||
}
|
||||
String sql = "DELETE FROM AP_IDENTITY_SERVER WHERE ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setInt(1, id);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to delete an identity server with the id " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to delete an identity server which has the id "
|
||||
+ id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,487 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.dao.impl.application.spapplication;
|
||||
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.dto.ApplicationDTO;
|
||||
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.application.mgt.core.dao.SPApplicationDAO;
|
||||
import io.entgra.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||
import io.entgra.application.mgt.core.util.DAOUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements SPApplicationDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SQLServerSPApplicationDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setInt(1, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved available identity servers" );
|
||||
}
|
||||
return DAOUtil.loadIdentityServers(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE TENANT_ID = ? AND "
|
||||
+ "ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, id);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved available identity servers" );
|
||||
}
|
||||
return DAOUtil.loadIdentityServer(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to retrieve available identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (UnexpectedServerErrorException e) {
|
||||
String msg = "Found more than one identity server for id: " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExistingIdentityServerUrl(String url, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP.ID AS ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE "
|
||||
+ "LOWER(URL) = LOWER(?) AND "
|
||||
+ "AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, url);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check if identity server url: " + url +
|
||||
" already exist";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check if identity server with the url " + url +
|
||||
" already exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExistingIdentityServerName(String name, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP.ID AS ID "
|
||||
+ "FROM AP_IDENTITY_SERVER "
|
||||
+ "WHERE "
|
||||
+ "LOWER(NAME) = LOWER(?) AND "
|
||||
+ "AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, name);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check if identity server name: " + name +
|
||||
" already exist";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check if identity server with the name " + name +
|
||||
" already exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIdentityServer(IdentityServerDTO updatedIdentityServerDTO, int tenantId, int identityServerId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "UPDATE AP_IDENTITY_SERVER " +
|
||||
"SET ";
|
||||
if (updatedIdentityServerDTO.getName() != null) {
|
||||
sql += "NAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUrl() != null) {
|
||||
sql += "URL = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getProviderName() != null) {
|
||||
sql += "PROVIDER_NAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUsername() != null) {
|
||||
sql += "USERNAME = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getPassword() != null) {
|
||||
sql += "PASSWORD = ?, ";
|
||||
}
|
||||
if (updatedIdentityServerDTO.getDescription() != null) {
|
||||
sql += "DESCRIPTION = ?, ";
|
||||
}
|
||||
sql += "API_PARAMS = ? " +
|
||||
"WHERE ID = ? AND TENANT_ID = ?";
|
||||
|
||||
try {
|
||||
int index = 1;
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
if (updatedIdentityServerDTO.getName() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getName());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUrl() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getUrl());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getProviderName() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getProviderName());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getUsername() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getUsername());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getPassword() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getPassword());
|
||||
}
|
||||
if (updatedIdentityServerDTO.getDescription() != null) {
|
||||
stmt.setString(index++, updatedIdentityServerDTO.getDescription());
|
||||
}
|
||||
stmt.setString(index++, updatedIdentityServerDTO.constructApiParamsJsonString());
|
||||
stmt.setInt(index++, identityServerId);
|
||||
stmt.setInt(index, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to update identity server.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when executing SQL to update identity server. Executed query: " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to create an identity server");
|
||||
}
|
||||
String sql = "INSERT INTO AP_IDENTITY_SERVER "
|
||||
+ "(PROVIDER_NAME, "
|
||||
+ "NAME, "
|
||||
+ "DESCRIPTION, URL, API_PARAMS, USERNAME, PASSWORD, TENANT_ID) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, identityServerDTO.getProviderName());
|
||||
stmt.setString(2, identityServerDTO.getName());
|
||||
stmt.setString(3, identityServerDTO.getDescription());
|
||||
stmt.setString(4, identityServerDTO.getUrl());
|
||||
stmt.setString(5, identityServerDTO.constructApiParamsJsonString());
|
||||
stmt.setString(6, identityServerDTO.getUsername());
|
||||
stmt.setString(7, identityServerDTO.getPassword());
|
||||
stmt.setInt(8, tenantId);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while creating identity server ";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an identity server ";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting identity server applications from the database");
|
||||
}
|
||||
String sql = "SELECT "
|
||||
+ "AP_APP.ID AS APP_ID, "
|
||||
+ "AP_APP.NAME AS APP_NAME, "
|
||||
+ "AP_APP.DESCRIPTION AS APP_DESCRIPTION, "
|
||||
+ "AP_APP.TYPE AS APP_TYPE, "
|
||||
+ "AP_APP.STATUS AS APP_STATUS, "
|
||||
+ "AP_APP.SUB_TYPE AS APP_SUB_TYPE, "
|
||||
+ "AP_APP.CURRENCY AS APP_CURRENCY, "
|
||||
+ "AP_APP.RATING AS APP_RATING, "
|
||||
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
|
||||
+ "AP_APP_RELEASE.ID AS RELEASE_ID, "
|
||||
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
|
||||
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
|
||||
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, "
|
||||
+ "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, "
|
||||
+ "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, "
|
||||
+ "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, "
|
||||
+ "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, "
|
||||
+ "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, "
|
||||
+ "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, "
|
||||
+ "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, "
|
||||
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
|
||||
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
|
||||
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
|
||||
+ "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, "
|
||||
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
|
||||
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
|
||||
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
|
||||
+ "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT "
|
||||
+ "FROM AP_APP "
|
||||
+ "LEFT JOIN AP_APP_RELEASE ON "
|
||||
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND "
|
||||
+ "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
|
||||
+ "INNER JOIN AP_IS_SP_APP_MAPPING as SP_APPS on SP_APPS.AP_APP_ID = AP_APP.ID "
|
||||
+ "WHERE "
|
||||
+ "SP_APPS.SP_UID = ? "
|
||||
+ "AND SP_APPS.IS_ID = ? "
|
||||
+ "AND AP_APP.TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, identityServerId);
|
||||
stmt.setInt(3, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Successfully retrieved basic details of the identity server applications");
|
||||
}
|
||||
return DAOUtil.loadApplications(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to get identity server applications for application release";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while getting identity server applications while executing query. Executed query: " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSPApplicationExist(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT AP_APP_ID AS ID "
|
||||
+ "FROM AP_IS_SP_APP_MAPPING SP_MAPPING "
|
||||
+ "WHERE "
|
||||
+ "SP_UID = ? AND AP_APP_ID = ? "
|
||||
+ "AND IS_ID = ? AND "
|
||||
+ "TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)){
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()){
|
||||
return rs.next();
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to check whether the existence of "
|
||||
+ "sp application with id " + appId + " for service provider which has UID " + spUID;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to check whether the existence of service provider application " +
|
||||
"with id " + appId + " for service provider which has UID " + spUID + ". executed query " + sql;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to map an application wit identity server:service provider");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("App ID : " + appId + " SP UID : " + spUID + " IS ID : " + identityServerId);
|
||||
}
|
||||
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING "
|
||||
+ "WHERE SP_UID = ? "
|
||||
+ "AND AP_APP_ID = ? "
|
||||
+ "AND IS_ID = ? "
|
||||
+ "AND TENANT_ID = ? ";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int attachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to map an application wit identity server:service provider");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("App ID : " + appId + " SP UID : " + spUID + " IS ID : " + identityServerId);
|
||||
}
|
||||
String sql = "INSERT INTO AP_IS_SP_APP_MAPPING "
|
||||
+ "(SP_UID, "
|
||||
+ "AP_APP_ID, "
|
||||
+ "IS_ID, TENANT_ID) "
|
||||
+ "VALUES (?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, spUID);
|
||||
stmt.setInt(2, appId);
|
||||
stmt.setInt(3, identityServerId);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to create an sp application mapping which has "
|
||||
+ "application id " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to create an application which has application id "
|
||||
+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteApplicationFromServiceProviders(int applicationId, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to delete application with the id: " + applicationId + " from service providers");
|
||||
}
|
||||
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING WHERE AP_APP_ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setInt(1, applicationId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to delete an sp application mapping which has "
|
||||
+ "application id " + applicationId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to delete an application which has application id "
|
||||
+ applicationId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteIdentityServer(int id, int tenantId) throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to delete identity server with the id: " + id);
|
||||
}
|
||||
String sql = "DELETE FROM AP_IDENTITY_SERVER WHERE ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setInt(1, id);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining the DB connection to delete an identity server with the id " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing SQL to delete an identity server which has the id "
|
||||
+ id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.identityserver.serviceprovider;
|
||||
|
||||
import io.entgra.application.mgt.common.SPApplication;
|
||||
import io.entgra.application.mgt.common.SPApplicationListResponse;
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
|
||||
import io.entgra.application.mgt.common.exception.InvalidConfigurationException;
|
||||
import io.entgra.application.mgt.core.config.ConfigurationManager;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.List;
|
||||
|
||||
public interface ISServiceProviderApplicationService {
|
||||
|
||||
Log log = LogFactory.getLog(ISServiceProviderApplicationService.class);
|
||||
|
||||
static ISServiceProviderApplicationService of(String identityServerName) throws InvalidConfigurationException {
|
||||
String className = ConfigurationManager.getInstance().getIdentityServerConfiguration().
|
||||
getIdentityServerDetailByProviderName(identityServerName).getProviderClassName();
|
||||
try {
|
||||
Class theClass = Class.forName(className);
|
||||
Constructor<ISServiceProviderApplicationService> constructor = theClass.getConstructor();
|
||||
return constructor.newInstance();
|
||||
} catch (Exception e) {
|
||||
String msg = "Unable to get instance of " + className;
|
||||
log.error(msg, e);
|
||||
throw new InvalidConfigurationException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to get IS Service specific api params
|
||||
*
|
||||
* @return IS Service specific api params
|
||||
*/
|
||||
List<String> getRequiredApiParams();
|
||||
|
||||
/**
|
||||
* Check if service provider application exists
|
||||
*
|
||||
* @param identityServer {@link IdentityServerDTO}
|
||||
* @param spAppId uid of the service provider
|
||||
* @return if service provider exist
|
||||
* @throws ApplicationManagementException
|
||||
*/
|
||||
boolean isSPApplicationExist(IdentityServerDTO identityServer, String spAppId) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Get service provider by identity server id and service provider uid
|
||||
* @param identityServer {@link IdentityServerDTO}
|
||||
* @param spAppId uid of service provider to be retrieved
|
||||
* @return {@link SPApplication}
|
||||
* @throws ApplicationManagementException
|
||||
*/
|
||||
SPApplication retrieveSPApplication(IdentityServerDTO identityServer, String spAppId) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Retrieve service provider apps from identity server
|
||||
*
|
||||
* @param identityServer {@link IdentityServerDTO}
|
||||
* @return {@link SPApplicationListResponse}
|
||||
* @throws ApplicationManagementException
|
||||
*/
|
||||
SPApplicationListResponse retrieveSPApplications(IdentityServerDTO identityServer, Integer limit, Integer offset)
|
||||
throws ApplicationManagementException;
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.identityserver.serviceprovider.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.entgra.application.mgt.common.SPApplication;
|
||||
import io.entgra.application.mgt.common.SPApplicationListResponse;
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
|
||||
import io.entgra.application.mgt.common.exception.IdentityServerManagementException;
|
||||
import io.entgra.application.mgt.core.identityserver.serviceprovider.ISServiceProviderApplicationService;
|
||||
import io.entgra.application.mgt.core.util.Constants;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.wso2.carbon.device.mgt.core.common.util.HttpUtil;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class WSO2IAMSPApplicationService implements ISServiceProviderApplicationService {
|
||||
|
||||
private static final List<String> REQUIRED_API_PARAM_LIST;
|
||||
private static final String TENANT_DOMAIN = "Tenant domain";
|
||||
private static final String SP_APPLICATION_API_CONTEXT = "/t/%s/api/server/v1/applications";
|
||||
private static final Log log = LogFactory.getLog(WSO2IAMSPApplicationService.class);
|
||||
|
||||
static {
|
||||
REQUIRED_API_PARAM_LIST = Collections.singletonList(TENANT_DOMAIN);
|
||||
}
|
||||
|
||||
public List<String> getRequiredApiParams() {
|
||||
return REQUIRED_API_PARAM_LIST;
|
||||
}
|
||||
|
||||
public boolean isSPApplicationExist(IdentityServerDTO identityServer, String spAppId) throws ApplicationManagementException {
|
||||
SPApplication application = retrieveSPApplication(identityServer, spAppId);
|
||||
return application != null;
|
||||
}
|
||||
|
||||
public SPApplication retrieveSPApplication(IdentityServerDTO identityServer, String spAppId) throws ApplicationManagementException {
|
||||
HttpGet req = new HttpGet();
|
||||
String uriString = constructAPIUrl(identityServer);
|
||||
uriString += Constants.FORWARD_SLASH + spAppId;
|
||||
req.setURI(HttpUtil.createURI(uriString));
|
||||
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
||||
HttpResponse response = invokeISAPI(identityServer, client, req);
|
||||
String responseBody = HttpUtil.getResponseString(response);
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
return new Gson().fromJson(responseBody,
|
||||
SPApplication.class);
|
||||
}
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
|
||||
return null;
|
||||
}
|
||||
String msg = constructErrorMessage(response);
|
||||
log.error(msg);
|
||||
throw new IdentityServerManagementException(msg);
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while calling SP Applications API. Make sure identity server is up and running";
|
||||
log.error(msg, e);
|
||||
throw new IdentityServerManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct error message string depending on service providers api response
|
||||
* (I.E If unauthorized a different message will be returned)
|
||||
*
|
||||
* @param response of the service provider api call
|
||||
* @return constructed error message
|
||||
*/
|
||||
private String constructErrorMessage(HttpResponse response) {
|
||||
String msg = "Error occurred while calling SP Applications API";
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
|
||||
msg += ". Make sure provided identity Server credentials are valid";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public SPApplicationListResponse retrieveSPApplications(IdentityServerDTO identityServer, Integer limit, Integer offset)
|
||||
throws ApplicationManagementException {
|
||||
HttpGet req = new HttpGet();
|
||||
String uriString = constructAPIUrl(identityServer);
|
||||
uriString += Constants.URI_QUERY_SEPARATOR + Constants.LIMIT_QUERY_PARAM + Constants.QUERY_KEY_VALUE_SEPARATOR
|
||||
+ limit;
|
||||
uriString += Constants.QUERY_STRING_SEPARATOR + Constants.OFFSET_QUERY_PARAM + Constants.QUERY_KEY_VALUE_SEPARATOR
|
||||
+ offset;
|
||||
req.setURI(HttpUtil.createURI(uriString));
|
||||
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
||||
HttpResponse response = invokeISAPI(identityServer, client, req);
|
||||
String responseBody = HttpUtil.getResponseString(response);
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
return new Gson().fromJson(responseBody,
|
||||
SPApplicationListResponse.class);
|
||||
}
|
||||
String msg = constructErrorMessage(response);
|
||||
log.error(msg);
|
||||
throw new IdentityServerManagementException(msg);
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while calling SP Applications API. Make sure identity server is up and running";
|
||||
log.error(msg, e);
|
||||
throw new IdentityServerManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes essential prerequisite steps (I.E setting authorization header),
|
||||
* invokes provided GET request and returns the response
|
||||
*
|
||||
* @param identityServer {@link IdentityServerDTO}
|
||||
* @param client httpClient that should be used to invoke
|
||||
* @param request GET request to be invoked
|
||||
* @return response of the invoked api
|
||||
*/
|
||||
private HttpResponse invokeISAPI(IdentityServerDTO identityServer, HttpClient client, HttpGet request) throws IOException {
|
||||
setBasicAuthHeader(identityServer, request);
|
||||
return client.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add basic auth header to provided service provider api request by getting the username and password
|
||||
* from identity server bean
|
||||
*
|
||||
* @param identityServer {@link IdentityServerDTO}
|
||||
* @param request service provider api request
|
||||
*/
|
||||
private void setBasicAuthHeader(IdentityServerDTO identityServer, HttpRequestBase request) {
|
||||
String basicAuthHeader = HttpUtil.getBasicAuthBase64Header(identityServer.getUsername(),
|
||||
identityServer.getPassword());
|
||||
request.setHeader(HttpHeaders.AUTHORIZATION, basicAuthHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helps to construct service provider api base url
|
||||
*
|
||||
* @param identityServer {@link IdentityServerDTO}
|
||||
* @return constructed service providers api url
|
||||
*/
|
||||
private String constructAPIUrl(IdentityServerDTO identityServer) {
|
||||
String identityServerUrl = identityServer.getUrl();
|
||||
// add "/" at the end, if the server url doesn't contain "/" at the end
|
||||
if (identityServerUrl.charAt(identityServerUrl.length() - 1) != Constants.FORWARD_SLASH.charAt(0)) {
|
||||
identityServerUrl += Constants.FORWARD_SLASH;
|
||||
}
|
||||
return identityServerUrl + String.format(SP_APPLICATION_API_CONTEXT, identityServer.getApiParams().get(TENANT_DOMAIN));
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,699 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.core.impl;
|
||||
|
||||
import io.entgra.application.mgt.common.IdentityServerResponse;
|
||||
import io.entgra.application.mgt.common.SPApplicationListResponse;
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.SPApplication;
|
||||
import io.entgra.application.mgt.common.dto.ApplicationDTO;
|
||||
import io.entgra.application.mgt.common.dto.IdentityServiceProviderDTO;
|
||||
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
|
||||
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.application.mgt.common.exception.TransactionManagementException;
|
||||
import io.entgra.application.mgt.common.response.Application;
|
||||
import io.entgra.application.mgt.common.services.ApplicationManager;
|
||||
import io.entgra.application.mgt.common.services.SPApplicationManager;
|
||||
import io.entgra.application.mgt.core.config.ConfigurationManager;
|
||||
import io.entgra.application.mgt.core.config.IdentityServiceProvider;
|
||||
import io.entgra.application.mgt.core.dao.ApplicationDAO;
|
||||
import io.entgra.application.mgt.core.dao.SPApplicationDAO;
|
||||
import io.entgra.application.mgt.core.dao.VisibilityDAO;
|
||||
import io.entgra.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.application.mgt.core.exception.BadRequestException;
|
||||
import io.entgra.application.mgt.core.exception.NotFoundException;
|
||||
import io.entgra.application.mgt.core.identityserver.serviceprovider.ISServiceProviderApplicationService;
|
||||
import io.entgra.application.mgt.core.internal.DataHolder;
|
||||
import io.entgra.application.mgt.core.lifecycle.LifecycleStateManager;
|
||||
import io.entgra.application.mgt.core.util.APIUtil;
|
||||
import io.entgra.application.mgt.core.util.ApplicationManagementUtil;
|
||||
import io.entgra.application.mgt.core.util.ConnectionManagerUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.validator.routines.UrlValidator;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SPApplicationManagerImpl implements SPApplicationManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SPApplicationManagerImpl.class);
|
||||
private ApplicationDAO applicationDAO;
|
||||
private SPApplicationDAO spApplicationDAO;
|
||||
private VisibilityDAO visibilityDAO;
|
||||
private final LifecycleStateManager lifecycleStateManager;
|
||||
|
||||
public SPApplicationManagerImpl() {
|
||||
initDataAccessObjects();
|
||||
lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
|
||||
}
|
||||
|
||||
private void initDataAccessObjects() {
|
||||
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
||||
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
|
||||
this.spApplicationDAO = ApplicationManagementDAOFactory.getSPApplicationDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityServerResponse getIdentityServerResponse(int identityServerId) throws ApplicationManagementException {
|
||||
IdentityServerDTO identityServerDTO = getIdentityServer(identityServerId);
|
||||
return APIUtil.identityServerDtoToIdentityServerResponse(identityServerDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is similar to getIdentityServerFromDB method except throws {@link NotFoundException} if identity server
|
||||
* does not exist for the given id
|
||||
*
|
||||
* @param identityServerId id of identity server
|
||||
* @return {@link IdentityServerDTO}
|
||||
*/
|
||||
private IdentityServerDTO getIdentityServer(int identityServerId) throws ApplicationManagementException {
|
||||
IdentityServerDTO identityServerDTO = getIdentityServerFromDB(identityServerId);
|
||||
if (identityServerDTO == null) {
|
||||
String msg = "Identity server with the id: " + identityServerId + " does not exist";
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
return identityServerDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to get {@link IdentityServerDTO} bean from database. Returns null if does not exist
|
||||
*
|
||||
* @param identityServerId id of identity server
|
||||
* @return {@link IdentityServerDTO}
|
||||
*/
|
||||
private IdentityServerDTO getIdentityServerFromDB(int identityServerId) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return spApplicationDAO.getIdentityServerById(identityServerId, tenantId);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred when getting database connection to get identity server with the id: " + identityServerId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg =
|
||||
"DAO exception while getting identity server with the id " + identityServerId ;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IdentityServerResponse> getIdentityServers() throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return spApplicationDAO.getIdentityServers(tenantId).stream().
|
||||
map(APIUtil::identityServerDtoToIdentityServerResponse).collect(Collectors.toList());
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred when getting database connection to get identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg =
|
||||
"DAO exception while getting identity servers";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityServerResponse createIdentityServer(IdentityServerDTO identityServerDTO) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
validateIdentityServerCreateRequest(identityServerDTO);
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
int id = spApplicationDAO.createIdentityServer(identityServerDTO, tenantId);
|
||||
identityServerDTO.setId(id);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return APIUtil.identityServerDtoToIdentityServerResponse(identityServerDTO);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while creating identity server " + identityServerDTO.getName();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityServerResponse updateIdentityServer(IdentityServerDTO updateIdentityServerDTO, int id)
|
||||
throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
IdentityServerDTO existingIdentityServerDTO = getIdentityServer(id);
|
||||
validateIdentityServerUpdateRequest(updateIdentityServerDTO, existingIdentityServerDTO);
|
||||
Map<String, String> updatedApiParams = constructUpdatedApiParams(updateIdentityServerDTO, existingIdentityServerDTO);
|
||||
updateIdentityServerDTO.setApiParams(updatedApiParams);
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
spApplicationDAO.updateIdentityServer(updateIdentityServerDTO, tenantId, id);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while creating identity server " + updateIdentityServerDTO.getName();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
return getIdentityServerResponse(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteIdentityServer(int id) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
validateIdentityServerDeleteRequest(id);
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
spApplicationDAO.deleteIdentityServer(id, tenantId);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while creating identity server with the id " + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the identity server delete request
|
||||
*
|
||||
* @param identityServerId identity server id
|
||||
* @throws BadRequestException if provided identity server id is invalid
|
||||
*/
|
||||
private void validateIdentityServerDeleteRequest(int identityServerId) throws ApplicationManagementException {
|
||||
IdentityServerDTO identityServerDTO = getIdentityServerFromDB(identityServerId);
|
||||
if (identityServerDTO == null) {
|
||||
String msg = "Identity server with the id: " + identityServerId + " does not exist to delete";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is useful to re-construct the api params Map using updated identity server bean {@link IdentityServerDTO}
|
||||
* For example updated identity server bean may contain only updated api param, in which case the existing api param values
|
||||
* should be re-added to updated identity server bean
|
||||
*
|
||||
* @param updatedIdentityServerDTO updated identity server request payload
|
||||
* @param existingIdentityServerDTO corresponding existing identity server of updated identity server
|
||||
* @return Constructed api param map
|
||||
*/
|
||||
private Map<String, String> constructUpdatedApiParams(IdentityServerDTO updatedIdentityServerDTO,
|
||||
IdentityServerDTO existingIdentityServerDTO) {
|
||||
Map<String, String> updatedApiParams = updatedIdentityServerDTO.getApiParams();
|
||||
Map<String, String> existingApiParams = existingIdentityServerDTO.getApiParams();
|
||||
if (updatedIdentityServerDTO.getProviderName().equals(existingIdentityServerDTO.getProviderName())) {
|
||||
existingApiParams.putAll(updatedApiParams);
|
||||
return existingApiParams;
|
||||
}
|
||||
return updatedApiParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the identity server update request payload
|
||||
*
|
||||
* @param updateIdentityServerDTO of identity server update request
|
||||
* @throws BadRequestException if any invalid payload found
|
||||
*/
|
||||
private void validateIdentityServerUpdateRequest(IdentityServerDTO updateIdentityServerDTO,
|
||||
IdentityServerDTO existingIdentityServerDTO) throws ApplicationManagementException {
|
||||
if (updateIdentityServerDTO.getProviderName() != null &&
|
||||
isIdentityServiceProviderNotConfigured(updateIdentityServerDTO.getProviderName())) {
|
||||
String msg = "No such providers configured. Provider name: " + updateIdentityServerDTO.getProviderName();
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (updateIdentityServerDTO.getName() != null) {
|
||||
if (!updateIdentityServerDTO.getName().equalsIgnoreCase(existingIdentityServerDTO.getName())
|
||||
&& isIdentityServerNameExist(updateIdentityServerDTO.getName())) {
|
||||
String msg = "Identity server already exist with the given name. Identity server name: " + updateIdentityServerDTO.getName();
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
if (updateIdentityServerDTO.getUrl() != null) {
|
||||
validateIdentityServerUrl(updateIdentityServerDTO.getUrl());
|
||||
if(!updateIdentityServerDTO.getUrl().equalsIgnoreCase(existingIdentityServerDTO.getUrl()) &&
|
||||
isIdentityServerUrlExist(updateIdentityServerDTO.getUrl())) {
|
||||
String msg = "Identity server already exist with the given url. Identity server url: " + updateIdentityServerDTO.getUrl();
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
validateUpdateIdentityServerRequestApiParam(updateIdentityServerDTO, existingIdentityServerDTO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate the identity server create request payload
|
||||
*
|
||||
* @param identityServerDTO of identity server create request
|
||||
* @throws BadRequestException if any invalid payload found
|
||||
*/
|
||||
private void validateIdentityServerCreateRequest(IdentityServerDTO identityServerDTO) throws ApplicationManagementException {
|
||||
if (identityServerDTO.getUsername() == null) {
|
||||
String msg = "Identity server username can not be null";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (identityServerDTO.getPassword() == null) {
|
||||
String msg = "Identity server password can not be null";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (identityServerDTO.getName() == null) {
|
||||
String msg = "Identity server name can not be null";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (identityServerDTO.getUrl() == null) {
|
||||
String msg = "Identity server url can not be null";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (isIdentityServiceProviderNotConfigured(identityServerDTO.getProviderName())) {
|
||||
String msg = "No such providers configured. Provider name: " + identityServerDTO.getProviderName();
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (isIdentityServerNameExist(identityServerDTO.getName())) {
|
||||
String msg = "Identity server already exist with the given name. Identity server name: " + identityServerDTO.getName();
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (isIdentityServerUrlExist(identityServerDTO.getUrl())) {
|
||||
String msg = "Identity server already exist with the given url. Identity server url: " + identityServerDTO.getUrl();
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
validateCreateIdentityServerRequestApiParams(identityServerDTO);
|
||||
validateIdentityServerUrl(identityServerDTO.getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate provided identity server url (For example make sure it uses http/https protocol)
|
||||
*
|
||||
* @param url url of the identity server
|
||||
* @throws BadRequestException if url is invalid
|
||||
*/
|
||||
private void validateIdentityServerUrl(String url) throws BadRequestException {
|
||||
String[] schemes = {"http","https"};
|
||||
UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS);
|
||||
if (!urlValidator.isValid(url)) {
|
||||
String msg = "Identity server url is not a valid url";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate provided api params map in a identity server updated request
|
||||
* For example the updated api param map may not contain all the required api params
|
||||
*
|
||||
* @param updatedIdentityServerDto Identity server update request payload bean
|
||||
* @param existingIdentityServerDTO Corresponding existing identity server bean of the updated identity server
|
||||
* @throws ApplicationManagementException if any api param is invalid
|
||||
*/
|
||||
private void validateUpdateIdentityServerRequestApiParam(IdentityServerDTO updatedIdentityServerDto,
|
||||
IdentityServerDTO existingIdentityServerDTO) throws ApplicationManagementException {
|
||||
ISServiceProviderApplicationService serviceProviderApplicationService =
|
||||
ISServiceProviderApplicationService.of(existingIdentityServerDTO.getProviderName());
|
||||
List<String> requiredApiParams = serviceProviderApplicationService.getRequiredApiParams();
|
||||
if (!updatedIdentityServerDto.getProviderName().equals(existingIdentityServerDTO.getProviderName())) {
|
||||
validateAllRequiredParamsExists(updatedIdentityServerDto, requiredApiParams);
|
||||
}
|
||||
validateIfAnyInvalidParamExists(updatedIdentityServerDto, requiredApiParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate api params map of identity server create request payload
|
||||
* For example the api param map may not contain all the required api params
|
||||
*
|
||||
* @param identityServerDTO {@link IdentityServerDTO}
|
||||
* @throws ApplicationManagementException if any api param is invalid
|
||||
*/
|
||||
private void validateCreateIdentityServerRequestApiParams(IdentityServerDTO identityServerDTO) throws ApplicationManagementException {
|
||||
ISServiceProviderApplicationService serviceProviderApplicationService =
|
||||
ISServiceProviderApplicationService.of(identityServerDTO.getProviderName());
|
||||
List<String> requiredApiParams = serviceProviderApplicationService.getRequiredApiParams();
|
||||
validateAllRequiredParamsExists(identityServerDTO, requiredApiParams);
|
||||
validateIfAnyInvalidParamExists(identityServerDTO, requiredApiParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure if all required api params exists for the given identity server bean
|
||||
*
|
||||
* @param identityServerDTO {@link IdentityServerDTO}
|
||||
* @param requiredApiParams all mandatory api params
|
||||
* @throws BadRequestException if a required api param does not exist
|
||||
*/
|
||||
private void validateAllRequiredParamsExists(IdentityServerDTO identityServerDTO, List<String> requiredApiParams)
|
||||
throws BadRequestException {
|
||||
for (String param : requiredApiParams) {
|
||||
if (identityServerDTO.getApiParams().get(param) == null) {
|
||||
String msg = param + " api parameter is required for " + identityServerDTO.getProviderName() + ". " +
|
||||
"Required api parameters: " + StringUtils.join(requiredApiParams, ",");
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure if all api params are valid
|
||||
* For example it may contain an unwanted api param
|
||||
*
|
||||
* @param identityServerDTO {@link IdentityServerDTO}
|
||||
* @param requiredApiParams all required api params
|
||||
* @throws BadRequestException if an unwanted api param exist
|
||||
*/
|
||||
private void validateIfAnyInvalidParamExists(IdentityServerDTO identityServerDTO, List<String> requiredApiParams)
|
||||
throws BadRequestException {
|
||||
for (String param : identityServerDTO.getApiParamKeys()) {
|
||||
if (!requiredApiParams.contains(param)) {
|
||||
String msg = "Invalid api parameter. " + param + " is not required for " + identityServerDTO.getProviderName() + ". " +
|
||||
"Required api parameters: " + StringUtils.join(requiredApiParams, ",");
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the given providerName does not exist in the identity server config file
|
||||
*
|
||||
* @param providerName Name of the identity service provider
|
||||
* @return if provider name exist in identity server config
|
||||
*/
|
||||
private boolean isIdentityServiceProviderNotConfigured(String providerName) {
|
||||
List<IdentityServiceProvider> identityServiceProviders = ConfigurationManager.getInstance().getIdentityServerConfiguration().
|
||||
getIdentityServiceProviders();
|
||||
return identityServiceProviders.stream().noneMatch(provider -> provider.getProviderName().equals(providerName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentityServerNameExist(String name) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return spApplicationDAO.isExistingIdentityServerName(name, tenantId);
|
||||
} catch (ApplicationManagementDAOException | DBConnectionException e) {
|
||||
String msg = "Error occurred while checking if identity server with the name " + name + " exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentityServerUrlExist(String url) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return spApplicationDAO.isExistingIdentityServerUrl(url, tenantId);
|
||||
} catch (ApplicationManagementDAOException | DBConnectionException e) {
|
||||
String msg = "Error occurred while checking if identity server with the url " + url + " exists.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPApplicationListResponse retrieveSPApplicationFromIdentityServer(int identityServerId, Integer offset, Integer limit)
|
||||
throws ApplicationManagementException {
|
||||
IdentityServerDTO identityServer = getIdentityServer(identityServerId);
|
||||
ISServiceProviderApplicationService serviceProviderApplicationService = ISServiceProviderApplicationService.of(identityServer.getProviderName());
|
||||
SPApplicationListResponse spApplicationListResponse = serviceProviderApplicationService.retrieveSPApplications(identityServer, offset, limit);
|
||||
addExistingApps(identityServerId, spApplicationListResponse.getApplications());
|
||||
return spApplicationListResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds existing consumer applications of service providers to the SPApplication bean
|
||||
*
|
||||
* @param identityServerId identity server id of the service provider
|
||||
* @param spApplications Service providers list to which the existing applications should be added
|
||||
* @throws ApplicationManagementException if error occurred while adding existing applications
|
||||
*/
|
||||
private void addExistingApps(int identityServerId, List<SPApplication> spApplications) throws ApplicationManagementException {
|
||||
for (SPApplication spApplication : spApplications) {
|
||||
List<Application> existingApplications = getSPApplications(identityServerId, spApplication.getId());
|
||||
spApplication.setExistingApplications(existingApplications);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Application> getSPApplications(int identityServerId, String spUID) throws
|
||||
ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
List<Application> applications = new ArrayList<>();
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
List<ApplicationDTO> appDTOs = spApplicationDAO.getSPApplications(identityServerId, spUID, tenantId);
|
||||
for (ApplicationDTO applicationDTO : appDTOs) {
|
||||
if (lifecycleStateManager.getEndState().equals(applicationDTO.getStatus())) {
|
||||
continue;
|
||||
}
|
||||
boolean isHideableApp = applicationManager.isHideableApp(applicationDTO.getApplicationReleaseDTOs());
|
||||
boolean isDeletableApp = applicationManager.isDeletableApp(applicationDTO.getApplicationReleaseDTOs());
|
||||
|
||||
//Set application categories, tags and unrestricted roles to the application DTO.
|
||||
applicationDTO
|
||||
.setUnrestrictedRoles(visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId));
|
||||
applicationDTO.setAppCategories(applicationDAO.getAppCategories(applicationDTO.getId(), tenantId));
|
||||
applicationDTO.setTags(applicationDAO.getAppTags(applicationDTO.getId(), tenantId));
|
||||
|
||||
applicationDTO.setApplicationReleaseDTOs(applicationDTO.getApplicationReleaseDTOs());
|
||||
Application application = APIUtil.appDtoToAppResponse(applicationDTO);
|
||||
application.setDeletableApp(isDeletableApp);
|
||||
application.setHideableApp(isHideableApp);
|
||||
applications.add(application);
|
||||
}
|
||||
|
||||
return applications;
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred when getting database connection to get applications by filtering from "
|
||||
+ "requested filter.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg =
|
||||
"DAO exception while getting applications of tenant " + tenantId ;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void validateAttachAppsRequest(int identityServerId, String serviceProviderId, List<Integer> appIds) throws ApplicationManagementException {
|
||||
validateServiceProviderUID(identityServerId, serviceProviderId);
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
for (int appId : appIds) {
|
||||
try {
|
||||
ApplicationDTO appDTO = applicationDAO.getApplication(appId, tenantId);
|
||||
if (appDTO == null) {
|
||||
String msg = "Payload contains invalid an app id. " + "No app exist with the appId: " + appId + ".";
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error occurred while trying to retrieve application with the id:" + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void validateDetachAppsRequest(int identityServerId, String spId, List<Integer> appIds) throws ApplicationManagementException {
|
||||
validateServiceProviderUID(identityServerId, spId);
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
for (int id : appIds) {
|
||||
try {
|
||||
boolean isSPAppExist = spApplicationDAO.isSPApplicationExist(identityServerId, spId, id, tenantId);
|
||||
if (!isSPAppExist) {
|
||||
String msg = "No service provider app exist with the appId: " + id + " for service provider with the " +
|
||||
"UID " + spId;
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error occurred while checking if application exists with the id:" + id;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IdentityServiceProviderDTO> getIdentityServiceProviders() throws ApplicationManagementException {
|
||||
List<IdentityServiceProvider> identityServiceProviders = ConfigurationManager.getInstance().
|
||||
getIdentityServerConfiguration().getIdentityServiceProviders();
|
||||
List<IdentityServiceProviderDTO> identityServiceProviderDTOS = new ArrayList<>();
|
||||
for (IdentityServiceProvider identityServiceProvider : identityServiceProviders) {
|
||||
try {
|
||||
identityServiceProviderDTOS.add(APIUtil.identityServiceProviderToDTO(identityServiceProvider));
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Identity service provider configuration file is invalid. Hence failed to proceed.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
return identityServiceProviderDTOS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Responsible for validating service provider in requests
|
||||
*
|
||||
* @param identityServerId identity server id of the service provider
|
||||
* @param spUID uid of the service provider
|
||||
* @throws ApplicationManagementException if invalid service provider
|
||||
*/
|
||||
private void validateServiceProviderUID(int identityServerId, String spUID) throws
|
||||
ApplicationManagementException {
|
||||
IdentityServerDTO identityServer = getIdentityServer(identityServerId);
|
||||
ISServiceProviderApplicationService serviceProviderApplicationService = ISServiceProviderApplicationService.of(identityServer.getProviderName());
|
||||
try {
|
||||
boolean isSPAppExists = serviceProviderApplicationService.
|
||||
isSPApplicationExist(identityServer, spUID);
|
||||
if (!isSPAppExists) {
|
||||
String errMsg = "Service provider with the uid " + spUID + " does not exist.";
|
||||
log.error(errMsg);
|
||||
throw new BadRequestException(errMsg);
|
||||
}
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to validate service provider uid";
|
||||
log.error(errMsg, e);
|
||||
throw new ApplicationManagementException(errMsg, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void attachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
for (int appId : appIds) {
|
||||
spApplicationDAO.attachSPApplication(identityServerId, spUID, appId, tenantId);
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e){
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg =
|
||||
"DAO exception while getting applications of tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void detachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
for (int id : appIds) {
|
||||
spApplicationDAO.detachSPApplication(identityServerId, spUID, id, tenantId);
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e){
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg =
|
||||
"DAO exception while getting applications of tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Application createSPApplication(T app, int identityServerId, String spId, boolean isPublished) throws ApplicationManagementException {
|
||||
validateServiceProviderUID(identityServerId, spId);
|
||||
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
|
||||
ApplicationDTO applicationDTO = applicationManager.uploadReleaseArtifactIfExist(app);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Application release create request is received. Application name: " + applicationDTO.getName()
|
||||
+ " Device type ID: " + applicationDTO.getDeviceTypeId());
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
Application createdApp = applicationManager.addAppDataIntoDB(applicationDTO, isPublished);
|
||||
attachCreatedSPApplication(createdApp, identityServerId, spId);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return createdApp;
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while getting database connection.";
|
||||
log.error(msg, e);
|
||||
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while disabling AutoCommit.";
|
||||
log.error(msg, e);
|
||||
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while creating and attaching application with the name " + applicationDTO.getName() ;
|
||||
log.error(msg, e);
|
||||
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void attachCreatedSPApplication(Application createdApp, int identityServerId, String spUID) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
spApplicationDAO.attachSPApplication(identityServerId, spUID, createdApp.getId(), tenantId);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error occurred while attaching application with the id " + createdApp.getId();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,393 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.publisher.api.services;
|
||||
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.wrapper.ApplicationWrapper;
|
||||
import io.entgra.application.mgt.common.wrapper.CustomAppWrapper;
|
||||
import io.entgra.application.mgt.common.wrapper.PublicAppWrapper;
|
||||
import io.entgra.application.mgt.common.wrapper.WebAppWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import io.swagger.annotations.Info;
|
||||
import io.swagger.annotations.SwaggerDefinition;
|
||||
import io.swagger.annotations.Tag;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "Service Provider Application Management Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "SPApplicationService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt-publisher/v1.0/identity-server-applications"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "application_management, device_management", description = "App publisher related APIs")
|
||||
}
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "view a service provider applications",
|
||||
description = "Get service provider application details",
|
||||
key = "perm:app:publisher:service-provider:view",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/app-mgt/publisher/service-provider/application/view"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Create new identity server",
|
||||
description = "Connect to new identity server",
|
||||
key = "perm:app:publisher:service-provider:connect",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/app-mgt/publisher/service-provider/application/connect"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Create a service provider application",
|
||||
description = "Create an application and attach (map) to service provider",
|
||||
key = "perm:app:publisher:service-provider:create",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/app-mgt/publisher/service-provider/application/create"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Attach a service provider application",
|
||||
description = "Map an application to service provider",
|
||||
key = "perm:app:publisher:service-provider:attach",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/app-mgt/publisher/service-provider/application/attach"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Detach a service provider application",
|
||||
description = "Remove an application from service provider",
|
||||
key = "perm:app:publisher:service-provider:detach",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/app-mgt/publisher/service-provider/application/detach"}
|
||||
)
|
||||
}
|
||||
)
|
||||
@Path("/identity-server-applications")
|
||||
@Api(value = "SPApplication Management")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface SPApplicationService {
|
||||
|
||||
String SCOPE = "scope";
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/identity-servers/identity-service-providers")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get available identity service providers",
|
||||
tags = "Identity Server Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response getIdentityServiceProviders();
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/identity-servers")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get all identity servers",
|
||||
tags = "Identity Server Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response getIdentityServers();
|
||||
|
||||
@Path("/identity-servers/{id}")
|
||||
@DELETE
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "DELETE",
|
||||
value = "get identity server by id",
|
||||
tags = "Identity Server Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:connect")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response deleteIdentityServer(@PathParam("id") int id);
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/identity-servers/{id}")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get identity server by id",
|
||||
tags = "Identity Server Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response getIdentityServer(@PathParam("id") int id);
|
||||
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/identity-servers")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "create new identity server",
|
||||
tags = "Identity Server Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:connect")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response createIdentityServer(IdentityServerDTO identityServerDTO);
|
||||
|
||||
@PUT
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/identity-servers/{id}")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "PUT",
|
||||
value = "edit existing identity server",
|
||||
tags = "Identity Server Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:connect")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response updateIdentityServer(IdentityServerDTO identityServerDTO, @PathParam("id") int id);
|
||||
|
||||
@GET
|
||||
@Path("/identity-servers/identity-server-name")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Check if identity server name is already exists",
|
||||
tags = "Identity Server Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response isIdentityServerNameExists(
|
||||
@QueryParam("identityServerName") String identityServerName);
|
||||
|
||||
@GET
|
||||
@Path("/identity-servers/identity-server-url")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Check if identity server url is already exists",
|
||||
tags = "Identity Server Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response isIdentityServerUrlExists(
|
||||
@QueryParam("identityServerUrl") String identityServerUrl);
|
||||
|
||||
/**
|
||||
* This method is used to register an APIM application for tenant domain.
|
||||
*/
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("{identity-server-id}/service-providers")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get service providers by identity server id",
|
||||
notes = "This will get service providers with the existing applications",
|
||||
tags = "Service Provider Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response getServiceProviders(@QueryParam("limit") Integer limit, @QueryParam("offset") Integer offset,
|
||||
@PathParam("identity-server-id") int identityServerId);
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/attach")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "map application to service provider",
|
||||
notes = "This will map a given list application ids with the given service provider id",
|
||||
tags = "Service Provider Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:attach")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response attachApps(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, List<Integer> appIds);
|
||||
|
||||
/**
|
||||
* This method is used to register an APIM application for tenant domain.
|
||||
*/
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/detach")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Remove mapping with service provider of the given application ids",
|
||||
notes = "This will remove applications from service provider",
|
||||
tags = "Service Provider Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:detach")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response detachApps(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, List<Integer> appIds);
|
||||
|
||||
/**
|
||||
* This method is used to register an APIM application for tenant domain.
|
||||
*/
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/ent-app")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Create enterprise application and attach to service provider",
|
||||
notes = "This will get create an enterprise application and map with service provider",
|
||||
tags = "Service Provider Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response createEntApp(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app,
|
||||
@ApiParam(
|
||||
name = "isPublished",
|
||||
value = "Published state of the application"
|
||||
)
|
||||
@QueryParam("isPublished") boolean isPublished);
|
||||
|
||||
/**
|
||||
* This method is used to register an APIM application for tenant domain.
|
||||
*/
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/public-app")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Create public application and attach to service provider",
|
||||
notes = "This will get create a public application and map with service provider",
|
||||
tags = "Service Provider Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response createPubApp(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app,
|
||||
@ApiParam(
|
||||
name = "isPublished",
|
||||
value = "Published state of the application"
|
||||
)
|
||||
@QueryParam("isPublished") boolean isPublished);
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Create web application and attach to service provider",
|
||||
notes = "This will get create a web application and map with service provider",
|
||||
tags = "Service Provider Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response createWebApp(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app,
|
||||
@ApiParam(
|
||||
name = "isPublished",
|
||||
value = "Published state of the application"
|
||||
)
|
||||
@QueryParam("isPublished") boolean isPublished);
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Create custom application and attach to service provider",
|
||||
notes = "This will get create an custom application and map with service provider",
|
||||
tags = "Service Provider Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response createCustomApp(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app,
|
||||
@ApiParam(
|
||||
name = "isPublished",
|
||||
value = "Published state of the application"
|
||||
)
|
||||
@QueryParam("isPublished") boolean isPublished);
|
||||
}
|
@ -0,0 +1,363 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package io.entgra.application.mgt.publisher.api.services.impl;
|
||||
|
||||
import io.entgra.application.mgt.common.IdentityServerResponse;
|
||||
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
|
||||
import io.entgra.application.mgt.common.SPApplicationListResponse;
|
||||
import io.entgra.application.mgt.common.dto.IdentityServiceProviderDTO;
|
||||
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
|
||||
import io.entgra.application.mgt.common.exception.RequestValidatingException;
|
||||
import io.entgra.application.mgt.common.response.Application;
|
||||
import io.entgra.application.mgt.common.services.SPApplicationManager;
|
||||
import io.entgra.application.mgt.common.wrapper.ApplicationWrapper;
|
||||
import io.entgra.application.mgt.common.wrapper.CustomAppWrapper;
|
||||
import io.entgra.application.mgt.common.wrapper.PublicAppWrapper;
|
||||
import io.entgra.application.mgt.common.wrapper.WebAppWrapper;
|
||||
import io.entgra.application.mgt.core.exception.BadRequestException;
|
||||
import io.entgra.application.mgt.core.exception.NotFoundException;
|
||||
import io.entgra.application.mgt.core.util.APIUtil;
|
||||
import io.entgra.application.mgt.publisher.api.services.SPApplicationService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/identity-server-applications")
|
||||
public class SPApplicationServiceImpl implements SPApplicationService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SPApplicationServiceImpl.class);
|
||||
|
||||
@Path("/identity-servers/identity-service-providers")
|
||||
@GET
|
||||
@Override
|
||||
public Response getIdentityServiceProviders() {
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
try {
|
||||
List<IdentityServiceProviderDTO> identityServiceProviders = spAppManager.getIdentityServiceProviders();
|
||||
return Response.status(Response.Status.OK).entity(identityServiceProviders).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while getting identity service providers";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/identity-servers")
|
||||
@GET
|
||||
@Override
|
||||
public Response getIdentityServers() {
|
||||
try {
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
List<IdentityServerResponse> identityServers = spAppManager.getIdentityServers();
|
||||
return Response.status(Response.Status.OK).entity(identityServers).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/identity-servers/{id}")
|
||||
@DELETE
|
||||
@Override
|
||||
public Response deleteIdentityServer(@PathParam("id") int id) {
|
||||
try {
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
spAppManager.deleteIdentityServer(id);
|
||||
return Response.status(Response.Status.OK).entity("Successfully deleted identity server").build();
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "Identity server with the id " + id + " does not exist.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/identity-servers/{id}")
|
||||
@GET
|
||||
@Override
|
||||
public Response getIdentityServer(@PathParam("id") int id) {
|
||||
try {
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
IdentityServerResponse identityServer = spAppManager.getIdentityServerResponse(id);
|
||||
return Response.status(Response.Status.OK).entity(identityServer).build();
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "Identity server with the id " + id + " does not exist.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/identity-servers/{id}")
|
||||
@PUT
|
||||
@Override
|
||||
public Response updateIdentityServer(IdentityServerDTO identityServerDTO, @PathParam("id") int id) {
|
||||
try {
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
IdentityServerResponse identityServerResponse = spAppManager.updateIdentityServer(identityServerDTO, id);
|
||||
return Response.status(Response.Status.OK).entity(identityServerResponse).build();
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "Identity server with the id " + id + " does not exist.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (BadRequestException e) {
|
||||
String errMsg = "Identity server request payload is invalid";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Path("/identity-servers")
|
||||
@POST
|
||||
@Override
|
||||
public Response createIdentityServer(IdentityServerDTO identityServerDTO) {
|
||||
try {
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
IdentityServerResponse identityServer = spAppManager.createIdentityServer(identityServerDTO);
|
||||
return Response.status(Response.Status.CREATED).entity(identityServer).build();
|
||||
} catch (BadRequestException e) {
|
||||
String errMsg = "Identity server request payload is invalid";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/identity-servers/identity-server-name")
|
||||
@Override
|
||||
public Response isIdentityServerNameExists(
|
||||
@QueryParam("identityServerName") String identityServerName) {
|
||||
try {
|
||||
if (identityServerName == null) {
|
||||
String msg = "Invalid identity server name, identityServerName query param cannot be empty/null.";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
if (spAppManager.isIdentityServerNameExist(identityServerName)) {
|
||||
return Response.status(Response.Status.CONFLICT).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (BadRequestException e) {
|
||||
String errMsg = "Identity server request payload is invalid";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/identity-servers/identity-server-url")
|
||||
@Override
|
||||
public Response isIdentityServerUrlExists(
|
||||
@QueryParam("identityServerUrl") String identityServerUrl) {
|
||||
try {
|
||||
if (identityServerUrl == null) {
|
||||
String msg = "Invalid identity server url, identityServerName query param cannot be empty/null.";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
if (spAppManager.isIdentityServerUrlExist(identityServerUrl)) {
|
||||
return Response.status(Response.Status.CONFLICT).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (BadRequestException e) {
|
||||
String errMsg = "Identity server request payload is invalid";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/{identity-server-id}/service-providers")
|
||||
@GET
|
||||
@Override
|
||||
public Response getServiceProviders(@DefaultValue("30") @QueryParam("limit") Integer limit,@DefaultValue("0") @QueryParam("offset") Integer offset,
|
||||
@PathParam("identity-server-id") int identityServerId) {
|
||||
try {
|
||||
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
|
||||
SPApplicationListResponse applications = spAppManager.retrieveSPApplicationFromIdentityServer(identityServerId, limit, offset);
|
||||
return Response.status(Response.Status.OK).entity(applications).build();
|
||||
} catch (NotFoundException e) {
|
||||
String errMsg = "No Identity server exist with the id: " + identityServerId;
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
|
||||
log.error(errMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/attach")
|
||||
@POST
|
||||
@Override
|
||||
public Response attachApps(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, List<Integer> appIds) {
|
||||
SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager();
|
||||
try {
|
||||
spApplicationManager.validateAttachAppsRequest(identityServerId, serviceProviderId, appIds);
|
||||
spApplicationManager.attachSPApplications(identityServerId, serviceProviderId, appIds);
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "No identity server exist with the id " + identityServerId;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Invalid appIds provided";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while attaching apps to service provider with the id" + serviceProviderId;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/detach")
|
||||
@POST
|
||||
@Override
|
||||
public Response detachApps(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, List<Integer> appIds) {
|
||||
SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager();
|
||||
try {
|
||||
spApplicationManager.validateDetachAppsRequest(identityServerId, serviceProviderId, appIds);
|
||||
spApplicationManager.detachSPApplications(identityServerId, serviceProviderId, appIds);
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "No identity server exist with the id " + identityServerId;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Invalid appIds provided";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while attaching apps to service provider with the id" + serviceProviderId;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/ent-app")
|
||||
@POST
|
||||
@Override
|
||||
public Response createEntApp(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app,
|
||||
@QueryParam("isPublished") boolean isPublished) {
|
||||
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
||||
}
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/public-app")
|
||||
@POST
|
||||
@Override
|
||||
public Response createPubApp(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app,
|
||||
@QueryParam("isPublished") boolean isPublished) {
|
||||
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
||||
}
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app")
|
||||
@POST
|
||||
@Override
|
||||
public Response createWebApp(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app,
|
||||
@QueryParam("isPublished") boolean isPublished) {
|
||||
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
||||
}
|
||||
|
||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app")
|
||||
@POST
|
||||
@Override
|
||||
public Response createCustomApp(@PathParam("identity-server-id") int identityServerId,
|
||||
@PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app,
|
||||
@QueryParam("isPublished") boolean isPublished) {
|
||||
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and creates service provider application
|
||||
*
|
||||
* @param identityServerId id of the identity server
|
||||
* @param spUID uid of the service provider
|
||||
* @param appWrapper application wrapper
|
||||
* @param <T> application wrapper class
|
||||
* @return Response
|
||||
*/
|
||||
private <T> Response createSPApplication(int identityServerId, String spUID, T appWrapper, boolean isPublished) {
|
||||
try {
|
||||
SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager();
|
||||
Application createdApp = spApplicationManager.createSPApplication(appWrapper, identityServerId, spUID, isPublished);
|
||||
return Response.status(Response.Status.CREATED).entity(createdApp).build();
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "No identity server exist with the id " + identityServerId;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Found incompatible payload with create service provider app request.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (RequestValidatingException e) {
|
||||
String msg = "Found invalid release payload with create service provider app request.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
}
|
||||
catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while creating service provider app";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.common;
|
||||
|
||||
public class Constants {
|
||||
public static final String SCHEME_SEPARATOR = "://";
|
||||
public static final String COLON = ":";
|
||||
public static final String URI_QUERY_SEPARATOR = "?";
|
||||
public static final String URI_SEPARATOR = "/";
|
||||
public static final String BASIC_AUTH_HEADER_PREFIX = "Basic ";
|
||||
public static final String BEARER = "Bearer ";
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.common.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
/**
|
||||
* Useful to remove path separator string "," from base64 string
|
||||
*
|
||||
* @param base64String base64 string
|
||||
* @return base64 string without path separator
|
||||
*/
|
||||
public static String removePathSeparatorFromBase64String(String base64String) {
|
||||
String partSeparator = ",";
|
||||
if (base64String.contains(partSeparator)) {
|
||||
return base64String.split(partSeparator)[1];
|
||||
}
|
||||
return base64String;
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful to convert base64 string to input stream
|
||||
*
|
||||
* @param base64 base64 string to be converted
|
||||
* @return {@link InputStream} of the provided base64 string
|
||||
*/
|
||||
public static InputStream base64ToInputStream(String base64) {
|
||||
base64 = FileUtil.removePathSeparatorFromBase64String(base64);
|
||||
byte[] base64Bytes = Base64.getDecoder().decode(base64);
|
||||
return new ByteArrayInputStream(base64Bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* This generates file name with a suffix depending on the duplicate name count, useful when saving
|
||||
* files with the same name
|
||||
*
|
||||
* @param fileNameCount File count
|
||||
* @return generated file name with suffix
|
||||
*/
|
||||
public static String generateDuplicateFileName(String fileName, int fileNameCount) {
|
||||
String suffix = generateDuplicateFileNameSuffix(fileNameCount);
|
||||
String fileNameWithoutExtension = extractFileNameWithoutExtension(fileName);
|
||||
String fileNameWithSuffix = fileNameWithoutExtension + suffix;
|
||||
fileNameWithSuffix = fileNameWithSuffix + '.' + extractFileExtension(fileName);
|
||||
return fileNameWithSuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* This generates file name suffix for duplicate file names. For example,
|
||||
* if it's the first file, the count is 1 in which case the name doesn't have any suffix
|
||||
* else it adds suffix with (count - 1)
|
||||
*
|
||||
* @param fileNameCount File count
|
||||
* @return generated file name suffix
|
||||
*/
|
||||
private static String generateDuplicateFileNameSuffix(int fileNameCount) {
|
||||
String suffix = "";
|
||||
if (fileNameCount < 1) {
|
||||
throw new IllegalArgumentException("file name count must be above 0");
|
||||
}
|
||||
if (fileNameCount > 1) {
|
||||
suffix = "(" + (fileNameCount - 1) + ")";
|
||||
}
|
||||
return suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to extract file extension from file name
|
||||
*
|
||||
* @param fileName name of the file
|
||||
* @return extension of the file
|
||||
*/
|
||||
private static String extractFileExtension(String fileName) {
|
||||
return fileName.substring(fileName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to extract the file name without the extension
|
||||
* For example if you provide "main.java" as the fileName this will return main
|
||||
*
|
||||
* @param fileName name of the file
|
||||
* @return file name without file extension
|
||||
*/
|
||||
private static String extractFileNameWithoutExtension(String fileName) {
|
||||
return fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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.
|
||||
-->
|
||||
|
||||
<IdentityServiceProviderConfiguration>
|
||||
<IdentityServiceProviders>
|
||||
<IdentityServiceProvider>
|
||||
<ProviderName>WSO2 IAM</ProviderName>
|
||||
<ProviderClassName>io.entgra.application.mgt.core.identityserver.serviceprovider.impl.WSO2IAMSPApplicationService</ProviderClassName>
|
||||
<ServiceProvidersPageUri>/carbon/application/list-service-providers.jsp</ServiceProvidersPageUri>
|
||||
<!-- <ServiceProvidersAPIContextPath>/t/carbon.super/api/server/v1/applications</ServiceProvidersAPIContextPath> -->
|
||||
</IdentityServiceProvider>
|
||||
</IdentityServiceProviders>
|
||||
</IdentityServiceProviderConfiguration>
|
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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.
|
||||
-->
|
||||
|
||||
<IdentityServiceProviderConfiguration>
|
||||
<IdentityServiceProviders>
|
||||
<IdentityServiceProvider>
|
||||
<ProviderName>WSO2 IAM</ProviderName>
|
||||
<ProviderClassName>io.entgra.application.mgt.core.identityserver.serviceprovider.impl.WSO2IAMSPApplicationService</ProviderClassName>
|
||||
<ServiceProvidersPageUri>/carbon/application/list-service-providers.jsp</ServiceProvidersPageUri>
|
||||
<!-- <ServiceProvidersAPIContextPath>/t/carbon.super/api/server/v1/applications</ServiceProvidersAPIContextPath> -->
|
||||
</IdentityServiceProvider>
|
||||
</IdentityServiceProviders>
|
||||
</IdentityServiceProviderConfiguration>
|
Loading…
Reference in new issue