Search in sources :

Example 1 with AuthenticatorProvider

use of io.kamax.mxisd.auth.provider.AuthenticatorProvider in project mxisd by kamax-io.

the class AuthManager method authenticate.

public UserAuthResult authenticate(String id, String password) {
    _MatrixID mxid = MatrixID.asAcceptable(id);
    for (AuthenticatorProvider provider : providers) {
        if (!provider.isEnabled()) {
            continue;
        }
        log.info("Attempting authentication with store {}", provider.getClass().getSimpleName());
        BackendAuthResult result = provider.authenticate(mxid, password);
        if (result.isSuccess()) {
            String mxId;
            if (UserIdType.Localpart.is(result.getId().getType())) {
                mxId = MatrixID.from(result.getId().getValue(), mxCfg.getDomain()).acceptable().getId();
            } else if (UserIdType.MatrixID.is(result.getId().getType())) {
                mxId = MatrixID.asAcceptable(result.getId().getValue()).getId();
            } else {
                log.warn("Unsupported User ID type {} for backend {}", result.getId().getType(), provider.getClass().getSimpleName());
                continue;
            }
            UserAuthResult authResult = new UserAuthResult().success(result.getProfile().getDisplayName());
            for (_ThreePid pid : result.getProfile().getThreePids()) {
                authResult.withThreePid(pid.getMedium(), pid.getAddress());
            }
            log.info("{} was authenticated by {}, publishing 3PID mappings, if any", id, provider.getClass().getSimpleName());
            for (ThreePid pid : authResult.getThreePids()) {
                log.info("Processing {} for {}", pid, id);
                invMgr.publishMappingIfInvited(new ThreePidMapping(pid, mxId));
            }
            try {
                MatrixID.asValid(mxId);
            } catch (IllegalArgumentException e) {
                log.warn("The returned User ID {} is not a valid Matrix ID. Login might fail at the Homeserver level", mxId);
            }
            invMgr.lookupMappingsForInvites();
            return authResult;
        }
    }
    return new UserAuthResult().failure();
}
Also used : BackendAuthResult(io.kamax.mxisd.auth.provider.BackendAuthResult) ThreePidMapping(io.kamax.mxisd.lookup.ThreePidMapping) AuthenticatorProvider(io.kamax.mxisd.auth.provider.AuthenticatorProvider) io.kamax.matrix._ThreePid(io.kamax.matrix._ThreePid) io.kamax.matrix._ThreePid(io.kamax.matrix._ThreePid) ThreePid(io.kamax.matrix.ThreePid) io.kamax.matrix._MatrixID(io.kamax.matrix._MatrixID)

Aggregations

ThreePid (io.kamax.matrix.ThreePid)1 io.kamax.matrix._MatrixID (io.kamax.matrix._MatrixID)1 io.kamax.matrix._ThreePid (io.kamax.matrix._ThreePid)1 AuthenticatorProvider (io.kamax.mxisd.auth.provider.AuthenticatorProvider)1 BackendAuthResult (io.kamax.mxisd.auth.provider.BackendAuthResult)1 ThreePidMapping (io.kamax.mxisd.lookup.ThreePidMapping)1