View Javadoc
1   package org.springframework.security.oauth2.provider.expression;
2   
3   import org.aopalliance.intercept.MethodInvocation;
4   import org.springframework.expression.ExpressionParser;
5   import org.springframework.expression.spel.support.StandardEvaluationContext;
6   import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
7   import org.springframework.security.core.Authentication;
8   
9   /**
10   * <p>
11   * A security expression handler that can handle default method security expressions plus the set provided by
12   * {@link OAuth2SecurityExpressionMethods} using the variable oauth2 to access the methods. For example, the expression
13   * <code>#oauth2.clientHasRole('ROLE_ADMIN')</code> would invoke {@link OAuth2SecurityExpressionMethods#clientHasRole}
14   * </p>
15   * <p>
16   * By default the {@link OAuth2ExpressionParser} is used. If this is undesirable one can inject their own
17   * {@link ExpressionParser} using {@link #setExpressionParser(ExpressionParser)}.
18   * </p>
19   * 
20   * @author Dave Syer
21   * @author Rob Winch
22   * @see OAuth2ExpressionParser
23   */
24  public class OAuth2MethodSecurityExpressionHandler extends DefaultMethodSecurityExpressionHandler {
25  
26  	public OAuth2MethodSecurityExpressionHandler() {
27  		setExpressionParser(new OAuth2ExpressionParser(getExpressionParser()));
28  	}
29  
30  	@Override
31  	public StandardEvaluationContext createEvaluationContextInternal(Authentication authentication, MethodInvocation mi) {
32  		StandardEvaluationContext ec = super.createEvaluationContextInternal(authentication, mi);
33  		ec.setVariable("oauth2", new OAuth2SecurityExpressionMethods(authentication));
34  		return ec;
35  	}
36  }