Use UriInfo and URIBuilder for generating URI for created responses
parent
10da2f6ef6
commit
a72ec4e8d9
|
|
@ -53,6 +53,9 @@ import org.libreccm.security.User;
|
|||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -61,6 +64,9 @@ import java.util.stream.Collectors;
|
|||
@Path("/groups")
|
||||
public class GroupsApi {
|
||||
|
||||
@Context
|
||||
private UriInfo uriInfo;
|
||||
|
||||
@Inject
|
||||
private GroupManager groupManager;
|
||||
|
||||
|
|
@ -139,11 +145,12 @@ public class GroupsApi {
|
|||
groupRepository.save(group);
|
||||
|
||||
return Response
|
||||
.status(Response.Status.CREATED)
|
||||
.contentLocation(
|
||||
URI.create(String.format("/api/groups/%s", group.getName()))
|
||||
)
|
||||
.build();
|
||||
.created(
|
||||
uriInfo
|
||||
.getRequestUriBuilder()
|
||||
.path(group.getName())
|
||||
.build()
|
||||
).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
|
|
|
|||
|
|
@ -132,8 +132,12 @@ public class RolesApi {
|
|||
|
||||
roleRepository.save(role);
|
||||
|
||||
return Response.created(
|
||||
URI.create(String.format("/api/admin/roles/%s", role.getName()))
|
||||
return Response
|
||||
.created(
|
||||
uriInfo
|
||||
.getBaseUriBuilder()
|
||||
.path(role.getName())
|
||||
.build()
|
||||
).build();
|
||||
}
|
||||
|
||||
|
|
@ -317,14 +321,14 @@ public class RolesApi {
|
|||
permission = permissionManager.grantPrivilege(
|
||||
privilege, role, object
|
||||
);
|
||||
return Response.created(
|
||||
URI.create(
|
||||
String.format(
|
||||
"/api/admin/roles/%s/permissions/UUID-%s",
|
||||
role.getName(),
|
||||
permission.getUuid()
|
||||
)
|
||||
)
|
||||
return Response
|
||||
.created(
|
||||
uriInfo
|
||||
.getBaseUriBuilder()
|
||||
.path(role.getName())
|
||||
.path("permissions")
|
||||
.path(String.format("UUID-%s", permission.getUuid()))
|
||||
.build()
|
||||
).build();
|
||||
}
|
||||
} else {
|
||||
|
|
@ -340,14 +344,14 @@ public class RolesApi {
|
|||
} else {
|
||||
permission = permissionManager.grantPrivilege(privilege, role);
|
||||
|
||||
return Response.created(
|
||||
URI.create(
|
||||
String.format(
|
||||
"/api/admin/roles/%s/permissions/UUID-%s",
|
||||
role.getName(),
|
||||
permission.getUuid()
|
||||
)
|
||||
)
|
||||
return Response
|
||||
.created(
|
||||
uriInfo
|
||||
.getRequestUriBuilder()
|
||||
.path(role.getName())
|
||||
.path("permissions")
|
||||
.path(String.format("UUID-%s", permission.getUuid()))
|
||||
.build()
|
||||
).build();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,9 @@ import org.libreccm.security.UserRepository;
|
|||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
/**
|
||||
* Provides RESTful API endpoints for managing users. Access to all endpoints
|
||||
* defined by this class requires admin privileges.
|
||||
|
|
@ -65,6 +68,9 @@ import java.util.stream.Collectors;
|
|||
@Path("/users")
|
||||
public class UsersApi {
|
||||
|
||||
@Context
|
||||
private UriInfo uriInfo;
|
||||
|
||||
@Inject
|
||||
private GroupManager groupManager;
|
||||
|
||||
|
|
@ -221,12 +227,12 @@ public class UsersApi {
|
|||
);
|
||||
|
||||
return Response
|
||||
.status(Response.Status.CREATED)
|
||||
.contentLocation(
|
||||
URI.create(String.format("/api/users/%s", user.getName())
|
||||
)
|
||||
)
|
||||
.build();
|
||||
.created(
|
||||
uriInfo
|
||||
.getBaseUriBuilder()
|
||||
.path(user.getName())
|
||||
.build()
|
||||
).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue