[STYLE] aspectの無駄な改行やスペースなどの削除
This commit is contained in:
@@ -5,10 +5,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* SessionCheckアノテーション
|
||||
* セッションチェックを行うメソッドに付与する
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface PermissionCheck {
|
||||
|
||||
@@ -1,114 +1,76 @@
|
||||
package com.example.rhizome.aop.aspect;
|
||||
|
||||
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
|
||||
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
|
||||
import com.example.rhizome.app.presentation.form.LoginUserForm;
|
||||
import com.example.rhizome.exception.InsufficientPermissionException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
|
||||
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
|
||||
import com.example.rhizome.app.presentation.form.LoginUserForm;
|
||||
import com.example.rhizome.exception.InsufficientPermissionException;
|
||||
|
||||
/**
|
||||
* 権限チェック用のAOP
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class PermissionCheckAspect {
|
||||
|
||||
HttpServletRequest request;
|
||||
HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
public PermissionCheckAspect(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
@Autowired
|
||||
public PermissionCheckAspect(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
// Aspectのフックを定義(今回はPermissionCheckアノテーションが定義されているメソッドが動作するタイミング)
|
||||
@Pointcut("@annotation(com.example.rhizome.aop.aspect.PermissionCheck)")
|
||||
public void permissionCheckMethod() {
|
||||
}
|
||||
@Pointcut("@annotation(com.example.rhizome.aop.aspect.PermissionCheck)")
|
||||
public void permissionCheckMethod() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 権限チェック
|
||||
*/
|
||||
@Before("permissionCheckMethod()")
|
||||
public void checkPermission() {
|
||||
// ログインユーザの取得
|
||||
LoginUserForm loginUserForm = (LoginUserForm) request.getSession().getAttribute(SessionKeyword.LOGIN_USER);
|
||||
@Before("permissionCheckMethod()")
|
||||
public void checkPermission() {
|
||||
LoginUserForm loginUserForm = (LoginUserForm) request.getSession().getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
// ログインユーザが取得できない場合、または権限がない場合はエラー画面に遷移
|
||||
if (loginUserForm == null || !hasRequiredPermission(request.getRequestURI(), loginUserForm)) {
|
||||
throw new InsufficientPermissionException("不正な遷移です");
|
||||
}
|
||||
if (loginUserForm == null || !hasRequiredPermission(request.getRequestURI(), loginUserForm)) {
|
||||
throw new InsufficientPermissionException("不正な遷移です");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 遷移先のURLとログインユーザの権限から、遷移可否を判定する
|
||||
*
|
||||
* @param targetURL 遷移したいURL
|
||||
* @param loginUserForm リクエスト元のユーザ
|
||||
* @return true:遷移可 false:遷移不可
|
||||
*/
|
||||
private boolean hasRequiredPermission(String targetURL, LoginUserForm loginUserForm) {
|
||||
private boolean hasRequiredPermission(String targetURL, LoginUserForm loginUserForm) {
|
||||
|
||||
// 管理者権限
|
||||
if (isAdminTransition(targetURL, loginUserForm)) {
|
||||
return true;
|
||||
}
|
||||
if (isAdminTransition(targetURL, loginUserForm)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 一般権限
|
||||
if (isUserTransition(targetURL, loginUserForm)) {
|
||||
return true;
|
||||
}
|
||||
if (isUserTransition(targetURL, loginUserForm)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// アクセス不許可の場合の処理(不正アクセス画面に遷移)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理者用のアカウントで管理者向けのページアクセスか
|
||||
*
|
||||
* @param targetURL 遷移したいURL
|
||||
* @param loginUserForm リクエスト元のユーザ
|
||||
* @return true:遷移可 false:遷移不可
|
||||
*/
|
||||
private boolean isAdminTransition(String targetURL, LoginUserForm loginUserForm) {
|
||||
private boolean isAdminTransition(String targetURL, LoginUserForm loginUserForm) {
|
||||
|
||||
// 管理者か
|
||||
if (!loginUserForm.isAdminUser()) {
|
||||
return false;
|
||||
}
|
||||
if (!loginUserForm.isAdminUser()) {
|
||||
return false;
|
||||
}
|
||||
if (!TransitionTargetPageNameKeyword.getAdminPageList().contains(targetURL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 管理者向けのページ遷移か
|
||||
if (!TransitionTargetPageNameKeyword.getAdminPageList().contains(targetURL)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private boolean isUserTransition(String targetURL, LoginUserForm loginUserForm) {
|
||||
|
||||
/**
|
||||
* 一般ユーザ用のアカウントで一般ユーザ向けのページアクセスか
|
||||
*
|
||||
* @param targetURL 遷移したいURL
|
||||
* @param loginUserForm リクエスト元のユーザ
|
||||
* @return true:遷移可 false:遷移不可
|
||||
*/
|
||||
private boolean isUserTransition(String targetURL, LoginUserForm loginUserForm) {
|
||||
if (loginUserForm.isAdminUser()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 管理者か
|
||||
if (loginUserForm.isAdminUser()) {
|
||||
return false;
|
||||
}
|
||||
return TransitionTargetPageNameKeyword.getUserPageList().contains(targetURL);
|
||||
|
||||
// 一般ユーザ向けのページ遷移か
|
||||
return TransitionTargetPageNameKeyword.getUserPageList().contains(targetURL);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* SessionCheckアノテーション
|
||||
* セッションチェックを行うメソッドに付与する
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface SessionCheck {
|
||||
|
||||
@@ -1,47 +1,40 @@
|
||||
package com.example.rhizome.aop.aspect;
|
||||
|
||||
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
|
||||
import com.example.rhizome.exception.NoSessionException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
|
||||
import com.example.rhizome.exception.NoSessionException;
|
||||
|
||||
/**
|
||||
* セッションチェック用のAOP
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class SessionCheckAspect {
|
||||
|
||||
HttpServletRequest request;
|
||||
HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
public SessionCheckAspect(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
@Autowired
|
||||
public SessionCheckAspect(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Pointcut("@annotation(com.example.rhizome.aop.aspect.SessionCheck)")
|
||||
public void sessionCheckMethod() {
|
||||
}
|
||||
@Pointcut("@annotation(com.example.rhizome.aop.aspect.SessionCheck)")
|
||||
public void sessionCheckMethod() {
|
||||
}
|
||||
|
||||
/**
|
||||
* セッションチェック
|
||||
*/
|
||||
@Before("sessionCheckMethod()")
|
||||
public void checkSession() {
|
||||
// セッションの取得
|
||||
HttpSession session = request.getSession(false);
|
||||
@Before("sessionCheckMethod()")
|
||||
public void checkSession() {
|
||||
HttpSession session = request.getSession(false);
|
||||
|
||||
// セッションが取得できない場合はエラー画面に遷移
|
||||
if (session == null || session.getAttribute(SessionKeyword.LOGIN_USER) == null) {
|
||||
throw new NoSessionException("不正なログインです");
|
||||
}
|
||||
if (session == null || session.getAttribute(SessionKeyword.LOGIN_USER) == null) {
|
||||
throw new NoSessionException("不正なログインです");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user