@@ -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 |
@@ -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); | |||
} | |||
} |
@@ -16,4 +16,7 @@ public interface UserMapper { | |||
UserBaseInfoDto getUserBaseInfo(String username); | |||
UserBaseInfoDto getMpUserInfo(String username); | |||
} |
@@ -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; | |||
} |
@@ -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); | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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> |