mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-05-06 11:46:10 +02:00
use store-api
This commit is contained in:
@@ -35,6 +35,7 @@ package sonia.scm.sample.auth;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -42,6 +43,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.plugin.ext.Extension;
|
||||
import sonia.scm.store.Store;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.web.security.AuthenticationHandler;
|
||||
@@ -49,7 +52,6 @@ import sonia.scm.web.security.AuthenticationResult;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -58,8 +60,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -70,16 +70,29 @@ public class SampleAuthenticationHandler implements AuthenticationHandler
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE = "sample";
|
||||
public static final String STORE_NAME = "sample-auth";
|
||||
|
||||
/** Field description */
|
||||
public static final String CONFIG_PATH =
|
||||
"config".concat(File.separator).concat("sample-auth.xml");
|
||||
public static final String TYPE = "sample";
|
||||
|
||||
/** the logger for SampleAuthenticationHandler */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(SampleAuthenticationHandler.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param storeFactory
|
||||
*/
|
||||
@Inject
|
||||
public SampleAuthenticationHandler(StoreFactory storeFactory)
|
||||
{
|
||||
store = storeFactory.getStore(SampleConfig.class, STORE_NAME);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -125,8 +138,13 @@ public class SampleAuthenticationHandler implements AuthenticationHandler
|
||||
@Override
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
configFile = new File(context.getBaseDirectory(), CONFIG_PATH);
|
||||
loadConfig();
|
||||
config = store.get();
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
config = new SampleConfig();
|
||||
}
|
||||
|
||||
addUser(new User("dent", "Arthur Dent", "arthur.dent@hitchhiker.com"));
|
||||
addUser(new User("perfect", "Ford Prefect", "ford.perfect@hitchhiker.com"));
|
||||
addUser(new User("slarti", "Slartibartfaß",
|
||||
@@ -134,45 +152,13 @@ public class SampleAuthenticationHandler implements AuthenticationHandler
|
||||
addUser(new User("marvin", "Marvin", "paranoid.android@hitchhiker.com"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void loadConfig()
|
||||
{
|
||||
if (configFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
config = JAXB.unmarshal(configFile, SampleConfig.class);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
config = new SampleConfig();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
public void storeConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
JAXB.marshal(config, configFile);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
store.set(config);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -266,7 +252,7 @@ public class SampleAuthenticationHandler implements AuthenticationHandler
|
||||
private SampleConfig config;
|
||||
|
||||
/** Field description */
|
||||
private File configFile;
|
||||
private Store<SampleConfig> store;
|
||||
|
||||
/** Field description */
|
||||
private Map<String, User> userDB = new ConcurrentHashMap<String, User>();
|
||||
|
||||
Reference in New Issue
Block a user