Fix response code

This commit is contained in:
Leonardo Loch Zanivan 2015-05-13 15:39:32 -03:00
parent dbf9525860
commit abcd830af1
2 changed files with 9 additions and 11 deletions

View file

@ -11,9 +11,7 @@ import javax.ws.rs.core.Response;
public class ErrorResponse { public class ErrorResponse {
public static Response exists(String message) { public static Response exists(String message) {
ErrorRepresentation error = new ErrorRepresentation(); return ErrorResponse.error(message, Response.Status.CONFLICT);
error.setErrorMessage(message);
return Response.status(Response.Status.CONFLICT).entity(error).type(MediaType.APPLICATION_JSON).build();
} }
public static Response error(String message, Response.Status status) { public static Response error(String message, Response.Status status) {

View file

@ -202,11 +202,11 @@ public class RealmAdminResource {
adminEvent.operation(OperationType.UPDATE).resourcePath(uriInfo.getPath()).representation(rep).success(); adminEvent.operation(OperationType.UPDATE).resourcePath(uriInfo.getPath()).representation(rep).success();
return Response.noContent().build(); return Response.noContent().build();
} catch (PatternSyntaxException e) { } catch (PatternSyntaxException e) {
return ErrorResponse.exists("Specified regex pattern(s) is invalid."); return ErrorResponse.error("Specified regex pattern(s) is invalid.", Response.Status.BAD_REQUEST);
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return ErrorResponse.exists("Realm " + rep.getRealm() + " already exists."); return ErrorResponse.exists("Realm " + rep.getRealm() + " already exists.");
} catch (Exception e) { } catch (Exception e) {
return ErrorResponse.exists("Failed to update " + rep.getRealm() + " Realm."); return ErrorResponse.error("Failed to update " + rep.getRealm() + " Realm.", Response.Status.INTERNAL_SERVER_ERROR);
} }
} }
@ -268,7 +268,7 @@ public class RealmAdminResource {
public GlobalRequestResult pushRevocation() { public GlobalRequestResult pushRevocation() {
auth.requireManage(); auth.requireManage();
adminEvent.operation(OperationType.ACTION).resourcePath(uriInfo.getPath()).success(); adminEvent.operation(OperationType.ACTION).resourcePath(uriInfo.getPath()).success();
return new ResourceAdminManager(session).pushRealmRevocationPolicy(uriInfo.getRequestUri(), realm); return new ResourceAdminManager(session).pushRealmRevocationPolicy(uriInfo.getRequestUri(), realm);
} }
/** /**
@ -280,8 +280,8 @@ public class RealmAdminResource {
@POST @POST
public GlobalRequestResult logoutAll() { public GlobalRequestResult logoutAll() {
session.sessions().removeUserSessions(realm); session.sessions().removeUserSessions(realm);
adminEvent.operation(OperationType.ACTION).resourcePath(uriInfo.getPath()).success(); adminEvent.operation(OperationType.ACTION).resourcePath(uriInfo.getPath()).success();
return new ResourceAdminManager(session).logoutAll(uriInfo.getRequestUri(), realm); return new ResourceAdminManager(session).logoutAll(uriInfo.getRequestUri(), realm);
} }
/** /**
@ -294,10 +294,10 @@ public class RealmAdminResource {
@DELETE @DELETE
public void deleteSession(@PathParam("session") String sessionId) { public void deleteSession(@PathParam("session") String sessionId) {
UserSessionModel userSession = session.sessions().getUserSession(realm, sessionId); UserSessionModel userSession = session.sessions().getUserSession(realm, sessionId);
if (userSession == null) throw new NotFoundException("Sesssion not found"); if (userSession == null) throw new NotFoundException("Sesssion not found");
AuthenticationManager.backchannelLogout(session, realm, userSession, uriInfo, connection, headers, true); AuthenticationManager.backchannelLogout(session, realm, userSession, uriInfo, connection, headers, true);
adminEvent.operation(OperationType.DELETE).resourcePath(uriInfo.getPath()).success(); adminEvent.operation(OperationType.DELETE).resourcePath(uriInfo.getPath()).success();
} }
/** /**