| <?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 :: Test Coverage</a> > <a href="../index.html" class="el_bundle">shiro-core</a> > <a href="index.source.html" class="el_package">org.apache.shiro.authz.aop</a> > <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 |
| * "License"); 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 |
| * "AS IS" 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 <tt>AnnotationMethodInterceptor</tt> 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 <code>handler</code> is set which will be used to perform the |
| * authorization assertion checks when a supported annotation is encountered. |
| * @param handler the internal <code>handler</code> used to perform authorization assertion checks when a |
| * supported annotation is encountered. |
| */ |
| public AuthorizingAnnotationMethodInterceptor( AuthorizingAnnotationHandler handler ) { |
| <span class="fc" id="L43"> super(handler);</span> |
| <span class="fc" id="L44"> }</span> |
| |
| /** |
| * |
| * @param handler |
| * @param resolver |
| * @since 1.1 |
| */ |
| public AuthorizingAnnotationMethodInterceptor( AuthorizingAnnotationHandler handler, |
| AnnotationResolver resolver) { |
| <span class="fc" id="L54"> super(handler, resolver);</span> |
| <span class="fc" id="L55"> }</span> |
| |
| /** |
| * Ensures the <code>methodInvocation</code> 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 <code>MethodInvocation</code> 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 <code>MethodInvocation</code>. |
| * <p/> |
| * 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 <code>MethodInvocation</code> 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="fc" id="L84"> ((AuthorizingAnnotationHandler)getHandler()).assertAuthorized(getAnnotation(mi));</span> |
| } |
| <span class="fc" 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="pc bpc" id="L90" title="1 of 2 branches missed."> if (ae.getCause() == null) ae.initCause(new AuthorizationException("Not authorized to invoke method: " + mi.getMethod()));</span> |
| <span class="fc" id="L91"> throw ae;</span> |
| <span class="fc" id="L92"> } </span> |
| <span class="fc" id="L93"> }</span> |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html> |