mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
added version to ScmState
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm;
|
package sonia.scm;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -39,6 +41,9 @@ import sonia.scm.util.Util;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -47,6 +52,9 @@ import java.io.IOException;
|
|||||||
public class BasicContextProvider implements SCMContextProvider
|
public class BasicContextProvider implements SCMContextProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String DEFAULT_VERSION = "unknown";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String DIRECTORY_DEFAULT = ".scm";
|
public static final String DIRECTORY_DEFAULT = ".scm";
|
||||||
|
|
||||||
@@ -56,6 +64,13 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String DIRECTORY_PROPERTY = "scm.home";
|
public static final String DIRECTORY_PROPERTY = "scm.home";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String MAVEN_PROPERTIES =
|
||||||
|
"/META-INF/maven/sonia.scm/scm-core/pom.properties";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String MAVEN_PROPERTY_VERSION = "version";
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +80,7 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
public BasicContextProvider()
|
public BasicContextProvider()
|
||||||
{
|
{
|
||||||
baseDirectory = findBaseDirectory();
|
baseDirectory = findBaseDirectory();
|
||||||
|
version = loadVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -99,6 +115,18 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
return baseDirectory;
|
return baseDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,8 +160,38 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String loadVersion()
|
||||||
|
{
|
||||||
|
Properties properties = new Properties();
|
||||||
|
InputStream input =
|
||||||
|
BasicContextProvider.class.getResourceAsStream(MAVEN_PROPERTIES);
|
||||||
|
|
||||||
|
if (input != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
properties.load(input);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
throw new ConfigurationException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return properties.getProperty(MAVEN_PROPERTY_VERSION, DEFAULT_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private File baseDirectory;
|
private File baseDirectory;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String version;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm;
|
package sonia.scm;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -58,4 +60,12 @@ public interface SCMContextProvider extends Closeable
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public File getBaseDirectory();
|
public File getBaseDirectory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getVersion();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,12 +67,16 @@ public class ScmState
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
* @param securityContext
|
* @param securityContext
|
||||||
* @param repositoryTypes
|
* @param repositoryTypes
|
||||||
*/
|
*/
|
||||||
public ScmState(WebSecurityContext securityContext,
|
public ScmState(SCMContextProvider provider,
|
||||||
|
WebSecurityContext securityContext,
|
||||||
Collection<Type> repositoryTypes)
|
Collection<Type> repositoryTypes)
|
||||||
{
|
{
|
||||||
|
this.version = provider.getVersion();
|
||||||
this.user = securityContext.getUser();
|
this.user = securityContext.getUser();
|
||||||
this.groups = securityContext.getGroups();
|
this.groups = securityContext.getGroups();
|
||||||
this.repositoryTypes = repositoryTypes;
|
this.repositoryTypes = repositoryTypes;
|
||||||
@@ -113,6 +117,17 @@ public class ScmState
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -170,6 +185,17 @@ public class ScmState
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param version
|
||||||
|
*/
|
||||||
|
public void setVersion(String version)
|
||||||
|
{
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@@ -184,4 +210,7 @@ public class ScmState
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String version;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,12 +36,14 @@ package sonia.scm.api.rest.resources;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.SCMContext;
|
import sonia.scm.SCMContext;
|
||||||
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.ScmState;
|
import sonia.scm.ScmState;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
@@ -66,8 +68,8 @@ import javax.ws.rs.core.Response;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Path("authentication")
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Path("authentication")
|
||||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
public class AuthenticationResource
|
public class AuthenticationResource
|
||||||
{
|
{
|
||||||
@@ -76,6 +78,27 @@ public class AuthenticationResource
|
|||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(AuthenticationResource.class);
|
LoggerFactory.getLogger(AuthenticationResource.class);
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param contextProvider
|
||||||
|
* @param repositoryManger
|
||||||
|
* @param securityContextProvider
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
public AuthenticationResource(
|
||||||
|
SCMContextProvider contextProvider,
|
||||||
|
RepositoryManager repositoryManger,
|
||||||
|
Provider<WebSecurityContext> securityContextProvider)
|
||||||
|
{
|
||||||
|
this.contextProvider = contextProvider;
|
||||||
|
this.repositoryManger = repositoryManger;
|
||||||
|
this.securityContextProvider = securityContextProvider;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,12 +120,14 @@ public class AuthenticationResource
|
|||||||
@FormParam("password") String password)
|
@FormParam("password") String password)
|
||||||
{
|
{
|
||||||
ScmState state = null;
|
ScmState state = null;
|
||||||
|
WebSecurityContext securityContext = securityContextProvider.get();
|
||||||
User user = securityContext.authenticate(request, response, username,
|
User user = securityContext.authenticate(request, response, username,
|
||||||
password);
|
password);
|
||||||
|
|
||||||
if ((user != null) &&!SCMContext.USER_ANONYMOUS.equals(user.getName()))
|
if ((user != null) &&!SCMContext.USER_ANONYMOUS.equals(user.getName()))
|
||||||
{
|
{
|
||||||
state = new ScmState(securityContext, repositoryManger.getTypes());
|
state = new ScmState(contextProvider, securityContext,
|
||||||
|
repositoryManger.getTypes());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -126,6 +151,8 @@ public class AuthenticationResource
|
|||||||
public Response logout(@Context HttpServletRequest request,
|
public Response logout(@Context HttpServletRequest request,
|
||||||
@Context HttpServletResponse response)
|
@Context HttpServletResponse response)
|
||||||
{
|
{
|
||||||
|
WebSecurityContext securityContext = securityContextProvider.get();
|
||||||
|
|
||||||
securityContext.logout(request, response);
|
securityContext.logout(request, response);
|
||||||
|
|
||||||
Response resp = null;
|
Response resp = null;
|
||||||
@@ -133,8 +160,10 @@ public class AuthenticationResource
|
|||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
resp = Response.ok(new ScmState(securityContext,
|
ScmState state = new ScmState(contextProvider, securityContext,
|
||||||
repositoryManger.getTypes())).build();
|
repositoryManger.getTypes());
|
||||||
|
|
||||||
|
resp = Response.ok(state).build();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -159,6 +188,7 @@ public class AuthenticationResource
|
|||||||
{
|
{
|
||||||
Response response = null;
|
Response response = null;
|
||||||
ScmState state = null;
|
ScmState state = null;
|
||||||
|
WebSecurityContext securityContext = securityContextProvider.get();
|
||||||
User user = securityContext.getUser();
|
User user = securityContext.getUser();
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
@@ -168,7 +198,8 @@ public class AuthenticationResource
|
|||||||
logger.debug("return state for user {}", user.getName());
|
logger.debug("return state for user {}", user.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
state = new ScmState(securityContext, repositoryManger.getTypes());
|
state = new ScmState(contextProvider, securityContext,
|
||||||
|
repositoryManger.getTypes());
|
||||||
response = Response.ok(state).build();
|
response = Response.ok(state).build();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -182,10 +213,11 @@ public class AuthenticationResource
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@Inject
|
private SCMContextProvider contextProvider;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
private RepositoryManager repositoryManger;
|
private RepositoryManager repositoryManger;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@Inject
|
private Provider<WebSecurityContext> securityContextProvider;
|
||||||
private WebSecurityContext securityContext;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user