[FIX] PostgresSQLCoreProvider and HttpAuthCoreProvider bug fixes

This commit is contained in:
Gravita 2022-03-18 19:02:58 +07:00
parent 6430b9e2d4
commit 96915b0f78
2 changed files with 39 additions and 6 deletions

View file

@ -252,8 +252,11 @@ public static class HttpUser implements User, UserSupportTextures, UserSupportPr
private String serverId;
private String accessToken;
private ClientPermissions permissions;
@Deprecated
private Texture skin;
@Deprecated
private Texture cloak;
private Map<String, Texture> assets;
private Map<String, String> properties;
public HttpUser() {
@ -288,6 +291,16 @@ public HttpUser(String username, UUID uuid, String serverId, String accessToken,
this.properties = properties;
}
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, Map<String, Texture> assets, Map<String, String> properties) {
this.username = username;
this.uuid = uuid;
this.serverId = serverId;
this.accessToken = accessToken;
this.permissions = permissions;
this.assets = assets;
this.properties = properties;
}
@Override
public String getUsername() {
return username;
@ -315,13 +328,33 @@ public ClientPermissions getPermissions() {
@Override
public Texture getSkinTexture() {
if(assets == null) {
return skin;
}
return assets.get("SKIN");
}
@Override
public Texture getCloakTexture() {
if(assets == null) {
return cloak;
}
return assets.get("CAPE");
}
public Map<String, Texture> getAssets() {
if(assets == null) {
Map<String, Texture> map = new HashMap<>();
if(skin != null) {
map.put("SKIN", skin);
}
if(cloak != null) {
map.put("CAPE", cloak);
}
return map;
}
return assets;
}
@Override
public Map<String, String> getProperties() {

View file

@ -83,11 +83,11 @@ public User getUserByLogin(String login) {
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired {
try {
var info = LegacySessionHelper.getJwtInfoFromAccessToken(accessToken, server.keyAgreementManager.ecdsaPublicKey);
var user = (MySQLCoreProvider.MySQLUser) getUserByUUID(info.uuid());
var user = (PostgresSQLUser) getUserByUUID(info.uuid());
if(user == null) {
return null;
}
return new MySQLCoreProvider.MySQLUserSession(user);
return new PostgresSQLCoreProvider.MySQLUserSession(user);
} catch (ExpiredJwtException e) {
throw new OAuthAccessTokenExpired();
} catch (JwtException e) {
@ -103,7 +103,7 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon
}
String username = parts[0];
String token = parts[1];
var user = (MySQLCoreProvider.MySQLUser) getUserByUsername(username);
var user = (PostgresSQLUser) getUserByUsername(username);
if(user == null || user.password == null) {
return null;
}
@ -112,7 +112,7 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon
return null;
}
var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now().plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey);
return new AuthManager.AuthReport(null, accessToken, refreshToken, expireSeconds * 1000L, new MySQLCoreProvider.MySQLUserSession(user));
return new AuthManager.AuthReport(null, accessToken, refreshToken, expireSeconds * 1000L, new PostgresSQLCoreProvider.MySQLUserSession(user));
}
@Override