zoukankan      html  css  js  c++  java
  • How to create custom methods for use in spring security expression language annotations

    From:http://stackoverflow.com/questions/6632982/how-to-create-custom-methods-for-use-in-spring-security-expression-language-anno

    None of the mentioned techniques will work anymore. It seems as though Spring has gone through great lengths to prevent users from overriding the SecurityExpressionRoot. Instead, create a bean like this:

    @Component("mySecurityService")publicclassMySecurityService{publicboolean hasPermission(String key){returntrue;}}

    Then do something like this in your jsp:

    <sec:authorize access="@mySecurityService.hasPermission('special')"><input type="button" value="Special Button"/></sec:authorize>

    Or annotate a method:

    @PreAuthorize("@mySecurityService.hasPermission('special')")publicvoid doSpecialStuff(){...}

    And remember: if you are using Spring and you have to solve a problem by extending classes, overriding methods, implementing interfaces, etc... then you're probably doing something wrong. It's all annotations and xml, that's why we love Spring so much and not (old versions of) EJB.

  • 相关阅读:
    URAL 1018 Binary Apple Tree
    URAL 1029 Ministry
    URAL 1039 Anniversary Party
    URAL 1078 Segments
    Codeforces 918D
    Codeforces 918C
    URAL 1495 One-two, One-two 2
    URAL 1244 Gentlemen
    URAL 1658 Sum of Digits
    URAL 1081 Binary Lexicographic Sequence
  • 原文地址:https://www.cnblogs.com/sun_moon_earth/p/3587679.html
Copyright © 2011-2022 走看看