Skip to content

Commit

Permalink
feat: create new exception types
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-martins-mx committed Oct 15, 2024
1 parent 5f810c9 commit 9aef423
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mx.path.model.mdx.web;

import com.mx.path.core.common.accessor.UnauthorizedException;

public class NotAuthenticatedException extends UnauthorizedException {
public NotAuthenticatedException() {
super("Not Authenticated", "Not Authenticated");
}

public NotAuthenticatedException(String message, String userMessage) {
super(message, userMessage);
}

public NotAuthenticatedException(String message, String userMessage, Throwable cause) {
super(message, userMessage, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mx.path.model.mdx.web;

import com.mx.path.core.common.accessor.UnauthorizedException;

public class SessionNotFoundException extends UnauthorizedException {
public SessionNotFoundException() {
super("Session not found", "Session not found");
}

public SessionNotFoundException(String message, String userMessage) {
super(message, userMessage);
}

public SessionNotFoundException(String message, String userMessage, Throwable cause) {
super(message, userMessage, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import com.mx.path.core.common.lang.Strings;
import com.mx.path.core.context.Session;
import com.mx.path.core.context.Session.SessionState;
import com.mx.path.model.mdx.web.NotAuthenticatedException;
import com.mx.path.model.mdx.web.PathTools;
import com.mx.path.model.mdx.web.SessionNotFoundException;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
Expand All @@ -38,14 +40,14 @@ protected final void doFilterInternal(HttpServletRequest request, HttpServletRes
if (PathTools.isSessionRequiredPath(path)
&& Session.current() == null) {

throw new UnauthorizedException("Session not found", "Session not found");
throw new SessionNotFoundException();
}

if (PathTools.isAuthenticationRequiredPath(path)
&& (Session.current() == null
|| Session.current().getSessionState() != SessionState.AUTHENTICATED)) {

throw new UnauthorizedException("Not Authenticated", "Not Authenticated");
throw new NotAuthenticatedException();
}

if (PathTools.isUserRequiredPath(path)) {
Expand Down

0 comments on commit 9aef423

Please sign in to comment.