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


Java AccessMgr.getUserId方法代码示例

本文整理汇总了Java中org.apache.directory.fortress.core.AccessMgr.getUserId方法的典型用法代码示例。如果您正苦于以下问题:Java AccessMgr.getUserId方法的具体用法?Java AccessMgr.getUserId怎么用?Java AccessMgr.getUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.directory.fortress.core.AccessMgr的用法示例。

在下文中一共展示了AccessMgr.getUserId方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getUserId

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
FortResponse getUserId( FortRequest request )
{
    FortResponse response = createResponse();
    
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( request.getContextId() );
        Session session = request.getSession();
        String userId = accessMgr.getUserId( session );
        User outUser = new User( userId );
        response.setSession( session );
        response.setEntity( outUser );
    }
    catch ( SecurityException se )
    {
        createError( response, LOG, se );
    }
    
    return response;
}
 
开发者ID:apache,项目名称:directory-fortress-enmasse,代码行数:21,代码来源:AccessMgrImpl.java


示例2: getUserIds

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * @param msg
 * @param uArray
 */
public static void getUserIds( String msg, String[][] uArray )
{
    LogUtil.logIt( msg );
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        for ( String[] usr : uArray )
        {
            User user = UserTestData.getUser( usr );
            Session session = accessMgr.authenticate( user.getUserId(), user.getPassword() );
            assertNotNull( session );
            String userId = accessMgr.getUserId( session );
            assertTrue( "getUserIds failed compare found userId [" + userId + "] valid userId ["
                + UserTestData.getUserId( usr ) + "]", userId.equalsIgnoreCase( UserTestData.getUserId( usr ) ) );
        }
        LOG.debug( "getUserIds successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error(
            "getUserIds: failed with SecurityException rc=" + ex.getErrorId() + ", msg="
                + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:30,代码来源:AccessMgrImplTest.java


示例3: createSessionsWithRoles

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void createSessionsWithRoles( String msg, String[][] uArray, String[][] rArray )
{
    LogUtil.logIt( msg );
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        for ( String[] usr : uArray )
        {
            User user = UserTestData.getUser( usr );
            List<UserRole> rlsRequested = new ArrayList<>();
            int cnt = 0;
            for ( String[] rle : rArray )
            {
                rlsRequested.add( RoleTestData.getUserRole( user.getUserId(), rle ) );
                user.setRoles( rlsRequested );
                Session session = accessMgr.createSession( user, false );
                assertTrue( CLS_NM + ".createSessionsWithRoles failed role search USER [" + user.getUserId()
                    + "] CNT [" + ++cnt + "] size [" + session.getRoles().size() + "]", cnt == session.getRoles()
                    .size() );
                String userId = accessMgr.getUserId( session );
                assertTrue( CLS_NM + ".createSessionsWithRoles failed compare found userId [" + userId
                    + "] valid userId [" + UserTestData.getUserId( usr ) + "]",
                    userId.equalsIgnoreCase( UserTestData.getUserId( usr ) ) );
                UserTestData.assertEquals( user, usr );
            }
        }
        LOG.debug( "createSessionsWithRoles successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error( "createSessionsWithRoles: failed with SecurityException rc=" + ex.getErrorId()
            + ", msg=" + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:41,代码来源:AccessMgrImplTest.java


示例4: createSessionsWithRolesTrusted

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void createSessionsWithRolesTrusted( String msg, String[][] uArray, String[][] rArray )
{
    LogUtil.logIt( msg );
    
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        
        for ( String[] usr : uArray )
        {
            User user = UserTestData.getUser( usr );
            List<UserRole> rlsRequested = new ArrayList<>();
            int cnt = 0;
            for ( String[] rle : rArray )
            {
                rlsRequested.add( RoleTestData.getUserRole( user.getUserId(), rle ) );
                user.setRoles( rlsRequested );
                Session session = accessMgr.createSession( user, true );
                assertTrue( CLS_NM + ".createSessionsWithRolesTrusted failed role search USER [" + user.getUserId()
                    + "] CNT [" + ++cnt + "] size [" + session.getRoles().size() + "]", cnt == session.getRoles()
                    .size() );
                String userId = accessMgr.getUserId( session );
                assertTrue( CLS_NM + ".createSessionsWithRolesTrusted failed compare found userId [" + userId
                    + "] valid userId [" + UserTestData.getUserId( usr ) + "]",
                    userId.equalsIgnoreCase( UserTestData.getUserId( usr ) ) );
                UserTestData.assertEquals( user, usr );
            }
        }
        LOG.debug( "createSessionsWithRolesTrusted successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error( "createSessionsWithRolesTrusted: failed with SecurityException rc=" + ex.getErrorId()
            + ", msg=" + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:43,代码来源:AccessMgrImplTest.java


示例5: sessionRoles

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void sessionRoles( String msg, String[][] uArray, String[][] rArray )
{
    LogUtil.logIt( msg );
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        for ( String[] usr : uArray )
        {
            User user = UserTestData.getUser( usr );
            Session session = accessMgr.createSession( user, false );
            assertNotNull( session );
            String userId = accessMgr.getUserId( session );
            assertTrue( CLS_NM + ".sessionRoles failed compare found userId [" + userId + "] valid userId ["
                + UserTestData.getUserId( usr ) + "]", userId.equalsIgnoreCase( UserTestData.getUserId( usr ) ) );
            UserTestData.assertEquals( user, usr );
            List<UserRole> uRoles = accessMgr.sessionRoles( session );
            assertNotNull( uRoles );
            assertEquals(
                CLS_NM + ".sessionRoles user role check failed list size user [" + user.getUserId() + "]",
                rArray.length, uRoles.size() );
            for ( String[] rle : rArray )
            {
                assertTrue( CLS_NM + ".sessionRoles failed role search USER [" + user.getUserId() + "] ROLE1 ["
                    + RoleTestData.getName( rle ) + "] should be present",
                    uRoles.contains( RoleTestData.getUserRole( UserTestData.getUserId( usr ), rle ) ) );
            }
        }
        LOG.debug( "sessionRoles successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error(
            "sessionRoles: failed with SecurityException rc=" + ex.getErrorId() + ", msg="
                + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:43,代码来源:AccessMgrImplTest.java


示例6: createSessions

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void createSessions( String msg, String[][] uArray, String[][] rArray )
{
    LogUtil.logIt( msg );
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        for ( String[] usr : uArray )
        {
            User user = UserTestData.getUser( usr );
            Session session = accessMgr.createSession( user, false );
            assertNotNull( session );
            String userId = accessMgr.getUserId( session );
            assertTrue( CLS_NM + ".createSessions failed compare found userId [" + userId + "] valid userId ["
                + UserTestData.getUserId( usr ) + "]", userId.equalsIgnoreCase( UserTestData.getUserId( usr ) ) );
            UserTestData.assertEquals( user, usr );
            List<UserRole> uRoles = session.getRoles();
            assertNotNull( uRoles );
            assertEquals( CLS_NM + ".createSessions user role check failed list size user [" + user.getUserId()
                + "]", rArray.length, uRoles.size() );
            for ( String[] rle : rArray )
            {
                assertTrue( CLS_NM + ".createSessions failed role search USER [" + user.getUserId() + "] ROLE1 ["
                    + RoleTestData.getName( rle ) + "] should be present",
                    uRoles.contains( RoleTestData.getUserRole( UserTestData.getUserId( usr ), rle ) ) );
            }

            // now try negative test case:
            try
            {
                User userBad = new User( user.getUserId(), "badpw" );
                accessMgr.createSession( userBad, false );
                fail( CLS_NM + ".createSessions failed negative test" );
            }
            catch ( SecurityException se )
            {
                assertTrue( CLS_NM + "createSessions excep id check", se.getErrorId() == GlobalErrIds.USER_PW_INVLD );
                // pass
            }
        }
        LOG.debug( "createSessions successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error(
            "createSessions: failed with SecurityException rc=" + ex.getErrorId() + ", msg="
                + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:55,代码来源:AccessMgrImplTest.java


示例7: createSessionsTrusted

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void createSessionsTrusted( String msg, String[][] uArray, String[][] rArray )
{
    LogUtil.logIt( msg );
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        for ( String[] usr : uArray )
        {
            User user = UserTestData.getUser( usr );
            Session session = accessMgr.createSession( user, true );
            assertNotNull( session );
            String userId = accessMgr.getUserId( session );
            assertTrue( CLS_NM + ".createSessionsTrusted failed compare found userId [" + userId
                + "] valid userId [" + UserTestData.getUserId( usr ) + "]",
                userId.equalsIgnoreCase( UserTestData.getUserId( usr ) ) );
            UserTestData.assertEquals( user, usr );
            List<UserRole> uRoles = session.getRoles();
            assertNotNull( uRoles );
            assertEquals(
                CLS_NM + ".createSessionsTrusted user role check failed list size user [" + user.getUserId() + "]",
                rArray.length, uRoles.size() );
            for ( String[] rle : rArray )
            {
                assertTrue( CLS_NM + ".createSessionsTrusted failed role search USER [" + user.getUserId()
                    + "] ROLE1 [" + RoleTestData.getName( rle ) + "] should be present",
                    uRoles.contains( RoleTestData.getUserRole( UserTestData.getUserId( usr ), rle ) ) );
            }

            // now try negative test case:
            try
            {
                User badUser = new User( user.getUserId() + "wrong" );
                accessMgr.createSession( badUser, true );
                fail( CLS_NM + ".createSessionsTrusted failed negative test" );
            }
            catch ( SecurityException se )
            {
                assertTrue( CLS_NM + "createSessionsTrusted excep id check",
                    se.getErrorId() == GlobalErrIds.USER_NOT_FOUND );
                // pass
            }
        }
        LOG.debug( "createSessionsTrusted successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error( "createSessionsTrusted: failed with SecurityException rc=" + ex.getErrorId()
            + ", msg=" + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:57,代码来源:AccessMgrImplTest.java


示例8: createSessionsDSD

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 *
 * @param msg
 * @param uArray
 * @param dsdArray
 */
public static void createSessionsDSD( String msg, String[][] uArray, String[][] dsdArray )
{
    LogUtil.logIt( msg );
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        int i = 0;
        for ( String[] usr : uArray )
        {
            SDSet dsd = RoleTestData.getSDSet( dsdArray[i++] );
            User user = UserTestData.getUser( usr );
            Session session = accessMgr.createSession( user, false );
            assertNotNull( session );
            String userId = accessMgr.getUserId( session );
            assertTrue( CLS_NM + ".createSessionsDSD failed compare found userId [" + userId + "] valid userId ["
                + UserTestData.getUserId( usr ) + "]", userId.equalsIgnoreCase( UserTestData.getUserId( usr ) ) );
            UserTestData.assertEquals( user, usr );
            List<UserRole> uRoles = session.getRoles();
            assertNotNull( uRoles );
            // was the number of members in test DSD greater than the cardinality?
            if ( dsd.getMembers().size() < dsd.getCardinality() )
            {
                assertEquals(
                    CLS_NM + ".createSessionsDSD role list size check failed user-role user [" + user.getUserId()
                        + "]", dsd.getMembers().size(), uRoles.size() );
            }
            else
            {
                assertEquals(
                    CLS_NM + ".createSessionsDSD role cardinality check failed user-role list size user ["
                        + user.getUserId() + "] dsd set [" + dsd.getName() + "] card [" + dsd.getCardinality()
                        + "] listsize [" + uRoles.size() + "]", dsd.getCardinality() - 1, uRoles.size() );
            }
        }
        LOG.debug( "createSessionsDSD successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error( "createSessionsDSD: failed with SecurityException rc=" + ex.getErrorId() + ", msg="
            + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:50,代码来源:AccessMgrImplTest.java


示例9: createSessionsHier

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 *
 * @param msg
 * @param uArray
 */
public static void createSessionsHier( String msg, String[][] uArray )
{
    LogUtil.logIt( msg );
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        for ( String[] usr : uArray )
        {
            User user = UserTestData.getUser( usr );
            Session session = accessMgr.createSession( user, false );
            assertNotNull( session );
            String userId = accessMgr.getUserId( session );
            assertTrue( CLS_NM + ".createSessionsHier failed compare found userId [" + userId + "] valid userId ["
                + UserTestData.getUserId( usr ) + "]", userId.equalsIgnoreCase( UserTestData.getUserId( usr ) ) );
            UserTestData.assertEquals( user, usr );

            // Get the authorized roles for this user:
            Collection<String> authZRoles = UserTestData.getAuthorizedRoles( usr );

            // If there are any assigned roles, add them to list of authorized.
            Set<String> asgnRoles = UserTestData.getAssignedRoles( usr );
            assertNotNull( asgnRoles );
            assertTrue( asgnRoles.size() > 0 );

            for ( String asgnRole : asgnRoles )
            {
                authZRoles.add( asgnRole );
            }

            Set<String> actualRoles = accessMgr.authorizedRoles( session );
            assertNotNull( actualRoles );
            assertEquals(
                CLS_NM + ".createSessionsHier authorized roles list size test case failed for [" + user.getUserId()
                    + "]", authZRoles.size(), actualRoles.size() );
            for ( String name : authZRoles )
            {
                assertTrue( CLS_NM + ".createSessionsHier authorized roles compare test case failed for USER ["
                    + user.getUserId() + "] expect role [" + name + "] nout found", actualRoles.contains( name ) );
            }
        }
        LOG.debug( "createSessionsHier successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error( "createSessionsHier: failed with SecurityException rc=" + ex.getErrorId() + ", msg="
            + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:55,代码来源:AccessMgrImplTest.java


示例10: createSession

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * Calls AccessMgr createSession API.  Will check to ensure the RBAC Session contains the expected number of Roles
 * activated.
 *
 * @param userId  Case insensitive userId.
 * @param password Password is case sensitive, clear text but is stored in directory as hashed value.
 * @param expectedRoles integer contains the expected number of Roles in the Session.
 */
public static void createSession(String userId, String password, int expectedRoles)
{
    String szLocation = ".createSession";
    try
    {
        // Instantiate the AccessMgr implementation which perform runtime RBAC operations.
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());

        // The User entity is used to pass data into the createSession API.
        User user = new User(userId, password);

        // This API will return a Session object that contains the User's activated Roles and other info.
        Session session = accessMgr.createSession(user, false);

        // createSession will throw SecurityException if fails thus the Session should never be null.
        assertNotNull(session);

        // Pull the userId from the Session.
        String sessUserId = accessMgr.getUserId(session);
        assertTrue(szLocation + " failed compare found userId in session [" + sessUserId + "] valid userId [" + userId + "]", userId.equalsIgnoreCase(sessUserId));

        // Get the User's activated Roles.
        List<UserRole> uRoles = session.getRoles();

        // do some validations
        assertNotNull(uRoles);
        assertEquals(szLocation + " user role check failed list size user [" + user.getUserId() + "]", expectedRoles, uRoles.size());
        // now try negative test case:
        try
        {
            // this better fail
            User userBad = new User(user.getUserId(), "badpw");

            // The API will authenticate the User password, evaluate password policies and perform Role activations.
            accessMgr.createSession(userBad, false);
            fail(szLocation + " userId [" + userId + "]  failed negative test");
        }
        catch (PasswordException pe)
        {
            assertTrue(szLocation + " userId [" + userId + "]  excep id check", pe.getErrorId() == GlobalErrIds.USER_PW_INVLD);
            // pass
        }
        catch (SecurityException se)
        {
            fail(szLocation + " userId [" + userId + "]  failed with unexpected errorId" + se.getErrorId() + " msg=" + se.getMessage());
            // pass
        }
        LOG.info(szLocation + " userId [" + userId + "] successful");
    }
    catch (SecurityException ex)
    {
        LOG.error(szLocation + " userId [" + userId + "]  caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:64,代码来源:CreateSessionSample.java



注:本文中的org.apache.directory.fortress.core.AccessMgr.getUserId方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。