Browse Source

新增账户密码登录

tags/V2.2.0
chenjiandong 2 years ago
parent
commit
3867697b36
7 changed files with 62 additions and 3 deletions
  1. +3
    -3
      tuoheng_oidc_server/src/main/java/com/tuoheng/config/SecurityConfig.java
  2. +11
    -0
      tuoheng_oidc_server/src/main/java/com/tuoheng/controller/UserController.java
  3. +3
    -0
      tuoheng_oidc_server/src/main/java/com/tuoheng/mapper/UserMapper.java
  4. +23
    -0
      tuoheng_oidc_server/src/main/java/com/tuoheng/model/param/GetUserInfoDto.java
  5. +3
    -0
      tuoheng_oidc_server/src/main/java/com/tuoheng/service/UserSevice.java
  6. +12
    -0
      tuoheng_oidc_server/src/main/java/com/tuoheng/service/impl/UserServiceImpl.java
  7. +7
    -0
      tuoheng_oidc_server/src/main/resources/mapper/UserMapper.xml

+ 3
- 3
tuoheng_oidc_server/src/main/java/com/tuoheng/config/SecurityConfig.java View File

@@ -47,7 +47,7 @@ import java.util.function.Function;
* @description: TODO
* @date 2022/9/22 14:58
*/
@EnableWebSecurity(debug = true)
@EnableWebSecurity
@Configuration(proxyBeanMethods = false)
@RequiredArgsConstructor
public class SecurityConfig {
@@ -111,8 +111,8 @@ public class SecurityConfig {
http.addFilterAt(new VerifyCodeFilter(),UsernamePasswordAuthenticationFilter.class);
http.csrf().disable()
.authorizeHttpRequests((authorize) -> authorize
.antMatchers("/toLogin", "/getHealth", "/static/**", "/vercode", "/userinfo").permitAll()
.antMatchers("/user/create").permitAll()
.antMatchers("/toLogin", "/getHealth", "/static/**", "/vercode").permitAll()
.antMatchers("/user/create","/user/getInfo").permitAll()
.anyRequest().authenticated()
)
// Form login handles the redirect to the login page from the

+ 11
- 0
tuoheng_oidc_server/src/main/java/com/tuoheng/controller/UserController.java View File

@@ -1,6 +1,7 @@
package com.tuoheng.controller;

import com.tuoheng.model.param.CreateUserDto;
import com.tuoheng.model.param.GetUserInfoDto;
import com.tuoheng.service.UserSevice;
import com.tuoheng.until.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,4 +25,14 @@ public class UserController {
return userSevice.createUser(createUserDto);
}

/**
* 小程序端获取用户信息端点
* @param getUserInfoDto
* @return
*/
@PostMapping("/getInfo")
public JsonResult getUserInfo(@RequestBody GetUserInfoDto getUserInfoDto){
return userSevice.getUserInfo(getUserInfoDto);
}

}

+ 3
- 0
tuoheng_oidc_server/src/main/java/com/tuoheng/mapper/UserMapper.java View File

@@ -16,4 +16,7 @@ public interface UserMapper {

UserBaseInfoDto getUserBaseInfo(String username);

UserBaseInfoDto getMpUserInfo(String username);


}

+ 23
- 0
tuoheng_oidc_server/src/main/java/com/tuoheng/model/param/GetUserInfoDto.java View File

@@ -0,0 +1,23 @@
package com.tuoheng.model.param;

import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* @author chenjiandong
* @description: TODO
* @date 2022/10/8 11:30
*/
@Data
public class GetUserInfoDto {

@NotEmpty(message = "username can not be empty!")
private String username;

@NotEmpty(message = "token can not be empty!")
private String token;

}

+ 3
- 0
tuoheng_oidc_server/src/main/java/com/tuoheng/service/UserSevice.java View File

@@ -1,6 +1,7 @@
package com.tuoheng.service;

import com.tuoheng.model.param.CreateUserDto;
import com.tuoheng.model.param.GetUserInfoDto;
import com.tuoheng.until.JsonResult;
/**
* @author chenjiandong
@@ -11,4 +12,6 @@ public interface UserSevice {

JsonResult createUser(CreateUserDto createUserDto);

JsonResult getUserInfo(GetUserInfoDto getUserInfoDto);

}

+ 12
- 0
tuoheng_oidc_server/src/main/java/com/tuoheng/service/impl/UserServiceImpl.java View File

@@ -2,7 +2,9 @@ package com.tuoheng.service.impl;

import com.tuoheng.mapper.AuthoritiesMapper;
import com.tuoheng.mapper.UserMapper;
import com.tuoheng.model.dto.UserBaseInfoDto;
import com.tuoheng.model.param.CreateUserDto;
import com.tuoheng.model.param.GetUserInfoDto;
import com.tuoheng.model.po.AuthoritiesPo;
import com.tuoheng.model.po.UserPo;
import com.tuoheng.service.UserSevice;
@@ -12,6 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
import org.springframework.security.oauth2.server.authorization.oidc.authentication.OidcUserInfoAuthenticationToken;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -54,4 +59,11 @@ public class UserServiceImpl implements UserSevice {
return JsonResult.success(userPo.getId());
}

@Override
public JsonResult getUserInfo(GetUserInfoDto getUserInfoDto){
UserBaseInfoDto userBaseInfoDto = userMapper.getMpUserInfo(getUserInfoDto.getUsername());
return JsonResult.success(userBaseInfoDto);
}


}

+ 7
- 0
tuoheng_oidc_server/src/main/resources/mapper/UserMapper.xml View File

@@ -24,4 +24,11 @@
where a.username = #{username}
</select>

<select id="getMpUserInfo" resultMap="UserBaseInfoMap">
select a.id as userId, a.username as userName, b.authority
from users a
inner join authorities b on a.id = b.user_id
where a.username = #{username}
</select>

</mapper>

Loading…
Cancel
Save