下面列出了javax.ws.rs.NotSupportedException#javax.ws.rs.core.SecurityContext 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
requestContext.setSecurityContext(new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return () -> USER_NAME;
}
@Override
public boolean isUserInRole(String string) {
return true;
}
@Override
public boolean isSecure() { return true; }
@Override
public String getAuthenticationScheme() { return "BASIC"; }
});
}
@GET
@Path("/rest/organizations/{organization}/pipelines/{pipeline}/runs")
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "", notes = "Retrieve all runs details for an organization pipeline", response = PipelineRuns.class, authorizations = {
@io.swagger.annotations.Authorization(value = "jenkins_auth")
}, tags={ "blueOcean", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successfully retrieved runs details", response = PipelineRuns.class),
@io.swagger.annotations.ApiResponse(code = 401, message = "Authentication failed - incorrect username and/or password", response = Void.class),
@io.swagger.annotations.ApiResponse(code = 403, message = "Jenkins requires authentication - please set username and password", response = Void.class) })
public Response getPipelineRuns( @PathParam("organization") String organization, @PathParam("pipeline") String pipeline,@Context SecurityContext securityContext)
throws NotFoundException {
return service.getPipelineRuns(organization,pipeline,securityContext);
}
@POST
@Path("/{name}.rw.html")
@io.swagger.annotations.ApiOperation(value = "", notes = "", response = Void.class, authorizations = {
@io.swagger.annotations.Authorization(value = "aemAuth")
}, tags={ "sling", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Default response", response = Void.class) })
public Response postNodeRw(@ApiParam(value = "",required=true) @PathParam("path") String path
,@ApiParam(value = "",required=true) @PathParam("name") String name
,@ApiParam(value = "") @QueryParam("addMembers") String addMembers
,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.postNodeRw(path,name,addMembers,securityContext);
}
@GET
@Path("/schemas/{name}/branches")
@ApiOperation(value = "Get list of registered schema branches",
response = SchemaBranch.class, responseContainer = "List",
tags = OPERATION_GROUP_OTHER)
@Timed
@UnitOfWork
public Response getAllBranches(@ApiParam(value = "Details about schema name",required = true) @PathParam("name") String schemaName,
@Context UriInfo uriInfo,
@Context SecurityContext securityContext) {
try {
Collection<SchemaBranch> schemaBranches = authorizationAgent.authorizeGetAllBranches(AuthorizationUtils.getUserAndGroups(securityContext),
schemaRegistry, schemaName, schemaRegistry.getSchemaBranches(schemaName));
return WSUtils.respondEntities(schemaBranches, Response.Status.OK);
} catch(SchemaNotFoundException e) {
return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaName);
} catch (Exception ex) {
LOG.error("Encountered error while listing schema branches", ex);
return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
}
}
@POST
@Path("/services/{serviceId}/configurations")
@Timed
public Response addServiceConfiguration(@PathParam("serviceId") Long serviceId, ServiceConfiguration serviceConfiguration,
@Context SecurityContext securityContext) {
SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, getClusterId(serviceId), WRITE);
// just overwrite the service id to given path param
serviceConfiguration.setServiceId(serviceId);
Service service = environmentService.getService(serviceId);
if (service == null) {
throw EntityNotFoundException.byId("service: " + serviceId.toString());
}
String configurationName = serviceConfiguration.getName();
ServiceConfiguration result = environmentService.getServiceConfigurationByName(serviceId, configurationName);
if (result != null) {
throw EntityAlreadyExistsException.byName("service id " +
serviceId + " and configuration name " + configurationName);
}
ServiceConfiguration createdConfiguration = environmentService.addServiceConfiguration(serviceConfiguration);
return WSUtils.respondEntity(createdConfiguration, CREATED);
}
@PUT
@Path("/services/{serviceId}/components")
@Timed
public Response addOrUpdateComponent(@PathParam("serviceId") Long serviceId, Component component,
@Context SecurityContext securityContext) {
SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, getClusterId(serviceId), WRITE);
// overwrite service id to given path param
component.setServiceId(serviceId);
Service service = environmentService.getService(serviceId);
if (service == null) {
throw EntityNotFoundException.byId("service: " + serviceId.toString());
}
Component createdComponent = environmentService.addOrUpdateComponent(serviceId, component);
return WSUtils.respondEntity(createdComponent, CREATED);
}
@POST
@Path("/topologies/{topologyId}/versions/{versionId}/actions/suspend")
@Timed
public Response suspendTopologyVersion(@PathParam("topologyId") Long topologyId,
@PathParam("versionId") Long versionId,
@Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN,
NAMESPACE, topologyId, READ, EXECUTE);
Topology result = catalogService.getTopology(topologyId, versionId);
if (result != null) {
actionsService.suspendTopology(result, WSUtils.getUserFromSecurityContext(securityContext));
return WSUtils.respondEntity(result, OK);
}
throw EntityNotFoundException.byVersion(topologyId.toString(), versionId.toString());
}
@GET
@Path("/rest/users/{user}/favorites")
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "", notes = "Retrieve user favorites details for an organization", response = UserFavorites.class, authorizations = {
@io.swagger.annotations.Authorization(value = "jenkins_auth")
}, tags={ "blueOcean", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successfully retrieved users favorites details", response = UserFavorites.class),
@io.swagger.annotations.ApiResponse(code = 401, message = "Authentication failed - incorrect username and/or password", response = Void.class),
@io.swagger.annotations.ApiResponse(code = 403, message = "Jenkins requires authentication - please set username and password", response = Void.class) })
public Response getUserFavorites( @PathParam("user") String user,@Context SecurityContext securityContext)
throws NotFoundException {
return service.getUserFavorites(user,securityContext);
}
@POST
@Path("/{petId}/uploadImage")
@Consumes({ "multipart/form-data" })
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "uploads an image", notes = "", response = ModelApiResponse.class, authorizations = {
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
})
}, tags={ "pet", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
public Response uploadFile(@ApiParam(value = "ID of pet to update", required = true) @PathParam("petId") @NotNull Long petId
,@ApiParam(value = "Additional data to pass to server")@FormDataParam("additionalMetadata") String additionalMetadata
,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail
,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.uploadFile(petId, additionalMetadata, fileInputStream, fileDetail, securityContext);
}
@POST
@Path("/{questionnaireId}/answer")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Allow the respondent save answers")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"),
@ApiResponse(code = 200, message = "Answer saved correctly") })
public Response saveAnswer(@ApiParam(value = "Answer", required = true)
Answer answer, @Context
final SecurityContext context, @PathParam("questionnaireId")
@ApiParam(value = "Questionnair id", required = true)
Integer questionnaireId, @QueryParam("questionCode")
@ApiParam(value = "Question Code", required = true)
String questionCode) {
logger.debug("New attempt for saving answer from {}", context.getUserPrincipal().getName());
try {
questionnairFacade.saveAnswer(questionnaireId, questionCode, answer);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
}
return Response.ok().build();
}
@GET
@RolesAllowed("standardRole")
@Path("principal-secured")
public String getPrincipalSecured(@Context SecurityContext sec) {
if (principal == null) {
throw new IllegalStateException("No injected principal");
}
String name = principal.getName();
return name;
}
@POST
@Path("/outer/composite")
@Produces({ "*/*" })
@io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of object with outer number type", response = OuterComposite.class, tags={ "fake", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Output composite", response = OuterComposite.class) })
public Response fakeOuterCompositeSerialize(@ApiParam(value = "Input composite as post body") @Valid OuterComposite body
,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.fakeOuterCompositeSerialize(body, securityContext);
}
@GET
@Path("/login")
@Produces({ "application/xml", "application/json" })
@io.swagger.annotations.ApiOperation(value = "Logs user into the system", notes = "", response = String.class, tags={ "user", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = String.class),
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid username/password supplied", response = Void.class) })
public Response loginUser(@ApiParam(value = "The user name for login", required = true) @QueryParam("username") @NotNull String username
,@ApiParam(value = "The password for login in clear text", required = true) @QueryParam("password") @NotNull String password
,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.loginUser(username, password, securityContext);
}
private boolean isAccessAllowed(List<Role> allowedRoles, SecurityContext securityContext) {
for (Role allowedRole : allowedRoles) {
if (securityContext.isUserInRole(allowedRole.name())) {
return true;
}
}
return false;
}
@GET
@Path("/rest/organizations/{organization}/pipelines/{folder}/pipelines/{pipeline}")
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "", notes = "Retrieve pipeline details for an organization folder", response = PipelineImpl.class, authorizations = {
@io.swagger.annotations.Authorization(value = "jenkins_auth")
}, tags={ "blueOcean", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successfully retrieved pipeline details", response = PipelineImpl.class),
@io.swagger.annotations.ApiResponse(code = 401, message = "Authentication failed - incorrect username and/or password", response = Void.class),
@io.swagger.annotations.ApiResponse(code = 403, message = "Jenkins requires authentication - please set username and password", response = Void.class) })
public Response getPipelineFolderPipeline( @PathParam("organization") String organization, @PathParam("pipeline") String pipeline, @PathParam("folder") String folder,@Context SecurityContext securityContext);
@Test
public void filter_CogUserPoolAndIamPossibleAndAllAllowed_ShouldSetScWithCogUserPoolPrincipal() {
GatewayRequest request = new GatewayRequestBuilder()
.prepareCognitoUserPoolRequest(true)
.prepareIamRequest(true)
.build();
SecurityContext sc = filter(request);
assertCognitoUserPoolPrincipal(sc.getUserPrincipal());
}
@Test
public void getArticle_NonSupportedAccept_ShouldReturnNotAcceptable() throws IOException {
when(testService.getArticle(1)).thenReturn("some article");
JRestlessResponseWriter responseWriter = createResponseWriterMock();
TestRequest req = new TestRequest("/articles/1", "GET");
req.getHeadersAsMultimap().add("Accept", MediaType.APPLICATION_XML);
container.handleRequest(req, responseWriter, mock(SecurityContext.class));
verify(responseWriter, times(1)).writeResponse(eq(Status.NOT_ACCEPTABLE), any(), emptyBaos());
}
@GET
@Path("/inventory")
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = {
@io.swagger.annotations.Authorization(value = "api_key")
}, tags={ "store", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Map.class, responseContainer = "Map") })
public Response getInventory(
@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.getInventory(securityContext);
}
@Path("/pipeline/{pipelineId}/stop")
@POST
@ApiOperation(value = "Stop Pipeline", response = PipelineStateJson.class,
authorizations = @Authorization(value = "basic"))
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({
AuthzRole.MANAGER,
AuthzRole.ADMIN,
AuthzRole.MANAGER_REMOTE,
AuthzRole.ADMIN_REMOTE
})
public Response stopPipeline(
@PathParam("pipelineId") String pipelineId,
@QueryParam("rev") @DefaultValue("0") String rev,
@Context SecurityContext context
) throws PipelineException {
PipelineInfo pipelineInfo = store.getInfo(pipelineId);
RestAPIUtils.injectPipelineInMDC(pipelineInfo.getTitle(), pipelineInfo.getPipelineId());
if (manager.isRemotePipeline(pipelineId, rev) && !context.isUserInRole(AuthzRole.ADMIN) &&
!context.isUserInRole(AuthzRole.ADMIN_REMOTE)) {
throw new PipelineException(ContainerError.CONTAINER_01101, "STOP_PIPELINE", pipelineId);
}
Runner runner = manager.getRunner(pipelineId, rev);
Utils.checkState(runner.getState().getExecutionMode() != ExecutionMode.SLAVE,
"This operation is not supported in SLAVE mode");
runner.stop(user);
return Response.ok()
.type(MediaType.APPLICATION_JSON)
.entity(BeanHelper.wrapPipelineState(runner.getState())).build();
}
@ResourceSecurity(WEB_UI)
@POST
@Path(UI_LOGIN)
public Response login(
@FormParam("username") String username,
@FormParam("password") String password,
@FormParam("redirectPath") String redirectPath,
@Context SecurityContext securityContext)
{
username = emptyToNull(username);
password = emptyToNull(password);
redirectPath = emptyToNull(redirectPath);
if (!formWebUiAuthenticationManager.isAuthenticationEnabled(securityContext.isSecure())) {
return Response.seeOther(DISABLED_LOCATION_URI).build();
}
Optional<NewCookie> authenticationCookie = formWebUiAuthenticationManager.checkLoginCredentials(username, password, securityContext.isSecure());
if (!authenticationCookie.isPresent()) {
// authentication failed, redirect back to the login page
return Response.seeOther(LOGIN_FORM_URI).build();
}
return redirectFromSuccessfulLoginResponse(redirectPath)
.cookie(authenticationCookie.get())
.build();
}
@GET
@Path("/rest/search/")
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "", notes = "Search for any resource details", response = String.class, authorizations = {
@io.swagger.annotations.Authorization(value = "jenkins_auth")
}, tags={ "blueOcean", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successfully retrieved search result", response = String.class),
@io.swagger.annotations.ApiResponse(code = 401, message = "Authentication failed - incorrect username and/or password", response = Void.class),
@io.swagger.annotations.ApiResponse(code = 403, message = "Jenkins requires authentication - please set username and password", response = Void.class) })
public Response search( @NotNull @QueryParam("q") String q,@Context SecurityContext securityContext);
@GET
@Path("/rest/organizations/{organization}/scm/{scm}")
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "", notes = "Retrieve SCM details for an organization", response = GithubScm.class, authorizations = {
@io.swagger.annotations.Authorization(value = "jenkins_auth")
}, tags={ "blueOcean", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successfully retrieved SCM details", response = GithubScm.class),
@io.swagger.annotations.ApiResponse(code = 401, message = "Authentication failed - incorrect username and/or password", response = Void.class),
@io.swagger.annotations.ApiResponse(code = 403, message = "Jenkins requires authentication - please set username and password", response = Void.class) })
public Response getSCM( @PathParam("organization") String organization, @PathParam("scm") String scm,@Context SecurityContext securityContext);
@GET
@Path("/networks/network/{networkId}/node/{nodeId}/")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "Retrieve node by ID", notes = "Retrieve operation of resource: node", response = NodeSchema.class, tags={ })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successful operation", response = NodeSchema.class),
@io.swagger.annotations.ApiResponse(code = 400, message = "Internal Error", response = NodeSchema.class) })
public Response retrieveNetworksNetworkNodeNodeById(
@ApiParam(value = "ID of networkId",required=true) @PathParam("networkId") String networkId,
@ApiParam(value = "ID of nodeId",required=true) @PathParam("nodeId") String nodeId,
@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.retrieveNetworksNetworkNodeNodeById(networkId,nodeId,securityContext);
}
@DELETE
@Path("/{petId}")
@io.swagger.annotations.ApiOperation(value = "Deletes a pet", notes = "", response = Void.class, authorizations = {
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
})
}, tags={ "pet", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) })
public Response deletePet( @PathParam("petId") Long petId, @ApiParam(value = "" ) @HeaderParam("api_key") String apiKey,@Context SecurityContext securityContext);
@PATCH
@Consumes({ "application/json" })
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "To test class name in snake case", notes = "To test class name in snake case", response = Client.class, authorizations = {
@io.swagger.annotations.Authorization(value = "api_key_query")
}, tags={ "fake_classname_tags 123#$%^", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Client.class) })
public Response testClassname(@ApiParam(value = "client model", required = true) @NotNull @Valid Client body
,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.testClassname(body, securityContext);
}
@GET()
@Path("permit-all")
@PermitAll
@Produces(MediaType.TEXT_PLAIN)
public String hello(@Context SecurityContext ctx) {
Principal caller = ctx.getUserPrincipal();
String name = caller == null ? "anonymous" : caller.getName();
String helloReply = String.format("hello + %s, isSecure: %s, authScheme: %s", name, ctx.isSecure(),
ctx.getAuthenticationScheme());
return helloReply;
}
@PUT
@Path("/namespaces/{id}")
@Timed
public Response addOrUpdateNamespace(@PathParam("id") Long namespaceId,
Namespace namespace, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN,
Namespace.NAMESPACE, namespaceId, WRITE);
try {
Namespace newNamespace = environmentService.addOrUpdateNamespace(namespaceId, namespace);
return WSUtils.respondEntity(newNamespace, OK);
} catch (ProcessingException ex) {
throw BadRequestException.of();
}
}
@PUT
@Path("/acls/{id}")
@Timed
public Response addOrUpdateAcl(@PathParam("id") Long aclId, AclEntry aclEntry, @Context SecurityContext securityContext) {
mayBeFillSidId(aclEntry);
checkAclOp(aclEntry, securityContext, this::shouldAllowAclAddOrUpdate);
AclEntry newAclEntry = catalogService.addOrUpdateAcl(aclId, aclEntry);
return WSUtils.respondEntity(newAclEntry, OK);
}
@GET
@Path("/inventory")
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = {
@io.swagger.annotations.Authorization(value = "api_key")
}, tags={ "store", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Map.class, responseContainer = "Map") })
public Response getInventory(@Context SecurityContext securityContext);
@POST
@Path("/roles")
@Timed
public Response addRole(Role role, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
Role createdRole = catalogService.addRole(role);
return WSUtils.respondEntity(createdRole, CREATED);
}