当前位置: 首页>>代码示例>>Java>>正文


Java GroupRef类代码示例

本文整理汇总了Java中org.osiam.resources.scim.GroupRef的典型用法代码示例。如果您正苦于以下问题:Java GroupRef类的具体用法?Java GroupRef怎么用?Java GroupRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GroupRef类属于org.osiam.resources.scim包,在下文中一共展示了GroupRef类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUsersWithGroup

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
/**
 * Gets all users in a group or all users not in a group.
 *
 * @param groupName name of group
 * @param invert    invert the search
 * @return List of User
 */
public List<User> getUsersWithGroup(String groupName, boolean invert) {
    List<User> users = getAllUsers();

    for (Iterator<User> i = users.iterator(); i.hasNext(); ) {
        User u = i.next();
        boolean groupFound = false;
        for (GroupRef g : u.getGroups()) {
            if (groupName.equals(g.getDisplay())) {
                groupFound = true;
                break;
            }
        }


        if ((!groupFound && !invert) || (groupFound && invert)) {
            i.remove();
        }
    }

    return users;
}
 
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:29,代码来源:OsiamContext.java

示例2: testRemoveUserFromGroup

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
@Test
public void testRemoveUserFromGroup() {
    List<Group> groups = new ArrayList<Group>();
    groups.add(new Group.Builder("group").build());
    SCIMSearchResult<Group> result = mock(SCIMSearchResult.class);
    when(result.getResources()).thenReturn(groups);
    when(con.searchGroups(eq(OsiamContext.createGroupFilter("group")), any(AccessToken.class))).thenReturn(result);

    assertFalse(oc.removeUserFromGroup("user", "group"));

    List<GroupRef> groupRefs = new ArrayList<GroupRef>();
    groupRefs.add(new GroupRef.Builder().setDisplay("group").build());
    User groupUser = new User.Builder("user").setId("userid").setGroups(groupRefs).build();

    List<User> users = new ArrayList<User>();
    users.add(groupUser);
    SCIMSearchResult<User> result2 = mock(SCIMSearchResult.class);
    when(result2.getResources()).thenReturn(users);
    when(con.searchUsers(eq(OsiamContext.createUserFilter("user")), any(AccessToken.class))).thenReturn(result2);

    assertTrue(oc.removeUserFromGroup("user", "group"));

}
 
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:24,代码来源:OsiamContextTest.java

示例3: testGetUsersInGroup

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
@Test
public void testGetUsersInGroup() {
    List<User> users = new ArrayList<User>();

    List<GroupRef> groupA = new ArrayList<GroupRef>();
    groupA.add(new GroupRef.Builder().setDisplay("groupA").build());

    List<GroupRef> groupB = new ArrayList<GroupRef>();
    groupB.add(new GroupRef.Builder().setDisplay("groupB").build());

    users.add(new User.Builder("user1").setGroups(groupA).build());
    users.add(new User.Builder("user2").setGroups(groupB).build());

    when(con.getAllUsers(any(AccessToken.class))).thenReturn(new ArrayList(users));

    List<User> result = oc.getUsersWithGroup("groupA", false);
    assertEquals(1, result.size());
    assertEquals("user1", result.get(0).getUserName());

    when(con.getAllUsers(any(AccessToken.class))).thenReturn(new ArrayList(users));

    result = oc.getUsersWithGroup("groupA", true);
    assertEquals(1, result.size());
    assertEquals("user2", result.get(0).getUserName());
}
 
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:26,代码来源:OsiamContextTest.java

示例4: entityGroupsToScim

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
private List<GroupRef> entityGroupsToScim(Set<GroupEntity> groupEntities) {
    List<GroupRef> groupsForMapping = new ArrayList<>();

    if (groupEntities != null) {
        for (GroupEntity groupEntity : groupEntities) {
            GroupRef groupRef = new GroupRef.Builder()
                    .setDisplay(groupEntity.getDisplayName()).setValue(groupEntity.getId().toString()).build();
            groupsForMapping.add(groupRef);
        }
    }

    return groupsForMapping;
}
 
开发者ID:osiam,项目名称:osiam,代码行数:14,代码来源:UserConverter.java

示例5: isMember

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
/**
 * Test if a user is member in a group
 *
 * @param u         user
 * @param groupName group name
 * @return true of user is member of the group
 */
