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