Skip to content

Commit

Permalink
Fix the WWW-Authenticate header generation
Browse files Browse the repository at this point in the history
This is dealing with the fault introduced while fixing MID-5725.
Now we consistently provide "WWW-Authenticate" with the values of
"Basic" and "SecQ".
  • Loading branch information
mederly authored and semancik committed Oct 11, 2019
1 parent cd01b50 commit 49f8389
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Expand Up @@ -108,7 +108,7 @@ public void handleRequest(AuthorizationPolicy policy, Message m, ContainerReques
CredentialsExpiredException | AccessDeniedException | AuthenticationCredentialsNotFoundException |
AuthenticationServiceException e) {
LOGGER.trace("Exception while authenticating username '{}' to REST service: {}", enteredUsername, e.getMessage(), e);
requestCtx.abortWith(Response.status(Status.UNAUTHORIZED).build());
RestServiceUtil.createAbortMessage(requestCtx);
return;
}

Expand Down Expand Up @@ -136,11 +136,9 @@ public void handleRequest(AuthorizationPolicy policy, Message m, ContainerReques
} catch (ObjectNotFoundException | SchemaException | SecurityViolationException
| CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
LOGGER.trace("Exception while authenticating user identified with '{}' to REST service: {}", oid, e.getMessage(), e);
requestCtx.abortWith(Response.status(Status.UNAUTHORIZED).build());
RestServiceUtil.createAbortMessage(requestCtx);
return;
}


}

m.put(RestServiceUtil.MESSAGE_PROPERTY_TASK_NAME, task);
Expand Down
Expand Up @@ -117,14 +117,14 @@ protected SecurityQuestionsAuthenticationContext createAuthenticationContext(Aut
}

if (users.size() != 1) {
requestCtx.abortWith(Response.status(Status.UNAUTHORIZED).build());
RestServiceUtil.createAbortMessage(requestCtx);
return null;
}

PrismObject<UserType> user = users.get(0);
PrismContainer<SecurityQuestionAnswerType> questionAnswerContainer = user.findContainer(SchemaConstants.PATH_SECURITY_QUESTIONS_QUESTION_ANSWER);
if (questionAnswerContainer == null || questionAnswerContainer.isEmpty()) {
requestCtx.abortWith(Response.status(Status.UNAUTHORIZED).build());
RestServiceUtil.createAbortMessage(requestCtx);
return null;
}

Expand Down
Expand Up @@ -176,8 +176,12 @@ public static Response.ResponseBuilder createResultHeaders(Response.ResponseBuil
// .header(OPERATION_RESULT_MESSAGE, result.getMessage());
}

public static void createAbortMessage(ContainerRequestContext requestCtx){
requestCtx.abortWith(Response.status(Status.UNAUTHORIZED).build());
public static void createAbortMessage(ContainerRequestContext requestCtx) {
requestCtx.abortWith(Response.status(Status.UNAUTHORIZED)
.header("WWW-Authenticate",
RestAuthenticationMethod.BASIC.getMethod() + " realm=\"midpoint\", " +
RestAuthenticationMethod.SECURITY_QUESTIONS.getMethod())
.build());
}

public static void createSecurityQuestionAbortMessage(ContainerRequestContext requestCtx, String secQChallenge){
Expand Down

0 comments on commit 49f8389

Please sign in to comment.