mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
added ScmRealm role based authorization tests
This commit is contained in:
@@ -36,12 +36,12 @@ package sonia.scm.security;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import org.apache.http.annotation.Immutable;
|
|
||||||
import org.apache.shiro.authc.AccountException;
|
import org.apache.shiro.authc.AccountException;
|
||||||
import org.apache.shiro.authc.AuthenticationInfo;
|
import org.apache.shiro.authc.AuthenticationInfo;
|
||||||
import org.apache.shiro.authc.AuthenticationToken;
|
import org.apache.shiro.authc.AuthenticationToken;
|
||||||
import org.apache.shiro.authc.UnknownAccountException;
|
import org.apache.shiro.authc.UnknownAccountException;
|
||||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||||
|
import org.apache.shiro.authz.AuthorizationInfo;
|
||||||
import org.apache.shiro.subject.PrincipalCollection;
|
import org.apache.shiro.subject.PrincipalCollection;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -94,6 +94,41 @@ public class ScmRealmTest
|
|||||||
realm.getAuthenticationInfo(token("marvin", trillian.getPassword()));
|
realm.getAuthenticationInfo(token("marvin", trillian.getPassword()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testAuthorizationAdminRoles()
|
||||||
|
{
|
||||||
|
User trillian = createSampleUser();
|
||||||
|
|
||||||
|
trillian.setAdmin(true);
|
||||||
|
|
||||||
|
AuthorizationInfo aci = authorizationInfo(trillian);
|
||||||
|
Collection<String> roles = aci.getRoles();
|
||||||
|
|
||||||
|
assertNotNull(roles);
|
||||||
|
assertEquals(2, roles.size());
|
||||||
|
assertTrue(roles.contains(Role.ADMIN));
|
||||||
|
assertTrue(roles.contains(Role.USER));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testAuthorizationUserRoles()
|
||||||
|
{
|
||||||
|
AuthorizationInfo aci = authorizationInfo(createSampleUser());
|
||||||
|
Collection<String> roles = aci.getRoles();
|
||||||
|
|
||||||
|
assertNotNull(roles);
|
||||||
|
assertEquals(1, roles.size());
|
||||||
|
assertEquals(Role.USER, roles.iterator().next());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -136,6 +171,25 @@ public class ScmRealmTest
|
|||||||
assertThat(groups, containsInAnyOrder("g1", "g2"));
|
assertThat(groups, containsInAnyOrder("g1", "g2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private AuthorizationInfo authorizationInfo(User user)
|
||||||
|
{
|
||||||
|
ScmRealm realm = createRealm(user);
|
||||||
|
AuthenticationInfo aui = realm.getAuthenticationInfo(token(user));
|
||||||
|
AuthorizationInfo aci = realm.doGetAuthorizationInfo(aui.getPrincipals());
|
||||||
|
|
||||||
|
assertNotNull(aci);
|
||||||
|
|
||||||
|
return aci;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user