public static boolean isMember(User u, String groupName) {
    for (GroupRef g : u.getGroups()) {
        if (groupName.equals(g.getDisplay())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:16,代码来源:OsiamTools.java

示例6: userHasAllowedRole

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
/**
 * Checks if user has at least one the allowed roles.
 *
 * @param u            User
 * @param allowedRoles Array of allowed roles.
 * @return true if user is member in at least one of the allowed roles, else false.
 */
private boolean userHasAllowedRole(User u, String[] allowedRoles) {

    for (GroupRef group : u.getGroups()) {

        if (Arrays.binarySearch(allowedRoles, group.getDisplay()) >= 0) {
            return true;
        }
    }

    return false;
}
 
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:19,代码来源:OsiamRoleAuthOAuthProvider.java

示例7: testAddUserToGroup

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
@Test
public void testAddUserToGroup() {
    List<Group> groups = new ArrayList<Group>();
    SCIMSearchResult<Group> result = mock(SCIMSearchResult.class);
    when(result.getResources()).thenReturn(groups);
    when(con.searchGroups(eq(OsiamContext.createGroupFilter("group")), any(AccessToken.class))).thenReturn(result);

    // adding user to non existing group shall return false
    assertFalse(oc.addUserToGroup("user", "group"));


    groups.add(new Group.Builder("group").build());

    // group exists, and user is not member in group
    assertTrue(oc.addUserToGroup("user", "group"));

    List<GroupRef> groupRefs = new ArrayList<GroupRef>();
    groupRefs.add(new GroupRef.Builder().setDisplay("group").build());
    User groupUser = new User.Builder("user").setGroups(groupRefs).build();

    List<User> users = new ArrayList<User>();
    users.add(groupUser);
    SCIMSearchResult<User> result2 = mock(SCIMSearchResult.class);
    when(result2.getResources()).thenReturn(users);
    when(con.searchUsers(eq(OsiamContext.createUserFilter("user")), any(AccessToken.class))).thenReturn(result2);

    // group exists, but user is already member
    assertFalse(oc.addUserToGroup("user", "group"));
}
 
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:30,代码来源:OsiamContextTest.java

示例8: testAuthenticate

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
public OsiamContext testAuthenticate(String usersGroup, String restrictedGroup) {
    OsiamDropwizard od = mock(OsiamDropwizard.class);

    OsiamContext octx = mock(OsiamContext.class);

    // return osiam context mock, when supplied with user and password
    when(od.getContextWithAccessToken(eq("myAccessToken"))).thenReturn(octx);
    List<GroupRef> groups = new ArrayList<GroupRef>();


    if(usersGroup != null) {
        // if group is supplied, we add this group to the users groups
        groups.add(new GroupRef.Builder().setDisplay(restrictedGroup).build());
    }

    // mock getCurrentUser
    when(octx.getCurrentUser()).thenReturn(new User.Builder("marissa").setGroups(groups).build());

    OsiamRoleAuthOAuthProvider orap = new OsiamRoleAuthOAuthProvider(od, "realm");

    RestrictedTo rt = mock(RestrictedTo.class);
    if(restrictedGroup != null) {
        // if restrictedTo group is supplied, we mock this
        when(rt.value()).thenReturn(new String[]{restrictedGroup});
    }

    AbstractHttpContextInjectable<OsiamContext> inj = (AbstractHttpContextInjectable) orap.getInjectable(null, rt, null);

    HttpContext ctx = mock(HttpContext.class);
    HttpRequestContext rctx = mock(HttpRequestContext.class);
    when(ctx.getRequest()).thenReturn(rctx);
    // mock header: username/password: marissa/koala
    when(rctx.getHeaderValue(HttpHeaders.AUTHORIZATION)).thenReturn("bearer myAccessToken");

    return inj.getValue(ctx);
}
 
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:37,代码来源:OsiamRoleAuthOAuthProviderTest.java

示例9: testIsMember

import org.osiam.resources.scim.GroupRef; //导入依赖的package包/类
@Test
public void testIsMember() {
    List<GroupRef> groups = new ArrayList<GroupRef>();
    groups.add(new GroupRef.Builder().setDisplay("groupA").build());
    groups.add(new GroupRef.Builder().setDisplay("groupB").build());
    User u = new User.Builder("user").setGroups(groups).build();

    assertTrue(OsiamTools.isMember(u, "groupA"));
    assertTrue(OsiamTools.isMember(u, "groupB"));
    assertFalse(OsiamTools.isMember(u, "groupC"));
}
 
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:12,代码来源:OsiamToolsTest.java


注:本文中的org.osiam.resources.scim.GroupRef类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。