-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2FA seems to be workinggit statusgit status
- Loading branch information
1 parent
6846137
commit 46d2e2c
Showing
13 changed files
with
157 additions
and
88 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
.../src/main/java/org/orcid/authorization/authentication/MFAAuthenticationDetailsSource.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,15 @@ | ||
package org.orcid.authorization.authentication; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.springframework.security.authentication.AuthenticationDetailsSource; | ||
import org.springframework.security.web.authentication.WebAuthenticationDetails; | ||
|
||
public class MFAAuthenticationDetailsSource implements AuthenticationDetailsSource<HttpServletRequest, MFAWebAuthenticationDetails> { | ||
|
||
@Override | ||
public MFAWebAuthenticationDetails buildDetails(HttpServletRequest context) { | ||
return new MFAWebAuthenticationDetails(context); | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...web/src/main/java/org/orcid/authorization/authentication/MFAWebAuthenticationDetails.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,77 @@ | ||
package org.orcid.authorization.authentication; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.apache.thrift.TSerializable; | ||
import org.springframework.security.web.authentication.WebAuthenticationDetails; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
public class MFAWebAuthenticationDetails implements Serializable { | ||
|
||
public static final String VERIFICATION_CODE_PARAMETER = "verificationCode"; | ||
|
||
public static final String RECOVERY_CODE_PARAMETER = "recoveryCode"; | ||
|
||
private final String verificationCode; | ||
|
||
private final String recoveryCode; | ||
|
||
private final String remoteAddress; | ||
|
||
private final String sessionId; | ||
|
||
public MFAWebAuthenticationDetails(HttpServletRequest request) { | ||
verificationCode = getParameterOrAttribute(request, VERIFICATION_CODE_PARAMETER); | ||
recoveryCode = getParameterOrAttribute(request, RECOVERY_CODE_PARAMETER); | ||
remoteAddress = request.getRemoteAddr(); | ||
HttpSession session = request.getSession(false); | ||
sessionId = session != null ? session.getId() : null; | ||
} | ||
|
||
public MFAWebAuthenticationDetails(String remoteAddress, String sessionId, String verificationCode, String recoveryCode) { | ||
this.verificationCode = verificationCode; | ||
this.recoveryCode = recoveryCode; | ||
this.remoteAddress = remoteAddress; | ||
this.sessionId = sessionId; | ||
} | ||
|
||
private String getParameterOrAttribute(HttpServletRequest request, String name) { | ||
String value = request.getParameter(name); | ||
if (value == null) { | ||
value = (String) request.getAttribute(name); | ||
} | ||
return value; | ||
} | ||
|
||
public String getVerificationCode() { | ||
return verificationCode; | ||
} | ||
|
||
public String getRecoveryCode() { | ||
return recoveryCode; | ||
} | ||
|
||
public String getRemoteAddress() { | ||
return remoteAddress; | ||
} | ||
|
||
public String getSessionId() { | ||
return sessionId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
MFAWebAuthenticationDetails that = (MFAWebAuthenticationDetails) o; | ||
return Objects.equals(verificationCode, that.verificationCode) && Objects.equals(recoveryCode, that.recoveryCode) && Objects.equals(remoteAddress, that.remoteAddress) && Objects.equals(sessionId, that.sessionId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(verificationCode, recoveryCode, remoteAddress, sessionId); | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
orcid-web/src/main/java/org/orcid/frontend/spring/OrcidAuthenticationDetailsSource.java
This file was deleted.
Oops, something went wrong.
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
41 changes: 0 additions & 41 deletions
41
orcid-web/src/main/java/org/orcid/frontend/spring/OrcidWebAuthenticationDetails.java
This file was deleted.
Oops, something went wrong.
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
6 changes: 3 additions & 3 deletions
6
orcid-web/src/main/java/org/orcid/frontend/spring/configuration/OrcidRequestCache.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
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
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
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
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
30 changes: 30 additions & 0 deletions
30
...eb/src/main/java/org/orcid/frontend/web/util/MFAWebAuthenticationDetailsDeserializer.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,30 @@ | ||
package org.orcid.frontend.web.util; | ||
|
||
import com.fasterxml.jackson.core.JacksonException; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.orcid.authorization.authentication.MFAWebAuthenticationDetails; | ||
|
||
import java.io.IOException; | ||
|
||
public class MFAWebAuthenticationDetailsDeserializer extends JsonDeserializer<MFAWebAuthenticationDetails> { | ||
@Override | ||
public MFAWebAuthenticationDetails deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException { | ||
ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec(); | ||
JsonNode jsonNode = mapper.readTree(jsonParser); | ||
JsonNode verificationCodeNode = jsonNode.get("verificationCode"); | ||
JsonNode recoveryCodeNode = jsonNode.get("recoveryCode"); | ||
JsonNode remoteAddressNode = jsonNode.get("remoteAddress"); | ||
JsonNode sessionIdNode = jsonNode.get("sessionId"); | ||
|
||
String verificationCode = (verificationCodeNode != null && verificationCodeNode.isTextual()) ? verificationCodeNode.asText() : null; | ||
String recoveryCode = (recoveryCodeNode != null && recoveryCodeNode.isTextual()) ? recoveryCodeNode.asText() : null; | ||
String remoteAddress = (remoteAddressNode != null && remoteAddressNode.isTextual()) ? remoteAddressNode.asText() : null; | ||
String sessionId = (sessionIdNode != null && sessionIdNode.isTextual()) ? sessionIdNode.asText() : null; | ||
|
||
return new MFAWebAuthenticationDetails(remoteAddress, sessionId, verificationCode, recoveryCode); | ||
} | ||
} |
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