api layer permission modification

pull/238/head
Isuri Mendis 1 year ago
parent 6fe4c628a6
commit cfb44e1c15

@ -46,7 +46,7 @@
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>api#deviceOrganization-mgt-v1.0.war</warName>
<warName>api#deviceOrganization-mgt-v1.0</warName>
</configuration>
</plugin>
<plugin>

@ -60,13 +60,14 @@ import javax.ws.rs.core.Response;
}
),
tags = {
@Tag(name = "deviceOrganization_management", description = "DeviceOrganization management related REST-API. " +
@Tag(name = "deviceOrganization_management, device_management", description = "DeviceOrganization management related REST-API. " +
"This can be used to manipulate device organization related details.")
}
)
@Path("/deviceOrganization")
@Api(value = "DeviceOrganization Management", description = "This API carries all device Organization management " +
"related operations.")
@Path("/deviceOrganization")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Scopes(scopes = {
@ -75,7 +76,7 @@ import javax.ws.rs.core.Response;
description = "Device Organization",
key = "dm:device-organization",
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/devices/owning-device/view"}
permissions = {"/device-mgt/devices/owning-device/organization"}
)
}
)

@ -0,0 +1,97 @@
/*
* Copyright (c) 2018 - 2023, 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.device.mgt.core.device.mgt.extensions.device.organization.api.beans;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@Provider
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, MessageBodyReader<Object> {
public static final String DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
private Gson gson;
private static final String UTF_8 = "UTF-8";
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
return true;
}
private Gson getGson() {
if (gson == null) {
final GsonBuilder gsonBuilder = new GsonBuilder();
gson = gsonBuilder.setDateFormat(DATE_FORMAT).create();
}
return gson;
}
public Object readFrom(Class<Object> objectClass, Type type, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> stringStringMultivaluedMap,
InputStream entityStream)
throws IOException, WebApplicationException {
InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8");
try {
return getGson().fromJson(reader, type);
} finally {
reader.close();
}
}
public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
return true;
}
public long getSize(Object o, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
return -1;
}
public void writeTo(Object object, Class<?> aClass, Type type, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> stringObjectMultivaluedMap,
OutputStream entityStream)
throws IOException, WebApplicationException {
OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8);
try {
getGson().toJson(object, type, writer);
} finally {
writer.close();
}
}
}

@ -26,17 +26,17 @@
<jaxrs:server id="services" address="/">
<jaxrs:serviceBeans>
<ref bean="deviceOrganizationMgtService"/>
<ref bean="swaggerResource"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<!--<ref bean="errorHandler"/>-->
<!-- <ref bean="jsonProvider"/>-->
<ref bean="swaggerWriter"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="ValidationInterceptor" class="io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans.ValidationInterceptor"/>
<bean id="io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans.ValidationInterceptor" class="io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans.ValidationInterceptor"/>
<!-- <bean id="GlobalExceptionMapper" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.exception.GlobalThrowableMapper"/>-->
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
@ -55,7 +55,6 @@
<bean id="deviceOrganizationMgtService" class="io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.DeviceOrganizationMgtServiceImpl"/>
<!--<bean id="errorHandler" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.common.ErrorHandler"/>-->
<cxf:bus>
<cxf:inInterceptors>
<ref bean="io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans.ValidationInterceptor"/>

Loading…
Cancel
Save