mark security context as deprecated and use shiro apis instead

This commit is contained in:
Sebastian Sdorra
2012-08-30 13:20:26 +02:00
parent 7d0980605e
commit 4a9d14b708
24 changed files with 277 additions and 298 deletions

View File

@@ -35,6 +35,9 @@ package sonia.scm.user;
//~--- non-JDK imports --------------------------------------------------------
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.junit.Test;
import sonia.scm.Manager;
@@ -56,7 +59,7 @@ import java.util.UUID;
* @author Sebastian Sdorra
*/
public abstract class UserManagerTestBase
extends ManagerTestBase<User, UserException>
extends ManagerTestBase<User, UserException>
{
/** Field description */
@@ -265,7 +268,7 @@ public abstract class UserManagerTestBase
*/
@Test
public void testMultiThreaded()
throws UserException, IOException, InterruptedException
throws UserException, IOException, InterruptedException
{
int initialSize = manager.getAll().size();
List<MultiThreadTester> testers = new ArrayList<MultiThreadTester>();
@@ -275,8 +278,11 @@ public abstract class UserManagerTestBase
testers.add(new MultiThreadTester(manager));
}
Subject subject = SecurityUtils.getSubject();
for (MultiThreadTester tester : testers)
{
subject.associateWith(tester);
new Thread(tester).start();
}
@@ -393,7 +399,7 @@ public abstract class UserManagerTestBase
{
String id = UUID.randomUUID().toString();
User user = new User(id, id.concat(" displayName"),
id.concat("@mail.com"));
id.concat("@mail.com"));
manager.create(user);
@@ -410,7 +416,7 @@ public abstract class UserManagerTestBase
* @throws UserException
*/
private void modifyAndDeleteUser(User user)
throws UserException, IOException
throws UserException, IOException
{
String name = user.getName();
String nd = name.concat(" new displayname");

View File

@@ -38,6 +38,7 @@ package sonia.scm.util;
import com.google.inject.Provider;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.mockito.invocation.InvocationOnMock;
@@ -67,6 +68,12 @@ import javax.servlet.http.HttpServletResponse;
public class MockUtil
{
/** Field description */
private static final User ADMIN = new User("scmadmin", "SCM Admin",
"scmadmin@scm.org");
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -101,6 +108,14 @@ public class MockUtil
when(subject.isPermittedAll()).thenReturn(Boolean.TRUE);
when(subject.hasRole("admin")).thenReturn(Boolean.TRUE);
PrincipalCollection collection = mock(PrincipalCollection.class);
when(collection.getPrimaryPrincipal()).thenReturn(ADMIN.getId());
when(collection.oneByType(User.class)).thenReturn(ADMIN);
when(subject.getPrincipal()).thenReturn(ADMIN.getId());
when(subject.getPrincipals()).thenReturn(collection);
return subject;
}