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:org.craftercms.profile.services.ProfileServiceIT.java

@Test
@DirtiesContext//from  w w  w  .j  av  a  2s . com
public void testNoSuchAccessTokenIdError() throws Exception {
    accessTokenIdResolver.setAccessTokenId(INVALID_ACCESS_TOKEN_ID);

    try {
        profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1, AVASQUEZ_EMAIL1,
                true, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
        fail("Exception " + ProfileRestServiceException.class.getName() + " expected");
    } catch (ProfileRestServiceException e) {
        assertEquals(HttpStatus.FORBIDDEN, e.getStatus());
        assertEquals(ErrorCode.NO_SUCH_ACCESS_TOKEN_ID, e.getErrorCode());
    }
}

From source file:net.maritimecloud.identityregistry.controllers.RoleController.java

/**
 * Deletes a Role/*w  w  w.j a va2 s . c o m*/
 *
 * @return a reply...
 * @throws McBasicRestException
 */
@RequestMapping(value = "/api/org/{orgMrn}/role/{roleId}", method = RequestMethod.DELETE)
@ResponseBody
@PreAuthorize("hasRole('ORG_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)")
public ResponseEntity<?> deleteRole(HttpServletRequest request, @PathVariable String orgMrn,
        @PathVariable Long roleId) throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        Role role = this.roleService.getById(roleId);
        if (role == null) {
            throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ROLE_NOT_FOUND,
                    request.getServletPath());
        }
        if (role.getIdOrganization().compareTo(org.getId()) == 0) {
            this.roleService.delete(roleId);
            return new ResponseEntity<>(HttpStatus.OK);
        }
        throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS,
                request.getServletPath());
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:org.craftercms.profile.services.AuthenticationServiceIT.java

@Test
public void testAuthenticateWithDisabledProfile() throws Exception {
    try {//from w  w  w  . ja va  2  s.c  o  m
        authenticationService.authenticate(DEFAULT_TENANT_NAME, DISABLED_USER_USERNAME, DISABLED_USER_PASSWORD);
        fail("Exception " + ProfileRestServiceException.class.getName() + " expected");
    } catch (ProfileRestServiceException e) {
        assertEquals(HttpStatus.FORBIDDEN, e.getStatus());
        assertEquals(ErrorCode.DISABLED_PROFILE, e.getErrorCode());
    }
}

From source file:org.cloudfoundry.maven.AbstractCloudFoundryMojo.java

/**
 * Cloud Foundry Connection Login//from  w w  w.  ja  v  a  2  s. c  o  m
 */
protected void connectToCloudFoundry(CloudFoundryClient client) throws MojoExecutionException {
    try {
        client.login();
    } catch (CloudFoundryException e) {
        if (HttpStatus.FORBIDDEN.equals(e.getStatusCode())) {
            throw new MojoExecutionException(String.format(
                    "Login failed to '%s' using username '%s'. Please verify your login credentials.", target,
                    username), e);
        } else if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
            throw new MojoExecutionException(String.format(
                    "The target host '%s' exists but it does not appear to be a valid Cloud Foundry target url.",
                    target), e);
        } else {
            throw e;
        }
    } catch (ResourceAccessException e) {
        throw new MojoExecutionException(String.format("Cannot access host at '%s'.", target), e);
    }
}

From source file:org.bremersee.common.spring.autoconfigure.WebMvcExceptionResolver.java

int determineStatusCode(Exception ex) {

    if (ex == null) {

        return HttpStatus.OK.value();

    } else if (ex instanceof StatusCodeAwareException) {

        return ((StatusCodeAwareException) ex).getHttpStatusCode();

    } else if (ex instanceof IllegalArgumentException) {

        return HttpStatus.BAD_REQUEST.value();

    } else if (instanceOf(ex.getClass(), "org.springframework.security.access.AccessDeniedException")) {

        return HttpStatus.FORBIDDEN.value();

    } else if (instanceOf(ex.getClass(), "javax.persistence.EntityNotFoundException")) {

        return HttpStatus.NOT_FOUND.value();

    } else {// w ww  .  j  av  a2 s.c  o  m

        return HttpStatus.INTERNAL_SERVER_ERROR.value();
    }
}

From source file:org.mitre.uma.web.ResourceSetRegistrationEndpoint.java

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String updateResourceSet(@PathVariable("id") Long id, @RequestBody String jsonString, Model m,
        Authentication auth) {/*from  ww w.  j  a  va  2s . co m*/
    ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);

    ResourceSet newRs = parseResourceSet(jsonString);

    if (newRs == null // there was no resource set in the body
            || Strings.isNullOrEmpty(newRs.getName()) // there was no name (required)
            || newRs.getScopes() == null // there were no scopes (required)
            || newRs.getId() == null || !newRs.getId().equals(id) // the IDs didn't match
    ) {

        logger.warn("Resource set registration missing one or more required fields.");

        m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
        m.addAttribute(JsonErrorView.ERROR_MESSAGE,
                "Resource request was missing one or more required fields.");
        return JsonErrorView.VIEWNAME;
    }

    ResourceSet rs = resourceSetService.getById(id);

    if (rs == null) {
        m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
        m.addAttribute(JsonErrorView.ERROR, "not_found");
        return JsonErrorView.VIEWNAME;
    } else {
        if (!auth.getName().equals(rs.getOwner())) {

            logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got "
                    + auth.getName());

            // it wasn't issued to this user
            m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
            return JsonErrorView.VIEWNAME;
        } else {

            ResourceSet saved = resourceSetService.update(rs, newRs);

            m.addAttribute(JsonEntityView.ENTITY, saved);
            m.addAttribute(ResourceSetEntityAbbreviatedView.LOCATION,
                    config.getIssuer() + URL + "/" + rs.getId());
            return ResourceSetEntityAbbreviatedView.VIEWNAME;
        }

    }
}

From source file:net.maritimecloud.identityregistry.controllers.EntityController.java

/**
 * Deletes a Device/* w ww  .j  a va  2  s.c  o  m*/
 *
 * @return a reply...
 * @throws McBasicRestException
 */
protected ResponseEntity<?> deleteEntity(HttpServletRequest request, String orgMrn, String entityMrn)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        // Check that the entity being deleted belongs to the organization
        if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn)
                .equals(MrnUtil.getOrgShortNameFromEntityMrn(entityMrn))) {
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS,
                    request.getServletPath());
        }
        T entity = this.entityService.getByMrn(entityMrn);
        if (entity == null) {
            throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND,
                    request.getServletPath());
        }
        if (entity.getIdOrganization().compareTo(org.getId()) == 0) {
            this.entityService.delete(entity.getId());
            return new ResponseEntity<>(HttpStatus.OK);
        }
        throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS,
                request.getServletPath());
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:org.ng200.openolympus.Application.java

public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory containerFactory = new TomcatEmbeddedServletContainerFactory(
            this.serverPort);
    containerFactory.getErrorPages().add(new ErrorPage(HttpStatus.NOT_FOUND, "/errors/404"));
    containerFactory.getErrorPages().add(new ErrorPage(HttpStatus.FORBIDDEN, "/errors/403"));

    containerFactory.setSessionTimeout(30);

    return containerFactory;
}

From source file:technology.tikal.gae.service.template.RestControllerTemplate.java

@ExceptionHandler(AccessDeniedException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
public void handleAccessDenied(AccessDeniedException ex, HttpServletRequest request,
        HttpServletResponse response) {//ww  w . j ava2s. co m
    if (this.logger.isInfoEnabled()) {
        ex.printStackTrace();
    }
}