27 changed files with 376 additions and 69 deletions
@ -0,0 +1,17 @@ |
|||||||
|
package net.sopod.soim.das.user.api.service; |
||||||
|
|
||||||
|
import net.sopod.soim.das.user.api.model.entity.ImUser; |
||||||
|
|
||||||
|
/** |
||||||
|
* DasUserService |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 23:28 |
||||||
|
*/ |
||||||
|
public interface UserDasService { |
||||||
|
|
||||||
|
ImUser getUserById(Long id); |
||||||
|
|
||||||
|
ImUser getUserByAccount(String account); |
||||||
|
|
||||||
|
} |
||||||
@ -1,7 +0,0 @@ |
|||||||
package net.sopod.soim.das.user.service; |
|
||||||
|
|
||||||
public interface HelloService { |
|
||||||
|
|
||||||
String sayHello(String name); |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,27 +0,0 @@ |
|||||||
package net.sopod.soim.das.user.service; |
|
||||||
|
|
||||||
import net.sopod.soim.logic.api.segmentid.core.SegmentIdGenerator; |
|
||||||
import org.apache.dubbo.config.annotation.DubboService; |
|
||||||
import org.apache.dubbo.rpc.RpcContext; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
|
|
||||||
/** |
|
||||||
* HelloServiceImpl |
|
||||||
* |
|
||||||
* @author tmy |
|
||||||
* @date 2022-03-28 16:23 |
|
||||||
*/ |
|
||||||
@DubboService(version = "1.0.0") |
|
||||||
public class HelloServiceImpl implements HelloService { |
|
||||||
|
|
||||||
@Resource |
|
||||||
private SegmentIdGenerator segmentIdGenerator; |
|
||||||
|
|
||||||
@Override |
|
||||||
public String sayHello(String name) { |
|
||||||
System.out.println("be invoked! client:" + RpcContext.getClientAttachment().getObjectAttachments()); |
|
||||||
return "hello "+ name; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,35 @@ |
|||||||
|
package net.sopod.soim.das.user.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import net.sopod.soim.das.user.api.model.entity.ImUser; |
||||||
|
import net.sopod.soim.das.user.api.service.UserDasService; |
||||||
|
import net.sopod.soim.das.user.dao.UserMapper; |
||||||
|
import org.apache.dubbo.config.annotation.DubboService; |
||||||
|
|
||||||
|
/** |
||||||
|
* UserDasServiceImpl |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 23:30 |
||||||
|
*/ |
||||||
|
@DubboService |
||||||
|
@AllArgsConstructor |
||||||
|
public class UserDasServiceImpl implements UserDasService { |
||||||
|
|
||||||
|
private UserMapper userMapper; |
||||||
|
|
||||||
|
@Override |
||||||
|
public ImUser getUserById(Long id) { |
||||||
|
return userMapper.selectById(id); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ImUser getUserByAccount(String account) { |
||||||
|
LambdaQueryWrapper<ImUser> accountQuery = new QueryWrapper<ImUser>().lambda() |
||||||
|
.eq(ImUser::getUsername, account); |
||||||
|
return userMapper.selectOne(accountQuery); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<parent> |
||||||
|
<artifactId>so-im</artifactId> |
||||||
|
<groupId>net.sopod</groupId> |
||||||
|
<version>1.0.0</version> |
||||||
|
</parent> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<artifactId>im-entry-http</artifactId> |
||||||
|
<description>提供im-entry监控,节点负载分配,http登录服务,后面用dubbo http网关替代</description> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>net.sopod</groupId> |
||||||
|
<artifactId>im-logic-user-api</artifactId> |
||||||
|
<version>${soim.version}</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.dubbo</groupId> |
||||||
|
<artifactId>dubbo-spring-boot-starter</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.dubbo</groupId> |
||||||
|
<artifactId>dubbo-registry-nacos</artifactId> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
package net.sopod.soim.entry.http; |
||||||
|
|
||||||
|
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; |
||||||
|
import org.springframework.boot.SpringApplication; |
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||||
|
|
||||||
|
/** |
||||||
|
* EntryHttpApplication |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 23:08 |
||||||
|
*/ |
||||||
|
@EnableDubbo |
||||||
|
@SpringBootApplication |
||||||
|
public class EntryHttpApplication { |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run(EntryHttpApplication.class, args); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
package net.sopod.soim.entry.http.controller; |
||||||
|
|
||||||
|
import net.sopod.soim.entry.http.model.ao.PwdAuthAO; |
||||||
|
import net.sopod.soim.logic.user.auth.model.ImAuth; |
||||||
|
import net.sopod.soim.logic.user.service.UserAuthService; |
||||||
|
import org.apache.dubbo.config.annotation.DubboReference; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
/** |
||||||
|
* AuthController |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 23:09 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/auth") |
||||||
|
public class AuthController { |
||||||
|
|
||||||
|
@DubboReference |
||||||
|
private UserAuthService userAuthService; |
||||||
|
|
||||||
|
@PostMapping("/pwdAuth") |
||||||
|
public ImAuth pwdAuth(@RequestBody PwdAuthAO authAO) { |
||||||
|
ImAuth imAuth = userAuthService.pwdAuth(authAO.getAccount(), authAO.getPassword()); |
||||||
|
String accessToken = imAuth.getAccessToken(); |
||||||
|
return imAuth; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
package net.sopod.soim.entry.http.model.ao; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* PwdAuthAO |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 23:14 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class PwdAuthAO { |
||||||
|
|
||||||
|
private String account; |
||||||
|
|
||||||
|
private String password; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
package net.sopod.soim.entry.http.service; |
||||||
|
|
||||||
|
/** |
||||||
|
* ImMonitorService |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 23:27 |
||||||
|
*/ |
||||||
|
public class ImEntryMonitorService { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
package net.sopod.soim.entry.http.service; |
||||||
|
|
||||||
|
/** |
||||||
|
* ImEntryService |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 23:27 |
||||||
|
*/ |
||||||
|
public class ImEntryService { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
spring: |
||||||
|
application: |
||||||
|
name: im-entry-http |
||||||
|
dubbo: |
||||||
|
application: |
||||||
|
name: ${spring.application.name} |
||||||
|
registry: |
||||||
|
address: nacos://124.222.131.236:3848 |
||||||
|
group: so-im |
||||||
|
provider: |
||||||
|
register: false # 不向注册中心注册服务 |
||||||
|
protocol: injvm # 服务提供只供jvm内部使用, 不暴露在外面 (不启动dubbo provider服务) |
||||||
|
consumer: |
||||||
|
check: false |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
package net.sopod.soim.entry.handler.auth; |
||||||
|
|
||||||
|
import com.google.protobuf.MessageLite; |
||||||
|
import net.sopod.soim.core.handler.NetUserMessageHandler; |
||||||
|
import net.sopod.soim.core.session.Account; |
||||||
|
import net.sopod.soim.core.session.NetUser; |
||||||
|
import net.sopod.soim.data.msg.auth.Auth; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* LoginHandler |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 22:20 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class LoginHandler extends NetUserMessageHandler<Auth.Login> { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(LoginHandler.class); |
||||||
|
|
||||||
|
@Override |
||||||
|
public MessageLite handle(NetUser netUser, Auth.Login msg) { |
||||||
|
logger.info("auth login: {}, {}", msg.getAccount(), msg.getPassword()); |
||||||
|
Account account = Account.AccountBuilder.newBuilder() |
||||||
|
.setNetUser(netUser) |
||||||
|
.setAccountId(1L) |
||||||
|
.setName(msg.getAccount()) |
||||||
|
.build(); |
||||||
|
// 注册为账号添加到连接
|
||||||
|
netUser.upgradeAccount(account); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,15 +1,18 @@ |
|||||||
package net.sopod.soim.logic.user.auth.model; |
package net.sopod.soim.logic.user.auth.model; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
/** |
/** |
||||||
* LoginParam |
* LoginParam |
||||||
* |
* |
||||||
* @author tmy |
* @author tmy |
||||||
* @date 2022-03-31 21:06 |
* @date 2022-03-31 21:06 |
||||||
*/ |
*/ |
||||||
public class ReqLogin { |
@Data |
||||||
|
public class ImAuth { |
||||||
|
|
||||||
private String username; |
private String accessToken; |
||||||
|
|
||||||
private String password; |
private long expireMs; |
||||||
|
|
||||||
} |
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
package net.sopod.soim.logic.user.service; |
||||||
|
|
||||||
|
import net.sopod.soim.logic.user.auth.model.ImAuth; |
||||||
|
|
||||||
|
/** |
||||||
|
* AuthService |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 22:55 |
||||||
|
*/ |
||||||
|
public interface UserAuthService { |
||||||
|
|
||||||
|
ImAuth pwdAuth(String account, String password); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
package net.sopod.soim.logic.user.service; |
||||||
|
|
||||||
|
import net.sopod.soim.das.user.api.model.entity.ImUser; |
||||||
|
import net.sopod.soim.das.user.api.service.UserDasService; |
||||||
|
import net.sopod.soim.logic.user.auth.model.ImAuth; |
||||||
|
import org.apache.dubbo.config.annotation.DubboReference; |
||||||
|
import org.apache.dubbo.config.annotation.DubboService; |
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture; |
||||||
|
|
||||||
|
/** |
||||||
|
* AuthServiceImpl |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-04-13 22:57 |
||||||
|
*/ |
||||||
|
@DubboService |
||||||
|
public class UserAuthServiceImpl implements UserAuthService { |
||||||
|
|
||||||
|
@DubboReference |
||||||
|
private UserDasService userDasService; |
||||||
|
|
||||||
|
@Override |
||||||
|
public ImAuth pwdAuth(String account, String password) { |
||||||
|
ImUser imUser = userDasService.getUserByAccount(account); |
||||||
|
if (imUser == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
// TODO status,
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue