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

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

Introduction

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

Prototype

EvaluationContext createEvaluationContext(Authentication authentication, T invocation);

Source Link

Document

Provides an evaluation context in which to evaluate security expressions for the invocation type.

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.//from w w w  .j  av  a  2 s  .  c  o 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;
}