gpt4 book ai didi

java - AuthorizationService 中 getAuthority() 上的 SonarQube 警告

转载 作者:行者123 更新时间:2023-12-02 09:03:56 24 4
gpt4 key购买 nike

我有一个 Spring Boot 应用程序,并且在调用 getAuthority() 的行中,我的方法收到以下 SonarQube 警告。我应该如何修复它?

Controlling permissions is security-sensitive. It has led in the past to the following vulnerabilities:

@Service    
public class AuthorizationService implements UserDetailsService {

@Autowired
private MRepository mRepository;

public UserDetails loadUserByUsername(String userId) {
MEntity user = mRepository.findByName(userId);
if (user == null) {
throw new UsernameNotFoundException("Invalid username or password.");
}
return new User(user.getName(), user.getPassword(), getAuthority());
}


private List<SimpleGrantedAuthority> getAuthority() { //here i get the warning
return Arrays.asList(new SimpleGrantedAuthority("ROLE_ADMIN"));
}

最佳答案

较新版本的 SonarQube 不仅为您提供代码气味、问题和错误警告,还提供安全热点。这些不是您的代码本身的问题。

正如稍后的警告所述:

This rule flags code that controls the access to resources and actions. The goal is to guide security code reviews.

这只是意味着您应该仔细查看,因为 Sonar 已在代码中识别出授予权限的行。这有助于审阅者发现与安全相关的代码片段。

SonarQube 但是无法判断该代码是否安全。您需要自己确保这一点。它只是告诉你在哪里要多看两眼。如果您觉得这段代码没问题,您可以将此 SonarQube 问题设置为“Resolve as Reviewed”。

另请参阅官方 SonarQube 文档:https://docs.sonarqube.org/latest/user-guide/security-hotspots/

关于java - AuthorizationService 中 getAuthority() 上的 SonarQube 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59967676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com