hotfix API token saving

This commit is contained in:
kirillius 2025-10-07 18:32:03 +03:00
parent 9d954c7213
commit 7337ab7021
1 changed files with 9 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import ru.kirillius.pf.sdn.core.Auth.TokenService;
import ru.kirillius.pf.sdn.core.Context;
import ru.kirillius.pf.sdn.web.ProtectedMethod;
import java.io.IOException;
import java.util.Date;
/**
@ -47,8 +48,10 @@ public class Auth implements RPC {
*/
@ProtectedMethod
@JRPCMethod
public void removeToken(@JRPCArgument(name = "token") String token) {
context.getServiceManager().getService(TokenService.class).remove(new AuthToken(token));
public void removeToken(@JRPCArgument(name = "token") String token) throws IOException {
var service = context.getServiceManager().getService(TokenService.class);
service.remove(new AuthToken(token));
service.store();
}
/**
@ -56,10 +59,12 @@ public class Auth implements RPC {
*/
@ProtectedMethod
@JRPCMethod
public String createAPIToken(@JRPCArgument(name = "description") String description) {
public String createAPIToken(@JRPCArgument(name = "description") String description) throws IOException {
var service = context.getServiceManager().getService(TokenService.class);
var token = new AuthToken();
token.setDescription(description);
context.getServiceManager().getService(TokenService.class).add(token);
service.add(token);
service.store();
return token.getToken();
}