本文整理匯總了Java中org.apache.kylin.rest.exception.ForbiddenException類的典型用法代碼示例。如果您正苦於以下問題:Java ForbiddenException類的具體用法?Java ForbiddenException怎麽用?Java ForbiddenException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ForbiddenException類屬於org.apache.kylin.rest.exception包,在下文中一共展示了ForbiddenException類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testBasics
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
@Test
public void testBasics() throws IOException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("http://localhost");
NotFoundException notFoundException = new NotFoundException("not found");
ErrorResponse errorResponse = basicController.handleBadRequest(request, notFoundException);
Assert.assertNotNull(errorResponse);
ForbiddenException forbiddenException = new ForbiddenException("forbidden");
errorResponse = basicController.handleForbidden(request, forbiddenException);
Assert.assertNotNull(errorResponse);
InternalErrorException internalErrorException = new InternalErrorException("error");
errorResponse = basicController.handleError(request, internalErrorException);
Assert.assertNotNull(errorResponse);
BadRequestException badRequestException = new BadRequestException("error");
errorResponse = basicController.handleBadRequest(request, badRequestException);
Assert.assertNotNull(errorResponse);
}
示例2: updateModelDesc
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
@RequestMapping(value = "", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public ModelRequest updateModelDesc(@RequestBody ModelRequest modelRequest) throws JsonProcessingException {
DataModelDesc modelDesc = deserializeDataModelDesc(modelRequest);
if (modelDesc == null) {
return modelRequest;
}
try {
modelDesc = modelService.updateModelAndDesc(modelRequest.getProject(), modelDesc);
} catch (AccessDeniedException accessDeniedException) {
throw new ForbiddenException("You don't have right to update this model.");
} catch (Exception e) {
logger.error("Failed to deal with the request:" + e.getLocalizedMessage(), e);
throw new InternalErrorException("Failed to deal with the request: " + e.getLocalizedMessage());
}
if (modelDesc.getError().isEmpty()) {
modelRequest.setSuccessful(true);
} else {
logger.warn("Model " + modelDesc.getName() + " fail to update because " + modelDesc.getError());
updateRequest(modelRequest, false, omitMessage(modelDesc.getError()));
}
String descData = JsonUtil.writeValueAsIndentString(modelDesc);
modelRequest.setModelDescData(descData);
return modelRequest;
}
示例3: hasPermission
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN
+ " or hasPermission(#project, 'ADMINISTRATION') or hasPermission(#project, 'MANAGEMENT')")
public CubeDesc saveCube(CubeDesc desc, ProjectInstance project) throws IOException {
Message msg = MsgPicker.getMsg();
desc.setDraft(false);
if (desc.getUuid() == null)
desc.updateRandomUuid();
try {
createCubeAndDesc(project, desc);
} catch (AccessDeniedException accessDeniedException) {
throw new ForbiddenException(msg.getUPDATE_CUBE_NO_RIGHT());
}
if (!desc.getError().isEmpty()) {
throw new BadRequestException(desc.getErrorMsg());
}
return desc;
}
示例4: updateCube
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
public CubeDesc updateCube(CubeInstance cube, CubeDesc desc, ProjectInstance project) throws IOException {
aclEvaluate.hasProjectWritePermission(cube.getProjectInstance());
Message msg = MsgPicker.getMsg();
String projectName = project.getName();
desc.setDraft(false);
try {
if (cube.getSegments().size() != 0 && !cube.getDescriptor().consistentWith(desc)) {
throw new BadRequestException(String.format(msg.getINCONSISTENT_CUBE_DESC(), desc.getName()));
}
desc = updateCubeAndDesc(cube, desc, projectName, true);
} catch (AccessDeniedException accessDeniedException) {
throw new ForbiddenException(msg.getUPDATE_CUBE_NO_RIGHT());
}
if (!desc.getError().isEmpty()) {
throw new BadRequestException(desc.getErrorMsg());
}
return desc;
}
示例5: updateModelToResourceStore
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
public DataModelDesc updateModelToResourceStore(DataModelDesc modelDesc, String projectName) throws IOException {
aclEvaluate.checkProjectWritePermission(projectName);
Message msg = MsgPicker.getMsg();
modelDesc.setDraft(false);
if (modelDesc.getUuid() == null)
modelDesc.updateRandomUuid();
try {
if (modelDesc.getLastModified() == 0) {
// new
modelDesc = createModelDesc(projectName, modelDesc);
} else {
// update
String error = checkIfBreakExistingCubes(modelDesc, projectName);
if (!error.isEmpty()) {
throw new BadRequestException(error);
}
modelDesc = updateModelAndDesc(projectName, modelDesc);
}
} catch (AccessDeniedException accessDeniedException) {
throw new ForbiddenException(msg.getUPDATE_MODEL_NO_RIGHT());
}
if (!modelDesc.getError().isEmpty()) {
throw new BadRequestException(String.format(msg.getBROKEN_MODEL_DESC(), modelDesc.getName()));
}
return modelDesc;
}
示例6: secureOwner
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
/**
* Protect admin permission granted to acl owner.
*
* @param acl
* @param indexOfAce
*/
private void secureOwner(MutableAcl acl, int indexOfAce) {
Message msg = MsgPicker.getMsg();
// Can't revoke admin permission from domain object owner
if (acl.getOwner().equals(acl.getEntries().get(indexOfAce).getSid())
&& BasePermission.ADMINISTRATION.equals(acl.getEntries().get(indexOfAce).getPermission())) {
throw new ForbiddenException(msg.getREVOKE_ADMIN_PERMISSION());
}
}
示例7: secureOwner
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
/**
* Protect admin permission granted to acl owner.
*
* @param acl
* @param indexOfAce
*/
private void secureOwner(MutableAcl acl, int indexOfAce) {
// Can't revoke admin permission from domain object owner
if (acl.getOwner().equals(acl.getEntries().get(indexOfAce).getSid()) && BasePermission.ADMINISTRATION.equals(acl.getEntries().get(indexOfAce).getPermission())) {
throw new ForbiddenException("Can't revoke admin permission of owner.");
}
}
示例8: handleForbidden
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(ForbiddenException.class)
@ResponseBody
ErrorResponse handleForbidden(HttpServletRequest req, Exception ex) {
return new ErrorResponse(req.getRequestURL().toString(), ex);
}
示例9: doQuery
import org.apache.kylin.rest.exception.ForbiddenException; //導入依賴的package包/類
private SQLResponse doQuery(SQLRequest sqlRequest) {
String sql = sqlRequest.getSql();
String project = sqlRequest.getProject();
logger.info("Using project: " + project);
logger.info("The original query: " + sql);
String serverMode = KylinConfig.getInstanceFromEnv().getServerMode();
if (!(Constant.SERVER_MODE_QUERY.equals(serverMode.toLowerCase()) || Constant.SERVER_MODE_ALL.equals(serverMode.toLowerCase()))) {
throw new InternalErrorException("Query is not allowed in " + serverMode + " mode.");
}
if (sql.toLowerCase().contains("select") == false) {
logger.debug("Directly return expection as not supported");
throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly("Not Supported SQL."));
}
SQLResponse sqlResponse = searchQueryInCache(sqlRequest);
try {
if (null == sqlResponse) {
sqlResponse = queryService.query(sqlRequest);
long durationThreshold = KylinConfig.getInstanceFromEnv().getQueryDurationCacheThreshold();
long scancountThreshold = KylinConfig.getInstanceFromEnv().getQueryScanCountCacheThreshold();
if (!sqlResponse.getIsException() && (sqlResponse.getDuration() > durationThreshold || sqlResponse.getTotalScanCount() > scancountThreshold)) {
cacheManager.getCache(SUCCESS_QUERY_CACHE).put(new Element(sqlRequest, sqlResponse));
}
}
checkQueryAuth(sqlResponse);
return sqlResponse;
} catch (AccessDeniedException ade) {
// Access exception is bind with each user, it will not be cached
logger.error("Exception when execute sql", ade);
throw new ForbiddenException(ade.getLocalizedMessage());
} catch (Throwable e) { // calcite may throw AssertError
SQLResponse exceptionRes = new SQLResponse(null, null, 0, true, e.getMessage());
Cache exceptionCache = cacheManager.getCache(EXCEPTION_QUERY_CACHE);
exceptionCache.put(new Element(sqlRequest, exceptionRes));
logger.error("Exception when execute sql", e);
throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly(e.getLocalizedMessage()));
}
}