From bd79f5e63562fd56ced8ba25a1600f37359df112 Mon Sep 17 00:00:00 2001 From: Maria Farooq Date: Fri, 9 Feb 2018 16:56:47 +0500 Subject: [PATCH] added WWW-Authenticate header for unauth requests --- .../org/restcomm/connect/http/security/SecurityFilter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/security/SecurityFilter.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/security/SecurityFilter.java index 8e37ce7de8..cf828303f3 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/security/SecurityFilter.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/security/SecurityFilter.java @@ -19,9 +19,12 @@ */ package org.restcomm.connect.http.security; +import static javax.ws.rs.core.Response.status; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.ext.Provider; @@ -61,7 +64,7 @@ public ContainerRequest filter(ContainerRequest cr) { */ protected void checkAuthenticatedAccount(UserIdentityContext userIdentityContext) { if (userIdentityContext.getEffectiveAccount() == null) { - throw new WebApplicationException(Status.UNAUTHORIZED); + throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).header("WWW-Authenticate", "Basic realm=\"Restcomm realm\"").build()); } } @@ -71,7 +74,7 @@ protected void checkAuthenticatedAccount(UserIdentityContext userIdentityContext */ protected void filterClosedAccounts(UserIdentityContext userIdentityContext){ if(userIdentityContext.getEffectiveAccount() != null && !userIdentityContext.getEffectiveAccount().getStatus().equals(Account.Status.ACTIVE)){ - throw new WebApplicationException(Status.FORBIDDEN); + throw new WebApplicationException(status(Status.FORBIDDEN).entity("Provided Account is not active").build()); } } }