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

[ELY-2548] BasicAuthenticationMechanism should return FORBIDDEN inste… #1899

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,6 +42,7 @@
import org.wildfly.common.iteration.ByteIterator;
import org.wildfly.security.auth.callback.AvailableRealmsCallback;
import org.wildfly.security.http.HttpAuthenticationException;
import org.wildfly.security.http.HttpConstants;
import org.wildfly.security.http.HttpServerRequest;
import org.wildfly.security.http.HttpServerResponse;
import org.wildfly.security.mechanism.http.UsernamePasswordAuthenticationMechanism;
Expand Down Expand Up @@ -170,7 +171,7 @@ public void evaluateRequest(final HttpServerRequest request) throws HttpAuthenti
httpBasic.debugf("User %s authorization failed.", username);
fail();

request.authenticationFailed(httpBasic.authorizationFailed(username), response -> prepareResponse(request, displayRealmName, response));
request.authenticationFailed(httpBasic.authorizationFailed(username), response -> response.setStatusCode(HttpConstants.FORBIDDEN));
return;
}

Expand Down
Expand Up @@ -99,4 +99,15 @@ public void testStatefulBasicRFC7617Examples() throws Exception {
testStatefulBasic("Aladdin", "WallyWorld", "open sesame", "basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
testStatefulBasic("test", "foo", "123\u00A3", "BASIC dGVzdDoxMjPCow==");
}

@Test
public void testBasicUnauthorizedUser() throws Exception {
HttpServerAuthenticationMechanism mechanism = basicFactory.createAuthenticationMechanism(HttpConstants.BASIC_NAME,
Collections.singletonMap(HttpConstants.CONFIG_REALM, "test-realm"), getCallbackHandler("unauthorizedUser", "test-realm", "password"));
TestingHttpServerRequest request = new TestingHttpServerRequest(new String[] {"Basic dW5hdXRob3JpemVkVXNlcjpwYXNzd29yZA=="});
mechanism.evaluateRequest(request);
Assert.assertEquals(Status.FAILED, request.getResult());
TestingHttpServerResponse response = request.getResponse();
Assert.assertEquals(HttpConstants.FORBIDDEN, response.getStatusCode());
}
}
Expand Up @@ -471,7 +471,10 @@ protected CallbackHandler getCallbackHandler(String username, String realm, Stri
Assert.assertNotNull(clearPwdCredential);
Assert.assertArrayEquals(password.toCharArray(), clearPwdCredential.getPassword());
} else if (callback instanceof AuthorizeCallback) {
if(username.equals(((AuthorizeCallback) callback).getAuthenticationID()) &&
if(username.equalsIgnoreCase("unauthorizedUser")){
((AuthorizeCallback) callback).setAuthorized(false);
}
else if(username.equals(((AuthorizeCallback) callback).getAuthenticationID()) &&
username.equals(((AuthorizeCallback) callback).getAuthorizationID())) {
((AuthorizeCallback) callback).setAuthorized(true);
} else {
Expand Down