View | Details | Raw Unified | Return to bug 39224
Collapse All | Expand All

(-)a/Koha/REST/V1/ShibbolethConfig.pm (+67 lines)
Line 0 Link Here
1
package Koha::REST::V1::ShibbolethConfig;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Try::Tiny qw(catch try);
23
24
use Koha::ShibbolethConfig;
25
use Koha::ShibbolethConfigs;
26
27
=head1 API
28
29
=head2 Methods
30
31
=head3 get
32
33
Get the Shibboleth configuration
34
35
=cut
36
37
sub get {
38
    my $c = shift->openapi->valid_input or return;
39
40
    return try {
41
        my $config = Koha::ShibbolethConfigs->new->get_configuration;
42
        return $c->render( status => 200, openapi => $c->objects->to_api($config) );
43
    } catch {
44
        $c->unhandled_exception($_);
45
    };
46
}
47
48
=head3 update
49
50
Update Shibboleth configuration
51
52
=cut
53
54
sub update {
55
    my $c = shift->openapi->valid_input or return;
56
57
    return try {
58
        my $config = Koha::ShibbolethConfigs->new->get_configuration;
59
        $config->set_from_api( $c->req->json )->store;
60
61
        return $c->render( status => 200, openapi => $c->objects->to_api($config) );
62
    } catch {
63
        $c->unhandled_exception($_);
64
    };
65
}
66
67
1;
(-)a/Koha/REST/V1/ShibbolethFieldMappings.pm (+150 lines)
Line 0 Link Here
1
package Koha::REST::V1::ShibbolethFieldMappings;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Try::Tiny    qw(catch try);
23
use Scalar::Util qw(blessed);
24
25
use Koha::ShibbolethFieldMapping;
26
use Koha::ShibbolethFieldMappings;
27
28
=head1 API
29
30
=head2 Methods
31
32
=head3 list
33
34
List all field mappings
35
36
=cut
37
38
sub list {
39
    my $c = shift->openapi->valid_input or return;
40
41
    return try {
42
        my $mappings = $c->objects->search( Koha::ShibbolethFieldMappings->new );
43
        return $c->render( status => 200, openapi => $mappings );
44
    } catch {
45
        $c->unhandled_exception($_);
46
    };
47
}
48
49
=head3 get
50
51
Get a specific mapping
52
53
=cut
54
55
sub get {
56
    my $c = shift->openapi->valid_input or return;
57
58
    return try {
59
        my $mapping = Koha::ShibbolethFieldMappings->find( $c->param('mapping_id') );
60
61
        return $c->render_resource_not_found('Mapping') unless $mapping;
62
63
        return $c->render( status => 200, openapi => $c->objects->to_api($mapping) );
64
    } catch {
65
        $c->unhandled_exception($_);
66
    };
67
}
68
69
=head3 add
70
71
Add a new field mapping
72
73
=cut
74
75
sub add {
76
    my $c = shift->openapi->valid_input or return;
77
78
    return try {
79
        my $mapping = Koha::ShibbolethFieldMapping->new_from_api( $c->req->json );
80
        $mapping->store;
81
        $c->res->headers->location( $c->req->url->to_string . '/' . $mapping->mapping_id );
82
83
        return $c->render(
84
            status  => 201,
85
            openapi => $c->objects->to_api($mapping)
86
        );
87
    } catch {
88
        if ( blessed $_ && $_->isa('Koha::Exceptions::MissingParameter') ) {
89
            return $c->render(
90
                status  => 400,
91
                openapi => { error => $_->error }
92
            );
93
        }
94
        $c->unhandled_exception($_);
95
    };
96
}
97
98
=head3 update
99
100
Update an existing mapping
101
102
=cut
103
104
sub update {
105
    my $c = shift->openapi->valid_input or return;
106
107
    my $mapping = Koha::ShibbolethFieldMappings->find( $c->param('mapping_id') );
108
109
    return $c->render_resource_not_found('Mapping') unless $mapping;
110
111
    return try {
112
        $mapping->set_from_api( $c->req->json )->store;
113
114
        return $c->render(
115
            status  => 200,
116
            openapi => $c->objects->to_api($mapping)
117
        );
118
    } catch {
119
        if ( blessed $_ && $_->isa('Koha::Exceptions::MissingParameter') ) {
120
            return $c->render(
121
                status  => 400,
122
                openapi => { error => $_->error }
123
            );
124
        }
125
        $c->unhandled_exception($_);
126
    };
127
}
128
129
=head3 delete
130
131
Delete a mapping
132
133
=cut
134
135
sub delete {
136
    my $c = shift->openapi->valid_input or return;
137
138
    my $mapping = Koha::ShibbolethFieldMappings->find( $c->param('mapping_id') );
139
140
    return $c->render_resource_not_found('Mapping') unless $mapping;
141
142
    return try {
143
        $mapping->delete;
144
        return $c->render_resource_deleted;
145
    } catch {
146
        $c->unhandled_exception($_);
147
    };
148
}
149
150
1;
(-)a/api/v1/swagger/definitions/shibboleth_config.yaml (+23 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  shibboleth_config_id:
5
    type: integer
6
    description: Internal configuration identifier
7
    readOnly: true
8
  force_opac_sso:
9
    type: boolean
10
    description: Enable SSO for OPAC
11
  force_staff_sso:
12
    type: boolean
13
    description: Enable SSO for staff interface
14
  autocreate:
15
    type: boolean
16
    description: Auto create users
17
  sync:
18
    type: boolean
19
    description: Sync user attributes
20
  welcome:
21
    type: boolean
22
    description: Send welcome email
23
additionalProperties: false
(-)a/api/v1/swagger/definitions/shibboleth_mapping.yaml (+26 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  mapping_id:
5
    type: integer
6
    description: Internal mapping identifier
7
    readOnly: true
8
  koha_field:
9
    type: string
10
    description: Koha database field
11
  idp_field:
12
    type:
13
      - string
14
      - "null"
15
    description: IdP attribute name
16
  default_content:
17
    type:
18
      - string
19
      - "null"
20
    description: Default value if attribute missing
21
  is_matchpoint:
22
    type: boolean
23
    description: Is this the matchpoint field
24
additionalProperties: false
25
required:
26
  - koha_field
(-)a/api/v1/swagger/paths/shibboleth.yaml (+221 lines)
Line 0 Link Here
1
---
2
/shibboleth/config:
3
  get:
4
    x-mojo-to: ShibbolethConfig#get
5
    operationId: getShibbolethConfig
6
    tags:
7
      - shibboleth
8
    summary: Get Shibboleth configuration
9
    produces:
10
      - application/json
11
    responses:
12
      "200":
13
        description: Shibboleth configuration
14
        schema:
15
          $ref: "../swagger.yaml#/definitions/shibboleth_config"
16
      "400":
17
        description: |
18
          Bad request. Possible `error_code` attribute values:
19
20
            * `invalid_query`
21
        schema:
22
          $ref: "../swagger.yaml#/definitions/error"
23
      "401":
24
        description: Authentication required
25
        schema:
26
          $ref: "../swagger.yaml#/definitions/error"
27
      "403":
28
        description: Access forbidden
29
        schema:
30
          $ref: "../swagger.yaml#/definitions/error"
31
    x-koha-authorization:
32
      permissions:
33
        parameters: manage_identity_providers
34
  put:
35
    x-mojo-to: ShibbolethConfig#update
36
    operationId: updateShibbolethConfig
37
    tags:
38
      - shibboleth
39
    summary: Update Shibboleth configuration
40
    parameters:
41
      - name: body
42
        in: body
43
        description: Shibboleth configuration object
44
        required: true
45
        schema:
46
          $ref: "../swagger.yaml#/definitions/shibboleth_config"
47
    produces:
48
      - application/json
49
    responses:
50
      "200":
51
        description: Configuration updated
52
        schema:
53
          $ref: "../swagger.yaml#/definitions/shibboleth_config"
54
      "400":
55
        description: Bad request
56
        schema:
57
          $ref: "../swagger.yaml#/definitions/error"
58
      "401":
59
        description: Authentication required
60
        schema:
61
          $ref: "../swagger.yaml#/definitions/error"
62
      "403":
63
        description: Access forbidden
64
        schema:
65
          $ref: "../swagger.yaml#/definitions/error"
66
    x-koha-authorization:
67
      permissions:
68
        parameters: manage_identity_providers
69
70
/shibboleth/mappings:
71
  get:
72
    x-mojo-to: ShibbolethFieldMappings#list
73
    operationId: listShibbolethMappings
74
    tags:
75
      - shibboleth
76
    summary: List Shibboleth field mappings
77
    parameters:
78
      - $ref: "../swagger.yaml#/parameters/match"
79
      - $ref: "../swagger.yaml#/parameters/order_by"
80
      - $ref: "../swagger.yaml#/parameters/page"
81
      - $ref: "../swagger.yaml#/parameters/per_page"
82
      - $ref: "../swagger.yaml#/parameters/q_param"
83
      - $ref: "../swagger.yaml#/parameters/q_body"
84
    produces:
85
      - application/json
86
    responses:
87
      "200":
88
        description: List of field mappings
89
        schema:
90
          type: array
91
          items:
92
            $ref: "../swagger.yaml#/definitions/shibboleth_mapping"
93
      "400":
94
        description: |
95
          Bad request. Possible `error_code` attribute values:
96
97
            * `invalid_query`
98
        schema:
99
          $ref: "../swagger.yaml#/definitions/error"
100
    x-koha-authorization:
101
      permissions:
102
        parameters: manage_identity_providers
103
  post:
104
    x-mojo-to: ShibbolethFieldMappings#add
105
    operationId: addShibbolethMapping
106
    tags:
107
      - shibboleth
108
    summary: Add new field mapping
109
    parameters:
110
      - name: body
111
        in: body
112
        description: Field mapping object
113
        required: true
114
        schema:
115
          $ref: "../swagger.yaml#/definitions/shibboleth_mapping"
116
    produces:
117
      - application/json
118
    responses:
119
      "201":
120
        description: Mapping created
121
        schema:
122
          $ref: "../swagger.yaml#/definitions/shibboleth_mapping"
123
      "400":
124
        description: Bad request
125
        schema:
126
          $ref: "../swagger.yaml#/definitions/error"
127
      "401":
128
        description: Authentication required
129
        schema:
130
          $ref: "../swagger.yaml#/definitions/error"
131
      "403":
132
        description: Access forbidden
133
        schema:
134
          $ref: "../swagger.yaml#/definitions/error"
135
    x-koha-authorization:
136
      permissions:
137
        parameters: manage_identity_providers
138
139
"/shibboleth/mappings/{mapping_id}":
140
  get:
141
    x-mojo-to: ShibbolethFieldMappings#get
142
    operationId: getShibbolethMapping
143
    tags:
144
      - shibboleth
145
    summary: Get field mapping
146
    parameters:
147
      - $ref: "../swagger.yaml#/parameters/mapping_id_pp"
148
    produces:
149
      - application/json
150
    responses:
151
      "200":
152
        description: Field mapping
153
        schema:
154
          $ref: "../swagger.yaml#/definitions/shibboleth_mapping"
155
      "400":
156
        description: Bad request
157
        schema:
158
          $ref: "../swagger.yaml#/definitions/error"
159
      "404":
160
        description: Mapping not found
161
        schema:
162
          $ref: "../swagger.yaml#/definitions/error"
163
    x-koha-authorization:
164
      permissions:
165
        parameters: manage_identity_providers
166
  put:
167
    x-mojo-to: ShibbolethFieldMappings#update
168
    operationId: updateShibbolethMapping
169
    tags:
170
      - shibboleth
171
    summary: Update field mapping
172
    parameters:
173
      - $ref: "../swagger.yaml#/parameters/mapping_id_pp"
174
      - name: body
175
        in: body
176
        description: Updated mapping object
177
        required: true
178
        schema:
179
          $ref: "../swagger.yaml#/definitions/shibboleth_mapping"
180
    produces:
181
      - application/json
182
    responses:
183
      "200":
184
        description: Mapping updated
185
        schema:
186
          $ref: "../swagger.yaml#/definitions/shibboleth_mapping"
187
      "400":
188
        description: Bad request
189
        schema:
190
          $ref: "../swagger.yaml#/definitions/error"
191
      "404":
192
        description: Mapping not found
193
        schema:
194
          $ref: "../swagger.yaml#/definitions/error"
195
    x-koha-authorization:
196
      permissions:
197
        parameters: manage_identity_providers
198
  delete:
199
    x-mojo-to: ShibbolethFieldMappings#delete
200
    operationId: deleteShibbolethMapping
201
    tags:
202
      - shibboleth
203
    summary: Delete field mapping
204
    parameters:
205
      - $ref: "../swagger.yaml#/parameters/mapping_id_pp"
206
    produces:
207
      - application/json
208
    responses:
209
      "204":
210
        description: Mapping deleted
211
      "400":
212
        description: Bad request
213
        schema:
214
          $ref: "../swagger.yaml#/definitions/error"
215
      "404":
216
        description: Mapping not found
217
        schema:
218
          $ref: "../swagger.yaml#/definitions/error"
219
    x-koha-authorization:
220
      permissions:
221
        parameters: manage_identity_providers
(-)a/api/v1/swagger/swagger.yaml (-1 / +19 lines)
Lines 180-185 definitions: Link Here
180
    $ref: ./definitions/rota.yaml
180
    $ref: ./definitions/rota.yaml
181
  search_filter:
181
  search_filter:
182
    $ref: ./definitions/search_filter.yaml
182
    $ref: ./definitions/search_filter.yaml
183
  shibboleth_config:
184
    $ref: ./definitions/shibboleth_config.yaml
185
  shibboleth_mapping:
186
    $ref: ./definitions/shibboleth_mapping.yaml
183
  smtp_server:
187
  smtp_server:
184
    $ref: ./definitions/smtp_server.yaml
188
    $ref: ./definitions/smtp_server.yaml
185
  file_transport:
189
  file_transport:
Lines 591-596 paths: Link Here
591
    $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}"
595
    $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}"
