Example usage for org.springframework.security.web.access.expression DefaultWebSecurityExpressionHandler getExpressionParser

List of usage examples for org.springframework.security.web.access.expression DefaultWebSecurityExpressionHandler getExpressionParser

Introduction

In this page you can find the example usage for org.springframework.security.web.access.expression DefaultWebSecurityExpressionHandler getExpressionParser.

Prototype

ExpressionParser getExpressionParser();

Source Link

Usage

From source file:it.scoppelletti.programmerpower.web.view.AuthorizeComponent.java

/**
 * Emette l’apertura del tag e verifica se deve essere emesso il
 * contenuto del tag stesso./*w  w  w  .j a  v  a 2  s . co m*/
 * 
 * @param  writer Flusso di scrittura.
 * @return        Esito della verifica.
 */
@Override
public boolean start(Writer writer) {
    Authentication currentUser;
    FilterInvocation filter;
    Expression accessExpr;
    DefaultWebSecurityExpressionHandler exprHandler;

    if (Strings.isNullOrEmpty(myAccess)) {
        throw new PropertyNotSetException(toString(), "access");
    }

    currentUser = SecurityContextHolder.getContext().getAuthentication();
    if (currentUser == null) {
        throw new ObjectNotFoundException(Authentication.class.getName());
    }

    exprHandler = getExpressionHandler();
    accessExpr = exprHandler.getExpressionParser().parseExpression(myAccess);

    filter = new FilterInvocation(ServletActionContext.getRequest(), ServletActionContext.getResponse(),
            new AuthorizeComponent.DummyChain());

    if (ExpressionUtils.evaluateAsBoolean(accessExpr,
            exprHandler.createEvaluationContext(currentUser, filter))) {
        return true;
    }

    return false;
}