added groups to state

This commit is contained in:
Sebastian Sdorra
2011-01-07 18:26:37 +01:00
parent adf7fae446
commit 1256ff7959
2 changed files with 41 additions and 28 deletions

View File

@@ -36,9 +36,12 @@ package sonia.scm;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import sonia.scm.user.User; import sonia.scm.user.User;
import sonia.scm.web.security.WebSecurityContext;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@@ -63,12 +66,15 @@ public class ScmState
* Constructs ... * Constructs ...
* *
* *
* @param user *
* @param securityContext
* @param repositoryTypes * @param repositoryTypes
*/ */
public ScmState(User user, Type[] repositoryTypes) public ScmState(WebSecurityContext securityContext,
Collection<Type> repositoryTypes)
{ {
this.user = user; this.user = securityContext.getUser();
this.groups = securityContext.getGroups();
this.repositoryTypes = repositoryTypes; this.repositoryTypes = repositoryTypes;
} }
@@ -80,7 +86,18 @@ public class ScmState
* *
* @return * @return
*/ */
public Type[] getRepositoryTypes() public Collection<String> getGroups()
{
return groups;
}
/**
* Method description
*
*
* @return
*/
public Collection<Type> getRepositoryTypes()
{ {
return repositoryTypes; return repositoryTypes;
} }
@@ -109,13 +126,24 @@ public class ScmState
//~--- set methods ---------------------------------------------------------- //~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param groups
*/
public void setGroups(Collection<String> groups)
{
this.groups = groups;
}
/** /**
* Method description * Method description
* *
* *
* @param repositoryTypes * @param repositoryTypes
*/ */
public void setRepositoryTypes(Type[] repositoryTypes) public void setRepositoryTypes(Collection<Type> repositoryTypes)
{ {
this.repositoryTypes = repositoryTypes; this.repositoryTypes = repositoryTypes;
} }
@@ -144,9 +172,12 @@ public class ScmState
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */
private Collection<String> groups;
/** Field description */ /** Field description */
@XmlElement(name = "repositoryTypes") @XmlElement(name = "repositoryTypes")
private Type[] repositoryTypes; private Collection<Type> repositoryTypes;
/** Field description */ /** Field description */
private boolean success = true; private boolean success = true;

View File

@@ -99,7 +99,8 @@ public class AuthenticationResource
if (user != null) if (user != null)
{ {
resp = Response.ok(getState(user)).build(); resp = Response.ok(new ScmState(securityContext,
repositoryManger.getTypes())).build();
} }
else else
{ {
@@ -135,7 +136,7 @@ public class AuthenticationResource
if (user != null) if (user != null)
{ {
state = getState(user); state = new ScmState(securityContext, repositoryManger.getTypes());
} }
else else
{ {
@@ -167,7 +168,7 @@ public class AuthenticationResource
logger.debug("return state for user {}", user.getName()); logger.debug("return state for user {}", user.getName());
} }
state = getState(user); state = new ScmState(securityContext, repositoryManger.getTypes());
response = Response.ok(state).build(); response = Response.ok(state).build();
} }
else else
@@ -178,25 +179,6 @@ public class AuthenticationResource
return response; return response;
} }
/**
* Method description
*
*
*
* @param user
*
* @return
*/
private ScmState getState(User user)
{
ScmState state = new ScmState();
state.setUser(user);
state.setRepositoryTypes(repositoryManger.getTypes().toArray(new Type[0]));
return state;
}
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */