-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3pid authentication #60
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9537f24
added login support w 3pid lookup + login invocation on hs (WIP) #49
3d26316
In memory identity store, for debug/test
2a933c9
implemented login support w 3pid lookup + error handling #49
774d1aa
better use of logger #49
82c7671
correction: changed LoginRequestJson wrt actual spec + removed checks…
dd8aee5
Corrected log message
380ccc5
Corrected log message
dfdbdd3
support of phone 3PID (WIP) #60
74f9baf
cleaned code - phone support is WIP #60
1067530
implemented phone support #60
fda5837
removed old unused class #60
4fd772f
created 3pid authentication documentation (WIP) #60
a101401
updated authentication documentation (WIP) #60
779b4d2
updated authentication documentation (WIP) #60
37aa524
updated authentication documentation - improved 3PID auth diagram #60
fb14650
corrections #60
4942d4a
Proxy login flow discovery
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/main/java/io/kamax/mxisd/backend/memory/MemoryIdentityStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* mxisd - Matrix Identity Server Daemon | ||
* Copyright (C) 2018 Maxime Dor | ||
* | ||
* https://www.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.memory; | ||
|
||
import io.kamax.matrix.MatrixID; | ||
import io.kamax.matrix.ThreePid; | ||
import io.kamax.matrix._MatrixID; | ||
import io.kamax.mxisd.UserIdType; | ||
import io.kamax.mxisd.auth.provider.AuthenticatorProvider; | ||
import io.kamax.mxisd.auth.provider.BackendAuthResult; | ||
import io.kamax.mxisd.config.MatrixConfig; | ||
import io.kamax.mxisd.config.memory.MemoryIdentityConfig; | ||
import io.kamax.mxisd.config.memory.MemoryStoreConfig; | ||
import io.kamax.mxisd.config.memory.MemoryThreePid; | ||
import io.kamax.mxisd.lookup.SingleLookupReply; | ||
import io.kamax.mxisd.lookup.SingleLookupRequest; | ||
import io.kamax.mxisd.lookup.ThreePidMapping; | ||
import io.kamax.mxisd.lookup.provider.IThreePidProvider; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Component | ||
public class MemoryIdentityStore implements AuthenticatorProvider, IThreePidProvider { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(MemoryIdentityStore.class); | ||
|
||
private final MatrixConfig mxCfg; | ||
private final MemoryStoreConfig cfg; | ||
|
||
@Autowired | ||
public MemoryIdentityStore(MatrixConfig mxCfg, MemoryStoreConfig cfg) { | ||
this.mxCfg = mxCfg; | ||
this.cfg = cfg; | ||
} | ||
|
||
public Optional<MemoryIdentityConfig> findByUsername(String username) { | ||
return cfg.getIdentities().stream().filter(id -> StringUtils.equals(id.getUsername(), username)).findFirst(); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return cfg.isEnabled(); | ||
} | ||
|
||
@Override | ||
public boolean isLocal() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public Optional<SingleLookupReply> find(SingleLookupRequest request) { | ||
logger.info("Performing lookup {} of type {}", request.getThreePid(), request.getType()); | ||
ThreePid req = new ThreePid(request.getType(), request.getThreePid()); | ||
for (MemoryIdentityConfig id : cfg.getIdentities()) { | ||
for (MemoryThreePid threepid : id.getThreepids()) { | ||
if (req.equals(new ThreePid(threepid.getMedium(), threepid.getAddress()))) { | ||
return Optional.of(new SingleLookupReply(request, new MatrixID(id.getUsername(), mxCfg.getDomain()))); | ||
} | ||
} | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public List<ThreePidMapping> populate(List<ThreePidMapping> mappings) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public BackendAuthResult authenticate(_MatrixID mxid, String password) { | ||
return findByUsername(mxid.getLocalPart()).map(id -> { | ||
if (!StringUtils.equals(id.getUsername(), mxid.getLocalPart())) { | ||
return BackendAuthResult.failure(); | ||
} else { | ||
return BackendAuthResult.success(mxid.getId(), UserIdType.MatrixID, ""); | ||
} | ||
}).orElseGet(BackendAuthResult::failure); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/io/kamax/mxisd/config/memory/MemoryIdentityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* mxisd - Matrix Identity Server Daemon | ||
* Copyright (C) 2018 Maxime Dor | ||
* | ||
* https://www.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.config.memory; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Component | ||
public class MemoryIdentityConfig { | ||
|
||
private String username; | ||
private String password; | ||
private List<MemoryThreePid> threepids = new ArrayList<>(); | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public List<MemoryThreePid> getThreepids() { | ||
return threepids; | ||
} | ||
|
||
public void setThreepids(List<MemoryThreePid> threepids) { | ||
this.threepids = threepids; | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/io/kamax/mxisd/config/memory/MemoryStoreConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* mxisd - Matrix Identity Server Daemon | ||
* Copyright (C) 2018 Maxime Dor | ||
* | ||
* https://www.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.config.memory; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@ConfigurationProperties("memory") | ||
public class MemoryStoreConfig { | ||
|
||
private boolean enabled; | ||
private List<MemoryIdentityConfig> identities; | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public List<MemoryIdentityConfig> getIdentities() { | ||
return identities; | ||
} | ||
|
||
public void setIdentities(List<MemoryIdentityConfig> identities) { | ||
this.identities = identities; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identity management
might be misleading, as mxisd doesn't do any management, only reads data.I like the spirit of the sentence, but not the wording :D I also don't have a good idea about the wording at this point