2
0

SecondaryAuthData.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.datatables;
  20. import java.io.File;
  21. import java.util.HashSet;
  22. import java.util.Set;
  23. import java.util.logging.Level;
  24. import org.w3c.dom.Node;
  25. import com.l2jserver.gameserver.engines.DocumentParser;
  26. /**
  27. * @author Nos
  28. */
  29. public class SecondaryAuthData extends DocumentParser
  30. {
  31. private boolean _enabled = false;
  32. private int _maxAttempts = 5;
  33. private int _banTime = 480;
  34. private String _recoveryLink = "";
  35. private final Set<String> _forbiddenPasswords = new HashSet<>();
  36. protected SecondaryAuthData()
  37. {
  38. load();
  39. }
  40. @Override
  41. public synchronized void load()
  42. {
  43. _forbiddenPasswords.clear();
  44. parseFile(new File("config/SecondaryAuth.xml"));
  45. _log.info(getClass().getSimpleName() + ": Loaded " + _forbiddenPasswords.size() + " forbidden passwords.");
  46. }
  47. @Override
  48. protected void parseDocument()
  49. {
  50. try
  51. {
  52. for (Node node = getCurrentDocument().getFirstChild(); node != null; node = node.getNextSibling())
  53. {
  54. if ("list".equalsIgnoreCase(node.getNodeName()))
  55. {
  56. for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())
  57. {
  58. if ("enabled".equalsIgnoreCase(list_node.getNodeName()))
  59. {
  60. _enabled = Boolean.parseBoolean(list_node.getTextContent());
  61. }
  62. else if ("maxAttempts".equalsIgnoreCase(list_node.getNodeName()))
  63. {
  64. _maxAttempts = Integer.parseInt(list_node.getTextContent());
  65. }
  66. else if ("banTime".equalsIgnoreCase(list_node.getNodeName()))
  67. {
  68. _banTime = Integer.parseInt(list_node.getTextContent());
  69. }
  70. else if ("recoveryLink".equalsIgnoreCase(list_node.getNodeName()))
  71. {
  72. _recoveryLink = list_node.getTextContent();
  73. }
  74. else if ("forbiddenPasswords".equalsIgnoreCase(list_node.getNodeName()))
  75. {
  76. for (Node forbiddenPasswords_node = list_node.getFirstChild(); forbiddenPasswords_node != null; forbiddenPasswords_node = forbiddenPasswords_node.getNextSibling())
  77. {
  78. if ("password".equalsIgnoreCase(forbiddenPasswords_node.getNodeName()))
  79. {
  80. _forbiddenPasswords.add(forbiddenPasswords_node.getTextContent());
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. catch (Exception e)
  89. {
  90. _log.log(Level.WARNING, "Failed to load secondary auth data from xml.", e);
  91. }
  92. }
  93. public boolean isEnabled()
  94. {
  95. return _enabled;
  96. }
  97. public int getMaxAttempts()
  98. {
  99. return _maxAttempts;
  100. }
  101. public int getBanTime()
  102. {
  103. return _banTime;
  104. }
  105. public String getRecoveryLink()
  106. {
  107. return _recoveryLink;
  108. }
  109. public Set<String> getForbiddenPasswords()
  110. {
  111. return _forbiddenPasswords;
  112. }
  113. public boolean isForbiddenPassword(String password)
  114. {
  115. return _forbiddenPasswords.contains(password);
  116. }
  117. public static SecondaryAuthData getInstance()
  118. {
  119. return SingletonHolder._instance;
  120. }
  121. private static class SingletonHolder
  122. {
  123. protected static final SecondaryAuthData _instance = new SecondaryAuthData();
  124. }
  125. }