-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:huankai/hk-examples
- Loading branch information
Showing
6 changed files
with
106 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 43 additions & 43 deletions
86
hk-weixin-example/src/main/java/com/hk/weixin/example/WxMpDemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
package com.hk.weixin.example; | ||
|
||
import com.hk.commons.util.ByteConstants; | ||
import com.hk.core.authentication.api.ClientAppInfo; | ||
import com.hk.core.authentication.security.SecurityUserPrincipal; | ||
import com.hk.core.authentication.security.UserDetailClientService; | ||
import org.springframework.boot.Banner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
|
||
/** | ||
* @author kevin | ||
* @date 2017年12月19日上午10:57:48 | ||
*/ | ||
@SpringBootApplication | ||
public class WxMpDemoApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication application = new SpringApplication(WxMpDemoApplication.class); | ||
application.setBannerMode(Banner.Mode.OFF); | ||
application.run(args); | ||
} | ||
|
||
@Bean | ||
public UserDetailsService userDetailsService() { | ||
return new UserDetailClientService() { | ||
@Override | ||
public SecurityUserPrincipal loadUserByLoginUsername(String username) { | ||
return new SecurityUserPrincipal(1L, null, null, null, null, username, false, | ||
username, ByteConstants.ONE, username, | ||
username, ByteConstants.ONE, null, "$2a$10$KgOArE6QpbY2iTQC0WGGS.hP72PQsHpToqbNVEEmUrd5LcEqrbzAG", ByteConstants.TWO, null, null); | ||
} | ||
|
||
@Override | ||
public ClientAppInfo getClientInfoById(Long clientId) { | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
} | ||
package com.hk.weixin.example; | ||
|
||
import com.hk.commons.util.ByteConstants; | ||
import com.hk.core.authentication.api.ClientAppInfo; | ||
import com.hk.core.authentication.security.SecurityUserPrincipal; | ||
import com.hk.core.authentication.security.UserDetailClientService; | ||
import org.springframework.boot.Banner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
|
||
/** | ||
* @author kevin | ||
* @date 2017年12月19日上午10:57:48 | ||
*/ | ||
@SpringBootApplication | ||
public class WxMpDemoApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication application = new SpringApplication(WxMpDemoApplication.class); | ||
application.setBannerMode(Banner.Mode.OFF); | ||
application.run(args); | ||
} | ||
|
||
@Bean | ||
public UserDetailsService userDetailsService() { | ||
return new UserDetailClientService() { | ||
@Override | ||
public SecurityUserPrincipal loadUserByLoginUsername(String username) { | ||
return new SecurityUserPrincipal(1L, null, null, null, null, username, | ||
username, ByteConstants.ONE, username, | ||
username, ByteConstants.ONE, null, "$2a$10$KgOArE6QpbY2iTQC0WGGS.hP72PQsHpToqbNVEEmUrd5LcEqrbzAG", ByteConstants.TWO, null, null); | ||
} | ||
|
||
@Override | ||
public ClientAppInfo getClientInfoById(Long clientId) { | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
} |
90 changes: 45 additions & 45 deletions
90
hk-weixin-example/src/main/java/com/hk/weixin/example/config/UserDetailServcieImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
/** | ||
* | ||
*/ | ||
package com.hk.weixin.example.config; | ||
|
||
import com.hk.commons.util.ByteConstants; | ||
import com.hk.core.authentication.api.ClientAppInfo; | ||
import com.hk.core.authentication.security.SecurityUserPrincipal; | ||
import com.hk.core.authentication.security.UserDetailClientService; | ||
import com.hk.weixin.example.domain.User; | ||
import com.hk.weixin.example.repository.jpa.UserRepository; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* @author kevin | ||
* @date 2018年2月5日下午3:03:07 | ||
*/ | ||
public class UserDetailServcieImpl implements UserDetailClientService { | ||
|
||
private UserRepository userRepository; | ||
|
||
@Override | ||
public SecurityUserPrincipal loadUserByLoginUsername(String username) { | ||
Optional<User> optional = userRepository.findUniqueByLoginName(username); | ||
if (!optional.isPresent()) { | ||
throw new UsernameNotFoundException("不存在的用户:" + username); | ||
} | ||
User user = optional.get(); | ||
return new SecurityUserPrincipal(user.getId(), null, null, null, null, user.getPhone(), false, | ||
user.getNickName(), ByteConstants.ONE, user.getPhone(), | ||
user.getEmail(), ByteConstants.ONE, user.getIconPath(), user.getPassWord(), ByteConstants.TWO, null, null); | ||
} | ||
|
||
@Override | ||
public ClientAppInfo getClientInfoById(Long clientId) { | ||
return null; | ||
} | ||
|
||
public void setUserRepository(UserRepository userRepository) { | ||
this.userRepository = userRepository; | ||
} | ||
|
||
} | ||
/** | ||
* | ||
*/ | ||
package com.hk.weixin.example.config; | ||
|
||
import com.hk.commons.util.ByteConstants; | ||
import com.hk.core.authentication.api.ClientAppInfo; | ||
import com.hk.core.authentication.security.SecurityUserPrincipal; | ||
import com.hk.core.authentication.security.UserDetailClientService; | ||
import com.hk.weixin.example.domain.User; | ||
import com.hk.weixin.example.repository.jpa.UserRepository; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* @author kevin | ||
* @date 2018年2月5日下午3:03:07 | ||
*/ | ||
public class UserDetailServcieImpl implements UserDetailClientService { | ||
|
||
private UserRepository userRepository; | ||
|
||
@Override | ||
public SecurityUserPrincipal loadUserByLoginUsername(String username) { | ||
Optional<User> optional = userRepository.findUniqueByLoginName(username); | ||
if (!optional.isPresent()) { | ||
throw new UsernameNotFoundException("不存在的用户:" + username); | ||
} | ||
User user = optional.get(); | ||
return new SecurityUserPrincipal(user.getId(), null, null, null, null, user.getPhone(), | ||
user.getNickName(), ByteConstants.ONE, user.getPhone(), | ||
user.getEmail(), ByteConstants.ONE, user.getIconPath(), user.getPassWord(), ByteConstants.TWO, null, null); | ||
} | ||
|
||
@Override | ||
public ClientAppInfo getClientInfoById(Long clientId) { | ||
return null; | ||
} | ||
|
||
public void setUserRepository(UserRepository userRepository) { | ||
this.userRepository = userRepository; | ||
} | ||
|
||
} |