Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package oidc.exceptions;

public class CookiesNotSupportedException extends BaseException {
public CookiesNotSupportedException() {
super("Cookies not supported");

public CookiesNotSupportedException(String message) {
super(message);
}

@Override
protected boolean suppressStackTrace() {
return true;
}


}
8 changes: 6 additions & 2 deletions oidc/src/main/java/oidc/saml/AuthnRequestContextConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ public void accept(OpenSaml5AuthenticationRequestResolver.AuthnRequestContext au
AuthnRequest authnRequest = authnRequestContext.getAuthnRequest();
HttpServletRequest request = authnRequestContext.getRequest();

String xForwardedFor = request.getHeader("X-Forwarded-For");
String remoteIp = StringUtils.hasText(xForwardedFor) && !xForwardedFor.equalsIgnoreCase("unknown")
? xForwardedFor.split(",")[0].trim() : request.getRemoteAddr();

HttpSession session = request.getSession(false);
if (session == null) {
LOG.warn("There is no session in the HttpServletRequest. CookiesNotSupportedException will be thrown");
LOG.warn(String.format("There is no session in the HttpServletRequest from IP: %s. CookiesNotSupportedException will be thrown", remoteIp));
} else {
Enumeration<String> attributeNames = session.getAttributeNames();
List<String> list = Collections.list(attributeNames);
Expand All @@ -84,7 +88,7 @@ public void accept(OpenSaml5AuthenticationRequestResolver.AuthnRequestContext au
SavedRequest savedRequest = requestCache.getRequest(request, null);

if (savedRequest == null) {
throw new CookiesNotSupportedException();
throw new CookiesNotSupportedException(String.format("There is no savedRequest or cookies are not supported from IP: %s", remoteIp));
}

Map<String, String[]> parameterMap = savedRequest.getParameterMap();
Expand Down
4 changes: 2 additions & 2 deletions oidc/src/test/java/oidc/web/CustomErrorControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void errorAuthorizationRequestContext() throws URISyntaxException {
@Test
@SuppressWarnings("unchecked")
public void noCookies() throws URISyntaxException {
ModelAndView modelAndView = (ModelAndView) doError(new CookiesNotSupportedException());
ModelAndView modelAndView = (ModelAndView) doError(new CookiesNotSupportedException("test"));
assertEquals("no_session_found", modelAndView.getViewName());
}

Expand All @@ -64,4 +64,4 @@ private Object doError(Exception exception) throws URISyntaxException {
return subject.error(request);
}

}
}
Loading