diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetFilterQueryClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetFilterQueryClientResource.java new file mode 100644 index 000000000..8881e6476 --- /dev/null +++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetFilterQueryClientResource.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.mgmt.client.resource; + +import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi; +import org.springframework.cloud.netflix.feign.FeignClient; + +/** + * Client binding for the Target filter query resource of the management API. + */ +@FeignClient(name = "MgmtTargetFilterQueryClient", url = "${hawkbit.url:localhost:8080}") +public interface MgmtTargetFilterQueryClientResource extends MgmtTargetFilterQueryRestApi { +} diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetFilterQueryBuilder.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetFilterQueryBuilder.java new file mode 100644 index 000000000..ddda6dcac --- /dev/null +++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetFilterQueryBuilder.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.mgmt.client.resource.builder; + +import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody; + +/** + * Builder pattern for building {@link MgmtTargetFilterQueryRequestBody}. + */ +// Exception squid:S1701 - builder pattern +@SuppressWarnings({ "squid:S1701" }) +public class TargetFilterQueryBuilder { + + private String name; + private String query; + + /** + * @param name + * the name of the filter + * @return the builder itself + */ + public TargetFilterQueryBuilder name(final String name) { + this.name = name; + return this; + } + + /** + * @param query + * the query filter + * @return the builder itself + */ + public TargetFilterQueryBuilder query(final String query) { + this.query = query; + return this; + } + + /** + * Builds a single entry of {@link MgmtTargetFilterQueryRequestBody} which + * can directly be used to post on the RESTful-API. + * + * @return a single entry of {@link MgmtTargetFilterQueryRequestBody} + */ + public MgmtTargetFilterQueryRequestBody build() { + final MgmtTargetFilterQueryRequestBody body = new MgmtTargetFilterQueryRequestBody(); + body.setName(name); + body.setQuery(query); + return body; + } +} diff --git a/hawkbit-ddi-dl-api/src/main/java/org/eclipse/hawkbit/ddi/dl/rest/api/DdiDlArtifactStoreControllerRestApi.java b/hawkbit-ddi-dl-api/src/main/java/org/eclipse/hawkbit/ddi/dl/rest/api/DdiDlArtifactStoreControllerRestApi.java index 4f6ddeab1..19b9962a3 100644 --- a/hawkbit-ddi-dl-api/src/main/java/org/eclipse/hawkbit/ddi/dl/rest/api/DdiDlArtifactStoreControllerRestApi.java +++ b/hawkbit-ddi-dl-api/src/main/java/org/eclipse/hawkbit/ddi/dl/rest/api/DdiDlArtifactStoreControllerRestApi.java @@ -12,7 +12,6 @@ import java.io.InputStream; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -43,7 +42,7 @@ public interface DdiDlArtifactStoreControllerRestApi { + "/{fileName}") @ResponseBody ResponseEntity downloadArtifactByFilename(@PathVariable("tenant") final String tenant, - @PathVariable("fileName") final String fileName, @AuthenticationPrincipal final Object principal); + @PathVariable("fileName") final String fileName); /** * Handles GET MD5 checksum file download request. diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index bf447d01c..ee9de1f01 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -36,7 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.WebApplicationContext; @@ -71,7 +71,8 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR @Override public ResponseEntity downloadArtifactByFilename(@PathVariable("tenant") final String tenant, - @PathVariable("fileName") final String fileName, @AuthenticationPrincipal final Object principal) { + @PathVariable("fileName") final String fileName) { + final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); final List foundArtifacts = artifactManagement.findArtifactByFilename(fileName); if (foundArtifacts.isEmpty()) {