Skip to content

Commit

Permalink
added WWW-Authenticate header for unauth requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Farooq committed Feb 9, 2018
1 parent d738d8d commit bd79f5e
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}
}

0 comments on commit bd79f5e

Please sign in to comment.