Add identity server config

Add api to create identity server
Return List of identity servers withtout extra bean for response
feature/traccar-sync
Mohamed Rashd 3 years ago
parent 986828bc16
commit 3dd0690552

@ -20,11 +20,12 @@ package io.entgra.application.mgt.common;
public class IdentityServer {
private int id;
private String providerName;
private String name;
private String description;
private String url;
private String spAppsUri;
private String spAppsApi;
private String apiUrl;
private String serviceProviderAppsUrl;
private String userName;
private String password;
@ -60,22 +61,6 @@ public class IdentityServer {
this.url = url;
}
public String getSpAppsUri() {
return spAppsUri;
}
public void setSpAppsURI(String spAppsUri) {
this.spAppsUri = spAppsUri;
}
public String getSpAppsApi() {
return spAppsApi;
}
public void setSpAppsApi(String spAppsApi) {
this.spAppsApi = spAppsApi;
}
public String getPassword() {
return password;
}
@ -91,4 +76,28 @@ public class IdentityServer {
public void setUserName(String userName) {
this.userName = userName;
}
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public String getApiUrl() {
return apiUrl;
}
public void setApiUrl(String apiUrl) {
this.apiUrl = apiUrl;
}
public String getServiceProviderAppsUrl() {
return serviceProviderAppsUrl;
}
public void setServiceProviderAppsUrl(String serviceProviderAppsUrl) {
this.serviceProviderAppsUrl = serviceProviderAppsUrl;
}
}

@ -18,16 +18,18 @@
package io.entgra.application.mgt.common;
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
import java.util.List;
public class IdentityServerList {
private List<IdentityServer> identityServers;
private List<IdentityServerDTO> identityServers;
public List<IdentityServer> getIdentityServers() {
public List<IdentityServerDTO> getIdentityServers() {
return identityServers;
}
public void setIdentityServers(List<IdentityServer> identityServers) {
public void setIdentityServers(List<IdentityServerDTO> identityServers) {
this.identityServers = identityServers;
}
}

@ -0,0 +1,94 @@
/*
* 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.dto;
public class IdentityServerDTO {
private int id;
private String providerName;
private String name;
private String description;
private String url;
private String apiUrl;
private String userName;
private String password;
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 getApiUrl() {
return apiUrl;
}
public void setApiUrl(String apiUrl) {
this.apiUrl = apiUrl;
}
}

@ -19,7 +19,7 @@
package io.entgra.application.mgt.common.services;
import io.entgra.application.mgt.common.IdentityServer;
import io.entgra.application.mgt.common.IdentityServerList;
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
import io.entgra.application.mgt.common.SPApplication;
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.application.mgt.common.exception.RequestValidatingException;
@ -70,7 +70,9 @@ public interface SPApplicationManager {
* @return Available identity servers
* @throws ApplicationManagementException if error occurred while getting identity servers
*/
IdentityServerList getIdentityServers() throws ApplicationManagementException;
List<IdentityServer> getIdentityServers() throws ApplicationManagementException;
IdentityServer createIdentityServer(IdentityServerDTO identityServerDTO) throws ApplicationManagementException;
/**
*

@ -36,8 +36,12 @@ public class ConfigurationManager {
private Configuration configuration;
private IdentityServerConfiguration identityServerConfiguration;
private static String configPath;
private static String identityServerConfigPath;
private static volatile ConfigurationManager configurationManager;
private ConfigurationManager() {
@ -60,6 +64,14 @@ public class ConfigurationManager {
return configurationManager;
}
public static synchronized void setIdentityServerConfigPathConfigLocation(String configPath) throws InvalidConfigurationException {
if (identityServerConfigPath == null) {
identityServerConfigPath = configPath;
} else {
throw new InvalidConfigurationException("Configuration path " + configPath + " is already defined");
}
}
public static synchronized void setConfigLocation(String configPath) throws InvalidConfigurationException {
if (ConfigurationManager.configPath == null) {
ConfigurationManager.configPath = configPath;
@ -74,9 +86,11 @@ public class ConfigurationManager {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
if (configPath == null) {
configPath = Constants.DEFAULT_CONFIG_FILE_LOCATION;
identityServerConfigPath = Constants.DEFAULT_IDENTITY_SERVERS_CONFIG_FILE_LOCATION;
}
//TODO: Add validation for the configurations
this.configuration = (Configuration) unmarshaller.unmarshal(new File(configPath));
this.identityServerConfiguration = (IdentityServerConfiguration) unmarshaller.unmarshal(new File(identityServerConfigPath));
} catch (Exception e) {
log.error(e);
throw new InvalidConfigurationException("Error occurred while initializing application config: "
@ -88,6 +102,10 @@ public class ConfigurationManager {
return configuration;
}
public IdentityServerConfiguration getIdentityServerConfiguration() {
return identityServerConfiguration;
}
public Extension getExtension(Extension.Name extName) throws InvalidConfigurationException {
for (Extension extension : configuration.getExtensions()) {
if (extension.getName().contentEquals(extName.toString())) {

@ -0,0 +1,52 @@
/*
* Copyright (c) 2019, 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 = "IdentityServerConfiguration")
public class IdentityServerConfiguration {
private List<IdentityServerDetail> identityServers;
@XmlElementWrapper(name = "IdentityServers")
@XmlElement(name = "IdentityServerDTO")
public List<IdentityServerDetail> getIdentityServers() {
return identityServers;
}
public IdentityServerDetail getIdentityServerDetailByProviderName(String identityServerProviderName) {
for (IdentityServerDetail identityServerDetail : identityServers) {
if (identityServerDetail.getProviderName().equals(identityServerProviderName)) {
return identityServerDetail;
}
}
return null;
}
public void setIdentityServers(List<IdentityServerDetail> identityServers) {
this.identityServers = identityServers;
}
}

@ -0,0 +1,37 @@
package io.entgra.application.mgt.core.config;
import javax.xml.bind.annotation.XmlAttribute;
public class IdentityServerDetail {
private String providerName;
private String serviceProvidersPageUri;
private String serviceProvidersAPIContextPath;
@XmlAttribute(name = "ProviderName")
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
@XmlAttribute(name = "ServiceProvidersPageUri")
public String getServiceProvidersPageUri() {
return serviceProvidersPageUri;
}
public void setServiceProvidersPageUri(String serviceProvidersPageUri) {
this.serviceProvidersPageUri = serviceProvidersPageUri;
}
@XmlAttribute(name = "ServiceProvidersAPIContextPath")
public String getServiceProvidersAPIContextPath() {
return serviceProvidersAPIContextPath;
}
public void setServiceProvidersAPIContextPath(String serviceProvidersAPIContextPath) {
this.serviceProvidersAPIContextPath = serviceProvidersAPIContextPath;
}
}

@ -18,7 +18,7 @@
package io.entgra.application.mgt.core.dao;
import io.entgra.application.mgt.common.IdentityServer;
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
import io.entgra.application.mgt.common.dto.ApplicationDTO;
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
@ -26,6 +26,8 @@ import java.util.List;
public interface SPApplicationDAO {
int createIdentityServer(IdentityServerDTO identityServer, int tenantId) throws ApplicationManagementDAOException;
/**
*
* @param identityServerId Id of identity server in which the service provider is in
@ -59,7 +61,7 @@ public interface SPApplicationDAO {
* @return All available identity servers
* @throws ApplicationManagementDAOException if any db error occurred
*/
List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException;
List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException;
/**
*
@ -67,7 +69,7 @@ public interface SPApplicationDAO {
* @return Identity Server of the given id
* @throws ApplicationManagementDAOException if any db error occurred
*/
IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException;
IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException;
/**
* Verify whether application exist for given identity server id, service provider id and application id.

@ -17,9 +17,6 @@
*/
package io.entgra.application.mgt.core.dao.impl.application;
import io.entgra.application.mgt.common.ApplicationType;
import io.entgra.application.mgt.common.IdentityServer;
import io.entgra.application.mgt.core.util.Constants;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -27,7 +24,6 @@ import io.entgra.application.mgt.common.AppLifecycleState;
import io.entgra.application.mgt.common.dto.ApplicationDTO;
import io.entgra.application.mgt.common.dto.CategoryDTO;
import io.entgra.application.mgt.common.Filter;
import io.entgra.application.mgt.common.dto.ReviewDTO;
import io.entgra.application.mgt.common.dto.TagDTO;
import io.entgra.application.mgt.common.exception.DBConnectionException;
import io.entgra.application.mgt.core.dao.ApplicationDAO;

@ -18,7 +18,7 @@
package io.entgra.application.mgt.core.dao.impl.application.spapplication;
import io.entgra.application.mgt.common.IdentityServer;
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;
@ -40,7 +40,7 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
@Override
public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?";
@ -67,7 +67,7 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
}
@Override
public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND "
@ -99,6 +99,46 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
}
}
@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_URL, 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.getApiUrl());
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()) {

@ -18,7 +18,7 @@
package io.entgra.application.mgt.core.dao.impl.application.spapplication;
import io.entgra.application.mgt.common.IdentityServer;
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;
@ -40,7 +40,7 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
private static final Log log = LogFactory.getLog(OracleSPApplicationDAOImpl.class);
@Override
public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?";
@ -67,7 +67,7 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
}
@Override
public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND "

