本文整理匯總了Java中javax.ws.rs.ForbiddenException類的典型用法代碼示例。如果您正苦於以下問題:Java ForbiddenException類的具體用法?Java ForbiddenException怎麽用?Java ForbiddenException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ForbiddenException類屬於javax.ws.rs包,在下文中一共展示了ForbiddenException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createApplication
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
private HttpResponse createApplication(String tenantName, String applicationName, HttpRequest request) {
authorizer.throwIfUnauthorized(new TenantId(tenantName), request);
Application application;
try {
application = controller.applications().createApplication(ApplicationId.from(tenantName, applicationName, "default"), authorizer.getNToken(request));
}
catch (ZmsException e) { // TODO: Push conversion down
if (e.getCode() == com.yahoo.jdisc.Response.Status.FORBIDDEN)
throw new ForbiddenException("Not authorized to create application", e);
else
throw e;
}
Slime slime = new Slime();
toSlime(application, slime.setObject(), request);
return new SlimeJsonResponse(slime);
}
示例2: pingWithAuthzFailed
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@Test( expected = ForbiddenException.class )
public void pingWithAuthzFailed()
throws Exception
{
try
{
String res = getPingService().pingWithAuthz();
fail( "not in exception" );
}
catch ( ForbiddenException e )
{
assertEquals( 403, e.getResponse().getStatus() );
throw e;
}
}
示例3: deleteArtifactKarmaFailed
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@Test( expected = ForbiddenException.class )
public void deleteArtifactKarmaFailed()
throws Exception
{
try
{
Artifact artifact = new Artifact();
artifact.setGroupId( "commons-logging" );
artifact.setArtifactId( "commons-logging" );
artifact.setVersion( "1.0.1" );
artifact.setPackaging( "jar" );
artifact.setContext( SOURCE_REPO_ID );
RepositoriesService repositoriesService = getRepositoriesService( null );
repositoriesService.deleteArtifact( artifact );
}
catch ( ForbiddenException e )
{
assertEquals( 403, e.getResponse().getStatus() );
throw e;
}
}
示例4: testCreateException
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@Test
public void testCreateException() {
assertExceptionType(Response.Status.INTERNAL_SERVER_ERROR, InternalServerErrorException.class);
assertExceptionType(Response.Status.NOT_FOUND, NotFoundException.class);
assertExceptionType(Response.Status.FORBIDDEN, ForbiddenException.class);
assertExceptionType(Response.Status.BAD_REQUEST, BadRequestException.class);
assertExceptionType(Response.Status.METHOD_NOT_ALLOWED, NotAllowedException.class);
assertExceptionType(Response.Status.UNAUTHORIZED, NotAuthorizedException.class);
assertExceptionType(Response.Status.NOT_ACCEPTABLE, NotAcceptableException.class);
assertExceptionType(Response.Status.UNSUPPORTED_MEDIA_TYPE, NotSupportedException.class);
assertExceptionType(Response.Status.SERVICE_UNAVAILABLE, ServiceUnavailableException.class);
assertExceptionType(Response.Status.TEMPORARY_REDIRECT, RedirectionException.class);
assertExceptionType(Response.Status.LENGTH_REQUIRED, ClientErrorException.class);
assertExceptionType(Response.Status.BAD_GATEWAY, ServerErrorException.class);
assertExceptionType(Response.Status.NO_CONTENT, WebApplicationException.class);
}
示例5: authenticatedUser
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
private HttpResponse authenticatedUser(HttpRequest request) {
String userIdString = request.getProperty("userOverride");
if (userIdString == null)
userIdString = userFrom(request)
.map(UserId::id)
.orElseThrow(() -> new ForbiddenException("You must be authenticated or specify userOverride"));
UserId userId = new UserId(userIdString);
List<Tenant> tenants = controller.tenants().asList(userId);
Slime slime = new Slime();
Cursor response = slime.setObject();
response.setString("user", userId.id());
Cursor tenantsArray = response.setArray("tenants");
for (Tenant tenant : tenants)
tenantInTenantsListToSlime(tenant, request.getUri(), tenantsArray.addObject());
response.setBool("tenantExists", tenants.stream().map(Tenant::getId).anyMatch(id -> id.isTenantFor(userId)));
return new SlimeJsonResponse(slime);
}
示例6: filter
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Instance<Object> instance = CDI.current();
User user = instance.select(User.class).get();
List<AccountRole> roles = user.getAccountRoles();
if (Arrays.stream(permissions.roles()).anyMatch(roles::contains)) {
return;
}
Permission permission = instance.select(permissions.value()).get();
if (permission.test(requestContext)) {
return;
}
throw new ForbiddenException();
}
示例7: testReadEventsScenario5
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
/**
* When forbidden exception has been thrown
*/
@Test
public void testReadEventsScenario5() {
resetAll();
// test data
final ReadEventsRequest request = getHelper().getReadEventsRequest();
final CronofyResponse<ReadEventsResponse> expectedResponse = new CronofyResponse<>(
ErrorTypeModel.FORBIDDEN
);
// expectations
expect(client.target(BASE_PATH)).andThrow(new ForbiddenException());
replayAll();
final CronofyResponse<ReadEventsResponse> result = cronofyClient.readEvents(request);
getHelper().assertResultResponse(expectedResponse, result);
verifyAll();
}
示例8: testFreeBusyScenario4
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
/**
* When forbidden exception has been thrown
*/
@Test
public void testFreeBusyScenario4() {
resetAll();
// test data
final FreeBusyRequest request = getHelper().getFreeBusyRequest();
final CronofyResponse<FreeBusyResponse> expectedResponse = new CronofyResponse<>(
ErrorTypeModel.FORBIDDEN
);
// expectations
expect(client.target(BASE_PATH)).andThrow(new ForbiddenException());
replayAll();
final CronofyResponse<FreeBusyResponse> result = cronofyClient.freeBusy(request);
getHelper().assertResultResponse(expectedResponse, result);
verifyAll();
}
示例9: test
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@Test
public void test() {
printHeader("Sending entity request for text:\n\n" + Configuration.TEXT_DE);
try {
// Request the resource with plain text
final EntityResult result = resource.getAll(Configuration.TEXT_DE);
printResult(result);
} catch (ForbiddenException e) {
// Handle forbidden response which is supposed to be caused by an invalid API key
System.err.println("Exception while calling Midas webservice: " + e.getMessage());
System.err.println("Maybe the API key \"" + Configuration.API_KEY + "\" is invalid.");
}
System.out.println(Configuration.SEPARATOR);
}
示例10: filter
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext)
throws IOException
{
// Only allow requests on the admin interfaces
Object listenAddressName = requestContext.getProperty(LISTEN_ADDRESS_NAME_ATTRIBUTE);
if (listenAddressName == null || !listenAddressName.equals(ServerConfig.ADMIN_ADDRESS)) {
throw new NotFoundException();
}
// Only allow admin users
Boolean admin = (Boolean) request.getAttribute("admin");
if (admin == null || !admin) {
throw new ForbiddenException();
}
}
示例11: createRepository
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@Transactional
public Result<Repository> createRepository(String userName, RepositoryForm repositoryForm) {
if (!repositoryForm.getOwner().equals(userName)) {
throw new ForbiddenException();
}
Repository check = emProvider.get().find(Repository.class, new RepositoryPK(userName, repositoryForm.getName()));
if (check != null) {
return Result.error("already exists");
}
Repository repository = new Repository();
repository.setPk(new RepositoryPK(userName, repositoryForm.getName()));
repository.setPrivateRepo(repositoryForm.isPrivateRepo());
repository.setDescription(repositoryForm.getDescription());
emProvider.get().persist(repository);
gitOperation.init(userName, repository.getPk().getRepositoryName(), repository.getDefaultBranch());
return Result.success(repository);
}
示例12: filter
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Repo repo = ResourceUtils.getAnnotation(resourceInfo, Repo.class).orElse(null);
if (repo != null) {
String owner = uriInfo.getPathParameters().getFirst(repo.ownerPath());
String repoName = uriInfo.getPathParameters().getFirst(repo.repositoryPath());
if (owner == null || repoName == null) {
throw new NotFoundException();
}
Optional<RepositoryContext> repoContext = repositoryController.getContext(new RepositoryPK(owner, repoName));
if (!repoContext.isPresent()) {
throw new NotFoundException();
}
servletRequest.setAttribute(RepositoryContext.ATTR_NAME, repoContext.get());
if (!repoContext.get().canAccess(repo.collaboratorOnly())) {
throw new ForbiddenException("collaborator-only");
}
}
}
示例13: getRemindersInList
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@GET
@Produces(MediaType.APPLICATION_JSON)
public java.util.List<Reminder> getRemindersInList(@PathParam("listid") long listId)
{
List list = em.find(List.class, listId);
if (list == null) {
throw new NotFoundException();
}
// Only admins can read another user's reminders.
if (!list.getOwner().getUsername().equals(context.getUserPrincipal().getName()) && !context.isUserInRole(Role.ADMINISTRATOR.name())) {
throw new ForbiddenException();
}
TypedQuery<Reminder> q = em.createNamedQuery("Reminder.findByList", Reminder.class).setParameter("list", list);
return q.getResultList();
}
示例14: addReminderToList
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addReminderToList(@PathParam("listid") long listId, Reminder reminder)
{
List list = em.find(List.class, listId);
if (list == null) {
throw new NotFoundException();
}
// Only admins can add reminders to another user's lists.
if (!list.getOwner().getUsername().equals(context.getUserPrincipal().getName()) && !context.isUserInRole(Role.ADMINISTRATOR.name())) {
throw new ForbiddenException();
}
reminder.setList(list);
Set<ConstraintViolation<Reminder>> violations = validator.validate(reminder);
if (!violations.isEmpty()) {
throw new BadRequestException(mergeMessages(violations));
}
em.persist(reminder);
return Response.created(URI.create("/lists/" + listId + "/reminders/" + reminder.getId())).build();
}
示例15: getReminder
import javax.ws.rs.ForbiddenException; //導入依賴的package包/類
@GET
@Path("{reminderid}")
@Produces(MediaType.APPLICATION_JSON)
public Reminder getReminder(@PathParam("listid") long listId, @PathParam("reminderid") long reminderId)
{
Reminder reminder = em.find(Reminder.class, reminderId);
if (reminder == null || reminder.getList().getId() != listId) {
throw new NotFoundException();
}
// Only admins can read another user's reminders.
if (!reminder.getList().getOwner().getUsername().equals(context.getUserPrincipal().getName()) && !context.isUserInRole(Role.ADMINISTRATOR.name())) {
throw new ForbiddenException();
}
return reminder;
}