mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
use XmlUserHandler for authentication
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.web.security;
|
package sonia.scm.web.security;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -40,19 +42,17 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.SCMContextProvider;
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.user.User;
|
|
||||||
import sonia.scm.security.EncryptionHandler;
|
import sonia.scm.security.EncryptionHandler;
|
||||||
|
import sonia.scm.user.User;
|
||||||
|
import sonia.scm.user.XmlUserHandler;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -86,13 +86,10 @@ public class XmlAuthenticator implements Authenticator
|
|||||||
HttpServletResponse response, String username,
|
HttpServletResponse response, String username,
|
||||||
String password)
|
String password)
|
||||||
{
|
{
|
||||||
User user = null;
|
User user = userHandler.get(username);
|
||||||
File userFile = new File(baseDirectory, username.concat(".xml"));
|
|
||||||
|
|
||||||
if ((userFile != null) && userFile.exists())
|
if (user != null)
|
||||||
{
|
{
|
||||||
user = JAXB.unmarshal(userFile, User.class);
|
|
||||||
|
|
||||||
String encryptedPassword = encryptionHandler.encrypt(password);
|
String encryptedPassword = encryptionHandler.encrypt(password);
|
||||||
|
|
||||||
if (!encryptedPassword.equalsIgnoreCase(user.getPassword()))
|
if (!encryptedPassword.equalsIgnoreCase(user.getPassword()))
|
||||||
@@ -106,6 +103,11 @@ public class XmlAuthenticator implements Authenticator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("user {} logged in successfully", username);
|
||||||
|
}
|
||||||
|
|
||||||
user.setPassword(null);
|
user.setPassword(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,21 +141,17 @@ public class XmlAuthenticator implements Authenticator
|
|||||||
@Override
|
@Override
|
||||||
public void init(SCMContextProvider provider)
|
public void init(SCMContextProvider provider)
|
||||||
{
|
{
|
||||||
baseDirectory = new File(provider.getBaseDirectory(), NAME_DIRECTORY);
|
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
// do nothing
|
||||||
{
|
|
||||||
logger.info("init XmlAuthenticator with directory {}",
|
|
||||||
baseDirectory.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private File baseDirectory;
|
@Inject
|
||||||
|
private EncryptionHandler encryptionHandler;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@Inject
|
@Inject
|
||||||
private EncryptionHandler encryptionHandler;
|
private XmlUserHandler userHandler;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user