use of org.springframework.web.bind.annotation.PathVariable in project alien4cloud by alien4cloud.
the class AbstractLocationResourcesSecurityController method grantAccessToUsers.
/**
*****************************************************************************************************************************
*
* SECURITY ON USERS
*
******************************************************************************************************************************
*/
/**
* Grant access to the location resoure to the user (deploy on the location)
*
* @param locationId The location's id.
* @param resourceId The location resource's id.
* @param userNames The authorized users.
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Grant access to the location's resource to the users, send back the new authorised users list", notes = "Only user with ADMIN role can grant access to another users.")
@RequestMapping(value = "/users", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<List<UserDTO>> grantAccessToUsers(@PathVariable String orchestratorId, @PathVariable String locationId, @PathVariable String resourceId, @RequestBody String[] userNames) {
Location location = locationService.getLocation(orchestratorId, locationId);
locationSecurityService.grantAuthorizationOnLocationIfNecessary(location, Subject.USER, userNames);
AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
// prefer using locationResourceService.saveResource so that the location update date is update.
// This will then trigger a deployment topology update
resourcePermissionService.grantPermission(resourceTemplate, (resource -> locationResourceService.saveResource(location, (AbstractLocationResourceTemplate) resource)), Subject.USER, userNames);
List<UserDTO> users = UserDTO.convert(resourcePermissionService.getAuthorizedUsers(resourceTemplate));
return RestResponseBuilder.<List<UserDTO>>builder().data(users).build();
}
use of org.springframework.web.bind.annotation.PathVariable in project alien4cloud by alien4cloud.
the class AbstractLocationResourcesSecurityController method grantAccessToGroups.
/**
*****************************************************************************************************************************
*
* SECURITY ON GROUPS
*
******************************************************************************************************************************
*/
/**
* Grant access to the location resource to the groups
*
* @param locationId The location's id.
* @param groupIds The authorized groups.
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Grant access to the location to the groups", notes = "Only user with ADMIN role can grant access to a group.")
@RequestMapping(value = "/groups", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<List<GroupDTO>> grantAccessToGroups(@PathVariable String orchestratorId, @PathVariable String locationId, @PathVariable String resourceId, @RequestBody String[] groupIds) {
Location location = locationService.getLocation(orchestratorId, locationId);
locationSecurityService.grantAuthorizationOnLocationIfNecessary(location, Subject.GROUP, groupIds);
AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
resourcePermissionService.grantPermission(resourceTemplate, (resource -> locationResourceService.saveResource(location, (AbstractLocationResourceTemplate) resource)), Subject.GROUP, groupIds);
List<GroupDTO> groups = GroupDTO.convert(resourcePermissionService.getAuthorizedGroups(resourceTemplate));
return RestResponseBuilder.<List<GroupDTO>>builder().data(groups).build();
}
use of org.springframework.web.bind.annotation.PathVariable in project spring-boot-admin by codecentric.
the class InstancesProxyController method endpointProxy.
@ResponseBody
@RequestMapping(path = INSTANCE_MAPPED_PATH, method = { RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS })
public void endpointProxy(@PathVariable("instanceId") String instanceId, HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
ServletServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
Flux<DataBuffer> requestBody = DataBufferUtils.readInputStream(request::getBody, this.bufferFactory, 4096);
InstanceWebProxy.ForwardRequest fwdRequest = createForwardRequest(request, requestBody, this.adminContextPath + INSTANCE_MAPPED_PATH);
this.instanceWebProxy.forward(this.registry.getInstance(InstanceId.of(instanceId)), fwdRequest, (clientResponse) -> {
ServerHttpResponse response = new ServletServerHttpResponse(servletResponse);
response.setStatusCode(clientResponse.statusCode());
response.getHeaders().addAll(this.httpHeadersFilter.filterHeaders(clientResponse.headers().asHttpHeaders()));
try {
OutputStream responseBody = response.getBody();
response.flush();
return clientResponse.body(BodyExtractors.toDataBuffers()).window(1).concatMap((body) -> writeAndFlush(body, responseBody)).then();
} catch (IOException ex) {
return Mono.error(ex);
}
}).block();
}
use of org.springframework.web.bind.annotation.PathVariable in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolver method createNamedValueInfo.
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
Assert.state(ann != null, "No PathVariable annotation");
return new PathVariableNamedValueInfo(ann);
}
use of org.springframework.web.bind.annotation.PathVariable in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolver method contributeMethodArgument.
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
return;
}
PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
String name = (ann != null && StringUtils.hasLength(ann.value()) ? ann.value() : parameter.getParameterName());
String formatted = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value);
uriVariables.put(name, formatted);
}
Aggregations