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