Example usage for org.springframework.http HttpStatus FORBIDDEN

List of usage examples for org.springframework.http HttpStatus FORBIDDEN

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus FORBIDDEN.

Prototype

HttpStatus FORBIDDEN

To view the source code for org.springframework.http HttpStatus FORBIDDEN.

Click Source Link

Document

403 Forbidden .

Usage

From source file:com.siblinks.ws.service.impl.VideoServiceImpl.java

/**
 * {@inheritDoc}//  www  .  ja va2  s.  com
 */
@Override
@RequestMapping(value = "/updateVideoWatched", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Response> updateVideoWatched(@RequestBody final RequestData request) {
    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        Object[] queryParams = { request.getRequest_data().getUid(), request.getRequest_data().getVid() };

        boolean status = false;
        String entityName = SibConstants.SqlMapper.SQL_CHECK_USER_WATCHED_VIDEO;
        List<Object> readObject = dao.readObjects(entityName, queryParams);
        if (readObject.size() < 1) {
            entityName = SibConstants.SqlMapper.SQL_UPDATE_USER_WATCHED_VIDEO;
            status = dao.insertUpdateObject(entityName, queryParams);
        }

        String message = "";
        if (status) {
            message = "Done";
        } else {
            message = "Fail";
        }

        response = new SimpleResponse("" + status, request.getRequest_data_type(),
                request.getRequest_data_method(), message);
    } catch (Exception e) {
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.VideoServiceImpl.java

/**
 * {@inheritDoc}/*from w w w  .ja v a 2 s . com*/
 */
@Override
@RequestMapping(value = "/getIdVideoWatched", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Response> getIdVideoWatched(@RequestBody final RequestData request) {
    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        Map<String, String> queryParams = new HashMap<String, String>();
        queryParams.put("uid", request.getRequest_data().getUid());

        String entityName = SibConstants.SqlMapper.SQL_GET_ID_VIDEO_USER_WATCHED;
        List<Object> readObject = dao.readObjects(entityName, queryParams);

        response = new SimpleResponse("", request.getRequest_data_type(), request.getRequest_data_method(),
                readObject);
    } catch (Exception e) {
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.VideoServiceImpl.java

/**
 * {@inheritDoc}//from  www  . j a va 2 s  . c o  m
 */
@Override
@RequestMapping(value = "/setSubscribeMentor", method = RequestMethod.POST)
public ResponseEntity<Response> setSubscribeMentor(@RequestBody final RequestData request) {
    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }
        Object[] queryParams = new Object[] { request.getRequest_data().getStudentId(),
                request.getRequest_data().getMentorId() };
        List<Object> readObject = null;
        // SELECT exists row
        String entityName = SibConstants.SqlMapper.SQL_FIND_STUDENT_SUBCRIBE;
        readObject = dao.readObjects(entityName, queryParams);
        boolean status = true;
        String message = "subs";
        if (readObject.size() == 0) {
            entityName = SibConstants.SqlMapper.SQL_SUBCRIBE_VIDEO_STUDENT;
            status = dao.insertUpdateObject(entityName, queryParams);

        } else {
            String subscribe = (String) ((Map) readObject.get(0)).get(Parameters.SUBCRIBE);
            if (subscribe != null && subscribe.equals("Y")) {
                message = "unsubs";
            }
            entityName = SibConstants.SqlMapper.SQL_SUBSCRIBE_UNSUBSCRIBE_MENTOR;
            status = dao.insertUpdateObject(entityName, queryParams);

        }

        response = new SimpleResponse("" + status, message, request.getRequest_data_method(), readObject);
    } catch (Exception e) {
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);

}

From source file:com.thoughtworks.go.server.controller.AgentRegistrationControllerTest.java

@Test
public void shouldRejectRegistrationRequestWhenInvalidTokenProvided() {
    when(goConfigService.hasAgent("blahAgent-uuid")).thenReturn(false);
    ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.agentUsername("blahAgent-uuid", request.getRemoteAddr(), "blahAgent-host"))
            .thenReturn(new Username("some-agent-login-name"));

    ResponseEntity responseEntity = controller.agentRequest("blahAgent-host", "blahAgent-uuid", "blah-location",
            "34567", "osx", "", "", "", "", "", "", false, "an-invalid-token", request);

    assertThat(responseEntity.getBody(), is("Not a valid token."));
    assertThat(responseEntity.getStatusCode(), is(HttpStatus.FORBIDDEN));

    verify(serverConfig, times(0)).shouldAutoRegisterAgentWith("someKey");
    verifyZeroInteractions(agentService);
    verifyZeroInteractions(agentConfigService);
}

From source file:com.vmware.appfactory.common.base.AbstractController.java

/**
 * Convert all thrown AfForbiddenException exceptions
 * into a 403 error code./*  w w w  .  j ava2s  .  c o m*/
 * @param ex
 * @return
 */
@ResponseBody
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(AfForbiddenException.class)
public String handleForbiddenException(Exception ex) {
    _log.error("Internal server error!", ex);
    return ex.getMessage();
}

From source file:com.wavemaker.tools.cloudfoundry.spinup.DefaultSpinupService.java

private String login(CloudFoundryClient cloudFoundryClient) {
    try {/*from  www  . ja v a 2  s .c  o m*/
        if (log.isTraceEnabled()) {
            log.trace("Logging into cloud foundry");
        }
        return cloudFoundryClient.login();
    } catch (CloudFoundryException e) {
        if (HttpStatus.FORBIDDEN.equals(e.getStatusCode())) {
            log.error("Login failed, thowing InvalidLoginCredentialsException");
            throw new InvalidLoginCredentialsException(e);
        }
        throw e;
    }
}

From source file:com.wavemaker.tools.deployment.cloudfoundry.CloudFoundryDeploymentTarget.java

@Override
public void undeploy(DeploymentInfo deploymentInfo, boolean deleteServices) throws DeploymentStatusException {
    CloudFoundryClient client = getClient(deploymentInfo);
    log.info("Deleting application " + deploymentInfo.getApplicationName());
    Timer timer = new Timer();
    timer.start();//w w  w  .  j a v  a  2 s  .  c  o m
    try {
        if (deleteServices) {
            CloudApplication app = client.getApplication(deploymentInfo.getApplicationName());
            for (String service : app.getServices()) {
                client.deleteService(service);
            }
        }
        client.deleteApplication(deploymentInfo.getApplicationName());
        log.info("Application " + deploymentInfo.getApplicationName() + " deleted successfully in "
                + timer.stop() + "ms");
    } catch (CloudFoundryException ex) {
        if (HttpStatus.FORBIDDEN == ex.getStatusCode()) {
            throw new DeploymentStatusException(TOKEN_EXPIRED_RESULT, ex);
        } else {
            throw ex;
        }
    }
}

From source file:com.yunmel.syncretic.core.BaseController.java

/**
 * 
 * 
 * @param e
 * @return
 */
protected ResponseEntity<Result> refuse(Result result) {
    return ResponseEntity.status(HttpStatus.FORBIDDEN).body(result);
}

From source file:edu.cornell.kfs.sys.web.controller.DataObjectRestServiceController.java

@ExceptionHandler(AccessDeniedException.class)
@ResponseStatus(value = HttpStatus.FORBIDDEN, reason = "Not authorized.")
public void handleAccessDeniedException(AccessDeniedException ex, HttpServletResponse response) {
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.BaseController.java

@ExceptionHandler(ForbiddenException.class)
@ResponseBody//from   w  ww  .  j a  v  a2  s  . co  m
@ResponseStatus(value = HttpStatus.FORBIDDEN)
public ErrorMessage handleForbiddenException(Exception e) {
    return new ErrorMessage(HttpStatus.FORBIDDEN.value(), HttpStatus.FORBIDDEN.getReasonPhrase(),
            e.getLocalizedMessage());
}