Merge branch 'application-mgt-new' of https://gitlab.com/tcdlpds/carbon-device-mgt into application-mgt-new

feature/appm-store/pbac
Jayasanka 6 years ago
commit 795acbe219

@ -1,17 +1,16 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

@ -1,19 +1,18 @@
/* * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) 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
* 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.
* 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.application.mgt.addons;

@ -1,12 +1,11 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
* 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

@ -1,20 +1,20 @@
package org.wso2.carbon.device.application.mgt.addons;/*
* Copyright (c) 2017, 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.
*
*/
/* Copyright (c) 2019, 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.
*/
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

@ -1,17 +1,16 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

@ -1,20 +1,18 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) 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
* 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.
* 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.application.mgt.addons.jaxrs;

@ -1,20 +1,18 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) 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
* 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.
* 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.application.mgt.addons.jaxrs;

@ -33,7 +33,6 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseW
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
import java.io.InputStream;
import java.util.List;
/**
@ -89,7 +88,7 @@ public interface ApplicationManager {
ApplicationList getApplications(Filter filter) throws ApplicationManagementException;
/**
* To get the ApplicationDTO for given Id.
* To get the Application for given Id.
*
* @param id id of the ApplicationDTO
* @param state state of the ApplicationDTO
@ -98,6 +97,15 @@ public interface ApplicationManager {
*/
Application getApplicationById(int id, String state) throws ApplicationManagementException;
/**
* To get the Application Release for given uuid.
*
* @param uuid uuid of the ApplicationDTO
* @return the Application Release identified by the UUID
* @throws ApplicationManagementException Application Management Exception.
*/
ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException;
/**
* To get the ApplicationDTO for given application relase UUID.
*

@ -40,6 +40,8 @@ public interface VisibilityDAO {
List<String> getUnrestrictedRoles(int applicationId, int tenantId) throws VisibilityManagementDAOException;
List<String> getUnrestrictedRolesByUUID(String uuid, int tenantId) throws VisibilityManagementDAOException;
void deleteUnrestrictedRoles(List<String> unrestrictedRoles, int applicationId, int tenantId) throws
VisibilityManagementDAOException;

@ -244,7 +244,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ "AR.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
+ "AR.RATED_USERS AS RATED_USER_COUNT "
+ "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.UUID = ? AND AR.TENAT_ID = ?";
+ "WHERE AR.UUID = ? AND AR.TENANT_ID = ?";
try {
connection = this.getDBConnection();

@ -104,6 +104,42 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
}
}
@Override
public List<String> getUnrestrictedRolesByUUID(String uuid, int tenantId) throws VisibilityManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get unrestricted roles for UUID: " + uuid);
}
Connection conn;
List<String> unrestrictedRoles = new ArrayList<>();
String sql = "SELECT ROLE FROM AP_UNRESTRICTED_ROLE "
+ "WHERE "
+ "AP_APP_ID = (SELECT AR.AP_APP_ID FROM AP_APP_RELEASE AR WHERE AR.UUID = ? AND AR.TENANT_ID = ? ) "
+ "AND TENANT_ID = ?";
try {
conn = this.getDBConnection();
conn.setAutoCommit(false);
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery();) {
while (rs.next()) {
unrestrictedRoles.add(rs.getString("ROLE"));
}
return unrestrictedRoles;
}
}
} catch (DBConnectionException e) {
throw new VisibilityManagementDAOException(
"Error occurred while obtaining the DB connection when getting unrestricted roles for UUID: "
+ uuid, e);
} catch (SQLException e) {
throw new VisibilityManagementDAOException(
"Error occurred while getting unrestricted roles for UUID: " + uuid, e);
}
}
@Override
public void deleteUnrestrictedRoles(List<String> unrestrictedRoles, int applicationId, int tenantId) throws VisibilityManagementDAOException {
if (log.isDebugEnabled()) {

@ -874,6 +874,53 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
@Override
public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException{
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isVisibleAppRelease = false;
try {
ConnectionManagerUtil.openDBConnection();
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
if (applicationReleaseDTO == null) {
String msg = "Couldn't find an application release for the UUID: " + uuid;
log.error(msg);
throw new NotFoundException(msg);
}
if (applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())) {
return null;
}
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRolesByUUID(uuid, tenantId);
if (!unrestrictedRoles.isEmpty()) {
if (hasUserRole(unrestrictedRoles, userName)) {
isVisibleAppRelease = true;
}
} else {
isVisibleAppRelease = true;
}
if (!isVisibleAppRelease) {
String msg = "You are trying to access release of visibility restricted application. You don't have "
+ "required roles to view this application,";
log.error(msg);
throw new ForbiddenException(msg);
}
return releaseDtoToRelease(applicationReleaseDTO);
} catch (LifecycleManagementException e) {
String msg = "Error occurred when getting the end state of the application lifecycle flow";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) {
String msg = "User-store exception while getting application with the application release UUID: " + uuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);

@ -180,6 +180,48 @@ public interface ApplicationManagementPublisherAPI {
@QueryParam("state") String state
);
@GET
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get the application release of requesting application UUID and state",
notes = "This will get the application release identified by the application release uuid and state.",
tags = "ApplicationDTO Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved relevant application release.",
response = ApplicationDTO.class),
@ApiResponse(
code = 403,
message = "Don't have permission to access the application release"),
@ApiResponse(
code = 404,
message = "Application release not found"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting relevant application release.",
response = ErrorResponse.class)
})
Response getApplicationRelease(
@ApiParam(
name = "uuid",
value = "application release uuid",
required = true)
@PathParam("uuid") String uuid
);
@PUT
@Path("/{appId}")
@Produces(MediaType.APPLICATION_JSON)

@ -125,6 +125,37 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
}
@GET
@Consumes("application/json")
@Path("/release/{uuid}")
public Response getApplicationRelease(
@PathParam("uuid") String uuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
ApplicationRelease applicationRelease = applicationManager.getApplicationReleaseByUUID(uuid);
if (applicationRelease == null){
String msg = "Application release is in the end state of the application lifecycle flow.";
log.error(msg);
return Response.status(Response.Status.OK).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) {
String msg = "Application Release with UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch(ForbiddenException e){
String msg = "You don't have permission to access the application release. application release UUID: : "
+ uuid;
log.error(msg);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
}
catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST
@Consumes("multipart/mixed")
public Response createApplication(

Loading…
Cancel
Save