/** * Returns the authorization context associated with a given subject. */ public final AuthorizationContext getAuthorizationContextForSubject(String subject) { if (getHost().isPrivilegedService(this)) { return getHost().getAuthorizationContextForSubject(subject); } else { throw new RuntimeException( "Service not allowed to get authorization context for a subject"); } }
/** * Returns the system user's authorization context. */ @Override public final AuthorizationContext getSystemAuthorizationContext() { if (getHost().isPrivilegedService(this)) { return getHost().getSystemAuthorizationContext(); } else { throw new RuntimeException("Service not allowed to get system authorization context"); } }
@Override public ServiceDocument getDocumentTemplate() { ServiceDocument d; try { d = this.stateType.newInstance(); } catch (Exception e) { logSevere(e); return null; } d.documentDescription = getHost().buildDocumentDescription(this); return d; }
@Override public void toggleOption(ServiceOption option, boolean enable) { if (enable) { if (option == ServiceOption.REPLICATION) { throw new IllegalArgumentException("Option is not supported"); } if (option == ServiceOption.IDEMPOTENT_POST) { throw new IllegalArgumentException("Option is not supported"); } } boolean optionsChanged = false; if (enable) { optionsChanged = this.options.add(option); } else { optionsChanged = this.options.remove(option); } if (enable && optionsChanged && option == ServiceOption.PERIODIC_MAINTENANCE && this.stage == ProcessingStage.AVAILABLE) { getHost().scheduleServiceMaintenance(this); } }
/** * Set authorization context on operation. */ @Override public final void setAuthorizationContext(Operation op, AuthorizationContext ctx) { if (getHost().isPrivilegedService(this)) { op.setAuthorizationContext(ctx); } else { throw new RuntimeException("Service not allowed to set authorization context"); } }
@Override public void setMaintenanceIntervalMicros(long micros) { if (micros < 0) { throw new IllegalArgumentException("micros must be positive"); } if (micros > 0 && micros < Service.MIN_MAINTENANCE_INTERVAL_MICROS) { logWarning("Maintenance interval %d is less than the minimum interval %d" + ", reducing to min interval", micros, Service.MIN_MAINTENANCE_INTERVAL_MICROS); micros = Service.MIN_MAINTENANCE_INTERVAL_MICROS; } this.maintenanceIntervalMicros = micros; if (getHost() != null && getProcessingStage() == ProcessingStage.AVAILABLE && micros < getHost().getMaintenanceCheckIntervalMicros()) { getHost().scheduleServiceMaintenance(this); } }
/** * Stops the service */ protected void handleStopCompletion(Operation op) { getHost().stopService(this); op.complete(); }
@Override public void setProcessingStage(ProcessingStage stage) { if (this.stage == stage) { return; } this.stage = stage; if (stage == ProcessingStage.AVAILABLE) { getHost().processPendingServiceAvailableOperations(this, null, false); getHost().getOperationTracker().processPendingServiceStartOperations( getSelfLink(), ProcessingStage.AVAILABLE, this); } if (stage == ProcessingStage.STOPPED) { getHost().getOperationTracker().processPendingServiceStartOperations( getSelfLink(), ProcessingStage.STOPPED, this); } }
@Override public void authorizeRequest(Operation op) { // A state-less service has no service state to apply policy to, but it does have a // self link. Create a document with the service link so we can apply roles with resource // specifications targeting the self link field ServiceDocument doc = new ServiceDocument(); doc.documentSelfLink = this.selfLink; if (getHost().isAuthorized(this, doc, op)) { op.complete(); return; } op.fail(Operation.STATUS_CODE_FORBIDDEN); }
protected void prepareRequest(Operation op) { op.setReferer(UriUtils.buildUri(getHost().getPublicUri(), getSelfLink())); }
private DeferredResult<T> doRetry() { Duration sleepDuration = this.retryDelay.getNextDelay(); this.service.logInfo(this.requestDescription + ": doRetry in (ms): " + sleepDuration.toMillis()); this.service.getHost().schedule( getAsyncRunnable(getCallbackInstance()), sleepDuration.toMillis(), TimeUnit.MILLISECONDS); return this.retryDeferredResult; }
private void handleGetCompletion(Operation op) { if (!this.options.contains(ServiceOption.PERSISTENCE)) { op.complete(); return; } URI documentQuery = UriUtils.buildDocumentQueryUri(getHost(), this.selfLink, true, false, this.options); sendRequest(Operation.createGet(documentQuery).setCompletion((o, e) -> { if (e != null) { op.fail(e); return; } op.setBodyNoCloning(o.getBodyRaw()).complete(); })); }
.createPost(AuthUtils.buildAuthProviderHostUri(service.getHost(), ServiceUriPaths.CORE_LOCAL_QUERY_TASKS)) .setBody(q)
.createPost(AuthUtils.buildAuthProviderHostUri(service.getHost(), ServiceUriPaths.CORE_LOCAL_QUERY_TASKS)) .setBody(authQuery)
OperationProcessingChain opProcessingChain = getOperationProcessingChain(); if (opProcessingChain != null) { OperationProcessingContext context = opProcessingChain.createContext(getHost()); context.setService(this); opProcessingChain.processRequest(op, context, o -> {