@ -18,7 +18,7 @@
package io.entgra.application.mgt.core.dao.impl.application.spapplication;
import io.entgra.application.mgt.common.IdentityServer;
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;
@ -40,7 +40,7 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
private static final Log log = LogFactory.getLog(PostgreSQLSPApplicationDAOImpl.class);
@Override
public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?";
@ -67,7 +67,7 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
}
@Override
public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND "

@ -18,7 +18,7 @@
package io.entgra.application.mgt.core.dao.impl.application.spapplication;
import io.entgra.application.mgt.common.IdentityServer;
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;
@ -40,7 +40,7 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
private static final Log log = LogFactory.getLog(SQLServerSPApplicationDAOImpl.class);
@Override
public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?";
@ -67,7 +67,7 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
}
@Override
public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND "

@ -19,7 +19,7 @@
package io.entgra.application.mgt.core.impl;
import io.entgra.application.mgt.common.IdentityServer;
import io.entgra.application.mgt.common.IdentityServerList;
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.exception.ApplicationManagementException;
@ -44,6 +44,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class SPApplicationManagerImpl implements SPApplicationManager {
@ -76,7 +77,8 @@ public class SPApplicationManagerImpl implements SPApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
ConnectionManagerUtil.openDBConnection();
return spApplicationDAO.getIdentityServerById(identityServerId, tenantId);
IdentityServerDTO identityServerDTO = spApplicationDAO.getIdentityServerById(identityServerId, tenantId);
return APIUtil.identityServerDtoToIdentityServerResponse(identityServerDTO);
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection to get identity server with the id: " + identityServerId;
log.error(msg, e);
@ -92,13 +94,12 @@ public class SPApplicationManagerImpl implements SPApplicationManager {
}
@Override
public IdentityServerList getIdentityServers() throws ApplicationManagementException {
public List<IdentityServer> getIdentityServers() throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
ConnectionManagerUtil.openDBConnection();
IdentityServerList identityServerList = new IdentityServerList();
identityServerList.setIdentityServers(spApplicationDAO.getIdentityServers(tenantId));
return identityServerList;
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);
@ -113,6 +114,20 @@ public class SPApplicationManagerImpl implements SPApplicationManager {
}
}
@Override
public IdentityServer createIdentityServer(IdentityServerDTO identityServerDTO) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
int id = spApplicationDAO.createIdentityServer(identityServerDTO, tenantId);
identityServerDTO.setId(id);
return APIUtil.identityServerDtoToIdentityServerResponse(identityServerDTO);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while creating identity server " + identityServerDTO.getName();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
@Override
public List<Application> getSPApplications(int identityServerId, String spUID) throws
ApplicationManagementException {

@ -18,6 +18,9 @@
package io.entgra.application.mgt.core.util;
import io.entgra.application.mgt.common.IdentityServer;
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
import io.entgra.application.mgt.core.config.IdentityServerDetail;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -363,6 +366,23 @@ public class APIUtil {
return applicationReleaseDTO;
}
public static IdentityServer identityServerDtoToIdentityServerResponse(IdentityServerDTO identityServerDTO) {
IdentityServer identityServer = new IdentityServer();
identityServer.setId(identityServerDTO.getId());
identityServer.setProviderName(identityServerDTO.getProviderName());
identityServer.setName(identityServerDTO.getName());
identityServer.setDescription(identityServerDTO.getDescription());
identityServer.setUrl(identityServerDTO.getUrl());
identityServer.setApiUrl(identityServerDTO.getApiUrl());
identityServer.setUserName(identityServerDTO.getUserName());
identityServer.setPassword(identityServerDTO.getPassword());
IdentityServerDetail identityServerDetail = ConfigurationManager.getInstance().getIdentityServerConfiguration()
.getIdentityServerDetailByProviderName(identityServerDTO.getProviderName());
String serviceProviderAppsUrl = identityServerDTO.getUrl() + Constants.FORWARD_SLASH + identityServerDetail.getServiceProvidersPageUri();
identityServer.setServiceProviderAppsUrl(serviceProviderAppsUrl);
return identityServer;
}
public static Application appDtoToAppResponse(ApplicationDTO applicationDTO) throws ApplicationManagementException {
Application application = new Application();

@ -31,9 +31,12 @@ import java.util.Map;
public class Constants {
public static final String APPLICATION_CONFIG_XML_FILE = "application-mgt.xml";
public static final String IDENTITY_SERVERS_CONFIG_XML_FILE = "identity-servers-config.xml";
public static final String DEFAULT_CONFIG_FILE_LOCATION = CarbonUtils.getCarbonConfigDirPath() + File.separator +
Constants.APPLICATION_CONFIG_XML_FILE;
public static final String DEFAULT_IDENTITY_SERVERS_CONFIG_FILE_LOCATION = CarbonUtils.getCarbonConfigDirPath() + File.separator +
IDENTITY_SERVERS_CONFIG_XML_FILE;
public static final String DEFAULT_VERSION = "1.0.0";
public static final String SCREENSHOT_NAME = "screenshot";
public static final String ICON_NAME = "icon";

@ -19,7 +19,7 @@ package io.entgra.application.mgt.core.util;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.entgra.application.mgt.common.IdentityServer;
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
@ -172,22 +172,22 @@ public class DAOUtil {
* To create application object from the result set retrieved from the Database.
*
* @param rs ResultSet
* @return IdentityServer that is retrieved from the Database.
* @return IdentityServerDTO that is retrieved from the Database.
* @throws SQLException SQL Exception
* @throws JSONException JSONException.
*/
public static IdentityServer loadIdentityServer(ResultSet rs)
public static IdentityServerDTO loadIdentityServer(ResultSet rs)
throws SQLException, JSONException, UnexpectedServerErrorException {
List<IdentityServer> identityServers = loadIdentityServers(rs);
if (identityServers.isEmpty()) {
List<IdentityServerDTO> identityServerDTOS = loadIdentityServers(rs);
if (identityServerDTOS.isEmpty()) {
return null;
}
if (identityServers.size() > 1) {
if (identityServerDTOS.size() > 1) {
String msg = "Internal server error. Found more than one identity server for requested ID";
log.error(msg);
throw new UnexpectedServerErrorException(msg);
}
return identityServers.get(0);
return identityServerDTOS.get(0);
}
/**
@ -198,21 +198,21 @@ public class DAOUtil {
* @throws SQLException SQL Exception
* @throws JSONException JSONException.
*/
public static List<IdentityServer> loadIdentityServers(ResultSet rs) throws SQLException, JSONException {
List<IdentityServer> identityServers = new ArrayList<>();
public static List<IdentityServerDTO> loadIdentityServers(ResultSet rs) throws SQLException, JSONException {
List<IdentityServerDTO> identityServerDTOS = new ArrayList<>();
while (rs.next()) {
IdentityServer identityServer = new IdentityServer();
identityServer.setId(rs.getInt("ID"));
identityServer.setName(rs.getString("NAME"));
identityServer.setDescription(rs.getString("DESCRIPTION"));
identityServer.setUrl(rs.getString("URL"));
identityServer.setSpAppsURI(rs.getString("SP_APPS_URI"));
identityServer.setSpAppsApi(rs.getString("SP_APPS_API"));
identityServer.setUserName(rs.getString("USERNAME"));
identityServer.setPassword(rs.getString("PASSWORD"));
identityServers.add(identityServer);
IdentityServerDTO identityServerDTO = new IdentityServerDTO();
identityServerDTO.setId(rs.getInt("ID"));
identityServerDTO.setProviderName(rs.getString("PROVIDER_NAME"));
identityServerDTO.setName(rs.getString("NAME"));
identityServerDTO.setDescription(rs.getString("DESCRIPTION"));
identityServerDTO.setUrl(rs.getString("URL"));
identityServerDTO.setApiUrl(rs.getString("API_URI"));
identityServerDTO.setUserName(rs.getString("USERNAME"));
identityServerDTO.setPassword(rs.getString("PASSWORD"));
identityServerDTOS.add(identityServerDTO);
}
return identityServers;
return identityServerDTOS;
}
/**

@ -18,6 +18,7 @@
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;
@ -66,6 +67,13 @@ import java.util.List;
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",
@ -128,6 +136,22 @@ public interface SPApplicationService {
)
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);
/**
* This method is used to register an APIM application for tenant domain.
*/

@ -19,6 +19,7 @@
package io.entgra.application.mgt.publisher.api.services.impl;
import io.entgra.application.mgt.common.IdentityServer;
import io.entgra.application.mgt.common.dto.IdentityServerDTO;
import io.entgra.application.mgt.common.IdentityServerList;
import io.entgra.application.mgt.common.SPApplicationListResponse;
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
@ -56,7 +57,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
public Response getIdentityServers() {
try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
IdentityServerList identityServers = spAppManager.getIdentityServers();
List<IdentityServer> 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";
@ -80,6 +81,21 @@ public class SPApplicationServiceImpl implements SPApplicationService {
}
}
@Path("/identity-servers")
@POST
@Override
public Response createIdentityServer(IdentityServerDTO identityServerDTO) {
try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
IdentityServer identityServer = spAppManager.createIdentityServer(identityServerDTO);
return Response.status(Response.Status.CREATED).entity(identityServer).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

@ -24,6 +24,8 @@ import io.entgra.application.mgt.common.SPApplication;
import io.entgra.application.mgt.common.SPApplicationListResponse;
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.application.mgt.common.services.SPApplicationManager;
import io.entgra.application.mgt.core.config.ConfigurationManager;
import io.entgra.application.mgt.core.config.IdentityServerDetail;
import io.entgra.application.mgt.core.util.APIUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -167,8 +169,9 @@ public class SPAppRequestHandlerUtil {
}
private static String getSPApplicationsAPI(IdentityServer identityServer) {
String api = identityServer.getSpAppsApi();
return api;
IdentityServerDetail identityServerDetail = ConfigurationManager.getInstance().getIdentityServerConfiguration().
getIdentityServerDetailByProviderName(identityServer.getProviderName());
return identityServer.getApiUrl() + identityServerDetail.getServiceProvidersAPIContextPath();
}
}
Loading…
Cancel
Save