diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/api/ApplicationRole.java | 25 | ||||
-rw-r--r-- | src/org/traccar/api/AuthorizationBasic.java | 4 | ||||
-rw-r--r-- | src/org/traccar/api/BaseResource.java | 3 | ||||
-rw-r--r-- | src/org/traccar/api/resource/DeviceResource.java | 12 | ||||
-rw-r--r-- | src/org/traccar/api/resource/UserResource.java | 11 | ||||
-rw-r--r-- | src/org/traccar/model/User.java | 3 |
6 files changed, 18 insertions, 40 deletions
diff --git a/src/org/traccar/api/ApplicationRole.java b/src/org/traccar/api/ApplicationRole.java deleted file mode 100644 index 4da5f6708..000000000 --- a/src/org/traccar/api/ApplicationRole.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed 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 org.traccar.api; - -public final class ApplicationRole { - - public static final String USER = "USER"; - public static final String ADMIN = "ADMIN"; - - private ApplicationRole() { - } -} diff --git a/src/org/traccar/api/AuthorizationBasic.java b/src/org/traccar/api/AuthorizationBasic.java index 807320940..291d0e5d6 100644 --- a/src/org/traccar/api/AuthorizationBasic.java +++ b/src/org/traccar/api/AuthorizationBasic.java @@ -77,9 +77,9 @@ public final class AuthorizationBasic { */ //Temporary solution - userPrincipal.getRoles().add(ApplicationRole.USER); + userPrincipal.getRoles().add(User.ROLE_USER); if (user.getAdmin()) { - userPrincipal.getRoles().add(ApplicationRole.ADMIN); + userPrincipal.getRoles().add(User.ROLE_ADMIN); } return true; } diff --git a/src/org/traccar/api/BaseResource.java b/src/org/traccar/api/BaseResource.java index 54d606ab6..6051fdb61 100644 --- a/src/org/traccar/api/BaseResource.java +++ b/src/org/traccar/api/BaseResource.java @@ -22,6 +22,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; import org.traccar.Context; import org.traccar.helper.Clazz; +import org.traccar.model.User; public class BaseResource<T, I> { @@ -45,7 +46,7 @@ public class BaseResource<T, I> { } public T getEntity(I id) { - validateSecurityContext(ApplicationRole.USER, id); + validateSecurityContext(User.ROLE_USER, id); T entity = Clazz.newInstance(clazz); try { Clazz.setId(entity, id); diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index 4152bcf81..98f1d1cca 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -28,8 +28,8 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.traccar.api.ApplicationRole; import org.traccar.model.Device; +import org.traccar.model.User; @Path("devices") @Produces(MediaType.APPLICATION_JSON) @@ -37,7 +37,7 @@ import org.traccar.model.Device; public class DeviceResource extends BaseResource<Device, Long> { @GET - @RolesAllowed(ApplicationRole.ADMIN) + @RolesAllowed(User.ROLE_ADMIN) @Override public Collection<Device> getEntities() { return super.getEntities(); @@ -45,14 +45,14 @@ public class DeviceResource extends BaseResource<Device, Long> { @GET @Path("{id}") - @RolesAllowed({ApplicationRole.ADMIN, ApplicationRole.USER}) + @RolesAllowed(User.ROLE_USER) @Override public Device getEntity(@PathParam("id") Long id) { return super.getEntity(id); } @POST - @RolesAllowed({ApplicationRole.ADMIN, ApplicationRole.USER}) + @RolesAllowed(User.ROLE_USER) @Override public Response postEntity(Device entity) { return super.postEntity(entity); @@ -60,7 +60,7 @@ public class DeviceResource extends BaseResource<Device, Long> { @PUT @Path("{id}") - @RolesAllowed({ApplicationRole.ADMIN, ApplicationRole.USER}) + @RolesAllowed(User.ROLE_USER) @Override public Response putEntity(@PathParam("id") Long id, Device entity) { return super.putEntity(id, entity); @@ -68,7 +68,7 @@ public class DeviceResource extends BaseResource<Device, Long> { @DELETE @Path("{id}") - @RolesAllowed({ApplicationRole.ADMIN, ApplicationRole.USER}) + @RolesAllowed(User.ROLE_USER) @Override public Response deleteEntity(@PathParam("id") Long id) { return super.deleteEntity(id); diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java index da615e052..d2964c983 100644 --- a/src/org/traccar/api/resource/UserResource.java +++ b/src/org/traccar/api/resource/UserResource.java @@ -27,7 +27,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.traccar.api.ApplicationRole; import org.traccar.api.BaseResource; import org.traccar.model.User; @@ -37,7 +36,7 @@ import org.traccar.model.User; public class UserResource extends BaseResource<User, Long> { @GET - @RolesAllowed(ApplicationRole.ADMIN) + @RolesAllowed(User.ROLE_ADMIN) @Override public Collection<User> getEntities() { return super.getEntities(); @@ -45,14 +44,14 @@ public class UserResource extends BaseResource<User, Long> { @GET @Path("{id}") - @RolesAllowed({ApplicationRole.ADMIN, ApplicationRole.USER}) + @RolesAllowed(User.ROLE_USER) @Override public User getEntity(@PathParam("id") Long id) { return super.getEntity(id); } @POST - @RolesAllowed({ApplicationRole.ADMIN, ApplicationRole.USER}) + @RolesAllowed(User.ROLE_USER) @Override public Response postEntity(User entity) { return super.postEntity(entity); @@ -60,7 +59,7 @@ public class UserResource extends BaseResource<User, Long> { @PUT @Path("{id}") - @RolesAllowed({ApplicationRole.ADMIN, ApplicationRole.USER}) + @RolesAllowed(User.ROLE_USER) @Override public Response putEntity(@PathParam("id") Long id, User entity) { return super.putEntity(id, entity); @@ -68,7 +67,7 @@ public class UserResource extends BaseResource<User, Long> { @DELETE @Path("{id}") - @RolesAllowed({ApplicationRole.ADMIN, ApplicationRole.USER}) + @RolesAllowed(User.ROLE_USER) @Override public Response deleteEntity(@PathParam("id") Long id) { return super.deleteEntity(id); diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java index 8ac9e9d32..1c404c38a 100644 --- a/src/org/traccar/model/User.java +++ b/src/org/traccar/model/User.java @@ -20,6 +20,9 @@ import org.traccar.web.JsonIgnore; public class User implements Factory { + public static final String ROLE_USER = "user"; + public static final String ROLE_ADMIN = "admin"; + @Override public User create() { return new User(); |