http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/JobBuildRequest2.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/JobBuildRequest2.java b/server-base/src/main/java/org/apache/kylin/rest/request/JobBuildRequest2.java new file mode 100644 index 0000000..dc3b433 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/JobBuildRequest2.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +public class JobBuildRequest2 { + + private long startSourceOffset; + + private long endSourceOffset; + + private String buildType; + + private boolean force; + + public long getStartSourceOffset() { + return startSourceOffset; + } + + public void setStartSourceOffset(long startSourceOffset) { + this.startSourceOffset = startSourceOffset; + } + + public long getEndSourceOffset() { + return endSourceOffset; + } + + public void setEndSourceOffset(long endSourceOffset) { + this.endSourceOffset = endSourceOffset; + } + + public String getBuildType() { + return buildType; + } + + public void setBuildType(String buildType) { + this.buildType = buildType; + } + + public boolean isForce() { + return force; + } + + public void setForce(boolean force) { + this.force = force; + } + +}
http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/JobListRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/JobListRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/JobListRequest.java new file mode 100644 index 0000000..51160d2 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/JobListRequest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +import java.util.List; + +/** + * @author xduo + * + */ +public class JobListRequest { + + private List<Integer> status; + private String cubeName; + private String projectName; + private Integer offset; + private Integer limit; + private Integer timeFilter; + + public JobListRequest() { + } + + public List<Integer> getStatus() { + return status; + } + + public void setStatus(List<Integer> status) { + this.status = status; + } + + public String getCubeName() { + return cubeName; + } + + public void setCubeName(String cubeName) { + this.cubeName = cubeName; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public Integer getOffset() { + return offset; + } + + public void setOffset(Integer offset) { + this.offset = offset; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + + public Integer getTimeFilter() { + return timeFilter; + } + + public void setTimeFilter(Integer timeFilter) { + this.timeFilter = timeFilter; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/MetaRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/MetaRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/MetaRequest.java new file mode 100644 index 0000000..66e8ec0 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/MetaRequest.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +/** + */ +public class MetaRequest { + + private String project; + + public MetaRequest() { + } + + public MetaRequest(String project) { + this.project = project; + } + + public String getProject() { + return project; + } + + public void setProject(String project) { + this.project = project; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/MetricsRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/MetricsRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/MetricsRequest.java new file mode 100644 index 0000000..daee8f0 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/MetricsRequest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +import java.util.Date; + +/** + * @author xduo + * + */ +public class MetricsRequest { + + private Date startTime; + + private Date endTime; + + private String account; + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/ModelRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/ModelRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/ModelRequest.java new file mode 100644 index 0000000..dc8e06e --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/ModelRequest.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +public class ModelRequest { + + private String uuid; + private String modelName; + private String modelDescData; + private boolean successful; + private String message; + private String project; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message + * the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the status + */ + public boolean getSuccessful() { + return successful; + } + + /** + * @param status + * the status to set + */ + public void setSuccessful(boolean status) { + this.successful = status; + } + + public ModelRequest() { + } + + public ModelRequest(String modelName, String modelDescData) { + this.modelName = modelName; + this.modelDescData = modelDescData; + } + + public String getModelDescData() { + return modelDescData; + } + + public void setModelDescData(String modelDescData) { + this.modelDescData = modelDescData; + } + + /** + * @return the modelName + */ + public String getModelName() { + return modelName; + } + + /** + * @param modelName + * the cubeName to set + */ + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getProject() { + return project; + } + + public void setProject(String project) { + this.project = project; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/PrepareSqlRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/PrepareSqlRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/PrepareSqlRequest.java new file mode 100644 index 0000000..95bc2f5 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/PrepareSqlRequest.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +import java.util.Arrays; + +/** + * @author xduo + * + */ +public class PrepareSqlRequest extends SQLRequest { + + public PrepareSqlRequest() { + super(); + } + + private StateParam[] params; + + public StateParam[] getParams() { + return params; + } + + public void setParams(StateParam[] params) { + this.params = params; + } + + public static class StateParam { + private String className; + private String value; + + public StateParam() { + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((className == null) ? 0 : className.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StateParam other = (StateParam) obj; + if (className == null) { + if (other.className != null) + return false; + } else if (!className.equals(other.className)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((params == null) ? 0 : Arrays.hashCode(params)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + if (!super.equals(obj)) + return false; + PrepareSqlRequest other = (PrepareSqlRequest) obj; + if (!Arrays.equals(params, other.params)) + return false; + return true; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/SQLRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/SQLRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/SQLRequest.java new file mode 100644 index 0000000..96f5faa --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/SQLRequest.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +import java.io.Serializable; +import java.util.Map; + +public class SQLRequest implements Serializable { + protected static final long serialVersionUID = 1L; + + private String sql; + private String project; + private Integer offset = 0; + private Integer limit = 0; + private boolean acceptPartial = false; + + private Map<String, String> backdoorToggles; + + public SQLRequest() { + } + + public Map<String, String> getBackdoorToggles() { + return backdoorToggles; + } + + public void setBackdoorToggles(Map<String, String> backdoorToggles) { + this.backdoorToggles = backdoorToggles; + } + + public String getProject() { + return project; + } + + public void setProject(String project) { + this.project = project; + } + + public String getSql() { + return sql; + } + + public void setSql(String sql) { + this.sql = sql; + } + + public Integer getOffset() { + return offset; + } + + public void setOffset(Integer offset) { + this.offset = offset; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + + public boolean isAcceptPartial() { + return acceptPartial; + } + + public void setAcceptPartial(boolean acceptPartial) { + this.acceptPartial = acceptPartial; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (acceptPartial ? 1231 : 1237); + result = prime * result + ((offset == null) ? 0 : offset.hashCode()); + result = prime * result + ((limit == null) ? 0 : limit.hashCode()); + result = prime * result + ((project == null) ? 0 : project.hashCode()); + result = prime * result + ((sql == null) ? 0 : sql.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SQLRequest other = (SQLRequest) obj; + if (acceptPartial != other.acceptPartial) + return false; + if (offset == null) { + if (other.offset != null) + return false; + } else if (!offset.equals(other.offset)) + return false; + if (limit == null) { + if (other.limit != null) + return false; + } else if (!limit.equals(other.limit)) + return false; + if (project == null) { + if (other.project != null) + return false; + } else if (!project.equals(other.project)) + return false; + if (sql == null) { + if (other.sql != null) + return false; + } else if (!sql.equals(other.sql)) + return false; + return true; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/SaveSqlRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/SaveSqlRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/SaveSqlRequest.java new file mode 100644 index 0000000..affab1c --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/SaveSqlRequest.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +/** + * @author xduo + * + */ +public class SaveSqlRequest { + private long id; + private String name; + private String sql; + private String project; + private String description; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSql() { + return sql; + } + + public void setSql(String sql) { + this.sql = sql; + } + + public String getProject() { + return project; + } + + public void setProject(String project) { + this.project = project; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/StreamingRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/StreamingRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/StreamingRequest.java new file mode 100644 index 0000000..96db4da --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/StreamingRequest.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kylin.rest.request; + +public class StreamingRequest { + + private String project; + + private String tableData; + + private String streamingConfig; + + private String kafkaConfig; + + private boolean successful; + + private String message; + + public String getProject() { + return project; + } + + public void setProject(String project) { + this.project = project; + } + + public String getTableData() { + return tableData; + } + + public void setTableData(String tableData) { + this.tableData = tableData; + } + + public boolean isSuccessful() { + return successful; + } + + public void setSuccessful(boolean successful) { + this.successful = successful; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getStreamingConfig() { + return streamingConfig; + } + + public void setStreamingConfig(String streamingConfig) { + this.streamingConfig = streamingConfig; + } + + public String getKafkaConfig() { + return kafkaConfig; + } + + public void setKafkaConfig(String kafkaConfig) { + this.kafkaConfig = kafkaConfig; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/UpdateConfigRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/UpdateConfigRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/UpdateConfigRequest.java new file mode 100644 index 0000000..50f7f9b --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/UpdateConfigRequest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +/** + * @author xduo + * + */ +public class UpdateConfigRequest { + private String key; + + private String value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/request/UpdateProjectRequest.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/UpdateProjectRequest.java b/server-base/src/main/java/org/apache/kylin/rest/request/UpdateProjectRequest.java new file mode 100644 index 0000000..29ba162 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/UpdateProjectRequest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.request; + +/** + */ +public class UpdateProjectRequest { + private String formerProjectName; + private String newProjectName; + private String newDescription; + + public UpdateProjectRequest() { + } + + public String getFormerProjectName() { + return formerProjectName; + } + + public void setFormerProjectName(String formerProjectName) { + + this.formerProjectName = formerProjectName; + } + + public String getNewDescription() { + return newDescription; + } + + public void setNewDescription(String newDescription) { + this.newDescription = newDescription; + } + + public String getNewProjectName() { + return newProjectName; + } + + public void setNewProjectName(String newProjectName) { + this.newProjectName = newProjectName; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/response/AccessEntryResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/AccessEntryResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/AccessEntryResponse.java new file mode 100644 index 0000000..5c55d58 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/AccessEntryResponse.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.response; + +import java.io.Serializable; + +import org.springframework.security.acls.model.Permission; +import org.springframework.security.acls.model.Sid; +import org.springframework.util.Assert; + +/** + * @author xduo + * + */ +public class AccessEntryResponse { + + private Permission permission; + private Serializable id; + private Sid sid; + private boolean granting; + + public AccessEntryResponse() { + } + + public AccessEntryResponse(Serializable id, Sid sid, Permission permission, boolean granting) { + Assert.notNull(sid, "Sid required"); + Assert.notNull(permission, "Permission required"); + this.id = id; + this.sid = sid; + this.permission = permission; + this.granting = granting; + } + + public Permission getPermission() { + return permission; + } + + public void setPermission(Permission permission) { + this.permission = permission; + } + + public Serializable getId() { + return id; + } + + public Sid getSid() { + return sid; + } + + public boolean isGranting() { + return granting; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/response/ErrorResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/ErrorResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/ErrorResponse.java new file mode 100644 index 0000000..3327cc0 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/ErrorResponse.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.response; + +/** + * @author xduo + * + */ +public class ErrorResponse { + + public String url; + public String exception; + + /** + * @param exception + */ + public ErrorResponse(String url, Exception exception) { + this.url = url; + this.exception = exception.getLocalizedMessage(); + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/response/GeneralResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/GeneralResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/GeneralResponse.java new file mode 100644 index 0000000..bc7c081 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/GeneralResponse.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.response; + +import java.util.Properties; + +/** + * @author xduo + * + */ +public class GeneralResponse extends Properties { + + private static final long serialVersionUID = -6540990247122312493L; + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java new file mode 100644 index 0000000..607d61a --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.response; + +import java.io.Serializable; + +public class HBaseResponse implements Serializable { + private static final long serialVersionUID = 7263557115683263492L; + private String tableName; + private long tableSize; + private int regionCount; + private long dateRangeStart; + private long dateRangeEnd; + + public HBaseResponse() { + } + + /** + * @return The hbase table name. + */ + public String getTableName() { + return tableName; + } + + /** + * @param tableName + * The hbase table name. + */ + public void setTableName(String tableName) { + this.tableName = tableName; + } + + /** + * @return the tableSize + */ + public long getTableSize() { + return tableSize; + } + + /** + * @param tableSize + * the tableSize to set + */ + public void setTableSize(long tableSize) { + this.tableSize = tableSize; + } + + /** + * @return the regionCount + */ + public int getRegionCount() { + return regionCount; + } + + /** + * @param regionCount + * the regionCount to set + */ + public void setRegionCount(int regionCount) { + this.regionCount = regionCount; + } + + /** + * @return the segmentStartTime + */ + public long getDateRangeStart() { + return dateRangeStart; + } + + /** + * @param segmentStartTime + * the segmentStartTime to set + */ + public void setDateRangeStart(long dateRangeStart) { + this.dateRangeStart = dateRangeStart; + } + + /** + * @return the segmentEndTime + */ + public long getDateRangeEnd() { + return dateRangeEnd; + } + + /** + * @param segmentEndTime + * the segmentEndTime to set + */ + public void setDateRangeEnd(long dateRangeEnd) { + this.dateRangeEnd = dateRangeEnd; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/response/MetricsResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/MetricsResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/MetricsResponse.java new file mode 100644 index 0000000..34cdfcb --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/MetricsResponse.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.response; + +import java.util.HashMap; + +/** + * @author xduo + * + */ +public class MetricsResponse extends HashMap<String, Float> { + + private static final long serialVersionUID = 1L; + + public void increase(String key) { + increase(key, (float) 1); + } + + public void increase(String key, Float increased) { + if (this.containsKey(key)) { + this.put(key, (this.get(key) + increased)); + } else { + this.put(key, increased); + } + } + + public void decrease(String key) { + decrease(key, (float) 1); + } + + public void decrease(String key, Float decreased) { + if (this.containsKey(key)) { + this.put(key, (this.get(key) - decreased)); + } else { + this.put(key, decreased); + } + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/response/SQLResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/SQLResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/SQLResponse.java new file mode 100644 index 0000000..9c4e9da --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/SQLResponse.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.response; + +import java.io.Serializable; +import java.util.List; + +import org.apache.kylin.rest.model.SelectedColumnMeta; + +public class SQLResponse implements Serializable { + protected static final long serialVersionUID = 1L; + + // private static final Logger logger = + // LoggerFactory.getLogger(SQLResponse.class); + + // the data type for each column + protected List<SelectedColumnMeta> columnMetas; + + // the results rows, each row contains several columns + protected List<List<String>> results; + + /** + * for historical reasons it is named "cube", however it might also refer to any realizations like hybrid, II or etc. + */ + protected String cube; + + // if not select query, only return affected row count + protected int affectedRowCount; + + // flag indicating whether an exception occurred + protected boolean isException; + + // if isException, the detailed exception message + protected String exceptionMessage; + + protected long duration; + + protected boolean isPartial = false; + + protected long totalScanCount; + + protected boolean hitExceptionCache = false; + + protected boolean storageCacheUsed = false; + + public SQLResponse() { + } + + public SQLResponse(List<SelectedColumnMeta> columnMetas, List<List<String>> results, int affectedRowCount, boolean isException, String exceptionMessage) { + this.columnMetas = columnMetas; + this.results = results; + this.affectedRowCount = affectedRowCount; + this.isException = isException; + this.exceptionMessage = exceptionMessage; + } + + public SQLResponse(List<SelectedColumnMeta> columnMetas, List<List<String>> results, String cube, int affectedRowCount, boolean isException, String exceptionMessage) { + this.columnMetas = columnMetas; + this.results = results; + this.cube = cube; + this.affectedRowCount = affectedRowCount; + this.isException = isException; + this.exceptionMessage = exceptionMessage; + } + + public SQLResponse(List<SelectedColumnMeta> columnMetas, List<List<String>> results, String cube, int affectedRowCount, boolean isException, String exceptionMessage, boolean isPartial) { + this.columnMetas = columnMetas; + this.results = results; + this.cube = cube; + this.affectedRowCount = affectedRowCount; + this.isException = isException; + this.exceptionMessage = exceptionMessage; + this.isPartial = isPartial; + } + + public List<SelectedColumnMeta> getColumnMetas() { + return columnMetas; + } + + public List<List<String>> getResults() { + return results; + } + + public void setResults(List<List<String>> results) { + this.results = results; + } + + public String getCube() { + return cube; + } + + public void setCube(String cube) { + this.cube = cube; + } + + public int getAffectedRowCount() { + return affectedRowCount; + } + + public boolean getIsException() { + return isException; + } + + public void setIsException(boolean v) { + isException = v; + } + + public String getExceptionMessage() { + return exceptionMessage; + } + + public void setExceptionMessage(String msg) { + exceptionMessage = msg; + } + + public long getDuration() { + return duration; + } + + public void setDuration(long duration) { + this.duration = duration; + } + + public boolean isPartial() { + + return isPartial; + } + + public long getTotalScanCount() { + return totalScanCount; + } + + public void setTotalScanCount(long totalScanCount) { + this.totalScanCount = totalScanCount; + } + + public boolean isHitExceptionCache() { + return hitExceptionCache; + } + + public void setHitExceptionCache(boolean hitExceptionCache) { + this.hitExceptionCache = hitExceptionCache; + } + + public boolean isStorageCacheUsed() { + return storageCacheUsed; + } + + public void setStorageCacheUsed(boolean storageCacheUsed) { + this.storageCacheUsed = storageCacheUsed; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/response/TableDescResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/TableDescResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/TableDescResponse.java new file mode 100644 index 0000000..c3b1e7c --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/TableDescResponse.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.response; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.kylin.metadata.model.TableDesc; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A response class to wrap TableDesc + * + * @author jianliu + * + */ +public class TableDescResponse extends TableDesc { + @JsonProperty("exd") + Map<String, String> descExd = new HashMap<String, String>(); + @JsonProperty("cardinality") + Map<String, Long> cardinality = new HashMap<String, Long>(); + + /** + * @return the cardinality + */ + public Map<String, Long> getCardinality() { + return cardinality; + } + + /** + * @param cardinality + * the cardinality to set + */ + public void setCardinality(Map<String, Long> cardinality) { + this.cardinality = cardinality; + } + + /** + * @return the descExd + */ + public Map<String, String> getDescExd() { + return descExd; + } + + /** + * @param descExd + * the descExd to set + */ + public void setDescExd(Map<String, String> descExd) { + this.descExd = descExd; + } + + /** + * @param table + */ + public TableDescResponse(TableDesc table) { + this.setColumns(table.getColumns()); + this.setDatabase(table.getDatabase()); + this.setName(table.getName()); + this.setSourceType(table.getSourceType()); + this.setUuid(table.getUuid()); + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/AclEntityFactory.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/AclEntityFactory.java b/server-base/src/main/java/org/apache/kylin/rest/security/AclEntityFactory.java new file mode 100644 index 0000000..621fbe4 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/AclEntityFactory.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.security; + +import org.apache.kylin.common.persistence.RootPersistentEntity; +import org.apache.kylin.cube.CubeInstance; +import org.apache.kylin.job.JobInstance; +import org.apache.kylin.metadata.model.DataModelDesc; +import org.apache.kylin.metadata.project.ProjectInstance; + +/** + * @author xduo + * + */ +public class AclEntityFactory { + + public static RootPersistentEntity createAclEntity(String entityType, String uuid) { + if ("CubeInstance".equals(entityType)) { + CubeInstance cubeInstance = new CubeInstance(); + cubeInstance.setUuid(uuid); + + return cubeInstance; + } + + if ("DataModelDesc".equals(entityType)) { + DataModelDesc modelInstance = new DataModelDesc(); + modelInstance.setUuid(uuid); + + return modelInstance; + } + + if ("JobInstance".equals(entityType)) { + JobInstance jobInstance = new JobInstance(); + jobInstance.setUuid(uuid); + + return jobInstance; + } + + if ("ProjectInstance".equals(entityType)) { + ProjectInstance projectInstance = new ProjectInstance(); + projectInstance.setUuid(uuid); + + return projectInstance; + } + + throw new RuntimeException("Unsupported entity type!"); + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/AclHBaseStorage.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/AclHBaseStorage.java b/server-base/src/main/java/org/apache/kylin/rest/security/AclHBaseStorage.java new file mode 100644 index 0000000..38f299e --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/AclHBaseStorage.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kylin.rest.security; + +import java.io.IOException; + +import org.apache.hadoop.hbase.client.HTableInterface; + +/** + */ +public interface AclHBaseStorage { + String DEFAULT_TABLE_PREFIX = "kylin_metadata"; + + String ACL_INFO_FAMILY = "i"; + String ACL_ACES_FAMILY = "a"; + String ACL_TABLE_NAME = "_acl"; + + String USER_AUTHORITY_FAMILY = "a"; + String USER_TABLE_NAME = "_user"; + String USER_AUTHORITY_COLUMN = "c"; + + String prepareHBaseTable(Class<?> clazz) throws IOException; + + HTableInterface getTable(String tableName) throws IOException; + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/AclPermission.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/AclPermission.java b/server-base/src/main/java/org/apache/kylin/rest/security/AclPermission.java new file mode 100644 index 0000000..4e2e182 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/AclPermission.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.security; + +import org.springframework.security.acls.domain.BasePermission; +import org.springframework.security.acls.model.Permission; + +/** + * @author xduo + * + */ +public class AclPermission extends BasePermission { + + private static final long serialVersionUID = 6121785617686149123L; + + public static final Permission MANAGEMENT = new AclPermission(1 << 5, 'M'); // 32 + public static final Permission OPERATION = new AclPermission(1 << 6, 'O'); // 64 + + protected AclPermission(int mask) { + super(mask); + } + + protected AclPermission(int mask, char code) { + super(mask, code); + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/AclPermissionFactory.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/AclPermissionFactory.java b/server-base/src/main/java/org/apache/kylin/rest/security/AclPermissionFactory.java new file mode 100644 index 0000000..d662403 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/AclPermissionFactory.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.security; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.springframework.security.acls.domain.DefaultPermissionFactory; +import org.springframework.security.acls.model.Permission; + +/** + * @author xduo + * + */ +public class AclPermissionFactory extends DefaultPermissionFactory { + + public AclPermissionFactory() { + super(); + registerPublicPermissions(AclPermission.class); + } + + public static List<Permission> getPermissions() { + List<Permission> permissions = new ArrayList<Permission>(); + Field[] fields = AclPermission.class.getFields(); + + for (Field field : fields) { + try { + Object fieldValue = field.get(null); + + if (Permission.class.isAssignableFrom(fieldValue.getClass())) { + // Found a Permission static field + permissions.add((Permission) fieldValue); + } + } catch (Exception ignore) { + //ignore on purpose + } + } + + return permissions; + } + + public static Permission getPermission(String perName) { + Field[] fields = AclPermission.class.getFields(); + + for (Field field : fields) { + try { + Object fieldValue = field.get(null); + + if (Permission.class.isAssignableFrom(fieldValue.getClass())) { + // Found a Permission static field + if (perName.equals(field.getName())) { + return (Permission) fieldValue; + } + } + } catch (Exception ignore) { + //ignore on purpose + } + } + + return null; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/AuthoritiesPopulator.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/AuthoritiesPopulator.java b/server-base/src/main/java/org/apache/kylin/rest/security/AuthoritiesPopulator.java new file mode 100644 index 0000000..7983fc0 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/AuthoritiesPopulator.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.security; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.kylin.rest.constant.Constant; +import org.springframework.ldap.core.ContextSource; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator; + +/** + * @author xduo + * + */ +public class AuthoritiesPopulator extends DefaultLdapAuthoritiesPopulator { + + String adminRole; + SimpleGrantedAuthority adminRoleAsAuthority; + + SimpleGrantedAuthority adminAuthority = new SimpleGrantedAuthority(Constant.ROLE_ADMIN); + SimpleGrantedAuthority modelerAuthority = new SimpleGrantedAuthority(Constant.ROLE_MODELER); + SimpleGrantedAuthority analystAuthority = new SimpleGrantedAuthority(Constant.ROLE_ANALYST); + + Set<GrantedAuthority> defaultAuthorities = new HashSet<GrantedAuthority>(); + + /** + * @param contextSource + * @param groupSearchBase + */ + public AuthoritiesPopulator(ContextSource contextSource, String groupSearchBase, String adminRole, String defaultRole) { + super(contextSource, groupSearchBase); + this.adminRole = adminRole; + this.adminRoleAsAuthority = new SimpleGrantedAuthority(adminRole); + + if (defaultRole.contains(Constant.ROLE_MODELER)) + this.defaultAuthorities.add(modelerAuthority); + if (defaultRole.contains(Constant.ROLE_ANALYST)) + this.defaultAuthorities.add(analystAuthority); + } + + @Override + public Set<GrantedAuthority> getGroupMembershipRoles(String userDn, String username) { + Set<GrantedAuthority> authorities = super.getGroupMembershipRoles(userDn, username); + + if (authorities.contains(adminRoleAsAuthority)) { + authorities.add(adminAuthority); + authorities.add(modelerAuthority); + authorities.add(analystAuthority); + } + + authorities.addAll(defaultAuthorities); + + return authorities; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/CrossDomainFilter.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/CrossDomainFilter.java b/server-base/src/main/java/org/apache/kylin/rest/security/CrossDomainFilter.java new file mode 100644 index 0000000..7d9d9ac --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/CrossDomainFilter.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.security; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; + +import org.apache.kylin.common.KylinConfig; + +/** + * @author xduo + * + */ +public class CrossDomainFilter implements Filter { + + /* + * (non-Javadoc) + * + * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) + */ + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, + * javax.servlet.ServletResponse, javax.servlet.FilterChain) + */ + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + if (KylinConfig.getInstanceFromEnv().isWebCrossDomainEnabled()) { + ((HttpServletResponse) response).addHeader("Access-Control-Allow-Origin", "*"); + ((HttpServletResponse) response).addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); + ((HttpServletResponse) response).addHeader("Access-Control-Allow-Headers", "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With, Accept, Authorization"); + } + + chain.doFilter(request, response); + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.Filter#destroy() + */ + @Override + public void destroy() { + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java b/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java new file mode 100644 index 0000000..d0dd06a --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kylin.rest.security; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +import org.apache.kylin.rest.service.UserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.util.Assert; + +import net.sf.ehcache.Cache; +import net.sf.ehcache.CacheManager; +import net.sf.ehcache.Element; + +/** + * A wrapper class for the authentication provider; Will do something more for Kylin. + */ +public class KylinAuthenticationProvider implements AuthenticationProvider { + + private static final Logger logger = LoggerFactory.getLogger(KylinAuthenticationProvider.class); + + @Autowired + UserService userService; + + @Autowired + private CacheManager cacheManager; + + //Embedded authentication provider + private AuthenticationProvider authenticationProvider; + + MessageDigest md = null; + + public KylinAuthenticationProvider(AuthenticationProvider authenticationProvider) { + super(); + Assert.notNull(authenticationProvider, "The embedded authenticationProvider should not be null."); + this.authenticationProvider = authenticationProvider; + try { + md = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Failed to init Message Digest ", e); + } + } + + @Override + public Authentication authenticate(Authentication authentication) throws AuthenticationException { + Authentication authed = null; + Cache userCache = cacheManager.getCache("UserCache"); + md.reset(); + byte[] hashKey = md.digest((authentication.getName() + authentication.getCredentials()).getBytes()); + String userKey = Arrays.toString(hashKey); + + Element authedUser = userCache.get(userKey); + if (null != authedUser) { + authed = (Authentication) authedUser.getObjectValue(); + SecurityContextHolder.getContext().setAuthentication(authed); + } else { + try { + authed = authenticationProvider.authenticate(authentication); + userCache.put(new Element(userKey, authed)); + } catch (AuthenticationException e) { + logger.error("Failed to auth user: " + authentication.getName(), e); + throw e; + } + + logger.debug("Authenticated user " + authed.toString()); + + UserDetails user; + + if (authed.getDetails() == null) { + //authed.setAuthenticated(false); + throw new UsernameNotFoundException("User not found in LDAP, check whether he/she has been added to the groups."); + } + + if (authed.getDetails() instanceof UserDetails) { + user = (UserDetails) authed.getDetails(); + } else { + user = new User(authentication.getName(), "skippped-ldap", authed.getAuthorities()); + } + Assert.notNull(user, "The UserDetail is null."); + + logger.debug("User authorities :" + user.getAuthorities()); + if (!userService.userExists(user.getUsername())) { + userService.createUser(user); + } else { + userService.updateUser(user); + } + } + + return authed; + } + + @Override + public boolean supports(Class<?> authentication) { + return authenticationProvider.supports(authentication); + } + + public AuthenticationProvider getAuthenticationProvider() { + return authenticationProvider; + } + + public void setAuthenticationProvider(AuthenticationProvider authenticationProvider) { + this.authenticationProvider = authenticationProvider; + } + +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java b/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java new file mode 100644 index 0000000..2c5fe50 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.apache.kylin.rest.security; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +import org.apache.kylin.rest.service.UserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; +import org.springframework.security.ldap.authentication.LdapAuthenticator; +import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator; + +import net.sf.ehcache.Cache; +import net.sf.ehcache.CacheManager; +import net.sf.ehcache.Element; + +/** + * @author xduo + * @deprecated replaced by KylinAuthenticationProvider + * + */ +public class LdapProvider extends LdapAuthenticationProvider { + + private static final Logger logger = LoggerFactory.getLogger(LdapProvider.class); + + @Autowired + UserService userService; + + @Autowired + private CacheManager cacheManager; + + MessageDigest md = null; + + /** + * @param authenticator + * @param authoritiesPopulator + */ + public LdapProvider(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) { + super(authenticator, authoritiesPopulator); + + try { + md = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Failed to init Message Digest ", e); + } + } + + @Override + public Authentication authenticate(Authentication authentication) throws AuthenticationException { + Authentication authed = null; + Cache userCache = cacheManager.getCache("UserCache"); + md.reset(); + byte[] hashKey = md.digest((authentication.getName() + authentication.getCredentials()).getBytes()); + String userKey = Arrays.toString(hashKey); + + Element authedUser = userCache.get(userKey); + if (null != authedUser) { + authed = (Authentication) authedUser.getObjectValue(); + SecurityContextHolder.getContext().setAuthentication(authed); + } else { + try { + authed = super.authenticate(authentication); + userCache.put(new Element(userKey, authed)); + } catch (AuthenticationException e) { + logger.error("Failed to auth user: " + authentication.getName(), e); + throw e; + } + + UserDetails user = new User(authentication.getName(), "skippped-ldap", authed.getAuthorities()); + + if (!userService.userExists(authentication.getName())) { + userService.createUser(user); + } else { + userService.updateUser(user); + } + } + + return authed; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/1a124e68/server-base/src/main/java/org/apache/kylin/rest/security/MockAclHBaseStorage.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/MockAclHBaseStorage.java b/server-base/src/main/java/org/apache/kylin/rest/security/MockAclHBaseStorage.java new file mode 100644 index 0000000..6c8081d --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/security/MockAclHBaseStorage.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kylin.rest.security; + +import java.io.IOException; + +import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.hbase.client.HTableInterface; +import org.apache.kylin.common.KylinConfig; +import org.apache.kylin.rest.service.AclService; +import org.apache.kylin.rest.service.UserService; + +/** + */ +public class MockAclHBaseStorage implements AclHBaseStorage { + + private static final String aclTableName = "MOCK-ACL-TABLE"; + private static final String userTableName = "MOCK-USER-TABLE"; + + private HTableInterface mockedAclTable; + private HTableInterface mockedUserTable; + private RealAclHBaseStorage realAcl; + + public MockAclHBaseStorage() { + String metadataUrl = KylinConfig.getInstanceFromEnv().getMetadataUrl(); + if (metadataUrl != null && metadataUrl.endsWith("hbase")) { + // hbase must be available since metadata is on it + // in this case, let us use a real ACL instead of mockup + realAcl = new RealAclHBaseStorage(); + } + } + + @Override + public String prepareHBaseTable(Class<?> clazz) throws IOException { + if (realAcl != null) { + return realAcl.prepareHBaseTable(clazz); + } + + if (clazz == AclService.class) { + mockedAclTable = new MockHTable(aclTableName, ACL_INFO_FAMILY, ACL_ACES_FAMILY); + return aclTableName; + } else if (clazz == UserService.class) { + mockedUserTable = new MockHTable(userTableName, USER_AUTHORITY_FAMILY); + return userTableName; + } else { + throw new IllegalStateException("prepareHBaseTable for unknown class: " + clazz); + } + } + + @Override + public HTableInterface getTable(String tableName) throws IOException { + if (realAcl != null) { + return realAcl.getTable(tableName); + } + + if (StringUtils.equals(tableName, aclTableName)) { + return mockedAclTable; + } else if (StringUtils.equals(tableName, userTableName)) { + return mockedUserTable; + } else { + throw new IllegalStateException("getTable failed" + tableName); + } + } +}
