Giter Club home page Giter Club logo

Comments (7)

Piscen avatar Piscen commented on September 26, 2024 1

感谢解答,问题已解决。应该是服务器环境问题,手动建了一台实例之后可以正常跑了。

from turms.

Piscen avatar Piscen commented on September 26, 2024

登录失败: (401, 1300) Unauthenticated

from turms.

JamesChenX avatar JamesChenX commented on September 26, 2024

想知道这个是有啥机制

In simple words, turms servers just compare the password passed from the HTTP request with the one on MongoDB, if they match, the request is authenticated. If not, unauthenticated.

Admin authentication code:

  1. im.turms.server.common.access.admin.web.HttpRequestAuthenticator#authenticate
  2. im.turms.server.common.domain.admin.service.BaseAdminService#authenticate

登录也需要鉴权么

In fact, there is no dedicated admin API for login.
The login logic on the login dialog in turms-admin just sends a head HTTP request to /admins to check if the account and password match, so no something like JWT, or session ID will be generated.

过了一段时间之后登录就出现401错误了。重启服务之后又正常了,过了一段时间又报错了

I never encountered this problem, and the authentication code should be fine after code review.
And you can upgrade your servers to the latest images or code, and try again.
If you still encounter the problem, you can set some breakpoints in the methods mentioned above to check why your request are unauthenticated.

from turms.

Piscen avatar Piscen commented on September 26, 2024

断点了一下BaseAdminService#authenticate,正常登录的时候accountToAdmin是有管理员账号数据的,失败的时候这个accountToAdmin空了,看代码是去查了一下账号又添加到这个map里了,但是adminRepository.findById(account)返回的依旧是空,这个是啥意思,数据库被自动清空了?
public Mono queryAdmin(@NotNull String account) {
try {
Validator.notNull(account, "account");
} catch (ResponseException e) {
return Mono.error(e);
}
AdminInfo adminInfo = accountToAdmin.get(account);
if (adminInfo == null) {
return adminRepository.findById(account)
.doOnNext(admin -> accountToAdmin.put(account, new AdminInfo(admin, null)));
}
return Mono.just(adminInfo.getAdmin());
}

from turms.

JamesChenX avatar JamesChenX commented on September 26, 2024

If adminRepository.findById(account) returns a Mono that emits nothing (e.g. Mono.empty()), it means there is no such admin account matching the account parameter as _id in MongoDB. In other words, the admin doesn't exist.

Turms servers do NOT delete admin accounts automatically unless you set turms.service.fake.clear-all-collections-before-faking to true, then turms-service will drop all data in MongoDB when the server starts up every time.
The property is only set to true by default to reset mock data when you running the servers in the test profile.

You can check if it is true by searching Start dropping databases in your logs when the server is starting but has not started.

from turms.

Piscen avatar Piscen commented on September 26, 2024

clear-all-collections-before-faking这个设置确实为true,不过这个是每次重启才会奇效吧,我现在是服务启动之后放着不动,过个把小时就登录报错了。测试用的阿里云抢占式实例,这个有关系么

from turms.

JamesChenX avatar JamesChenX commented on September 26, 2024

You can run turms servers in the prod or dev profile so that your data won't be removed by servers automatically. The test profile with the true clear-all-collections-before-faking is used to run tests (e.g. integration tests, system tests) and will remove collections every time for testing.

测试用的阿里云抢占式实例,这个有关系么

Alicloud Spot/Preemptive instances will remove data whenever the instance stops, so it may related to the problem, and it depends on how you deploy turms servers and MongoDB.

from turms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.