github-advanced-security[bot] commented on code in PR #15321:
URL: 
https://github.com/apache/dolphinscheduler/pull/15321#discussion_r1531941215


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java:
##########
@@ -41,6 +51,34 @@
         return new Result<>(e.getCode(), e.getMessage());
     }
 
+    @ExceptionHandler(AccessDeniedException.class)
+    public ResponseEntity<Object> exceptionHandler(AccessDeniedException e, 
WebRequest request) {
+
+        return new ResponseEntity<>(
+                e.getMessage(),
+                HttpStatus.FORBIDDEN);
+    }
+
+    @ExceptionHandler(ResponseStatusException.class)
+    public ResponseEntity<Object> exceptionHandler(ResponseStatusException e, 
WebRequest request) {

Review Comment:
   ## Useless parameter
   
   The parameter 'request' is never used.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4058)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java:
##########
@@ -41,6 +51,34 @@
         return new Result<>(e.getCode(), e.getMessage());
     }
 
+    @ExceptionHandler(AccessDeniedException.class)
+    public ResponseEntity<Object> exceptionHandler(AccessDeniedException e, 
WebRequest request) {
+
+        return new ResponseEntity<>(
+                e.getMessage(),
+                HttpStatus.FORBIDDEN);
+    }
+
+    @ExceptionHandler(ResponseStatusException.class)
+    public ResponseEntity<Object> exceptionHandler(ResponseStatusException e, 
WebRequest request) {
+        return new ResponseEntity<>(
+                e.getReason(),
+                e.getStatus());
+    }
+
+    @ExceptionHandler(MethodArgumentNotValidException.class)
+    public ResponseEntity<Object> 
exceptionHandler(MethodArgumentNotValidException e, WebRequest request) {

Review Comment:
   ## Useless parameter
   
   The parameter 'request' is never used.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4057)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/v3/security/SecurityConfiguration.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.dolphinscheduler.api.v3.security;
