34
34
/**
35
35
* @author Gunnar Hillert
36
36
*/
37
- public class DefaultAuthoritiesMapperTests {
37
+ class DefaultAuthoritiesMapperTests {
38
38
39
39
@ Test
40
- public void testNullConstructor () throws Exception {
40
+ void nullConstructor () throws Exception {
41
41
assertThatThrownBy (() -> {
42
42
new DefaultAuthoritiesMapper (null , "" );
43
43
}).isInstanceOf (IllegalArgumentException .class ).hasMessageContaining ("providerRoleMappings must not be null." );
44
44
}
45
45
46
46
@ Test
47
- public void testMapScopesToAuthoritiesWithNullParameters () throws Exception {
47
+ void mapScopesToAuthoritiesWithNullParameters () throws Exception {
48
48
DefaultAuthoritiesMapper authoritiesMapper = new DefaultAuthoritiesMapper (Collections .emptyMap (), "" );
49
49
50
50
assertThatThrownBy (() -> {
@@ -56,18 +56,19 @@ public void testMapScopesToAuthoritiesWithNullParameters() throws Exception {
56
56
}
57
57
58
58
@ Test
59
- public void testThat7AuthoritiesAreReturned () throws Exception {
59
+ void that7AuthoritiesAreReturned () throws Exception {
60
60
DefaultAuthoritiesMapper authoritiesMapper = new DefaultAuthoritiesMapper ("uaa" , false );
61
61
Set <GrantedAuthority > authorities = authoritiesMapper .mapScopesToAuthorities ("uaa" , Collections .emptySet (), null );
62
62
63
63
assertThat (authorities ).hasSize (7 );
64
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
64
+ assertThat (authorities )
65
+ .extracting (GrantedAuthority ::getAuthority )
65
66
.containsExactlyInAnyOrder ("ROLE_MANAGE" , "ROLE_CREATE" , "ROLE_VIEW" , "ROLE_DEPLOY" , "ROLE_MODIFY" ,
66
67
"ROLE_SCHEDULE" , "ROLE_DESTROY" );
67
68
}
68
69
69
70
@ Test
70
- public void testEmptyMapConstructor () throws Exception {
71
+ void emptyMapConstructor () throws Exception {
71
72
Set <String > scopes = new HashSet <>();
72
73
scopes .add ("dataflow.manage" );
73
74
scopes .add ("dataflow.view" );
@@ -77,12 +78,13 @@ public void testEmptyMapConstructor() throws Exception {
77
78
Collection <? extends GrantedAuthority > authorities = authoritiesMapper .mapScopesToAuthorities ("uaa" , scopes , null );
78
79
79
80
assertThat (authorities ).hasSize (3 );
80
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
81
+ assertThat (authorities )
82
+ .extracting (GrantedAuthority ::getAuthority )
81
83
.containsExactlyInAnyOrder ("ROLE_MANAGE" , "ROLE_CREATE" , "ROLE_VIEW" );
82
84
}
83
85
84
86
@ Test
85
- public void testMapConstructorWithIncompleteRoleMappings () throws Exception {
87
+ void mmapConstructorWithIncompleteRoleMappings () throws Exception {
86
88
ProviderRoleMapping roleMapping = new ProviderRoleMapping ();
87
89
roleMapping .setMapOauthScopes (true );
88
90
roleMapping .addRoleMapping ("ROLE_MANAGE" , "foo-scope-in-oauth" );
@@ -93,107 +95,115 @@ public void testMapConstructorWithIncompleteRoleMappings() throws Exception {
93
95
}
94
96
95
97
@ Test
96
- public void testThat3MappedAuthoritiesAreReturned () throws Exception {
97
- Map <String , String > roleMappings = new HashMap <>();
98
- roleMappings .put ("ROLE_MANAGE" , "dataflow_manage" );
99
- roleMappings .put ("ROLE_VIEW" , "dataflow_view" );
100
- roleMappings .put ("ROLE_CREATE" , "dataflow_create" );
101
- roleMappings .put ("ROLE_MODIFY" , "dataflow_modify" );
102
- roleMappings .put ("ROLE_DEPLOY" , "dataflow_deploy" );
103
- roleMappings .put ("ROLE_DESTROY" , "dataflow_destroy" );
104
- roleMappings .put ("ROLE_SCHEDULE" , "dataflow_schedule" );
98
+ void that3MappedAuthoritiesAreReturned () throws Exception {
99
+ Map <String , String > roleMappings = Map .of (
100
+ "ROLE_MANAGE" , "dataflow_manage" ,
101
+ "ROLE_VIEW" , "dataflow_view" ,
102
+ "ROLE_CREATE" , "dataflow_create" ,
103
+ "ROLE_MODIFY" , "dataflow_modify" ,
104
+ "ROLE_DEPLOY" , "dataflow_deploy" ,
105
+ "ROLE_DESTROY" , "dataflow_destroy" ,
106
+ "ROLE_SCHEDULE" , "dataflow_schedule"
107
+ );
105
108
106
109
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping ();
107
110
providerRoleMapping .setMapOauthScopes (true );
108
111
providerRoleMapping .getRoleMappings ().putAll (roleMappings );
109
112
110
- Set <String > roles = new HashSet <>();
111
- roles .add ("dataflow_manage" );
112
- roles .add ("dataflow_view" );
113
- roles .add ("dataflow_deploy" );
113
+ Set <String > roles = Set .of ("dataflow_manage" , "dataflow_view" , "dataflow_deploy" );
114
114
115
115
DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper ("uaa" , providerRoleMapping );
116
116
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesMapper .mapScopesToAuthorities ("uaa" ,
117
117
roles , null );
118
118
119
119
assertThat (authorities ).hasSize (3 );
120
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
120
+ assertThat (authorities )
121
+ .extracting (GrantedAuthority ::getAuthority )
121
122
.containsExactlyInAnyOrder ("ROLE_DEPLOY" , "ROLE_MANAGE" , "ROLE_VIEW" );
122
123
}
123
- public void testThat7MappedAuthoritiesAreReturned () throws Exception {
124
- Map <String , String > roleMappings = new HashMap <>();
125
- roleMappings .put ("ROLE_MANAGE" , "foo-manage" );
126
- roleMappings .put ("ROLE_VIEW" , "bar-view" );
127
- roleMappings .put ("ROLE_CREATE" , "blubba-create" );
128
- roleMappings .put ("ROLE_MODIFY" , "foo-modify" );
129
- roleMappings .put ("ROLE_DEPLOY" , "foo-deploy" );
130
- roleMappings .put ("ROLE_DESTROY" , "foo-destroy" );
131
- roleMappings .put ("ROLE_SCHEDULE" , "foo-schedule" );
124
+ @ Test
125
+ void that7MappedAuthoritiesAreReturned () throws Exception {
126
+ Map <String , String > roleMappings = Map .of (
127
+ "ROLE_MANAGE" , "foo-manage" ,
128
+ "ROLE_VIEW" , "bar-view" ,
129
+ "ROLE_CREATE" , "blubba-create" ,
130
+ "ROLE_MODIFY" , "foo-modify" ,
131
+ "ROLE_DEPLOY" , "foo-deploy" ,
132
+ "ROLE_DESTROY" , "foo-destroy" ,
133
+ "ROLE_SCHEDULE" , "foo-schedule"
134
+ );
132
135
133
136
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping ();
134
137
providerRoleMapping .setMapOauthScopes (true );
135
138
providerRoleMapping .getRoleMappings ().putAll (roleMappings );
136
139
137
- Set <String > scopes = new HashSet <>();
138
- scopes .add ("foo-manage" );
139
- scopes .add ("bar-view" );
140
- scopes .add ("blubba-create" );
141
- scopes .add ("foo-modify" );
142
- scopes .add ("foo-deploy" );
143
- scopes .add ("foo-destroy" );
144
- scopes .add ("foo-schedule" );
140
+ Set <String > scopes = Set .of (
141
+ "foo-manage" ,
142
+ "bar-view" ,
143
+ "blubba-create" ,
144
+ "foo-modify" ,
145
+ "foo-deploy" ,
146
+ "foo-destroy" ,
147
+ "foo-schedule"
148
+ );
145
149
146
150
DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper ("uaa" , providerRoleMapping );
147
151
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesMapper .mapScopesToAuthorities ("uaa" ,
148
152
scopes , null );
149
153
150
154
assertThat (authorities ).hasSize (7 );
151
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
155
+ assertThat (authorities )
156
+ .extracting (GrantedAuthority ::getAuthority )
152
157
.containsExactlyInAnyOrder ("ROLE_CREATE" , "ROLE_DEPLOY" , "ROLE_DESTROY" , "ROLE_MANAGE" , "ROLE_MODIFY" ,
153
158
"ROLE_SCHEDULE" , "ROLE_VIEW" );
154
159
}
155
160
156
161
@ Test
157
- public void testThat3MappedAuthoritiesAreReturnedForDefaultMapping () throws Exception {
162
+ void that3MappedAuthoritiesAreReturnedForDefaultMapping () throws Exception {
158
163
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping ();
159
164
providerRoleMapping .setMapOauthScopes (true );
160
165
161
- Set <String > scopes = new HashSet <>();
162
- scopes .add ("dataflow.manage" );
163
- scopes .add ("dataflow.view" );
164
- scopes .add ("dataflow.create" );
166
+ Set <String > scopes = Set .of (
167
+ "dataflow.manage" ,
168
+ "dataflow.view" ,
169
+ "dataflow.create"
170
+ );
165
171
166
172
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , providerRoleMapping );
167
173
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
168
174
scopes , null );
169
175
170
176
assertThat (authorities ).hasSize (3 );
171
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
177
+ assertThat (authorities )
178
+ .extracting (GrantedAuthority ::getAuthority )
172
179
.containsExactlyInAnyOrder ("ROLE_MANAGE" , "ROLE_CREATE" , "ROLE_VIEW" );
173
180
}
174
181
175
182
@ Test
176
- public void testThat7MappedAuthoritiesAreReturnedForDefaultMappingWithoutMappingScopes () throws Exception {
177
- Set <String > scopes = new HashSet <>();
178
- scopes .add ("dataflow.manage" );
179
- scopes .add ("dataflow.view" );
180
- scopes .add ("dataflow.create" );
183
+ void that7MappedAuthoritiesAreReturnedForDefaultMappingWithoutMappingScopes () throws Exception {
184
+ Set <String > scopes = Set .of (
185
+ "dataflow.manage" ,
186
+ "dataflow.view" ,
187
+ "dataflow.create"
188
+ );
181
189
182
190
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , false );
183
191
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
184
192
scopes , null );
185
193
186
194
assertThat (authorities ).hasSize (7 );
187
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
195
+ assertThat (authorities )
196
+ .extracting (GrantedAuthority ::getAuthority )
188
197
.containsExactlyInAnyOrder ("ROLE_CREATE" , "ROLE_DEPLOY" , "ROLE_DESTROY" , "ROLE_MANAGE" , "ROLE_MODIFY" ,
189
198
"ROLE_SCHEDULE" , "ROLE_VIEW" );
190
199
}
191
200
192
201
@ Test
193
- public void testThat2MappedAuthoritiesAreReturnedForDefaultMapping () throws Exception {
194
- Set <String > scopes = new HashSet <>();
195
- scopes .add ("dataflow.view" );
196
- scopes .add ("dataflow.create" );
202
+ void that2MappedAuthoritiesAreReturnedForDefaultMapping () throws Exception {
203
+ Set <String > scopes = Set .of (
204
+ "dataflow.view" ,
205
+ "dataflow.create"
206
+ );
197
207
198
208
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , true );
199
209
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
@@ -205,19 +215,18 @@ public void testThat2MappedAuthoritiesAreReturnedForDefaultMapping() throws Exce
205
215
}
206
216
207
217
@ Test
208
- public void testThat7AuthoritiesAreReturnedAndOneOAuthScopeCoversMultipleServerRoles () throws Exception {
209
- Map <String , String > roleMappings = new HashMap <>();
210
- roleMappings .put ("ROLE_MANAGE" , "foo-manage" );
211
- roleMappings .put ("ROLE_VIEW" , "foo-manage" );
212
- roleMappings .put ("ROLE_DEPLOY" , "foo-manage" );
213
- roleMappings .put ("ROLE_DESTROY" , "foo-manage" );
214
- roleMappings .put ("ROLE_MODIFY" , "foo-manage" );
215
- roleMappings .put ("ROLE_SCHEDULE" , "foo-manage" );
216
- roleMappings .put ("ROLE_CREATE" , "blubba-create" );
217
-
218
- Set <String > scopes = new HashSet <>();
219
- scopes .add ("foo-manage" );
220
- scopes .add ("blubba-create" );
218
+ void that7AuthoritiesAreReturnedAndOneOAuthScopeCoversMultipleServerRoles () throws Exception {
219
+ Map <String , String > roleMappings = Map .of (
220
+ "ROLE_MANAGE" , "foo-manage" ,
221
+ "ROLE_VIEW" , "foo-manage" ,
222
+ "ROLE_DEPLOY" , "foo-manage" ,
223
+ "ROLE_DESTROY" , "foo-manage" ,
224
+ "ROLE_MODIFY" , "foo-manage" ,
225
+ "ROLE_SCHEDULE" , "foo-manage" ,
226
+ "ROLE_CREATE" , "blubba-create"
227
+ );
228
+
229
+ Set <String > scopes = Set .of ("foo-manage" , "blubba-create" );
221
230
222
231
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , true , roleMappings );
223
232
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
@@ -230,61 +239,64 @@ public void testThat7AuthoritiesAreReturnedAndOneOAuthScopeCoversMultipleServerR
230
239
}
231
240
232
241
@ Test
233
- public void testThatUriStyleScopeRemovesLeadingPart () throws Exception {
234
- Map <String , String > roleMappings = new HashMap <>();
235
- roleMappings .put ("ROLE_MANAGE" , "foo-manage" );
236
- roleMappings .put ("ROLE_VIEW" , "foo-manage" );
237
- roleMappings .put ("ROLE_DEPLOY" , "foo-manage" );
238
- roleMappings .put ("ROLE_DESTROY" , "foo-manage" );
239
- roleMappings .put ("ROLE_MODIFY" , "foo-manage" );
240
- roleMappings .put ("ROLE_SCHEDULE" , "foo-manage" );
241
- roleMappings .put ("ROLE_CREATE" , "blubba-create" );
242
-
243
- Set <String > scopes = new HashSet <>();
244
- scopes .add ("api://foobar/foo-manage" );
245
- scopes .add ("blubba-create" );
242
+ void thatUriStyleScopeRemovesLeadingPart () throws Exception {
243
+ Map <String , String > roleMappings = Map .of (
244
+ "ROLE_MANAGE" , "foo-manage" ,
245
+ "ROLE_VIEW" , "foo-manage" ,
246
+ "ROLE_DEPLOY" , "foo-manage" ,
247
+ "ROLE_DESTROY" , "foo-manage" ,
248
+ "ROLE_MODIFY" , "foo-manage" ,
249
+ "ROLE_SCHEDULE" , "foo-manage" ,
250
+ "ROLE_CREATE" , "blubba-create"
251
+ );
252
+
253
+ Set <String > scopes = Set .of ("api://foobar/foo-manage" , "blubba-create" );
246
254
247
255
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , true , roleMappings );
248
256
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
249
257
scopes , null );
250
258
251
259
assertThat (authorities ).hasSize (7 );
252
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
260
+ assertThat (authorities )
261
+ .extracting (GrantedAuthority ::getAuthority )
253
262
.containsExactlyInAnyOrder ("ROLE_CREATE" , "ROLE_DEPLOY" , "ROLE_DESTROY" , "ROLE_MANAGE" , "ROLE_MODIFY" ,
254
263
"ROLE_SCHEDULE" , "ROLE_VIEW" );
255
264
}
256
265
257
266
@ Test
258
- public void testThatUriStyleScopeParsingCanBeDisabled () throws Exception {
259
- Map <String , String > roleMappings = new HashMap <>();
260
- roleMappings .put ("ROLE_MANAGE" , "/ROLE/2000803042" );
261
- roleMappings .put ("ROLE_VIEW" , "/ROLE/2000803036" );
262
- roleMappings .put ("ROLE_DEPLOY" , "/ROLE/2000803039" );
263
- roleMappings .put ("ROLE_DESTROY" , "/ROLE/20008030340" );
264
- roleMappings .put ("ROLE_MODIFY" , "/ROLE/2000803037" );
265
- roleMappings .put ("ROLE_SCHEDULE" , "/ROLE/2000803038" );
266
- roleMappings .put ("ROLE_CREATE" , "/ROLE/2000803041" );
267
+ void thatUriStyleScopeParsingCanBeDisabled () throws Exception {
268
+ Map <String , String > roleMappings = Map .of (
269
+ "ROLE_MANAGE" , "/ROLE/2000803042" ,
270
+ "ROLE_VIEW" , "/ROLE/2000803036" ,
271
+ "ROLE_DEPLOY" , "/ROLE/2000803039" ,
272
+ "ROLE_DESTROY" , "/ROLE/20008030340" ,
273
+ "ROLE_MODIFY" , "/ROLE/2000803037" ,
274
+ "ROLE_SCHEDULE" , "/ROLE/2000803038" ,
275
+ "ROLE_CREATE" , "/ROLE/2000803041"
276
+ );
267
277
268
278
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping ();
269
279
providerRoleMapping .setMapOauthScopes (true );
270
280
providerRoleMapping .setParseOauthScopePathParts (false );
271
281
providerRoleMapping .getRoleMappings ().putAll (roleMappings );
272
282
273
- Set <String > scopes = new HashSet <>();
274
- scopes .add ("/ROLE/2000803042" );
275
- scopes .add ("/ROLE/2000803036" );
276
- scopes .add ("/ROLE/2000803039" );
277
- scopes .add ("/ROLE/20008030340" );
278
- scopes .add ("/ROLE/2000803037" );
279
- scopes .add ("/ROLE/2000803038" );
280
- scopes .add ("/ROLE/2000803041" );
283
+ Set <String > scopes = Set .of (
284
+ "/ROLE/2000803042" ,
285
+ "/ROLE/2000803036" ,
286
+ "/ROLE/2000803039" ,
287
+ "/ROLE/20008030340" ,
288
+ "/ROLE/2000803037" ,
289
+ "/ROLE/2000803038" ,
290
+ "/ROLE/2000803041"
291
+ );
281
292
282
293
DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper ("uaa" , providerRoleMapping );
283
294
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesMapper .mapScopesToAuthorities ("uaa" ,
284
295
scopes , null );
285
296
286
297
assertThat (authorities ).hasSize (7 );
287
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
298
+ assertThat (authorities )
299
+ .extracting (GrantedAuthority ::getAuthority )
288
300
.containsExactlyInAnyOrder ("ROLE_CREATE" , "ROLE_DEPLOY" , "ROLE_DESTROY" , "ROLE_MANAGE" , "ROLE_MODIFY" ,
289
301
"ROLE_SCHEDULE" , "ROLE_VIEW" );
290
302
}
0 commit comments