Browse Source

user, jsp -> html , test

pull/4/head
shengzhaoli.shengz 1 year ago
parent
commit
36f7c32557
  1. 3
      src/main/java/com/monkeyk/sos/domain/user/UserRepository.java
  2. 22
      src/main/java/com/monkeyk/sos/service/impl/OauthServiceImpl.java
  3. 20
      src/main/java/com/monkeyk/sos/service/impl/UserServiceImpl.java

3
src/main/java/com/monkeyk/sos/domain/user/UserRepository.java

@ -18,5 +18,8 @@ public interface UserRepository extends Repository {
User findByUsername(String username);
/**
* 注意产品化的设计此处应该有分页会更好
*/
List<User> findUsersByUsername(String username);
}

22
src/main/java/com/monkeyk/sos/service/impl/OauthServiceImpl.java

@ -1,16 +1,14 @@
package com.monkeyk.sos.service.impl;
import com.monkeyk.sos.service.dto.OauthClientDetailsDto;
import com.monkeyk.sos.domain.oauth.OauthClientDetails;
import com.monkeyk.sos.domain.oauth.OauthRepository;
import com.monkeyk.sos.service.OauthService;
import com.monkeyk.sos.service.dto.OauthClientDetailsDto;
import com.monkeyk.sos.web.WebUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -27,38 +25,42 @@ public class OauthServiceImpl implements OauthService {
private OauthRepository oauthRepository;
@Override
@Transactional(readOnly = true)
// @Transactional(readOnly = true)
public OauthClientDetails loadOauthClientDetails(String clientId) {
return oauthRepository.findOauthClientDetails(clientId);
}
@Override
@Transactional(readOnly = true)
// @Transactional(readOnly = true)
public List<OauthClientDetailsDto> loadAllOauthClientDetailsDtos() {
List<OauthClientDetails> clientDetailses = oauthRepository.findAllOauthClientDetails();
return OauthClientDetailsDto.toDtos(clientDetailses);
}
@Override
@Transactional(propagation = Propagation.REQUIRED)
// @Transactional(propagation = Propagation.REQUIRED)
public void archiveOauthClientDetails(String clientId) {
oauthRepository.updateOauthClientDetailsArchive(clientId, true);
LOG.debug("{}|Update OauthClientDetails(clientId: {}) archive = true", WebUtils.getIp(), clientId);
if (LOG.isDebugEnabled()) {
LOG.debug("{}|Update OauthClientDetails(clientId: {}) archive = true", WebUtils.getIp(), clientId);
}
}
@Override
@Transactional(readOnly = true)
// @Transactional(readOnly = true)
public OauthClientDetailsDto loadOauthClientDetailsDto(String clientId) {
final OauthClientDetails oauthClientDetails = oauthRepository.findOauthClientDetails(clientId);
return oauthClientDetails != null ? new OauthClientDetailsDto(oauthClientDetails) : null;
}
@Override
@Transactional(propagation = Propagation.REQUIRED)
// @Transactional(propagation = Propagation.REQUIRED)
public void registerClientDetails(OauthClientDetailsDto formDto) {
OauthClientDetails clientDetails = formDto.createDomain();
oauthRepository.saveOauthClientDetails(clientDetails);
LOG.debug("{}|Save OauthClientDetails: {}", WebUtils.getIp(), clientDetails);
if (LOG.isDebugEnabled()) {
LOG.debug("{}|Save OauthClientDetails: {}", WebUtils.getIp(), clientDetails);
}
}
}

20
src/main/java/com/monkeyk/sos/service/impl/UserServiceImpl.java

@ -1,28 +1,23 @@
package com.monkeyk.sos.service.impl;
import com.monkeyk.sos.service.dto.UserDto;
import com.monkeyk.sos.service.dto.UserFormDto;
import com.monkeyk.sos.service.dto.UserJsonDto;
import com.monkeyk.sos.service.dto.UserOverviewDto;
import com.monkeyk.sos.domain.shared.security.SOSUserDetails;
import com.monkeyk.sos.domain.user.User;
import com.monkeyk.sos.domain.user.UserRepository;
import com.monkeyk.sos.service.UserService;
import com.monkeyk.sos.service.dto.UserDto;
import com.monkeyk.sos.service.dto.UserFormDto;
import com.monkeyk.sos.service.dto.UserJsonDto;
import com.monkeyk.sos.service.dto.UserOverviewDto;
import com.monkeyk.sos.web.WebUtils;
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.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
@ -59,11 +54,14 @@ public class UserServiceImpl implements UserService {
// (principal instanceof String || principal instanceof org.springframework.security.core.userdetails.User)) {
// return loadOauthUserJsonDto((OAuth2Authentication) authentication);
// } else {
final SOSUserDetails userDetails = (SOSUserDetails) principal;
return new UserJsonDto(userRepository.findByGuid(userDetails.user().guid()));
final SOSUserDetails userDetails = (SOSUserDetails) principal;
return new UserJsonDto(userRepository.findByGuid(userDetails.user().guid()));
// }
}
/**
* 注意产品化的设计此处应该有分页会更好
*/
@Override
// @Transactional(readOnly = true)
public UserOverviewDto loadUserOverviewDto(UserOverviewDto overviewDto) {

Loading…
Cancel
Save