Streamline Backend auth mechanism/return values

This commit is contained in:
Maxime Dor
2017-09-17 21:19:29 +02:00
parent 0182ec7251
commit efc54e73f2
9 changed files with 182 additions and 66 deletions

View File

@@ -25,8 +25,8 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.kamax.matrix.MatrixID;
import io.kamax.matrix._MatrixID;
import io.kamax.mxisd.auth.UserAuthResult;
import io.kamax.mxisd.auth.provider.AuthenticatorProvider;
import io.kamax.mxisd.auth.provider.BackendAuthResult;
import io.kamax.mxisd.config.rest.RestBackendConfig;
import io.kamax.mxisd.util.GsonParser;
import io.kamax.mxisd.util.RestClientUtils;
@@ -62,7 +62,7 @@ public class RestAuthProvider implements AuthenticatorProvider {
}
@Override
public UserAuthResult authenticate(String id, String password) {
public BackendAuthResult authenticate(String id, String password) {
_MatrixID mxid = new MatrixID(id);
RestAuthRequestJson auth = new RestAuthRequestJson();
auth.setMxid(id);
@@ -72,19 +72,12 @@ public class RestAuthProvider implements AuthenticatorProvider {
HttpUriRequest req = RestClientUtils.post(cfg.getEndpoints().getAuth(), gson, "auth", auth);
try (CloseableHttpResponse res = client.execute(req)) {
UserAuthResult result = new UserAuthResult();
int status = res.getStatusLine().getStatusCode();
if (status < 200 || status >= 300) {
return result.failure();
return BackendAuthResult.failure();
}
RestAuthReplyJson reply = parser.parse(res, "auth", RestAuthReplyJson.class);
if (!reply.isSuccess()) {
return result.failure();
}
return result.success(reply.getMxid(), reply.getProfile().getDisplayName());
return parser.parse(res, "auth", BackendAuthResult.class);
} catch (IOException e) {
throw new RuntimeException(e);
}

View File

@@ -1,81 +0,0 @@
/*
* mxisd - Matrix Identity Server Daemon
* Copyright (C) 2017 Maxime Dor
*
* https://max.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.kamax.mxisd.backend.rest;
import io.kamax.mxisd.ThreePid;
import java.util.ArrayList;
import java.util.List;
public class RestAuthReplyJson {
public static class RestAuthProfileData {
private String displayName;
private List<ThreePid> threePids = new ArrayList<>();
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public List<ThreePid> getThreePids() {
return threePids;
}
public void setThreePids(List<ThreePid> threePids) {
this.threePids = threePids;
}
}
private Boolean success;
private String mxid;
private RestAuthProfileData profile;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMxid() {
return mxid;
}
public void setMxid(String mxid) {
this.mxid = mxid;
}
public RestAuthProfileData getProfile() {
return profile;
}
public void setProfile(RestAuthProfileData profile) {
this.profile = profile;
}
}