Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue #203] Catch Win32Exception and make 401 #206

Merged
merged 2 commits into from
Apr 11, 2015
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* [#187](https://github.com/dblock/waffle/pull/187): Removed Spring 2 and Tomcat 5 support.
* [#188](https://github.com/dblock/waffle/issues/188): Added support for service provider to authorize the principal.
* [#192](https://github.com/dblock/waffle/pull/192): Fix: Tomcat 8 MixedAuthenticator uses LoginConfig out of context.
* [#206](https://github.com/dblock/waffle/pull/206): Fix issue [#203](https://github.com/dblock/waffle/issues/203)
** Tomcat negotiate filters reporting Win32Error 500 status error instead of 401.
** Related to issue [#107](https://github.com/dblock/waffle/issues/107)

* Created 1.7.x branch for spring 2 and tomcat 5 continued support for one year.
* Created 1.7.x branch for spring 2 and tomcat 5 continued support for one year. Only complete show stoppers to be addressed there.
* Github gh-pages now built via mvn site plugin.
* We use sfl4j, so use jcl-over-slf4j instead of allowing spring to bring in commons-logging.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.slf4j.LoggerFactory;

import com.google.common.io.BaseEncoding;
import com.sun.jna.platform.win32.Win32Exception;

import waffle.util.AuthorizationHeader;
import waffle.util.NtlmServletRequest;
Expand Down Expand Up @@ -104,7 +105,14 @@ public boolean authenticate(final Request request, final Response response, fina
try {
final byte[] tokenBuffer = authorizationHeader.getTokenBytes();
this.log.debug("token buffer: {} byte(s)", Integer.valueOf(tokenBuffer.length));
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage);
try {
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage);
} catch (final Win32Exception e) {
this.log.warn("error logging in user: {}", e.getMessage());
this.log.trace("{}", e);
sendUnauthorized(response);
return false;
}
this.log.debug("continue required: {}", Boolean.valueOf(securityContext.isContinue()));

final byte[] continueTokenBytes = securityContext.getToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ public void testPOSTEmpty() {
break;
}

if (response.getHeader("WWW-Authenticate").startsWith(securityPackage + ",")) {
Assert.assertEquals("close", response.getHeader("Connection"));
Assert.assertEquals(2, response.getHeaderNames().length);
Assert.assertEquals(401, response.getStatus());
return;
}

Assert.assertTrue(response.getHeader("WWW-Authenticate").startsWith(securityPackage + " "));
Assert.assertEquals("keep-alive", response.getHeader("Connection"));
Assert.assertEquals(2, response.getHeaderNames().length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.slf4j.LoggerFactory;

import com.google.common.io.BaseEncoding;
import com.sun.jna.platform.win32.Win32Exception;

import waffle.util.AuthorizationHeader;
import waffle.util.NtlmServletRequest;
Expand Down Expand Up @@ -106,7 +107,14 @@ public boolean authenticate(final Request request, final HttpServletResponse res
try {
final byte[] tokenBuffer = authorizationHeader.getTokenBytes();
this.log.debug("token buffer: {} byte(s)", Integer.valueOf(tokenBuffer.length));
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage);
try {
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage);
} catch (final Win32Exception e) {
this.log.warn("error logging in user: {}", e.getMessage());
this.log.trace("{}", e);
sendUnauthorized(response);
return false;
}
this.log.debug("continue required: {}", Boolean.valueOf(securityContext.isContinue()));

final byte[] continueTokenBytes = securityContext.getToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ public void testPOSTEmpty() {
break;
}

if (response.getHeader("WWW-Authenticate").startsWith(securityPackage + ",")) {
Assert.assertEquals("close", response.getHeader("Connection"));
Assert.assertEquals(2, response.getHeaderNames().size());
Assert.assertEquals(401, response.getStatus());
return;
}

Assert.assertTrue(response.getHeader("WWW-Authenticate").startsWith(securityPackage + " "));
Assert.assertEquals("keep-alive", response.getHeader("Connection"));
Assert.assertEquals(2, response.getHeaderNames().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.slf4j.LoggerFactory;

import com.google.common.io.BaseEncoding;
import com.sun.jna.platform.win32.Win32Exception;

import waffle.util.AuthorizationHeader;
import waffle.util.NtlmServletRequest;
Expand Down Expand Up @@ -105,7 +106,14 @@ public boolean authenticate(final Request request, final HttpServletResponse res
try {
final byte[] tokenBuffer = authorizationHeader.getTokenBytes();
this.log.debug("token buffer: {} byte(s)", Integer.valueOf(tokenBuffer.length));
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage);
try {
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage);
} catch (final Win32Exception e) {
this.log.warn("error logging in user: {}", e.getMessage());
this.log.trace("{}", e);
sendUnauthorized(response);
return false;
}
this.log.debug("continue required: {}", Boolean.valueOf(securityContext.isContinue()));

final byte[] continueTokenBytes = securityContext.getToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ public void testPOSTEmpty() {
break;
}

if (response.getHeader("WWW-Authenticate").startsWith(securityPackage + ",")) {
Assert.assertEquals("close", response.getHeader("Connection"));
Assert.assertEquals(2, response.getHeaderNames().size());
Assert.assertEquals(401, response.getStatus());
return;
}

Assert.assertTrue(response.getHeader("WWW-Authenticate").startsWith(securityPackage + " "));
Assert.assertEquals("keep-alive", response.getHeader("Connection"));
Assert.assertEquals(2, response.getHeaderNames().size());
Expand Down