001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019 package org.tynamo.shiro.extension.authz.annotations.utils.casters.method;
020
021 import org.apache.shiro.authz.annotation.RequiresAuthentication;
022 import org.apache.shiro.authz.annotation.RequiresGuest;
023 import org.apache.shiro.authz.annotation.RequiresPermissions;
024 import org.apache.shiro.authz.annotation.RequiresRoles;
025 import org.apache.shiro.authz.annotation.RequiresUser;
026 import org.apache.shiro.authz.aop.AuthenticatedAnnotationHandler;
027 import org.apache.shiro.authz.aop.AuthorizingAnnotationHandler;
028 import org.apache.shiro.authz.aop.GuestAnnotationHandler;
029 import org.apache.shiro.authz.aop.PermissionAnnotationHandler;
030 import org.apache.shiro.authz.aop.RoleAnnotationHandler;
031 import org.apache.shiro.authz.aop.UserAnnotationHandler;
032
033
034 /**
035 * Creates a handler based on the annotation type.
036 *
037 */
038 public class HandlerCreateVisitor implements MethodAnnotationCasterVisitor {
039
040 private AuthorizingAnnotationHandler handler;
041
042 @Override
043 public void visitRequiresAuthentication(RequiresAuthentication annotation) {
044 handler = new AuthenticatedAnnotationHandler();
045 }
046
047 @Override
048 public void visitRequiresGuest(RequiresGuest annotation) {
049 handler = new GuestAnnotationHandler();
050 }
051
052 @Override
053 public void visitRequiresPermissions(RequiresPermissions annotation) {
054 handler = new PermissionAnnotationHandler();
055 }
056
057 @Override
058 public void visitRequiresRoles(RequiresRoles annotation) {
059 handler = new RoleAnnotationHandler();
060 }
061
062 @Override
063 public void visitRequiresUser(RequiresUser annotation) {
064 handler = new UserAnnotationHandler();
065 }
066
067 @Override
068 public void visitNotFound() {
069 handler = null;
070
071 }
072
073 public AuthorizingAnnotationHandler getHandler() {
074 return handler;
075 }
076
077 }