spring-el

Spring-Boot @PreAuthorize allow operation only for admin or if the authenticated user id is same as path parameter id

六眼飞鱼酱① 提交于 2020-08-27 22:09:51
问题 I have a controller which has User CRUD operations. @Controller public class UserController { // @TODO need to check whether userId == authUser.id or authUser is admin?? // @PreAuthorize("hasRole('ROLE_ADMIN) or ...???...") @PostMapping("/user/{id}/edit") public boolean editUser(@PathVariable("id") long userId, @RequestBody User newUserObj, @CurrentUser authUser) { // I don't like to always call a helper function from here // check(authUser.getId() == userId); return userService.edit(userId,

How to add an object without a constructor to a list using Spring Expression Language

为君一笑 提交于 2020-08-08 13:54:04
问题 I want to add a BigDecimal to a list using Spring Expression Language. public class SpelTest { public List<BigDecimal> values; StandardEvaluationContext context; SpelExpressionParser parser; @Before public void setup() { values = new ArrayList<>(); context = new StandardEvaluationContext(this); parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); } @Test public void shouldChangeValue() { values.add(BigDecimal.ONE); parser.parseExpression("values[0]").setValue(context,

How to add an object without a constructor to a list using Spring Expression Language

☆樱花仙子☆ 提交于 2020-08-08 13:51:58
问题 I want to add a BigDecimal to a list using Spring Expression Language. public class SpelTest { public List<BigDecimal> values; StandardEvaluationContext context; SpelExpressionParser parser; @Before public void setup() { values = new ArrayList<>(); context = new StandardEvaluationContext(this); parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); } @Test public void shouldChangeValue() { values.add(BigDecimal.ONE); parser.parseExpression("values[0]").setValue(context,

How to assign values for a list of some objects defined as variable with Spring Expression Language(Or the other expression languages you aware of)

喜你入骨 提交于 2020-07-23 02:41:40
问题 In Spel, it is easy to assign some values for a List property. For example having object foo with a property defined as List, I usually do: SpelParserConfiguration config = new SpelParserConfiguration(true,true); ExpressionParser parser = new SpelExpressionParser(config); Foo foo = new Foo(); EvaluationContext context = new StandardEvaluationContext(foo); parser.parseExpression("barList[1].test='11111111'") .getValue(context); But what do you do for the case you want to assign values for a

How to assign values for a list of some objects defined as variable with Spring Expression Language(Or the other expression languages you aware of)

旧城冷巷雨未停 提交于 2020-07-23 02:40:55
问题 In Spel, it is easy to assign some values for a List property. For example having object foo with a property defined as List, I usually do: SpelParserConfiguration config = new SpelParserConfiguration(true,true); ExpressionParser parser = new SpelExpressionParser(config); Foo foo = new Foo(); EvaluationContext context = new StandardEvaluationContext(foo); parser.parseExpression("barList[1].test='11111111'") .getValue(context); But what do you do for the case you want to assign values for a