增加sonar测试并修复sonar测试的问题

This commit is contained in:
zlt
2019-02-04 14:18:47 +08:00
parent e16d8f5d02
commit 110bdc5a84
58 changed files with 181 additions and 233 deletions
@@ -4,7 +4,6 @@ import com.central.common.utils.ResponseUtil;
import com.central.oauth.handler.OauthLogoutHandler;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
@@ -116,7 +116,7 @@ public class OAuth2Controller {
* @return
*/
@ApiOperation(value = "当前登陆用户信息")
@RequestMapping(value = {"/oauth/userinfo"}, produces = "application/json") // 获取用户信息。/auth/user
@GetMapping(value = {"/oauth/userinfo"}, produces = "application/json") // 获取用户信息。/auth/user
public Map<String, Object> getCurrentUserDetail(@LoginUser SysUser user) {
Map<String, Object> userInfo = new HashMap<>();
if (user != null) {
@@ -35,8 +35,7 @@ public class ValidateCodeController {
* @throws Exception
*/
@GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{deviceId}")
public void createCode(@PathVariable String deviceId, HttpServletResponse response)
throws Exception {
public void createCode(@PathVariable String deviceId, HttpServletResponse response) throws Exception {
Assert.notNull(deviceId, "机器码不能为空");
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
@@ -59,7 +59,7 @@ public class ValidateCodeFilter extends OncePerRequestFilter {
return true;
}
}
} catch (IOException e) {
} catch (Exception e) {
log.error("解析client信息失败", e);
}
}
@@ -39,7 +39,6 @@ public class OauthLogoutHandler implements LogoutHandler {
log.info("remove existingAccessToken!", existingAccessToken);
tokenStore.removeAccessToken(existingAccessToken);
}
return;
}
}
}
@@ -13,13 +13,5 @@ import com.central.oauth.model.Client;
* @author zlt
*/
public interface ClientMapper extends SuperMapper<Client> {
//int count(@Param("params") Map<String, Object> params);
List<Client> findList(Page<Client> page, @Param("params") Map<String, Object> params );
/*@Select("select * from oauth_client_details t where t.client_id = #{clientId}")
Client getClient(String clientId);*/
/*@Update("update oauth_client_details t set t.client_secret = #{clientSecret},t.client_secret_str = #{clientSecretStr} where t.id = #{id}")
int update(Client client);*/
}
@@ -19,7 +19,7 @@ public class MobileAuthenticationProvider implements AuthenticationProvider {
private PasswordEncoder passwordEncoder;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
public Authentication authenticate(Authentication authentication) {
MobileAuthenticationToken authenticationToken = (MobileAuthenticationToken) authentication;
String mobile = (String) authenticationToken.getPrincipal();
String password = (String) authenticationToken.getCredentials();
@@ -69,7 +69,7 @@ public class MobileAuthenticationToken extends AbstractAuthenticationToken {
}
@Override
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
public void setAuthenticated(boolean isAuthenticated) {
if (isAuthenticated) {
throw new IllegalArgumentException(
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
@@ -15,7 +15,7 @@ public class OpenIdAuthenticationProvider implements AuthenticationProvider {
private SocialUserDetailsService userDetailsService;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
public Authentication authenticate(Authentication authentication) {
OpenIdAuthenticationToken authenticationToken = (OpenIdAuthenticationToken) authentication;
String openId = (String) authenticationToken.getPrincipal();
UserDetails user = userDetailsService.loadUserByUserId(openId);
@@ -1,6 +1,3 @@
/**
*
*/
package com.central.oauth.openid;
import org.springframework.security.authentication.AbstractAuthenticationToken;
@@ -66,7 +63,7 @@ public class OpenIdAuthenticationToken extends AbstractAuthenticationToken {
}
@Override
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
public void setAuthenticated(boolean isAuthenticated) {
if (isAuthenticated) {
throw new IllegalArgumentException(
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
@@ -9,5 +9,11 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
* @date 2018/12/28
*/
public interface ZltUserDetailsService extends UserDetailsService {
UserDetails loadUserByMobile(String mobile) throws UsernameNotFoundException;
/**
* 根据电话号码查询用户
*
* @param mobile
* @return
*/
UserDetails loadUserByMobile(String mobile);
}
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.central.common.constant.CommonConstant;
import com.central.common.lock.DistributedLock;
import com.central.common.model.SysUser;
import com.central.common.redis.template.RedisRepository;
import com.central.common.constant.SecurityConstants;
import com.central.common.model.PageResult;
@@ -37,7 +37,7 @@ public class RedisClientDetailsService extends JdbcClientDetailsService {
}
@Override
public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
public ClientDetails loadClientByClientId(String clientId) {
// 先从redis获取
ClientDetails clientDetails = (ClientDetails) redisTemplate.opsForValue().get(clientRedisKey(clientId));
if (clientDetails == null) {
@@ -70,19 +70,19 @@ public class RedisClientDetailsService extends JdbcClientDetailsService {
}
@Override
public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException {
public void updateClientDetails(ClientDetails clientDetails) {
super.updateClientDetails(clientDetails);
cacheAndGetClient(clientDetails.getClientId());
}
@Override
public void updateClientSecret(String clientId, String secret) throws NoSuchClientException {
public void updateClientSecret(String clientId, String secret) {
super.updateClientSecret(clientId, secret);
cacheAndGetClient(clientId);
}
@Override
public void removeClientDetails(String clientId) throws NoSuchClientException {
public void removeClientDetails(String clientId) {
super.removeClientDetails(clientId);
removeRedisCache(clientId);
}
@@ -106,9 +106,7 @@ public class RedisClientDetailsService extends JdbcClientDetailsService {
return;
}
list.parallelStream().forEach(client -> {
redisTemplate.opsForValue().set(clientRedisKey(client.getClientId()), client);
});
list.parallelStream().forEach(client -> redisTemplate.opsForValue().set(clientRedisKey(client.getClientId()), client));
}
private String clientRedisKey(String clientId) {
@@ -26,7 +26,7 @@ public class UserDetailServiceImpl implements ZltUserDetailsService, SocialUserD
private UserService userService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
public UserDetails loadUserByUsername(String username) {
LoginAppUser loginAppUser = userService.findByUsername(username);
if (loginAppUser == null) {
throw new InternalAuthenticationServiceException("用户名或密码错误");
@@ -35,13 +35,13 @@ public class UserDetailServiceImpl implements ZltUserDetailsService, SocialUserD
}
@Override
public SocialUserDetails loadUserByUserId(String openId) throws UsernameNotFoundException {
public SocialUserDetails loadUserByUserId(String openId) {
LoginAppUser loginAppUser = userService.findByOpenId(openId);
return checkUser(loginAppUser);
}
@Override
public UserDetails loadUserByMobile(String mobile) throws UsernameNotFoundException {
public UserDetails loadUserByMobile(String mobile) {
LoginAppUser loginAppUser = userService.findByMobile(mobile);
return checkUser(loginAppUser);
}
@@ -95,7 +95,7 @@ public class ValidateCodeServiceImpl implements IValidateCodeService {
* 验证验证码
*/
@Override
public void validate(HttpServletRequest request) throws ValidateCodeException {
public void validate(HttpServletRequest request) {
String deviceId = request.getParameter("deviceId");
if (StringUtils.isBlank(deviceId)) {
throw new ValidateCodeException("请在请求参数中携带deviceId参数");