PublicAPIsv2 { @POST @Path("/api/servicedef/") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @Produces({ "application/json", "application/xml" }) public RangerServiceDef createServiceDef(RangerServiceDef serviceDef) { return serviceREST.createServiceDef(serviceDef); }  @POST @Path("/api/zones") RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone); @PUT @Path("/api/zones/{id}") RangerSecurityZone updateSecurityZone(@PathParam("id") Long zoneId, RangerSecurityZone securityZone); @DELETE @Path("/api/zones/name/{name}") void deleteSecurityZone(@PathParam("name") String zoneName); @DELETE @Path("/api/zones/{id}") void deleteSecurityZone(@PathParam("id") Long zoneId); @GET @Path("/api/zones/name/{name}") RangerSecurityZone getSecurityZone(@PathParam("name") String zoneName); @GET @Path("/api/zones/{id}") RangerSecurityZone getSecurityZone(@PathParam("id") Long id); @GET @Path("/api/zones") List<RangerSecurityZone> getAllZones(@Context HttpServletRequest request); @GET @Path("/api/servicedef/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @Produces({ "application/json", "application/xml" }) RangerServiceDef getServiceDef(@PathParam("id") Long id); @GET @Path("/api/servicedef/name/{name}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @Produces({ "application/json", "application/xml" }) RangerServiceDef getServiceDefByName(@PathParam("name") String name); @GET @Path("/api/servicedef/") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @Produces({ "application/json", "application/xml" }) List<RangerServiceDef> searchServiceDefs(@Context HttpServletRequest request); @POST @Path("/api/servicedef/") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @Produces({ "application/json", "application/xml" }) RangerServiceDef createServiceDef(RangerServiceDef serviceDef); @PUT @Path("/api/servicedef/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @Produces({ "application/json", "application/xml" }) RangerServiceDef updateServiceDef(RangerServiceDef serviceDef, @PathParam("id") Long id); @PUT @Path("/api/servicedef/name/{name}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @Produces({ "application/json", "application/xml" }) RangerServiceDef updateServiceDefByName(RangerServiceDef serviceDef,
	                                     @PathParam("name") String name); @DELETE @Path("/api/servicedef/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteServiceDef(@PathParam("id") Long id, @Context HttpServletRequest request); @DELETE @Path("/api/servicedef/name/{name}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteServiceDefByName(@PathParam("name") String name, @Context HttpServletRequest request); @GET @Path("/api/service/{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()") RangerService getService(@PathParam("id") Long id); @GET @Path("/api/service/name/{name}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()") RangerService getServiceByName(@PathParam("name") String name); @GET @Path("/api/service/") @Produces({ "application/json", "application/xml" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()") List<RangerService> searchServices(@Context HttpServletRequest request); @POST @Path("/api/service/") @PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()") @Produces({ "application/json", "application/xml" }) RangerService createService(RangerService service); @PUT @Path("/api/service/{id}") @PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()") @Produces({ "application/json", "application/xml" }) RangerService updateService(RangerService service, @PathParam("id") Long id,
                                       @Context HttpServletRequest request); @PUT @Path("/api/service/name/{name}") @PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()") @Produces({ "application/json", "application/xml" }) RangerService updateServiceByName(RangerService service,
                                             @PathParam("name") String name,
                                             @Context HttpServletRequest request); @DELETE @Path("/api/service/{id}") @PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()") void deleteService(@PathParam("id") Long id); @DELETE @Path("/api/service/name/{name}") @PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()") void deleteServiceByName(@PathParam("name") String name); @GET @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) RangerPolicy getPolicy(@PathParam("id") Long id); @GET @Path("/api/policy/") @Produces({ "application/json", "application/xml" }) List<RangerPolicy> getPolicies(@Context HttpServletRequest request); @GET @Path("/api/service/{servicename}/policy/{policyname}") @Produces({ "application/json", "application/xml" }) RangerPolicy getPolicyByName(@PathParam("servicename") String serviceName,
	                                    @PathParam("policyname") String policyName,
	                                    @Context HttpServletRequest request); @GET @Path("/api/service/{servicename}/policy/") @Produces({ "application/json", "application/xml" }) List<RangerPolicy> searchPolicies(@PathParam("servicename") String serviceName,
	                                         @Context HttpServletRequest request); @GET @Path("/api/policies/{serviceDefName}/for-resource/") @Produces({ "application/json", "application/xml" }) List<RangerPolicy> getPoliciesForResource(@PathParam("serviceDefName") String serviceDefName,
													 @DefaultValue("") @QueryParam("serviceName") String serviceName,
													 @Context HttpServletRequest request); @POST @Path("/api/policy/") @Produces({ "application/json", "application/xml" }) RangerPolicy createPolicy(RangerPolicy policy , @Context HttpServletRequest request); @POST @Path("/api/policy/apply/") @Produces({ "application/json", "application/xml" }) RangerPolicy applyPolicy(RangerPolicy policy, @Context HttpServletRequest request); @PUT @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) RangerPolicy updatePolicy(RangerPolicy policy, @PathParam("id") Long id); @PUT @Path("/api/service/{servicename}/policy/{policyname}") @Produces({ "application/json", "application/xml" }) RangerPolicy updatePolicyByName(RangerPolicy policy,
	                                               @PathParam("servicename") String serviceName,
	                                               @PathParam("policyname") String policyName,
	                                               @Context HttpServletRequest request); @DELETE @Path("/api/policy/{id}") void deletePolicy(@PathParam("id") Long id); @DELETE @Path("/api/policy") void deletePolicyByName(@QueryParam("servicename") String serviceName,
	                               @QueryParam("policyname") String policyName,
	                               @Context HttpServletRequest request); @GET @Path("/api/plugins/info") List<RangerPluginInfo> getPluginsInfo(@Context HttpServletRequest request); @DELETE @Path("/api/server/policydeltas") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deletePolicyDeltas(@DefaultValue("7") @QueryParam("days") Integer olderThan, @Context HttpServletRequest request); @DELETE @Path("/api/server/tagdeltas") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTagDeltas(@DefaultValue("7") @QueryParam("days") Integer olderThan, @Context HttpServletRequest request); @DELETE @Path("/api/server/purgepolicies/{serviceName}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void purgeEmptyPolicies(@PathParam("serviceName") String serviceName, @Context HttpServletRequest request); @POST @Path("/api/roles") @Produces({ "application/json", "application/xml" }) RangerRole createRole(@QueryParam("serviceName") String serviceName, RangerRole role
			, @DefaultValue("false") @QueryParam("createNonExistUserGroup") Boolean createNonExistUserGroup
			, @Context HttpServletRequest request); @PUT @Path("/api/roles/{id}") @Produces({ "application/json", "application/xml" }) RangerRole updateRole(@PathParam("id") Long roleId, RangerRole role
			, @DefaultValue("false") @QueryParam("createNonExistUserGroup") Boolean createNonExistUserGroup
			, @Context HttpServletRequest request); @DELETE @Path("/api/roles/name/{name}") void deleteRole(@QueryParam("serviceName") String serviceName, @QueryParam("execUser") String userName, @PathParam("name") String roleName, @Context HttpServletRequest request); @DELETE @Path("/api/roles/{id}") void deleteRole(@PathParam("id") Long roleId, @Context HttpServletRequest request); @GET @Path("/api/roles/name/{name}") @Produces({ "application/json", "application/xml" }) RangerRole getRole(@QueryParam("serviceName") String serviceName, @QueryParam("execUser") String userName, @PathParam("name") String roleName, @Context HttpServletRequest request); @GET @Path("/api/roles/{id}") @Produces({ "application/json", "application/xml" }) RangerRole getRole(@PathParam("id") Long id, @Context HttpServletRequest request); @GET @Path("/api/roles") @Produces({ "application/json", "application/xml" }) List<RangerRole> getAllRoles(@Context HttpServletRequest request); @GET @Path("/api/roles/names") @Produces({ "application/json", "application/xml" }) List<String> getAllRoleNames(@QueryParam("serviceName") String serviceName, @QueryParam("execUser") String userName, @Context HttpServletRequest request); @GET @Path("/api/roles/user/{user}") @Produces({ "application/json", "application/xml" }) List<String> getUserRoles(@PathParam("user") String userName, @Context HttpServletRequest request); @PUT @Path("/api/roles/{id}/addUsersAndGroups") RangerRole addUsersAndGroups(@PathParam("id") Long roleId, List<String> users, List<String> groups, Boolean isAdmin, @Context HttpServletRequest request); @PUT @Path("/api/roles/{id}/removeUsersAndGroups") RangerRole removeUsersAndGroups(@PathParam("id") Long roleId, List<String> users, List<String> groups, @Context HttpServletRequest request); @PUT @Path("/api/roles/{id}/removeAdminFromUsersAndGroups") RangerRole removeAdminFromUsersAndGroups(@PathParam("id") Long roleId, List<String> users, List<String> groups, @Context HttpServletRequest request); @PUT @Path("/api/roles/grant/{serviceName}") @Consumes({ "application/json", "application/xml" }) @Produces({ "application/json", "application/xml" }) RESTResponse grantRole(@PathParam("serviceName") String serviceName, GrantRevokeRoleRequest grantRoleRequest, @Context HttpServletRequest request); @PUT @Path("/api/roles/revoke/{serviceName}") @Consumes({ "application/json", "application/xml" }) @Produces({ "application/json", "application/xml" }) RESTResponse revokeRoleUsersAndRoles(@PathParam("serviceName") String serviceName, GrantRevokeRoleRequest revokeRoleRequest, @Context HttpServletRequest request);  }
@Test public void test4createServiceDef() throws Exception { RangerServiceDef rangerServiceDef = rangerServiceDef(); Mockito.when(serviceREST.createServiceDef(rangerServiceDef)).thenReturn(rangerServiceDef); RangerServiceDef dbRangerServiceDef = publicAPIsv2.createServiceDef(rangerServiceDef); Assert.assertNotNull(dbRangerServiceDef); Assert.assertEquals(dbRangerServiceDef, rangerServiceDef); Assert.assertEquals(dbRangerServiceDef.getId(), rangerServiceDef.getId()); Assert.assertEquals(dbRangerServiceDef.getName(), rangerServiceDef.getName()); Mockito.verify(serviceREST).createServiceDef(rangerServiceDef); }