View Javadoc
1   /*
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   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.rest.api.service;
20  
21  import io.swagger.v3.oas.annotations.Operation;
22  import io.swagger.v3.oas.annotations.headers.Header;
23  import io.swagger.v3.oas.annotations.media.Schema;
24  import io.swagger.v3.oas.annotations.responses.ApiResponse;
25  import io.swagger.v3.oas.annotations.responses.ApiResponses;
26  import io.swagger.v3.oas.annotations.security.SecurityRequirement;
27  import io.swagger.v3.oas.annotations.tags.Tag;
28  import javax.ws.rs.BeanParam;
29  import javax.ws.rs.Consumes;
30  import javax.ws.rs.DELETE;
31  import javax.ws.rs.GET;
32  import javax.ws.rs.POST;
33  import javax.ws.rs.Path;
34  import javax.ws.rs.PathParam;
35  import javax.ws.rs.Produces;
36  import javax.ws.rs.core.MediaType;
37  import javax.ws.rs.core.Response;
38  import org.apache.syncope.common.lib.to.AccessTokenTO;
39  import org.apache.syncope.common.lib.to.PagedResult;
40  import org.apache.syncope.common.rest.api.RESTHeaders;
41  import org.apache.syncope.common.rest.api.beans.AccessTokenQuery;
42  
43  /**
44   * REST operations for access tokens.
45   */
46  @Tag(name = "AccessTokens")
47  @Path("accessTokens")
48  public interface AccessTokenService extends JAXRSService {
49  
50      /**
51       * Returns an empty response bearing the X-Syncope-Token header value, in case of successful authentication.
52       * The provided value is a signed JSON Web Token.
53       *
54       * @return empty response bearing the X-Syncope-Token header value, in case of successful authentication
55       */
56      @Operation(security = {
57          @SecurityRequirement(name = "BasicAuthentication") })
58      @ApiResponses({
59          @ApiResponse(responseCode = "204",
60                  description = "JWT successfully generated", headers = {
61                      @Header(name = RESTHeaders.TOKEN, schema =
62                              @Schema(type = "string"), description = "Generated JWT"),
63                      @Header(name = RESTHeaders.TOKEN_EXPIRE, schema =
64                              @Schema(type = "string"), description = "Expiration of the generated JWT") }),
65          @ApiResponse(responseCode = "401", description = "Invalid username or password")
66      })
67      @POST
68      @Path("login")
69      @Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
70      Response login();
71  
72      /**
73       * Returns an empty response bearing the X-Syncope-Token header value, with extended lifetime.
74       * The provided value is a signed JSON Web Token.
75       *
76       * @return an empty response bearing the X-Syncope-Token header value, with extended lifetime
77       */
78      @Operation(security = {
79          @SecurityRequirement(name = "Bearer") })
80      @ApiResponses(
81              @ApiResponse(responseCode = "204",
82                      description = "JWT successfully refreshed", headers = {
83                  @Header(name = RESTHeaders.TOKEN, schema =
84                          @Schema(type = "string"),
85                          description = "Generated JWT"),
86                  @Header(name = RESTHeaders.TOKEN_EXPIRE, schema =
87                          @Schema(type = "string"),
88                          description = "Expiration of the refreshed JWT") }))
89      @POST
90      @Path("refresh")
91      @Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
92      Response refresh();
93  
94      /**
95       * Invalidates the access token of the requesting user.
96       */
97      @Operation(security = {
98          @SecurityRequirement(name = "Bearer") })
99      @ApiResponses(
100             @ApiResponse(responseCode = "204", description = "Operation was successful"))
101     @POST
102     @Path("logout")
103     @Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
104     void logout();
105 
106     /**
107      * Returns a paged list of existing access tokens matching the given query.
108      *
109      * @param query query conditions
110      * @return paged list of existing access tokens matching the given query
111      */
112     @Operation(security = {
113         @SecurityRequirement(name = "BasicAuthentication"),
114         @SecurityRequirement(name = "Bearer") })
115     @GET
116     @Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
117     @Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
118     PagedResult<AccessTokenTO> list(@BeanParam AccessTokenQuery query);
119 
120     /**
121      * Invalidates the access token matching the provided key.
122      *
123      * @param key access token key
124      */
125     @Operation(security = {
126         @SecurityRequirement(name = "BasicAuthentication"),
127         @SecurityRequirement(name = "Bearer") })
128     @ApiResponses(
129             @ApiResponse(responseCode = "204", description = "Operation was successful"))
130     @DELETE
131     @Path("{key}")
132     @Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
133     void delete(@PathParam("key") String key);
134 }