TOTP Model modify & Test Code
This commit is contained in:
parent
2f453bc38d
commit
ab8c44efca
|
@ -132,6 +132,7 @@ public class EmailAuthService {
|
||||||
return this.emailAuthDAO.save(emailAuth);
|
return this.emailAuthDAO.save(emailAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Todo Send Email Refactoring
|
||||||
public EmailAuth sendEmailResetPassword(Member member) throws UnsupportedEncodingException, MailException {
|
public EmailAuth sendEmailResetPassword(Member member) throws UnsupportedEncodingException, MailException {
|
||||||
EmailAuth auth = new EmailAuth();
|
EmailAuth auth = new EmailAuth();
|
||||||
auth.setMember(member);
|
auth.setMember(member);
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class MemberTotp {
|
||||||
private String secretCode;
|
private String secretCode;
|
||||||
private Date createDate;
|
private Date createDate;
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
private String otpAuthURL;
|
private String otpAuth;
|
||||||
|
|
||||||
public MemberTotp() {
|
public MemberTotp() {
|
||||||
}
|
}
|
||||||
|
@ -76,11 +76,11 @@ public class MemberTotp {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
public String getOtpAuthURL() {
|
public String getOtpAuth() {
|
||||||
return otpAuthURL;
|
return otpAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOtpAuthURL(String otpAuthURL) {
|
public void setOtpAuth(String otpAuthURL) {
|
||||||
this.otpAuthURL = otpAuthURL;
|
this.otpAuth = otpAuthURL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.loafle.overflow.module.member.model.MemberTotp;
|
||||||
import com.warrenstrange.googleauth.GoogleAuthenticator;
|
import com.warrenstrange.googleauth.GoogleAuthenticator;
|
||||||
import com.warrenstrange.googleauth.GoogleAuthenticatorKey;
|
import com.warrenstrange.googleauth.GoogleAuthenticatorKey;
|
||||||
import com.warrenstrange.googleauth.GoogleAuthenticatorQRGenerator;
|
import com.warrenstrange.googleauth.GoogleAuthenticatorQRGenerator;
|
||||||
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -66,12 +67,35 @@ public class MemberTotpService {
|
||||||
|
|
||||||
String secret = key.getKey();
|
String secret = key.getKey();
|
||||||
// List<Integer> scratchCodes = key.getScratchCodes();
|
// List<Integer> scratchCodes = key.getScratchCodes();
|
||||||
String otpAuthURL = GoogleAuthenticatorQRGenerator.getOtpAuthURL("overFlow", member.getEmail(), key);
|
// String otpAuthURL = GoogleAuthenticatorQRGenerator.getOtpAuthURL("overFlow", member.getEmail(), key);
|
||||||
|
URIBuilder uri = (new URIBuilder()).setScheme("otpauth")
|
||||||
|
.setHost("totp")
|
||||||
|
.setPath("/" + formatLabel("overFlow", member.getEmail()))
|
||||||
|
.setParameter("secret", key.getKey());
|
||||||
|
|
||||||
totp.setMember(member);
|
totp.setMember(member);
|
||||||
totp.setSecretCode(secret);
|
totp.setSecretCode(secret);
|
||||||
totp.setOtpAuthURL(otpAuthURL);
|
totp.setOtpAuth(uri.toString());
|
||||||
|
|
||||||
return totp;
|
return totp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String formatLabel(String issuer, String accountName) {
|
||||||
|
if(accountName != null && accountName.trim().length() != 0) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if(issuer != null) {
|
||||||
|
if(issuer.contains(":")) {
|
||||||
|
throw new IllegalArgumentException("Issuer cannot contain the ':' character.");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(issuer);
|
||||||
|
sb.append(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(accountName);
|
||||||
|
return sb.toString();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Account name must not be empty.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class MemberTotpServiceTest {
|
||||||
MemberTotp totp = this.totpService.createTotp(m);
|
MemberTotp totp = this.totpService.createTotp(m);
|
||||||
|
|
||||||
System.out.println(totp.getSecretCode());
|
System.out.println(totp.getSecretCode());
|
||||||
System.out.println(totp.getOtpAuthURL());
|
System.out.println(totp.getOtpAuth());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user