blob: 3ab3f1a6216387047a6221936e29ac4b2cd1b577 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>AuthorizingAnnotationMethodInterceptor.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Shiro :: Core</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.authz.aop</a> &gt; <span class="el_source">AuthorizingAnnotationMethodInterceptor.java</span></div><h1>AuthorizingAnnotationMethodInterceptor.java</h1><pre class="source lang-java linenums">/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.authz.aop;
import org.apache.shiro.aop.AnnotationMethodInterceptor;
import org.apache.shiro.aop.AnnotationResolver;
import org.apache.shiro.aop.MethodInvocation;
import org.apache.shiro.authz.AuthorizationException;
/**
* An &lt;tt&gt;AnnotationMethodInterceptor&lt;/tt&gt; that asserts the calling code is authorized to execute the method
* before allowing the invocation to continue by inspecting code annotations to perform an access control check.
*
* @since 0.1
*/
public abstract class AuthorizingAnnotationMethodInterceptor extends AnnotationMethodInterceptor
{
/**
* Constructor that ensures the internal &lt;code&gt;handler&lt;/code&gt; is set which will be used to perform the
* authorization assertion checks when a supported annotation is encountered.
* @param handler the internal &lt;code&gt;handler&lt;/code&gt; used to perform authorization assertion checks when a
* supported annotation is encountered.
*/
public AuthorizingAnnotationMethodInterceptor( AuthorizingAnnotationHandler handler ) {
<span class="nc" id="L43"> super(handler);</span>
<span class="nc" id="L44"> }</span>
/**
*
* @param handler
* @param resolver
* @since 1.1
*/
public AuthorizingAnnotationMethodInterceptor( AuthorizingAnnotationHandler handler,
AnnotationResolver resolver) {
<span class="nc" id="L54"> super(handler, resolver);</span>
<span class="nc" id="L55"> }</span>
/**
* Ensures the &lt;code&gt;methodInvocation&lt;/code&gt; is allowed to execute first before proceeding by calling the
* {@link #assertAuthorized(org.apache.shiro.aop.MethodInvocation) assertAuthorized} method first.
*
* @param methodInvocation the method invocation to check for authorization prior to allowing it to proceed/execute.
* @return the return value from the method invocation (the value of {@link org.apache.shiro.aop.MethodInvocation#proceed() MethodInvocation.proceed()}).
* @throws org.apache.shiro.authz.AuthorizationException if the &lt;code&gt;MethodInvocation&lt;/code&gt; is not allowed to proceed.
* @throws Throwable if any other error occurs.
*/
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
<span class="nc" id="L67"> assertAuthorized(methodInvocation);</span>
<span class="nc" id="L68"> return methodInvocation.proceed();</span>
}
/**
* Ensures the calling Subject is authorized to execute the specified &lt;code&gt;MethodInvocation&lt;/code&gt;.
* &lt;p/&gt;
* As this is an AnnotationMethodInterceptor, this implementation merely delegates to the internal
* {@link AuthorizingAnnotationHandler AuthorizingAnnotationHandler} by first acquiring the annotation by
* calling {@link #getAnnotation(MethodInvocation) getAnnotation(methodInvocation)} and then calls
* {@link AuthorizingAnnotationHandler#assertAuthorized(java.lang.annotation.Annotation) handler.assertAuthorized(annotation)}.
*
* @param mi the &lt;code&gt;MethodInvocation&lt;/code&gt; to check to see if it is allowed to proceed/execute.
* @throws AuthorizationException if the method invocation is not allowed to continue/execute.
*/
public void assertAuthorized(MethodInvocation mi) throws AuthorizationException {
try {
<span class="nc" id="L84"> ((AuthorizingAnnotationHandler)getHandler()).assertAuthorized(getAnnotation(mi));</span>
}
<span class="nc" id="L86"> catch(AuthorizationException ae) {</span>
// Annotation handler doesn't know why it was called, so add the information here if possible.
// Don't wrap the exception here since we don't want to mask the specific exception, such as
// UnauthenticatedException etc.
<span class="nc bnc" id="L90" title="All 2 branches missed."> if (ae.getCause() == null) ae.initCause(new AuthorizationException(&quot;Not authorized to invoke method: &quot; + mi.getMethod()));</span>
<span class="nc" id="L91"> throw ae;</span>
<span class="nc" id="L92"> } </span>
<span class="nc" id="L93"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html>