fix: checkstyle
This commit is contained in:
parent
57fbdbbd22
commit
dfeaac5292
|
@ -1,9 +1,9 @@
|
|||
package com.databasir.api;
|
||||
|
||||
import com.databasir.common.JsonData;
|
||||
import com.databasir.core.domain.app.OAuthAppService;
|
||||
import com.databasir.core.domain.app.OpenAuthAppService;
|
||||
import com.databasir.core.domain.app.data.*;
|
||||
import com.databasir.core.domain.app.handler.OAuthHandler;
|
||||
import com.databasir.core.domain.app.handler.OpenAuthHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -19,11 +19,11 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class OAuth2AppController {
|
||||
public class OpenAuth2AppController {
|
||||
|
||||
private final OAuthHandler oAuthHandler;
|
||||
private final OpenAuthHandler openAuthHandler;
|
||||
|
||||
private final OAuthAppService oAuthAppService;
|
||||
private final OpenAuthAppService openAuthAppService;
|
||||
|
||||
/**
|
||||
* 无需授权
|
||||
|
@ -31,7 +31,7 @@ public class OAuth2AppController {
|
|||
@GetMapping("/oauth2/authorization/{registrationId}")
|
||||
@ResponseBody
|
||||
public JsonData<String> authorization(@PathVariable String registrationId) {
|
||||
String authorization = oAuthHandler.authorization(registrationId);
|
||||
String authorization = openAuthHandler.authorization(registrationId);
|
||||
return JsonData.ok(authorization);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class OAuth2AppController {
|
|||
@GetMapping("/oauth2/apps")
|
||||
@ResponseBody
|
||||
public JsonData<List<OAuthAppResponse>> listApps() {
|
||||
return JsonData.ok(oAuthAppService.listAll());
|
||||
return JsonData.ok(openAuthAppService.listAll());
|
||||
}
|
||||
|
||||
@GetMapping(Routes.OAuth2App.LIST_PAGE)
|
||||
|
@ -50,14 +50,14 @@ public class OAuth2AppController {
|
|||
public JsonData<Page<OAuthAppPageResponse>> listPage(@PageableDefault(sort = "id", direction = DESC)
|
||||
Pageable page,
|
||||
OAuthAppPageCondition condition) {
|
||||
return JsonData.ok(oAuthAppService.listPage(page, condition));
|
||||
return JsonData.ok(openAuthAppService.listPage(page, condition));
|
||||
}
|
||||
|
||||
@GetMapping(Routes.OAuth2App.GET_ONE)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<OAuthAppDetailResponse> getOne(@PathVariable Integer id) {
|
||||
return JsonData.ok(oAuthAppService.getOne(id));
|
||||
return JsonData.ok(openAuthAppService.getOne(id));
|
||||
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class OAuth2AppController {
|
|||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<Integer> create(@RequestBody @Valid OAuthAppCreateRequest request) {
|
||||
Integer id = oAuthAppService.create(request);
|
||||
Integer id = openAuthAppService.create(request);
|
||||
return JsonData.ok(id);
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class OAuth2AppController {
|
|||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<Void> updateById(@RequestBody @Valid OAuthAppUpdateRequest request) {
|
||||
oAuthAppService.updateById(request);
|
||||
openAuthAppService.updateById(request);
|
||||
return JsonData.ok();
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class OAuth2AppController {
|
|||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<Void> deleteById(@PathVariable Integer id) {
|
||||
oAuthAppService.deleteById(id);
|
||||
openAuthAppService.deleteById(id);
|
||||
return JsonData.ok();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.databasir.api.config;
|
||||
|
||||
import com.databasir.api.Routes;
|
||||
import com.databasir.api.config.oauth2.DatabasirOauth2LoginFilter;
|
||||
import com.databasir.api.config.security.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -46,7 +45,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/login", Routes.Login.REFRESH_ACCESS_TOKEN).permitAll()
|
||||
.antMatchers("/oauth2/apps", "/oauth2/failure", "/oauth2/authorization/*", "/oauth2/login/*").permitAll()
|
||||
.antMatchers("/oauth2/apps", "/oauth2/failure", "/oauth2/authorization/*", "/oauth2/login/*")
|
||||
.permitAll()
|
||||
.antMatchers("/", "/*.html", "/js/**", "/css/**", "/img/**", "/*.ico").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.databasir.api.config.oauth2;
|
|||
|
||||
import com.databasir.api.config.security.DatabasirUserDetailService;
|
||||
import com.databasir.core.domain.user.data.UserDetailResponse;
|
||||
import com.databasir.core.domain.app.OAuthAppService;
|
||||
import com.databasir.core.domain.app.OpenAuthAppService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
|
@ -28,16 +28,16 @@ public class DatabasirOauth2LoginFilter extends AbstractAuthenticationProcessing
|
|||
public static final String OAUTH_LOGIN_URI = "/oauth2/login/*";
|
||||
|
||||
@Autowired
|
||||
private OAuthAppService oAuthAppService;
|
||||
private OpenAuthAppService openAuthAppService;
|
||||
|
||||
@Autowired
|
||||
private DatabasirUserDetailService databasirUserDetailService;
|
||||
|
||||
public DatabasirOauth2LoginFilter(AuthenticationManager authenticationManager,
|
||||
OAuth2AuthenticationSuccessHandler oAuth2AuthenticationSuccessHandler,
|
||||
OAuth2AuthenticationSuccessHandler auth2AuthenticationSuccessHandler,
|
||||
AuthenticationFailureHandler authenticationFailureHandler) {
|
||||
super(OAUTH_LOGIN_URI, authenticationManager);
|
||||
this.setAuthenticationSuccessHandler(oAuth2AuthenticationSuccessHandler);
|
||||
this.setAuthenticationSuccessHandler(auth2AuthenticationSuccessHandler);
|
||||
this.setAuthenticationFailureHandler(authenticationFailureHandler);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class DatabasirOauth2LoginFilter extends AbstractAuthenticationProcessing
|
|||
throws AuthenticationException, IOException, ServletException {
|
||||
Map<String, String[]> params = request.getParameterMap();
|
||||
String registrationId = new AntPathMatcher().extractPathWithinPattern(OAUTH_LOGIN_URI, request.getRequestURI());
|
||||
UserDetailResponse userDetailResponse = oAuthAppService.oauthCallback(registrationId, params);
|
||||
UserDetailResponse userDetailResponse = openAuthAppService.oauthCallback(registrationId, params);
|
||||
UserDetails details = databasirUserDetailService.loadUserByUsername(userDetailResponse.getUsername());
|
||||
DatabasirOAuth2Authentication authentication = new DatabasirOAuth2Authentication(details);
|
||||
if (!userDetailResponse.getEnabled()) {
|
||||
|
|
|
@ -38,7 +38,6 @@ public class JsonData<T> {
|
|||
return jsonData;
|
||||
}
|
||||
|
||||
|
||||
public static <T> JsonData<T> error(String errorCode, String errMessage) {
|
||||
JsonData<T> jsonData = new JsonData<>();
|
||||
jsonData.setErrCode(errorCode);
|
||||
|
|
|
@ -4,13 +4,13 @@ import com.databasir.core.domain.DomainErrors;
|
|||
import com.databasir.core.domain.app.converter.OAuthAppPojoConverter;
|
||||
import com.databasir.core.domain.app.converter.OAuthAppResponseConverter;
|
||||
import com.databasir.core.domain.app.data.*;
|
||||
import com.databasir.core.domain.app.handler.OAuthHandler;
|
||||
import com.databasir.core.domain.app.handler.OpenAuthHandler;
|
||||
import com.databasir.core.domain.app.handler.OAuthProcessContext;
|
||||
import com.databasir.core.domain.app.handler.OAuthProcessResult;
|
||||
import com.databasir.core.domain.user.data.UserCreateRequest;
|
||||
import com.databasir.core.domain.user.data.UserDetailResponse;
|
||||
import com.databasir.core.domain.user.service.UserService;
|
||||
import com.databasir.dao.impl.OAuthAppDao;
|
||||
import com.databasir.dao.impl.OauthAppDao;
|
||||
import com.databasir.dao.tables.pojos.OauthAppPojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
|
@ -27,23 +27,23 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class OAuthAppService {
|
||||
public class OpenAuthAppService {
|
||||
|
||||
private final List<OAuthHandler> oAuthHandlers;
|
||||
private final List<OpenAuthHandler> openAuthHandlers;
|
||||
|
||||
private final OAuthAppDao oAuthAppDao;
|
||||
private final OauthAppDao oauthAppDao;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final OAuthAppResponseConverter oAuthAppResponseConverter;
|
||||
private final OAuthAppResponseConverter oauthAppResponseConverter;
|
||||
|
||||
private final OAuthAppPojoConverter oAuthAppPojoConverter;
|
||||
private final OAuthAppPojoConverter oauthAppPojoConverter;
|
||||
|
||||
public UserDetailResponse oauthCallback(String registrationId, Map<String, String[]> params) {
|
||||
|
||||
// match handler
|
||||
OauthAppPojo app = oAuthAppDao.selectByRegistrationId(registrationId);
|
||||
OAuthHandler oAuthHandler = oAuthHandlers.stream()
|
||||
OauthAppPojo app = oauthAppDao.selectByRegistrationId(registrationId);
|
||||
OpenAuthHandler openAuthHandler = openAuthHandlers.stream()
|
||||
.filter(handler -> handler.support(app.getAppType()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new UsernameNotFoundException("暂不支持该类型登陆"));
|
||||
|
@ -53,7 +53,7 @@ public class OAuthAppService {
|
|||
.callbackParameters(params)
|
||||
.registrationId(registrationId)
|
||||
.build();
|
||||
OAuthProcessResult result = oAuthHandler.process(context);
|
||||
OAuthProcessResult result = openAuthHandler.process(context);
|
||||
|
||||
// get or create new user
|
||||
return userService.get(result.getEmail())
|
||||
|
@ -71,41 +71,41 @@ public class OAuthAppService {
|
|||
}
|
||||
|
||||
public List<OAuthAppResponse> listAll() {
|
||||
List<OauthAppPojo> apps = oAuthAppDao.selectAll();
|
||||
List<OauthAppPojo> apps = oauthAppDao.selectAll();
|
||||
return apps.stream()
|
||||
.map(oAuthAppResponseConverter::to)
|
||||
.map(oauthAppResponseConverter::to)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
if (oAuthAppDao.existsById(id)) {
|
||||
oAuthAppDao.deleteById(id);
|
||||
if (oauthAppDao.existsById(id)) {
|
||||
oauthAppDao.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateById(OAuthAppUpdateRequest request) {
|
||||
OauthAppPojo pojo = oAuthAppPojoConverter.of(request);
|
||||
OauthAppPojo pojo = oauthAppPojoConverter.of(request);
|
||||
try {
|
||||
oAuthAppDao.updateById(pojo);
|
||||
oauthAppDao.updateById(pojo);
|
||||
} catch (DuplicateKeyException e) {
|
||||
throw DomainErrors.REGISTRATION_ID_DUPLICATE.exception();
|
||||
}
|
||||
}
|
||||
|
||||
public Integer create(OAuthAppCreateRequest request) {
|
||||
OauthAppPojo pojo = oAuthAppPojoConverter.of(request);
|
||||
OauthAppPojo pojo = oauthAppPojoConverter.of(request);
|
||||
try {
|
||||
return oAuthAppDao.insertAndReturnId(pojo);
|
||||
return oauthAppDao.insertAndReturnId(pojo);
|
||||
} catch (DuplicateKeyException e) {
|
||||
throw DomainErrors.REGISTRATION_ID_DUPLICATE.exception();
|
||||
}
|
||||
}
|
||||
|
||||
public Page<OAuthAppPageResponse> listPage(Pageable page, OAuthAppPageCondition condition) {
|
||||
return oAuthAppDao.selectByPage(page, condition.toCondition()).map(oAuthAppPojoConverter::toPageResponse);
|
||||
return oauthAppDao.selectByPage(page, condition.toCondition()).map(oauthAppPojoConverter::toPageResponse);
|
||||
}
|
||||
|
||||
public Optional<OAuthAppDetailResponse> getOne(Integer id) {
|
||||
return oAuthAppDao.selectOptionalById(id).map(oAuthAppPojoConverter::toDetailResponse);
|
||||
return oauthAppDao.selectOptionalById(id).map(oauthAppPojoConverter::toDetailResponse);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
package com.databasir.core.domain.app.handler;
|
||||
|
||||
|
||||
import com.databasir.core.domain.DomainErrors;
|
||||
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
||||
import com.databasir.core.infrastructure.remote.github.GithubRemoteService;
|
||||
import com.databasir.dao.enums.OAuthAppType;
|
||||
import com.databasir.dao.impl.OAuthAppDao;
|
||||
import com.databasir.dao.impl.OauthAppDao;
|
||||
import com.databasir.dao.tables.pojos.OauthAppPojo;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
@ -18,11 +17,11 @@ import java.util.Map;
|
|||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class GithubOauthHandler implements OAuthHandler {
|
||||
public class GithubOpenAuthHandler implements OpenAuthHandler {
|
||||
|
||||
private final GithubRemoteService githubRemoteService;
|
||||
|
||||
private final OAuthAppDao oAuthAppDao;
|
||||
private final OauthAppDao oauthAppDao;
|
||||
|
||||
@Override
|
||||
public boolean support(String oauthAppType) {
|
||||
|
@ -31,7 +30,7 @@ public class GithubOauthHandler implements OAuthHandler {
|
|||
|
||||
@Override
|
||||
public String authorization(String registrationId) {
|
||||
OauthAppPojo app = oAuthAppDao.selectByRegistrationId(registrationId);
|
||||
OauthAppPojo app = oauthAppDao.selectByRegistrationId(registrationId);
|
||||
String authUrl = app.getAuthUrl();
|
||||
String clientId = app.getClientId();
|
||||
String authorizeUrl = authUrl + "/login/oauth/authorize";
|
||||
|
@ -46,7 +45,7 @@ public class GithubOauthHandler implements OAuthHandler {
|
|||
|
||||
@Override
|
||||
public OAuthProcessResult process(OAuthProcessContext context) {
|
||||
OauthAppPojo authApp = oAuthAppDao.selectByRegistrationId(context.getRegistrationId());
|
||||
OauthAppPojo authApp = oauthAppDao.selectByRegistrationId(context.getRegistrationId());
|
||||
String clientId = authApp.getClientId();
|
||||
String clientSecret = authApp.getClientSecret();
|
||||
String baseUrl = authApp.getResourceUrl();
|
|
@ -1,6 +1,6 @@
|
|||
package com.databasir.core.domain.app.handler;
|
||||
|
||||
public interface OAuthHandler {
|
||||
public interface OpenAuthHandler {
|
||||
|
||||
boolean support(String oauthAppType);
|
||||
|
|
@ -111,10 +111,12 @@ public class LoginService {
|
|||
data.setUsername(user.getUsername());
|
||||
data.setAccessToken(login.getAccessToken());
|
||||
data.setAvatar(user.getAvatar());
|
||||
long expireAt = login.getAccessTokenExpireAt().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
long expireAt = login.getAccessTokenExpireAt()
|
||||
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
data.setAccessTokenExpireAt(expireAt);
|
||||
data.setRefreshToken(login.getRefreshToken());
|
||||
List<UserRolePojo> rolePojoList = userRoleDao.selectByUserIds(Collections.singletonList(user.getId()));
|
||||
List<UserRolePojo> rolePojoList =
|
||||
userRoleDao.selectByUserIds(Collections.singletonList(user.getId()));
|
||||
List<UserLoginResponse.RoleResponse> roles = rolePojoList
|
||||
.stream()
|
||||
.map(ur -> {
|
||||
|
|
|
@ -12,13 +12,13 @@ import java.util.Optional;
|
|||
import static com.databasir.dao.Tables.OAUTH_APP;
|
||||
|
||||
@Repository
|
||||
public class OAuthAppDao extends BaseDao<OauthAppPojo> {
|
||||
public class OauthAppDao extends BaseDao<OauthAppPojo> {
|
||||
|
||||
@Autowired
|
||||
@Getter
|
||||
private DSLContext dslContext;
|
||||
|
||||
public OAuthAppDao() {
|
||||
public OauthAppDao() {
|
||||
super(OAUTH_APP, OauthAppPojo.class);
|
||||
}
|
||||
|
Loading…
Reference in New Issue