+
+import org.apache.dolphinscheduler.api.v3.security.filter.AuthenticationFilter;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.Customizer;
+import 
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+import 
org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import 
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import 
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.web.SecurityFilterChain;
+import 
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+
+@Configuration
+@EnableWebSecurity
+@EnableGlobalMethodSecurity(prePostEnabled = true)
+public class SecurityConfiguration {
+
+    @Bean
+    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception 
{
+        http.csrf(AbstractHttpConfigurer::disable)

Review Comment:
   ## Disabled Spring CSRF protection
   
   CSRF vulnerability due to protection being disabled.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4060)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/v3/service/impl/ProjectV3ServiceImpl.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.dolphinscheduler.api.v3.service.impl;
+
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ServiceException;
+import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
+import org.apache.dolphinscheduler.api.v3.service.ProjectV3Service;
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
+import org.apache.dolphinscheduler.dao.entity.Project;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.v3.ProjectV3Mapper;
+
+import java.util.Date;
+import java.util.List;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PostAuthorize;
+import org.springframework.security.access.prepost.PostFilter;
+import org.springframework.stereotype.Service;
+
+/**
+ * project service impl
+ **/
+@Service
+@Slf4j
+public class ProjectV3ServiceImpl extends BaseServiceImpl implements 
ProjectV3Service {
+
+    @Autowired
+    private ProjectV3Mapper projectMapper;
+
+    /**
+     * query project details by code
+     *
+     * @param projectCode project code
+     * @return project detail information
+     */
+    @Override
+    @PostAuthorize("hasAuthority('ADMIN_USER') or returnObject.perm == 7 or 
returnObject.userId == authentication.getUserId()")
+    public Project queryProjectForUpdate(User user, long projectCode) {
+        Project project = 
projectMapper.queryProjectByCodeForUpdate(user.getId(), projectCode);
+
+        if (project == null) {
+            throw new ServiceException(Status.PROJECT_NOT_FOUND, projectCode);
+        }
+
+        return project;
+    }
+
+    /**
+     * admin can view all projects
+     *
+     * @param user       User
+     * @param searchVal  search value
+     * @param maxResults max result
+     * @return project list which the login user have permission to see
+     */
+    @PostFilter("hasAuthority('ADMIN_USER') or filterObject.perm > 0 or 
filterObject.userId == authentication.getUserId()")
+    public List<Project> listAuthorizedProject(User user, int offset, int 
maxResults, String searchVal) {
+        return projectMapper.listProjects(
+                user.getId(),
+                offset,
+                maxResults,
+                searchVal);
+    }
+
+    public Project createProject(User user, String projectName, String desc) {
+        Project existProject = projectMapper.queryProjectByName(projectName);
+
+        if (existProject != null) {
+            throw new ServiceException(Status.PROJECT_ALREADY_EXISTS, 
projectName);
+        }
+
+        long projectCode;
+
+        try {
+            projectCode = CodeGenerateUtils.getInstance().genCode();
+        } catch (CodeGenerateUtils.CodeGenerateException e) {
+            throw new ServiceException(Status.PROJECT_PARAMETER_CODE_EMPTY);
+        }
+
+        Date now = new Date();
+
+        Project project = Project
+                .builder()
+                .name(projectName)
+                .code(projectCode)
+                .description(desc)
+                .userId(user.getId())
+                .userName(user.getUserName())
+                .createTime(now)
+                .updateTime(now)
+                .build();
+
+        if (projectMapper.insert(project) <= 0) {
+            throw new ServiceException(Status.CREATE_PROJECT_ERROR);
+        }
+
+        return project;
+    }
+
+    public void deleteProject(Project project) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [ProjectV3Service.deleteProject](1); it is advisable 
to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4063)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/v3/security/filter/AuthenticationFilter.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.dolphinscheduler.api.v3.security.filter;
+
+import org.apache.dolphinscheduler.api.v3.security.AuthenticationService;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.http.MediaType;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.web.filter.GenericFilterBean;
+
+public class AuthenticationFilter extends GenericFilterBean {
+
+    @Override
+    public void doFilter(ServletRequest request, ServletResponse response,
+                         FilterChain filterChain) throws IOException, 
ServletException {
+        if (((HttpServletRequest) request).getRequestURI().contains("/v3/")) {
+            try {
+                Authentication authentication =
+                        
AuthenticationService.getInstance().getAuthentication((HttpServletRequest) 
request);
+                
SecurityContextHolder.getContext().setAuthentication(authentication);
+            } catch (Exception exp) {
+                HttpServletResponse httpResponse = (HttpServletResponse) 
response;
+                httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+                httpResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
+                PrintWriter writer = httpResponse.getWriter();
+                writer.print(exp.getMessage());

Review Comment:
   ## Information exposure through a stack trace
   
   [Error information](1) can be exposed to an external user.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4061)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java:
##########
@@ -41,6 +51,34 @@
         return new Result<>(e.getCode(), e.getMessage());
     }
 
+    @ExceptionHandler(AccessDeniedException.class)
+    public ResponseEntity<Object> exceptionHandler(AccessDeniedException e, 
WebRequest request) {

Review Comment:
   ## Useless parameter
   
   The parameter 'request' is never used.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4059)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/v3/service/impl/ProjectV3ServiceImpl.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.dolphinscheduler.api.v3.service.impl;
+
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ServiceException;
+import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
+import org.apache.dolphinscheduler.api.v3.service.ProjectV3Service;
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
+import org.apache.dolphinscheduler.dao.entity.Project;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.v3.ProjectV3Mapper;
+
+import java.util.Date;
+import java.util.List;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PostAuthorize;
+import org.springframework.security.access.prepost.PostFilter;
+import org.springframework.stereotype.Service;
+
+/**
+ * project service impl
+ **/
+@Service
+@Slf4j
+public class ProjectV3ServiceImpl extends BaseServiceImpl implements 
ProjectV3Service {
+
+    @Autowired
+    private ProjectV3Mapper projectMapper;
+
+    /**
+     * query project details by code
+     *
+     * @param projectCode project code
+     * @return project detail information
+     */
+    @Override
+    @PostAuthorize("hasAuthority('ADMIN_USER') or returnObject.perm == 7 or 
returnObject.userId == authentication.getUserId()")
+    public Project queryProjectForUpdate(User user, long projectCode) {
+        Project project = 
projectMapper.queryProjectByCodeForUpdate(user.getId(), projectCode);
+
+        if (project == null) {
+            throw new ServiceException(Status.PROJECT_NOT_FOUND, projectCode);
+        }
+
+        return project;
+    }
+
+    /**
+     * admin can view all projects
+     *
+     * @param user       User
+     * @param searchVal  search value
+     * @param maxResults max result
+     * @return project list which the login user have permission to see
+     */
+    @PostFilter("hasAuthority('ADMIN_USER') or filterObject.perm > 0 or 
filterObject.userId == authentication.getUserId()")
+    public List<Project> listAuthorizedProject(User user, int offset, int 
maxResults, String searchVal) {
+        return projectMapper.listProjects(
+                user.getId(),
+                offset,
+                maxResults,
+                searchVal);
+    }
+
+    public Project createProject(User user, String projectName, String desc) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [ProjectV3Service.createProject](1); it is advisable 
to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4064)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/v3/service/impl/ProjectV3ServiceImpl.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.dolphinscheduler.api.v3.service.impl;
+
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ServiceException;
+import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
+import org.apache.dolphinscheduler.api.v3.service.ProjectV3Service;
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
+import org.apache.dolphinscheduler.dao.entity.Project;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.v3.ProjectV3Mapper;
+
+import java.util.Date;
+import java.util.List;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PostAuthorize;
+import org.springframework.security.access.prepost.PostFilter;
+import org.springframework.stereotype.Service;
+
+/**
+ * project service impl
+ **/
+@Service
+@Slf4j
+public class ProjectV3ServiceImpl extends BaseServiceImpl implements 
ProjectV3Service {
+
+    @Autowired
+    private ProjectV3Mapper projectMapper;
+
+    /**
+     * query project details by code
+     *
+     * @param projectCode project code
+     * @return project detail information
+     */
+    @Override
+    @PostAuthorize("hasAuthority('ADMIN_USER') or returnObject.perm == 7 or 
returnObject.userId == authentication.getUserId()")
+    public Project queryProjectForUpdate(User user, long projectCode) {
+        Project project = 
projectMapper.queryProjectByCodeForUpdate(user.getId(), projectCode);
+
+        if (project == null) {
+            throw new ServiceException(Status.PROJECT_NOT_FOUND, projectCode);
+        }
+
+        return project;
+    }
+
+    /**
+     * admin can view all projects
+     *
+     * @param user       User
+     * @param searchVal  search value
+     * @param maxResults max result
+     * @return project list which the login user have permission to see
+     */
+    @PostFilter("hasAuthority('ADMIN_USER') or filterObject.perm > 0 or 
filterObject.userId == authentication.getUserId()")
+    public List<Project> listAuthorizedProject(User user, int offset, int 
maxResults, String searchVal) {
+        return projectMapper.listProjects(
+                user.getId(),
+                offset,
+                maxResults,
+                searchVal);
+    }
+
+    public Project createProject(User user, String projectName, String desc) {
+        Project existProject = projectMapper.queryProjectByName(projectName);
+
+        if (existProject != null) {
+            throw new ServiceException(Status.PROJECT_ALREADY_EXISTS, 
projectName);
+        }
+
+        long projectCode;
+
+        try {
+            projectCode = CodeGenerateUtils.getInstance().genCode();
+        } catch (CodeGenerateUtils.CodeGenerateException e) {
+            throw new ServiceException(Status.PROJECT_PARAMETER_CODE_EMPTY);
+        }
+
+        Date now = new Date();
+
+        Project project = Project
+                .builder()
+                .name(projectName)
+                .code(projectCode)
+                .description(desc)
+                .userId(user.getId())
+                .userName(user.getUserName())
+                .createTime(now)
+                .updateTime(now)
+                .build();
+
+        if (projectMapper.insert(project) <= 0) {
+            throw new ServiceException(Status.CREATE_PROJECT_ERROR);
+        }
+
+        return project;
+    }
+
+    public void deleteProject(Project project) {
+        if (projectMapper.deleteById(project.getId()) <= 0) {
+            throw new ServiceException(Status.DELETE_PROJECT_ERROR);
+        }
+    }
+
+    public Project updateProject(Project project, String name, String 
description) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [ProjectV3Service.updateProject](1); it is advisable 
to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4062)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/v3/service/impl/ProjectV3ServiceImpl.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.dolphinscheduler.api.v3.service.impl;
+
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ServiceException;
+import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
+import org.apache.dolphinscheduler.api.v3.service.ProjectV3Service;
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
+import org.apache.dolphinscheduler.dao.entity.Project;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.v3.ProjectV3Mapper;
+
+import java.util.Date;
+import java.util.List;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PostAuthorize;
+import org.springframework.security.access.prepost.PostFilter;
+import org.springframework.stereotype.Service;
+
+/**
+ * project service impl
+ **/
+@Service
+@Slf4j
+public class ProjectV3ServiceImpl extends BaseServiceImpl implements 
ProjectV3Service {
+
+    @Autowired
+    private ProjectV3Mapper projectMapper;
+
+    /**
+     * query project details by code
+     *
+     * @param projectCode project code
+     * @return project detail information
+     */
+    @Override
+    @PostAuthorize("hasAuthority('ADMIN_USER') or returnObject.perm == 7 or 
returnObject.userId == authentication.getUserId()")
+    public Project queryProjectForUpdate(User user, long projectCode) {
+        Project project = 
projectMapper.queryProjectByCodeForUpdate(user.getId(), projectCode);
+
+        if (project == null) {
+            throw new ServiceException(Status.PROJECT_NOT_FOUND, projectCode);
+        }
+
+        return project;
+    }
+
+    /**
+     * admin can view all projects
+     *
+     * @param user       User
+     * @param searchVal  search value
+     * @param maxResults max result
+     * @return project list which the login user have permission to see
+     */
+    @PostFilter("hasAuthority('ADMIN_USER') or filterObject.perm > 0 or 
filterObject.userId == authentication.getUserId()")
+    public List<Project> listAuthorizedProject(User user, int offset, int 
maxResults, String searchVal) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [ProjectV3Service.listAuthorizedProject](1); it is 
advisable to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4065)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to