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 mapConstructorWithIncompleteRoleMappings () throws Exception {
86
88
ProviderRoleMapping roleMapping = new ProviderRoleMapping ();
87
89
roleMapping .setMapOauthScopes (true );
88
90
roleMapping .addRoleMapping ("ROLE_MANAGE" , "foo-scope-in-oauth" );
@@ -93,80 +95,115 @@ public void testMapConstructorWithIncompleteRoleMappings() throws Exception {
93
95
}
94
96
95
97
@ Test
96
- public void testThat7MappedAuthoritiesAreReturned () throws Exception {
97
- Map <String , String > roleMappings = new HashMap <>();
98
- roleMappings .put ("ROLE_MANAGE" , "foo-manage" );
99
- roleMappings .put ("ROLE_VIEW" , "bar-view" );
100
- roleMappings .put ("ROLE_CREATE" , "blubba-create" );
101
- roleMappings .put ("ROLE_MODIFY" , "foo-modify" );
102
- roleMappings .put ("ROLE_DEPLOY" , "foo-deploy" );
103
- roleMappings .put ("ROLE_DESTROY" , "foo-destroy" );
104
- roleMappings .put ("ROLE_SCHEDULE" , "foo-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 > scopes = new HashSet <>();
111
- scopes .add ("foo-manage" );
112
- scopes .add ("bar-view" );
113
- scopes .add ("blubba-create" );
114
- scopes .add ("foo-modify" );
115
- scopes .add ("foo-deploy" );
116
- scopes .add ("foo-destroy" );
117
- scopes .add ("foo-schedule" );
113
+ Set <String > roles = Set .of ("dataflow_manage" , "dataflow_view" , "dataflow_deploy" );
114
+
115
+ DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper ("uaa" , providerRoleMapping );
116
+ Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesMapper .mapScopesToAuthorities ("uaa" ,
117
+ roles , null );
118
+
119
+ assertThat (authorities ).hasSize (3 );
120
+ assertThat (authorities )
121
+ .extracting (GrantedAuthority ::getAuthority )
122
+ .containsExactlyInAnyOrder ("ROLE_DEPLOY" , "ROLE_MANAGE" , "ROLE_VIEW" );
123
+ }
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
+ );
135
+
136
+ ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping ();
137
+ providerRoleMapping .setMapOauthScopes (true );
138
+ providerRoleMapping .getRoleMappings ().putAll (roleMappings );
139
+
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
+ );
118
149
119
150
DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper ("uaa" , providerRoleMapping );
120
151
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesMapper .mapScopesToAuthorities ("uaa" ,
121
152
scopes , null );
122
153
123
154
assertThat (authorities ).hasSize (7 );
124
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
155
+ assertThat (authorities )
156
+ .extracting (GrantedAuthority ::getAuthority )
125
157
.containsExactlyInAnyOrder ("ROLE_CREATE" , "ROLE_DEPLOY" , "ROLE_DESTROY" , "ROLE_MANAGE" , "ROLE_MODIFY" ,
126
158
"ROLE_SCHEDULE" , "ROLE_VIEW" );
127
159
}
128
160
129
161
@ Test
130
- public void testThat3MappedAuthoritiesAreReturnedForDefaultMapping () throws Exception {
162
+ void that3MappedAuthoritiesAreReturnedForDefaultMapping () throws Exception {
131
163
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping ();
132
164
providerRoleMapping .setMapOauthScopes (true );
133
165
134
- Set <String > scopes = new HashSet <>();
135
- scopes .add ("dataflow.manage" );
136
- scopes .add ("dataflow.view" );
137
- scopes .add ("dataflow.create" );
166
+ Set <String > scopes = Set .of (
167
+ "dataflow.manage" ,
168
+ "dataflow.view" ,
169
+ "dataflow.create"
170
+ );
138
171
139
172
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , providerRoleMapping );
140
173
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
141
174
scopes , null );
142
175
143
176
assertThat (authorities ).hasSize (3 );
144
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
177
+ assertThat (authorities )
178
+ .extracting (GrantedAuthority ::getAuthority )
145
179
.containsExactlyInAnyOrder ("ROLE_MANAGE" , "ROLE_CREATE" , "ROLE_VIEW" );
146
180
}
147
181
148
182
@ Test
149
- public void testThat7MappedAuthoritiesAreReturnedForDefaultMappingWithoutMappingScopes () throws Exception {
150
- Set <String > scopes = new HashSet <>();
151
- scopes .add ("dataflow.manage" );
152
- scopes .add ("dataflow.view" );
153
- 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
+ );
154
189
155
190
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , false );
156
191
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
157
192
scopes , null );
158
193
159
194
assertThat (authorities ).hasSize (7 );
160
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
195
+ assertThat (authorities )
196
+ .extracting (GrantedAuthority ::getAuthority )
161
197
.containsExactlyInAnyOrder ("ROLE_CREATE" , "ROLE_DEPLOY" , "ROLE_DESTROY" , "ROLE_MANAGE" , "ROLE_MODIFY" ,
162
198
"ROLE_SCHEDULE" , "ROLE_VIEW" );
163
199
}
164
200
165
201
@ Test
166
- public void testThat2MappedAuthoritiesAreReturnedForDefaultMapping () throws Exception {
167
- Set <String > scopes = new HashSet <>();
168
- scopes .add ("dataflow.view" );
169
- scopes .add ("dataflow.create" );
202
+ void that2MappedAuthoritiesAreReturnedForDefaultMapping () throws Exception {
203
+ Set <String > scopes = Set .of (
204
+ "dataflow.view" ,
205
+ "dataflow.create"
206
+ );
170
207
171
208
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , true );
172
209
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
@@ -178,19 +215,18 @@ public void testThat2MappedAuthoritiesAreReturnedForDefaultMapping() throws Exce
178
215
}
179
216
180
217
@ Test
181
- public void testThat7AuthoritiesAreReturnedAndOneOAuthScopeCoversMultipleServerRoles () throws Exception {
182
- Map <String , String > roleMappings = new HashMap <>();
183
- roleMappings .put ("ROLE_MANAGE" , "foo-manage" );
184
- roleMappings .put ("ROLE_VIEW" , "foo-manage" );
185
- roleMappings .put ("ROLE_DEPLOY" , "foo-manage" );
186
- roleMappings .put ("ROLE_DESTROY" , "foo-manage" );
187
- roleMappings .put ("ROLE_MODIFY" , "foo-manage" );
188
- roleMappings .put ("ROLE_SCHEDULE" , "foo-manage" );
189
- roleMappings .put ("ROLE_CREATE" , "blubba-create" );
190
-
191
- Set <String > scopes = new HashSet <>();
192
- scopes .add ("foo-manage" );
193
- 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" );
194
230
195
231
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , true , roleMappings );
196
232
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
@@ -203,61 +239,64 @@ public void testThat7AuthoritiesAreReturnedAndOneOAuthScopeCoversMultipleServerR
203
239
}
204
240
205
241
@ Test
206
- public void testThatUriStyleScopeRemovesLeadingPart () throws Exception {
207
- Map <String , String > roleMappings = new HashMap <>();
208
- roleMappings .put ("ROLE_MANAGE" , "foo-manage" );
209
- roleMappings .put ("ROLE_VIEW" , "foo-manage" );
210
- roleMappings .put ("ROLE_DEPLOY" , "foo-manage" );
211
- roleMappings .put ("ROLE_DESTROY" , "foo-manage" );
212
- roleMappings .put ("ROLE_MODIFY" , "foo-manage" );
213
- roleMappings .put ("ROLE_SCHEDULE" , "foo-manage" );
214
- roleMappings .put ("ROLE_CREATE" , "blubba-create" );
215
-
216
- Set <String > scopes = new HashSet <>();
217
- scopes .add ("api://foobar/foo-manage" );
218
- 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" );
219
254
220
255
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper ("uaa" , true , roleMappings );
221
256
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesExtractor .mapScopesToAuthorities ("uaa" ,
222
257
scopes , null );
223
258
224
259
assertThat (authorities ).hasSize (7 );
225
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
260
+ assertThat (authorities )
261
+ .extracting (GrantedAuthority ::getAuthority )
226
262
.containsExactlyInAnyOrder ("ROLE_CREATE" , "ROLE_DEPLOY" , "ROLE_DESTROY" , "ROLE_MANAGE" , "ROLE_MODIFY" ,
227
263
"ROLE_SCHEDULE" , "ROLE_VIEW" );
228
264
}
229
265
230
266
@ Test
231
- public void testThatUriStyleScopeParsingCanBeDisabled () throws Exception {
232
- Map <String , String > roleMappings = new HashMap <>();
233
- roleMappings .put ("ROLE_MANAGE" , "/ROLE/2000803042" );
234
- roleMappings .put ("ROLE_VIEW" , "/ROLE/2000803036" );
235
- roleMappings .put ("ROLE_DEPLOY" , "/ROLE/2000803039" );
236
- roleMappings .put ("ROLE_DESTROY" , "/ROLE/20008030340" );
237
- roleMappings .put ("ROLE_MODIFY" , "/ROLE/2000803037" );
238
- roleMappings .put ("ROLE_SCHEDULE" , "/ROLE/2000803038" );
239
- 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
+ );
240
277
241
278
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping ();
242
279
providerRoleMapping .setMapOauthScopes (true );
243
280
providerRoleMapping .setParseOauthScopePathParts (false );
244
281
providerRoleMapping .getRoleMappings ().putAll (roleMappings );
245
282
246
- Set <String > scopes = new HashSet <>();
247
- scopes .add ("/ROLE/2000803042" );
248
- scopes .add ("/ROLE/2000803036" );
249
- scopes .add ("/ROLE/2000803039" );
250
- scopes .add ("/ROLE/20008030340" );
251
- scopes .add ("/ROLE/2000803037" );
252
- scopes .add ("/ROLE/2000803038" );
253
- 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
+ );
254
292
255
293
DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper ("uaa" , providerRoleMapping );
256
294
Collection <? extends GrantedAuthority > authorities = defaultAuthoritiesMapper .mapScopesToAuthorities ("uaa" ,
257
295
scopes , null );
258
296
259
297
assertThat (authorities ).hasSize (7 );
260
- assertThat (authorities .stream ().map (authority -> authority .getAuthority ()).collect (Collectors .toList ()))
298
+ assertThat (authorities )
299
+ .extracting (GrantedAuthority ::getAuthority )
261
300
.containsExactlyInAnyOrder ("ROLE_CREATE" , "ROLE_DEPLOY" , "ROLE_DESTROY" , "ROLE_MANAGE" , "ROLE_MODIFY" ,
262
301
"ROLE_SCHEDULE" , "ROLE_VIEW" );
263
302
}
0 commit comments