本文整理汇总了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()));
}
}