Skip to content

Commit b440372

Browse files
committed
size() to length, updated config, fixed hasRole
1 parent cfda706 commit b440372

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ module.exports = function (grunt) {
5858
'<%= config.app %>/ast/*.js',
5959

6060
'<%= config.app %>/SpelExpressionParser.js',
61-
'<%= config.app %>/SpelExpressionEvaluator.js'
61+
'<%= config.app %>/SpelExpressionEvaluator.js',
62+
'<%= config.app %>/StandardContext.js'
6263
],
6364
dest: '<%= config.dist %>/spel2js.js'
6465
}

src/StandardContext.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,22 @@
88
context.principal = principal || {};
99

1010
context.hasRole = function (role) {
11-
if (!context.authentication && !context.authentication.authorities) {
11+
var hasRole = false;
12+
13+
if (!role) {
14+
return false;
15+
}
16+
if (!context.authentication && !Array.isArray(context.authentication.authorities)) {
1217
return false;
1318
}
1419

15-
return !!~context.authentication.authorities.indexOf(role);
20+
context.authentication.authorities.forEach(function (grantedAuthority) {
21+
if (grantedAuthority.authority.toLowerCase() === role.toLowerCase()) {
22+
hasRole = true;
23+
}
24+
});
25+
26+
return hasRole;
1627
};
1728

1829
context.hasPermission = function (/*variable arguments*/) {
@@ -21,7 +32,9 @@
2132
if (args.length === 1) {
2233
return context.hasRole(args[0]);
2334
}
24-
}
35+
};
36+
37+
return context;
2538
}
2639

2740
exports.StandardContext = {

src/ast/MethodReference.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
return context[methodName.charAt(3).toLowerCase() + methodName.substring(4)] = compiledArgs[0];
5353
}
5454

55+
//size() -> length
56+
if (methodName === 'size' && args.length === 0) {
57+
return context.length;
58+
}
59+
5560
method = maybeHandleNullSafeNavigation(context[methodName]);
5661
if (method) {
5762
return method.apply(context, compiledArgs);

src/ast/PropertyReference.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,21 @@
2121
}
2222
}
2323

24-
//handle safe navigation
2524
if (context[propertyName] === undefined) {
25+
//handle safe navigation
2626
if (nullSafeNavigation) {
2727
return null;
2828
}
2929

30+
//handle conversion of Java properties to JavaScript properties
31+
//this might cause problems, I'll look into alternatives
32+
if (propertyName === 'size') {
33+
return context.length;
34+
}
35+
3036
throw {
3137
name: 'NullPointerException',
32-
message: 'Property ' + propertyName + ' does not exist.'
38+
message: 'Property \'' + propertyName + '\' does not exist.'
3339
};
3440
}
3541

test/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ module.exports = function (config) {
9595

9696
'src/SpelExpressionParser.js',
9797
'src/SpelExpressionEvaluator.js',
98+
'<%= config.app %>/StandardContext.js',
9899

99100
'test/spec/**/*.spec.js'
100101
]

0 commit comments

Comments
 (0)