| .. | .. |
|---|
| 33 | 33 | import net.curisit.securis.services.exception.SeCurisServiceException; |
|---|
| 34 | 34 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 35 | 35 | |
|---|
| 36 | | -import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; |
|---|
| 37 | | -import org.apache.logging.log4j.Logger; |
|---|
| 38 | 36 | import org.apache.logging.log4j.LogManager; |
|---|
| 37 | +import org.apache.logging.log4j.Logger; |
|---|
| 38 | +import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; |
|---|
| 39 | 39 | |
|---|
| 40 | 40 | import com.google.inject.persist.Transactional; |
|---|
| 41 | 41 | |
|---|
| .. | .. |
|---|
| 56 | 56 | @Inject |
|---|
| 57 | 57 | Provider<EntityManager> emProvider; |
|---|
| 58 | 58 | |
|---|
| 59 | | - public LicenseResource() {} |
|---|
| 59 | + public LicenseResource() { |
|---|
| 60 | + } |
|---|
| 60 | 61 | |
|---|
| 61 | 62 | /** |
|---|
| 62 | 63 | * |
|---|
| .. | .. |
|---|
| 65 | 66 | @GET |
|---|
| 66 | 67 | @Path("/") |
|---|
| 67 | 68 | @Securable |
|---|
| 68 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 69 | + @Produces({ |
|---|
| 70 | + MediaType.APPLICATION_JSON |
|---|
| 71 | + }) |
|---|
| 69 | 72 | public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) { |
|---|
| 70 | 73 | LOG.info("Getting licenses list "); |
|---|
| 71 | 74 | |
|---|
| .. | .. |
|---|
| 97 | 100 | @GET |
|---|
| 98 | 101 | @Path("/{licId}") |
|---|
| 99 | 102 | @Securable |
|---|
| 100 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 103 | + @Produces({ |
|---|
| 104 | + MediaType.APPLICATION_JSON |
|---|
| 105 | + }) |
|---|
| 101 | 106 | public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 102 | 107 | LOG.info("Getting organization data for id: {}: ", licId); |
|---|
| 103 | 108 | |
|---|
| .. | .. |
|---|
| 114 | 119 | @GET |
|---|
| 115 | 120 | @Path("/{licId}/download") |
|---|
| 116 | 121 | @Securable |
|---|
| 117 | | - @Produces({ MediaType.APPLICATION_OCTET_STREAM }) |
|---|
| 122 | + @Produces({ |
|---|
| 123 | + MediaType.APPLICATION_OCTET_STREAM |
|---|
| 124 | + }) |
|---|
| 118 | 125 | public Response download(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 119 | 126 | |
|---|
| 120 | 127 | EntityManager em = emProvider.get(); |
|---|
| .. | .. |
|---|
| 137 | 144 | @Securable |
|---|
| 138 | 145 | @Transactional |
|---|
| 139 | 146 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 140 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 147 | + @Produces({ |
|---|
| 148 | + MediaType.APPLICATION_JSON |
|---|
| 149 | + }) |
|---|
| 141 | 150 | public Response activate(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 142 | 151 | |
|---|
| 143 | 152 | EntityManager em = emProvider.get(); |
|---|
| .. | .. |
|---|
| 163 | 172 | @Securable |
|---|
| 164 | 173 | @Transactional |
|---|
| 165 | 174 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 166 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 175 | + @Produces({ |
|---|
| 176 | + MediaType.APPLICATION_JSON |
|---|
| 177 | + }) |
|---|
| 167 | 178 | public Response send(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 168 | 179 | |
|---|
| 169 | 180 | EntityManager em = emProvider.get(); |
|---|
| .. | .. |
|---|
| 183 | 194 | @Securable |
|---|
| 184 | 195 | @Transactional |
|---|
| 185 | 196 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 186 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 197 | + @Produces({ |
|---|
| 198 | + MediaType.APPLICATION_JSON |
|---|
| 199 | + }) |
|---|
| 187 | 200 | public Response cancel(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 188 | 201 | |
|---|
| 189 | 202 | EntityManager em = emProvider.get(); |
|---|
| .. | .. |
|---|
| 208 | 221 | @Path("/") |
|---|
| 209 | 222 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 210 | 223 | @Securable |
|---|
| 211 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 224 | + @Produces({ |
|---|
| 225 | + MediaType.APPLICATION_JSON |
|---|
| 226 | + }) |
|---|
| 212 | 227 | @Transactional |
|---|
| 213 | 228 | public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 214 | 229 | LOG.info("Creating new license from create()"); |
|---|
| .. | .. |
|---|
| 221 | 236 | return Response.status(Status.NOT_FOUND) |
|---|
| 222 | 237 | .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build(); |
|---|
| 223 | 238 | } else { |
|---|
| 224 | | - if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) { |
|---|
| 225 | | - if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) { |
|---|
| 226 | | - LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal()); |
|---|
| 227 | | - return Response.status(Status.UNAUTHORIZED) |
|---|
| 228 | | - .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build(); |
|---|
| 229 | | - } |
|---|
| 239 | + if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN) && !bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) { |
|---|
| 240 | + LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal()); |
|---|
| 241 | + return Response.status(Status.UNAUTHORIZED) |
|---|
| 242 | + .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build(); |
|---|
| 230 | 243 | } |
|---|
| 231 | 244 | } |
|---|
| 232 | 245 | } |
|---|
| .. | .. |
|---|
| 248 | 261 | @Path("/") |
|---|
| 249 | 262 | @Consumes(MediaType.MULTIPART_FORM_DATA) |
|---|
| 250 | 263 | @Securable |
|---|
| 251 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 264 | + @Produces({ |
|---|
| 265 | + MediaType.APPLICATION_JSON |
|---|
| 266 | + }) |
|---|
| 252 | 267 | @Transactional |
|---|
| 253 | 268 | public Response createWithFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException { |
|---|
| 254 | 269 | License lic = new License(); |
|---|
| .. | .. |
|---|
| 268 | 283 | @Securable |
|---|
| 269 | 284 | @Transactional |
|---|
| 270 | 285 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 271 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 286 | + @Produces({ |
|---|
| 287 | + MediaType.APPLICATION_JSON |
|---|
| 288 | + }) |
|---|
| 272 | 289 | public Response modify(License lic, @PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 273 | 290 | LOG.info("Modifying organization with id: {}", licId); |
|---|
| 274 | 291 | |
|---|
| .. | .. |
|---|
| 290 | 307 | @Path("/{licId}") |
|---|
| 291 | 308 | @Transactional |
|---|
| 292 | 309 | @Securable |
|---|
| 293 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 310 | + @Produces({ |
|---|
| 311 | + MediaType.APPLICATION_JSON |
|---|
| 312 | + }) |
|---|
| 294 | 313 | public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 295 | 314 | LOG.info("Deleting license with id: {}", licId); |
|---|
| 296 | 315 | EntityManager em = emProvider.get(); |
|---|
| .. | .. |
|---|
| 317 | 336 | LOG.error("License with id {} not found in DB", licId); |
|---|
| 318 | 337 | throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "License not found for ID: " + licId); |
|---|
| 319 | 338 | } |
|---|
| 320 | | - if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) { |
|---|
| 321 | | - if (!bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) { |
|---|
| 322 | | - LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal()); |
|---|
| 323 | | - throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data"); |
|---|
| 324 | | - } |
|---|
| 339 | + if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN) && !bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) { |
|---|
| 340 | + LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal()); |
|---|
| 341 | + throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data"); |
|---|
| 325 | 342 | } |
|---|
| 326 | 343 | return lic; |
|---|
| 327 | 344 | } |
|---|