All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quincy.auth.interceptor.AuthorizationAnnotationInterceptor Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package com.quincy.auth.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;

import com.quincy.auth.annotation.LoginRequired;
import com.quincy.auth.annotation.PermissionNeeded;

@Component("authorizationAnnotationInterceptor")
public class AuthorizationAnnotationInterceptor extends AuthorizationInterceptorAbstract {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		if(handler instanceof HandlerMethod) {
			HandlerMethod method = (HandlerMethod)handler;
			PermissionNeeded permissionNeededAnnotation = method.getMethod().getDeclaredAnnotation(PermissionNeeded.class);
			boolean permissionNeeded = permissionNeededAnnotation!=null;
			boolean loginRequired = method.getMethod().getDeclaredAnnotation(LoginRequired.class)!=null;
			return (!permissionNeeded&&!loginRequired)?true:this.doAuth(request, response, handler, permissionNeeded?permissionNeededAnnotation.value():null);
		} else
			return true;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy