You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SecurityConfigurationService.java 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. package org.apache.archiva.rest.api.services.v2;/*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. * Unless required by applicable law or agreed to in writing,
  12. * software distributed under the License is distributed on an
  13. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. * KIND, either express or implied. See the License for the
  15. * specific language governing permissions and limitations
  16. * under the License.
  17. */
  18. import io.swagger.v3.oas.annotations.Operation;
  19. import io.swagger.v3.oas.annotations.Parameter;
  20. import io.swagger.v3.oas.annotations.Parameters;
  21. import io.swagger.v3.oas.annotations.enums.ParameterIn;
  22. import io.swagger.v3.oas.annotations.media.ArraySchema;
  23. import io.swagger.v3.oas.annotations.media.Content;
  24. import io.swagger.v3.oas.annotations.media.Schema;
  25. import io.swagger.v3.oas.annotations.parameters.RequestBody;
  26. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  27. import io.swagger.v3.oas.annotations.security.SecurityRequirement;
  28. import io.swagger.v3.oas.annotations.tags.Tag;
  29. import org.apache.archiva.components.rest.model.PagedResult;
  30. import org.apache.archiva.components.rest.model.PropertyEntry;
  31. import org.apache.archiva.redback.authorization.RedbackAuthorization;
  32. import org.apache.archiva.rest.api.model.v2.BeanInformation;
  33. import org.apache.archiva.rest.api.model.v2.CacheConfiguration;
  34. import org.apache.archiva.rest.api.model.v2.LdapConfiguration;
  35. import org.apache.archiva.rest.api.model.v2.SecurityConfiguration;
  36. import org.apache.archiva.security.common.ArchivaRoleConstants;
  37. import javax.ws.rs.Consumes;
  38. import javax.ws.rs.DefaultValue;
  39. import javax.ws.rs.GET;
  40. import javax.ws.rs.POST;
  41. import javax.ws.rs.PUT;
  42. import javax.ws.rs.Path;
  43. import javax.ws.rs.PathParam;
  44. import javax.ws.rs.Produces;
  45. import javax.ws.rs.QueryParam;
  46. import javax.ws.rs.core.MediaType;
  47. import javax.ws.rs.core.Response;
  48. import java.util.List;
  49. import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
  50. import static org.apache.archiva.rest.api.services.v2.Configuration.DEFAULT_PAGE_LIMIT;
  51. /**
  52. *
  53. * Service for configuration of redback and security related settings.
  54. *
  55. * @author Martin Stockhammer <martin_s@apache.org>
  56. * @since 3.0
  57. */
  58. @Path( "/security" )
  59. @Tag(name = "v2")
  60. @Tag(name = "v2/Security")
  61. @SecurityRequirement(name = "BearerAuth")
  62. public interface SecurityConfigurationService
  63. {
  64. @Path("config")
  65. @GET
  66. @Produces({ APPLICATION_JSON })
  67. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  68. @Operation( summary = "Returns the security configuration that is currently active.",
  69. security = {
  70. @SecurityRequirement(
  71. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  72. )
  73. },
  74. responses = {
  75. @ApiResponse( responseCode = "200",
  76. description = "If the configuration could be retrieved",
  77. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = SecurityConfiguration.class))
  78. ),
  79. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  80. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  81. }
  82. )
  83. SecurityConfiguration getConfiguration()
  84. throws ArchivaRestServiceException;
  85. @Path("config")
  86. @PUT
  87. @Consumes({ APPLICATION_JSON })
  88. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  89. @Operation( summary = "Updates the security configuration.",
  90. security = {
  91. @SecurityRequirement(
  92. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  93. )
  94. },
  95. responses = {
  96. @ApiResponse( responseCode = "200",
  97. description = "If the configuration was updated"
  98. ),
  99. @ApiResponse( responseCode = "422", description = "Invalid content data",
  100. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
  101. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to update the configuration",
  102. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  103. }
  104. )
  105. SecurityConfiguration updateConfiguration( SecurityConfiguration newConfiguration)
  106. throws ArchivaRestServiceException;
  107. @Path( "config/properties" )
  108. @GET
  109. @Produces( { APPLICATION_JSON } )
  110. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  111. @Operation( summary = "Returns all configuration properties. The result is paged.",
  112. parameters = {
  113. @Parameter(name = "q", description = "Search term"),
  114. @Parameter(name = "offset", description = "The offset of the first element returned"),
  115. @Parameter(name = "limit", description = "Maximum number of items to return in the response"),
  116. @Parameter(name = "orderBy", description = "List of attribute used for sorting (key, value)"),
  117. @Parameter(name = "order", description = "The sort order. Either ascending (asc) or descending (desc)")
  118. },
  119. security = {
  120. @SecurityRequirement(
  121. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  122. )
  123. },
  124. responses = {
  125. @ApiResponse( responseCode = "200",
  126. description = "If the list could be returned",
  127. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = PagedResult.class))
  128. ),
  129. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  130. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  131. }
  132. )
  133. PagedResult<PropertyEntry> getConfigurationProperties( @QueryParam("q") @DefaultValue( "" ) String searchTerm,
  134. @QueryParam( "offset" ) @DefaultValue( "0" ) Integer offset,
  135. @QueryParam( "limit" ) @DefaultValue( value = DEFAULT_PAGE_LIMIT ) Integer limit,
  136. @QueryParam( "orderBy") @DefaultValue( "key" ) List<String> orderBy,
  137. @QueryParam("order") @DefaultValue( "asc" ) String order ) throws ArchivaRestServiceException;
  138. @Path("config/properties/{propertyName}")
  139. @GET
  140. @Produces({ APPLICATION_JSON })
  141. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  142. @Operation( summary = "Returns a single configuration property value.",
  143. security = {
  144. @SecurityRequirement(
  145. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  146. )
  147. },
  148. parameters = {
  149. @Parameter(in = ParameterIn.PATH, name="propertyName", description = "The name of the property to get the value for")
  150. },
  151. responses = {
  152. @ApiResponse( responseCode = "200",
  153. description = "If the configuration could be retrieved",
  154. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = PropertyEntry.class))
  155. ),
  156. @ApiResponse( responseCode = "404", description = "The given property name does not exist",
  157. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
  158. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  159. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  160. }
  161. )
  162. PropertyEntry getConfigurationProperty( @PathParam ( "propertyName" ) String propertyName)
  163. throws ArchivaRestServiceException;
  164. @Path("config/properties/{propertyName}")
  165. @PUT
  166. @Consumes({ APPLICATION_JSON})
  167. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  168. @Operation( summary = "Updates a single property value of the security configuration.",
  169. security = {
  170. @SecurityRequirement(
  171. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  172. )
  173. },
  174. parameters = {
  175. @Parameter(in = ParameterIn.PATH, name="propertyName", description = "The name of the property to update")
  176. },
  177. responses = {
  178. @ApiResponse( responseCode = "200",
  179. description = "If the property value was updated."
  180. ),
  181. @ApiResponse( responseCode = "400", description = "The body data is not valid",
  182. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
  183. @ApiResponse( responseCode = "404", description = "The given property name does not exist",
  184. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
  185. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  186. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  187. }
  188. )
  189. Response updateConfigurationProperty( @PathParam ( "propertyName" ) String propertyName, PropertyEntry propertyValue)
  190. throws ArchivaRestServiceException;
  191. @Path("config/ldap")
  192. @GET
  193. @Produces({ APPLICATION_JSON })
  194. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  195. @Operation( summary = "Returns the LDAP configuration that is currently active.",
  196. security = {
  197. @SecurityRequirement(
  198. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  199. )
  200. },
  201. responses = {
  202. @ApiResponse( responseCode = "200",
  203. description = "If the configuration could be retrieved",
  204. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = LdapConfiguration.class))
  205. ),
  206. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  207. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  208. }
  209. )
  210. LdapConfiguration getLdapConfiguration( ) throws ArchivaRestServiceException;
  211. @Path("config/ldap")
  212. @PUT
  213. @Consumes({ APPLICATION_JSON })
  214. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  215. @Operation( summary = "Updates the LDAP configuration that is currently active.",
  216. security = {
  217. @SecurityRequirement(
  218. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  219. )
  220. },
  221. responses = {
  222. @ApiResponse( responseCode = "200",
  223. description = "If the configuration was updated"
  224. ),
  225. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to update the information",
  226. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  227. }
  228. )
  229. LdapConfiguration updateLdapConfiguration( LdapConfiguration configuration ) throws ArchivaRestServiceException;
  230. @Path("config/ldap/verify")
  231. @POST
  232. @Consumes({ APPLICATION_JSON })
  233. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  234. @Operation( summary = "Checks the given LDAP configuration.",
  235. security = {
  236. @SecurityRequirement(
  237. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  238. )
  239. },
  240. responses = {
  241. @ApiResponse( responseCode = "200",
  242. description = "If the check was successful"
  243. ),
  244. @ApiResponse( responseCode = "400",
  245. description = "If the check was not successful",
  246. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class ))
  247. ),
  248. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to update the information",
  249. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  250. }
  251. )
  252. Response verifyLdapConfiguration( LdapConfiguration configuration ) throws ArchivaRestServiceException;
  253. @Path("config/cache")
  254. @GET
  255. @Produces({ APPLICATION_JSON })
  256. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  257. @Operation( summary = "Returns the cache configuration that is currently active.",
  258. security = {
  259. @SecurityRequirement(
  260. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  261. )
  262. },
  263. responses = {
  264. @ApiResponse( responseCode = "200",
  265. description = "If the configuration could be retrieved",
  266. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = CacheConfiguration.class))
  267. ),
  268. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  269. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  270. }
  271. )
  272. CacheConfiguration getCacheConfiguration( ) throws ArchivaRestServiceException;
  273. @Path("config/cache")
  274. @PUT
  275. @Consumes({ APPLICATION_JSON })
  276. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  277. @Operation( summary = "Updates the LDAP configuration that is currently active.",
  278. security = {
  279. @SecurityRequirement(
  280. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  281. )
  282. },
  283. responses = {
  284. @ApiResponse( responseCode = "200",
  285. description = "If the configuration was updated"
  286. ),
  287. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to update the information",
  288. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  289. }
  290. )
  291. Response updateCacheConfiguration( CacheConfiguration cacheConfiguration ) throws ArchivaRestServiceException;
  292. @Path("user_managers")
  293. @GET
  294. @Produces({ APPLICATION_JSON })
  295. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  296. @Operation( summary = "Returns the available user manager implementations.",
  297. security = {
  298. @SecurityRequirement(
  299. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  300. )
  301. },
  302. responses = {
  303. @ApiResponse( responseCode = "200",
  304. description = "If the list could be retrieved",
  305. content = @Content(mediaType = APPLICATION_JSON, array = @ArraySchema(
  306. schema = @Schema(implementation = BeanInformation.class)))
  307. ),
  308. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  309. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  310. }
  311. )
  312. List<BeanInformation> getAvailableUserManagers()
  313. throws ArchivaRestServiceException;
  314. @Path("rbac_managers")
  315. @GET
  316. @Produces({ APPLICATION_JSON })
  317. @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
  318. @Operation( summary = "Returns the available RBAC manager implementations.",
  319. security = {
  320. @SecurityRequirement(
  321. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  322. )
  323. },
  324. responses = {
  325. @ApiResponse( responseCode = "200",
  326. description = "If the list could be retrieved",
  327. content = @Content(mediaType = APPLICATION_JSON, array = @ArraySchema(
  328. schema = @Schema(implementation = BeanInformation.class)))
  329. ),
  330. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  331. content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
  332. }
  333. )
  334. List<BeanInformation> getAvailableRbacManagers()
  335. throws ArchivaRestServiceException;
  336. }