Update application interceptor

Clean code
This commit is contained in:
Salman Manoe 2024-02-02 13:06:39 +07:00
parent f8f426a7aa
commit f6d6a2faf5
10 changed files with 81 additions and 49 deletions

View File

@ -1,12 +1,10 @@
package com.jasamedika.medifirst2000.interceptor;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
/**
* Interceptor class for All annotation method controller @AppPermission
@ -17,8 +15,6 @@ public class AppInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
HandlerMethod hm = (HandlerMethod) handler;
Method method = hm.getMethod();
return true;
}

View File

@ -96,8 +96,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -176,7 +175,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -228,7 +227,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -292,7 +291,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;

View File

@ -96,8 +96,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -176,7 +175,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -228,7 +227,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -293,7 +292,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;

View File

@ -96,8 +96,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -176,7 +175,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -228,7 +227,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -292,7 +291,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;

View File

@ -96,8 +96,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -176,7 +175,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -228,7 +227,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -292,7 +291,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;

View File

@ -97,8 +97,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -177,7 +176,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -229,7 +228,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -293,7 +292,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;

View File

@ -96,8 +96,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -176,7 +175,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -228,7 +227,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -292,7 +291,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;

View File

@ -96,8 +96,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -176,7 +175,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -228,7 +227,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -292,7 +291,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;

View File

@ -97,8 +97,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -177,7 +176,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -229,7 +228,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -293,7 +292,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;

View File

@ -96,8 +96,7 @@ public class AppInterceptor implements HandlerInterceptor {
return potongan.toString();
}
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response, String AlamatUrlForm,
boolean supervisi) throws Exception {
private boolean checkAuthSecure(HttpServletRequest request, HttpServletResponse response) throws Exception {
Authentication authentication = tokenAuthenticationService.getAuthentication(request);
namaUser = authentication.getName();
loginUser = loginUserDao.findByNamaUser(namaUser);
@ -176,7 +175,7 @@ public class AppInterceptor implements HandlerInterceptor {
.findByAlamatUrlForm(filterUrlForm(AlamatUrlForm));
if (CommonUtil.isNullOrEmpty(objekModulAplikasi))
return true;
if (!checkAuthSecure(request, response, AlamatUrlForm, false))
if (!checkAuthSecure(request, response))
return false;
int resultUser = checkUserPermision(loginUser.get(0), objekModulAplikasi.get(0), action);
if (resultUser == 0) {
@ -228,7 +227,7 @@ public class AppInterceptor implements HandlerInterceptor {
hm = (HandlerMethod) handler;
method = hm.getMethod();
} else {
return checkAuthSecure(request, response, AlamatUrlForm, true);
return checkAuthSecure(request, response);
}
boolean usingAnno = method != null && method.isAnnotationPresent(AppPermission.class);
boolean postM = "POST".equals(methodHttp);
@ -292,7 +291,12 @@ public class AppInterceptor implements HandlerInterceptor {
: request.getHeader(Constants.HttpHeader.TGL_KIRIM);
boolean notHttpOK = response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST;
boolean notLewatMenu = CommonUtil.isNullOrEmpty(AlamatUrlForm) || CommonUtil.isNullOrEmpty(KdRuangan);
Integer ruanganAsalId = Integer.parseInt(KdRuangan);
Integer ruanganAsalId;
try {
ruanganAsalId = Integer.parseInt(KdRuangan);
} catch (NumberFormatException e) {
ruanganAsalId = null;
}
boolean adaError = CommonUtil.isNotNullOrEmpty(ex);
if (notHttpOK || notLewatMenu || adaError)
return;