592
  "/rotas/{rota_id}/stages/{stage_id}/position":
596
  "/rotas/{rota_id}/stages/{stage_id}/position":
593
    $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}~1stages~1{stage_id}~1position"
597
    $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}~1stages~1{stage_id}~1position"
598
  /shibboleth/config:
599
    $ref: ./paths/shibboleth.yaml#/~1shibboleth~1config
600
  /shibboleth/mappings:
601
    $ref: ./paths/shibboleth.yaml#/~1shibboleth~1mappings
602
  "/shibboleth/mappings/{mapping_id}":
603
    $ref: "./paths/shibboleth.yaml#/~1shibboleth~1mappings~1{mapping_id}"
594
  /suggestions:
604
  /suggestions:
595
    $ref: ./paths/suggestions.yaml#/~1suggestions
605
    $ref: ./paths/suggestions.yaml#/~1suggestions
596
  "/suggestions/{suggestion_id}":
606
  "/suggestions/{suggestion_id}":
Lines 858-863 parameters: Link Here
858
    name: license_id
868
    name: license_id
859
    required: true
869
    required: true
860
    type: integer
870
    type: integer
871
  mapping_id_pp:
872
    description: Shibboleth field mapping internal identifier
873
    in: path
874
    name: mapping_id
875
    required: true
876
    type: integer
861
  match:
877
  match:
862
    description: Matching criteria
878
    description: Matching criteria
863
    enum:
879
    enum:
Lines 1345-1350 tags: Link Here
1345
  - description: "Manage file transport configurations\n"
1361
  - description: "Manage file transport configurations\n"
1346
    name: file_transports
1362
    name: file_transports
1347
    x-displayName: File transports
1363
    x-displayName: File transports
1364
  - description: "Manage Shibboleth authentication\n"
1365
    name: shibboleth
1366
    x-displayName: Shibboleth
1348
  - description: "Manage tickets\n"
1367
  - description: "Manage tickets\n"
1349
    name: tickets
1368
    name: tickets
1350
    x-displayName: Tickets
1369
    x-displayName: Tickets
1351
- 

Return to bug 39224