Fixing minor issues

feature/appm-store/pbac
megala21 7 years ago
parent c10f4e3587
commit 9c31b93937

@ -46,6 +46,8 @@ public class Filter {
private String sortBy; private String sortBy;
private String userName;
public int getLimit() { public int getLimit() {
return limit; return limit;
} }
@ -102,6 +104,14 @@ public class Filter {
this.sortBy = sortBy; this.sortBy = sortBy;
} }
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean hasCondition() { public boolean hasCondition() {
if (filterProperties != null || searchQuery != null || filter != null) { if (filterProperties != null || searchQuery != null || filter != null) {
return true; return true;
@ -109,5 +119,4 @@ public class Filter {
return false; return false;
} }
} }

@ -37,7 +37,7 @@ public interface ApplicationDAO {
ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException; ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException;
Application getApplication(String uuid, int tenantId) throws ApplicationManagementDAOException; Application getApplication(String uuid, int tenantId, String userName) throws ApplicationManagementDAOException;
int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException; int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException;

@ -140,12 +140,17 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "APP.APPLICATION_CATEGORY_ID = CAT.ID INNER JOIN APPM_LIFECYCLE_STATE AS " + "APP.APPLICATION_CATEGORY_ID = CAT.ID INNER JOIN APPM_LIFECYCLE_STATE AS "
+ "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? "; + "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? ";
String userName = filter.getUserName();
if (!userName.equals("ALL")) {
sql += " AND APP.CREATED_BY = ? ";
}
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
sql += "AND APP.NAME LIKE ? "; sql += "AND APP.NAME LIKE ? ";
} }
sql += "LIMIT ?,?;"; sql += "LIMIT ?,?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(++index, userName);
stmt.setInt(++index, tenantId); stmt.setInt(++index, tenantId);
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
stmt.setString(++index, "%" + filter.getSearchQuery() + "%"); stmt.setString(++index, "%" + filter.getSearchQuery() + "%");
@ -244,7 +249,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public Application getApplication(String uuid, int tenantId) throws ApplicationManagementDAOException { public Application getApplication(String uuid, int tenantId, String userName) throws
ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application with the UUID(" + uuid + ") from the database"); log.debug("Getting application with the UUID(" + uuid + ") from the database");
} }
@ -261,11 +267,17 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS " + "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS "
+ "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON " + "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON "
+ "APP.APPLICATION_CATEGORY_ID = CAT.ID INNER JOIN APPM_LIFECYCLE_STATE AS " + "APP.APPLICATION_CATEGORY_ID = CAT.ID INNER JOIN APPM_LIFECYCLE_STATE AS "
+ "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE UUID = ? AND APP.TENANT_ID = ?"; + "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE UUID = ? AND APP.TENANT_ID = ? ";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid); stmt.setString(1, uuid);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
if (!userName.equals("ALL")) {
sql += "AND APP.CREATED_BY = ?";
stmt.setString(3, userName);
}
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -174,6 +174,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
if (isAuthorized(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
userName = "ALL";
}
} catch (UserStoreException e) {
throw new ApplicationManagementException("User-store exception while checking whether the user " +
userName + " of tenant " + tenantId + " has the publisher permission");
}
filter.setUserName(userName);
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
@ -278,9 +290,19 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public Application getApplication(String uuid) throws ApplicationManagementException { public Application getApplication(String uuid) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
if (isAuthorized(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
userName = "ALL";
}
} catch (UserStoreException e) {
throw new ApplicationManagementException(
"User-store exception while getting application with the UUID " + uuid);
}
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
return DAOFactory.getApplicationDAO().getApplication(uuid, tenantId); return DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -304,7 +326,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
Application application = DAOFactory.getApplicationDAO().getApplication(applicationUUID, tenantId); Application application = DAOFactory.getApplicationDAO().getApplication(applicationUUID, tenantId,userName);
return application.getUser().getUserName().equals(userName) return application.getUser().getUserName().equals(userName)
&& application.getUser().getTenantId() == tenantId; && application.getUser().getTenantId() == tenantId;
} finally { } finally {

Loading…
Cancel
Save