Browse Source

(118) - Add java-config(零配置) 的支持

2.0.0
Li Shengzhao 9 years ago
parent
commit
221c3eab70
  1. 7
      src/main/java/com/monkeyk/sos/service/impl/OauthServiceImpl.java
  2. 7
      src/main/java/com/monkeyk/sos/service/impl/UserServiceImpl.java
  3. 0
      src/main/resources/spring/context.xml.old
  4. 0
      src/main/resources/spring/transaction.xml.old

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

@ -6,6 +6,8 @@ import com.monkeyk.sos.domain.oauth.OauthRepository;
import com.monkeyk.sos.service.OauthService;
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;
@ -19,28 +21,33 @@ public class OauthServiceImpl implements OauthService {
private OauthRepository oauthRepository;
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public OauthClientDetails loadOauthClientDetails(String clientId) {
return oauthRepository.findOauthClientDetails(clientId);
}
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public List<OauthClientDetailsDto> loadAllOauthClientDetailsDtos() {
List<OauthClientDetails> clientDetailses = oauthRepository.findAllOauthClientDetails();
return OauthClientDetailsDto.toDtos(clientDetailses);
}
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void archiveOauthClientDetails(String clientId) {
oauthRepository.updateOauthClientDetailsArchive(clientId, true);
}
@Override
@Transactional(propagation = Propagation.SUPPORTS, 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)
public void registerClientDetails(OauthClientDetailsDto formDto) {
OauthClientDetails clientDetails = formDto.createDomain();
oauthRepository.saveOauthClientDetails(clientDetails);

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

@ -16,6 +16,8 @@ import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
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;
@ -30,6 +32,7 @@ public class UserServiceImpl implements UserService {
private UserRepository userRepository;
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepository.findByUsername(username);
if (user == null || user.archived()) {
@ -40,6 +43,7 @@ public class UserServiceImpl implements UserService {
}
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public UserJsonDto loadCurrentUserJsonDto() {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
final Object principal = authentication.getPrincipal();
@ -54,6 +58,7 @@ public class UserServiceImpl implements UserService {
}
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public UserOverviewDto loadUserOverviewDto(UserOverviewDto overviewDto) {
List<User> users = userRepository.findUsersByUsername(overviewDto.getUsername());
overviewDto.setUserDtos(UserDto.toDtos(users));
@ -61,12 +66,14 @@ public class UserServiceImpl implements UserService {
}
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public boolean isExistedUsername(String username) {
final User user = userRepository.findByUsername(username);
return user != null;
}
@Override
@Transactional(propagation = Propagation.REQUIRED)
public String saveUser(UserFormDto formDto) {
User user = formDto.newUser();
userRepository.saveUser(user);

0
src/main/resources/spring/context.xml → src/main/resources/spring/context.xml.old

0
src/main/resources/spring/transaction.xml → src/main/resources/spring/transaction.xml.old

Loading…
Cancel
Save