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


Java AccessMgr.createSession方法代码示例

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

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

示例1: createResponse

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * Creates a group-type trusted session
 *
 * @param request The request We want to create a session for
 * @return The created response
 */
/* no qualifier*/ FortResponse createGroupSession( FortRequest request )
{
    FortResponse response = createResponse();

    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( request.getContextId() );
        Group inGroup = (Group) request.getEntity();
        Session outSession = accessMgr.createSession( inGroup );
        response.setSession( outSession );
    }
    catch ( SecurityException se )
    {
        createError( response, LOG, se );
    }

    return response;
}
 
开发者ID:apache,项目名称:directory-fortress-enmasse,代码行数:25,代码来源:AccessMgrImpl.java


示例2: createSession

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * Creates a session, trusted or untrested
 * 
 * @param request The request We want to create a session for
 * @param trusted Is the session trusted or not
 * @return The created response
 */
private FortResponse createSession( FortRequest request, boolean trusted )
{
    FortResponse response = createResponse();
    
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( request.getContextId() );
        User inUser = (User) request.getEntity();
        Session outSession = accessMgr.createSession( inUser, trusted );
        response.setSession( outSession );
    }
    catch ( SecurityException se )
    {
        createError( response, LOG, se );
    }
    
    return response;
}
 
开发者ID:apache,项目名称:directory-fortress-enmasse,代码行数:26,代码来源:AccessMgrImpl.java


示例3: getUsers

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * @param msg
 * @param uArray
 */
public static void getUsers( 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 );
            user = accessMgr.getUser( session );
            UserTestData.assertEquals( user, usr );
        }
        LOG.debug( "getUsers successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error(
            "getUsers: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(),
            ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:29,代码来源:AccessMgrImplTest.java


示例4: createAdminSession

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 *
 */
public static Session createAdminSession()
{
    Session adminSess = null;
    try
    {
        AccessMgr accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
        User admin = UserTestData.getUser( UserTestData.USERS_TU0[0] );
        adminSess = accessMgr.createSession( admin, false );
    }
    catch ( SecurityException ex )
    {
        String error = " static initializer caught SecurityException rc=" + ex.getErrorId() + ", msg="
            + ex.getMessage();
        LOG.error( error );
    }
    return adminSess;
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:21,代码来源:DelegatedMgrImplTest.java


示例5: createSessionTrusted

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * Create trusted RBAC Session.  This API will attempt to activate all of the User's assigned Roles.
 *
 * @param userId  Case insensitive userId.
 */
public static void createSessionTrusted(String userId)
{
    String szLocation = ".createSessionTrusted";
    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);

        // The API will verify User is good and perform Role activations.  Request will fail if User is locked out of ldap for any reason.
        Session session = accessMgr.createSession(user, true);

        // createSession will throw SecurityException if fails thus the Session should never be null.
        assertNotNull(session);
        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,代码行数:30,代码来源:CreateSessionSample.java


示例6: createSession

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * Test Utility wraps OpenAcccessManager createSession API.
 *
 * @param userId          String contains case insensitive userId field.
 * @param password        String contains case sensitive, clear text password field.
 * @param activationRoles array of Role names targeted for activation into User's RBAC Session.
 * @return User RBAC Session that is used for subsequent AccessMgr API calls.
 */
private static Session createSession( String userId, String password, String[] activationRoles, AccessMgr accessMgr )
{
    String szLocation = ".createSession";
    Session session = null;
    try
    {
        User user = new User( userId, password, activationRoles );
        user.addProperty( "system.user.name", System.getProperty( "user.name" ) );
        //user.addProperty("system.timezone VAL", System.getProperty("user.timezone VAL"));
        user.addProperty( "system.country", System.getProperty( "user.country" ) );

        // Create an Fortress Session.  The Session contains the user's activated
        // roles along with other related attributes and status information (i.e. password status)
        session = accessMgr.createSession( user, false );
        LOG.info( szLocation + " with roles successful" );
    }
    catch ( SecurityException ex )
    {
        LOG.error(
            szLocation + " with roles caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(),
            ex );
        fail( ex.getMessage() );
    }
    return session;
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:34,代码来源:AccessMgrSample.java


示例7: 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


示例8: 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


示例9: 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


示例10: createSessionsWithRole

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * Call the AccessMgr createSession API passing a single Role for activation.  Successful RBAC Session should
 * contains same Role activated.
 *
 * @param userId  Case insensitive userId.
 * @param password Password is case sensitive, clear text but is stored in directory as hashed value.
 * @param role contains role name of Role targeted for Activation.
 */
public static void createSessionsWithRole(String userId, String password, String role)
{
    String szLocation = ".createSessionsWithRole";
    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, role);

        // The API will authenticate the User password, evaluate password policies and perform Role activations.
        Session session = accessMgr.createSession(user, false);

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

        // do some validations
        // Get the User's activated Roles.
        List<UserRole> sessRoles = session.getRoles();
        assertTrue(szLocation + " userId [" + userId + "]  with roles failed role check", sessRoles.contains(new UserRole(role)));
        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,代码行数:38,代码来源:CreateSessionSample.java


示例11: 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


示例12: 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


示例13: 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


示例14: 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


示例15: sessionPermissions

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 * @param msg
 * @param uArray
 * @param oArray
 * @param opArray
 */
public static void sessionPermissions( String msg, String[][] uArray, String[][] oArray, String[][] opArray )
{
    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 );
            List<Permission> pOps = accessMgr.sessionPermissions( session );
            assertNotNull( pOps );
            // There should be objs * ops number of perms in the list returned from sessionPermissions method:
            assertEquals( CLS_NM +
                ".sessionPermissions failed list size user[" + user.getUserId() + "]",
                oArray.length * opArray.length, pOps.size() );

            // Iterate over objs x ops, see if every expected valid permission is contained within the returned list:
            for ( String[] obj : oArray )
            {
                for ( String[] op : opArray )
                {
                    Permission validPOp = PermTestData.getOp( PermTestData.getName( obj ), op );
                    assertTrue( CLS_NM +
                        ".sessionPermissions failed perm list compare USER [" + user.getUserId() +
                        "] PERM Obj [" + PermTestData.getName( obj ) + "] " +
                        "OPER [" + PermTestData.getName( op ) + "]",
                        pOps.contains( validPOp ) );
                }
            }
        }
    }
    catch ( SecurityException ex )
    {
        LOG.error( "sessionPermissions: failed with SecurityException rc=" + ex.getErrorId() + ", msg="
            + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:47,代码来源:AccessMgrImplTest.java


示例16: canAssignUsers

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 *
 * @param msg
 * @param op
 * @param uraArray
 * @param uaArray
 * @param uArray
 * @param rArray
 */
public static void canAssignUsers( String msg, ASSIGN_OP op, String[][] uraArray, String[][] uaArray,
    String[][] uArray,
    String[][] rArray )
{
    LogUtil.logIt( msg );
    Role role;
    Map<URA, URA> uraTestResults = URATestData.getURAs( uraArray );

    try
    {
        DelAccessMgr delAccessMgr = DelAccessMgrFactory.createInstance( TestUtils.getContext() );
        AccessMgr accessMgr = ( AccessMgr ) delAccessMgr;
        int i = 0;
        for ( String[] aUsr : uaArray )
        {
            User aUser = UserTestData.getUser( aUsr );
            Session session = accessMgr.createSession( aUser, false );
            assertNotNull( session );
            for ( String[] usr : uArray )
            {
                User user = UserTestData.getUser( usr );
                i++;
                for ( String[] rle : rArray )
                {
                    role = RoleTestData.getRole( rle );
                    String methodName;
                    boolean result;
                    if ( op == ASSIGN_OP.ASSIGN )
                    {
                        result = delAccessMgr.canAssign( session, user, role );
                        methodName = ".canAssignUsers";
                    }
                    else
                    {
                        result = delAccessMgr.canDeassign( session, user, role );
                        methodName = ".canDeassignUsers";
                    }

                    List<UserAdminRole> aRoles = session.getAdminRoles();
                    assertNotNull( aRoles );
                    assertTrue( CLS_NM + methodName + " Admin User invalid number of roles", aRoles.size() == 1 );
                    // since this user should only have one admin role, get the first one from list:
                    UserAdminRole aRole = aRoles.get( 0 );
                    URA sourceUra = new URA( aRole.getName(), user.getOu(), role.getName(), result );
                    URA targetUra = uraTestResults.get( sourceUra );
                    assertTrue( CLS_NM + methodName + " cannot find target URA admin role [" + sourceUra.getArole()
                        + " uou [" + sourceUra.getUou() + "] role [" + sourceUra.getUrole() + "] Result ["
                        + sourceUra.isCanAssign() + "] actual result [" + result + "]", targetUra != null );
                    LOG.debug( methodName + " User [" + user.getUserId()
                        + "] success URA using admin role [" + targetUra.getArole() + " uou [" + targetUra.getUou()
                        + "] role [" + targetUra.getUrole() + "] target result [" + targetUra.isCanAssign()
                        + "] actual result [" + result + "]" );
                }
            }
        }
    }
    catch ( SecurityException ex )
    {
        LOG.error( "canAssignUsers op [" + op + "] caught SecurityException rc=" + ex.getErrorId()
            + ", msg=" + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:73,代码来源:DelegatedMgrImplTest.java


示例17: canGrantPerms

import org.apache.directory.fortress.core.AccessMgr; //导入方法依赖的package包/类
/**
 *
 * @param msg
 * @param op
 * @param uraArray
 * @param uaArray
 * @param pArray
 * @param rArray
 */
public static void canGrantPerms( String msg, GRANT_OP op, String[][] uraArray, String[][] uaArray,
    String[][] pArray,
    String[][] rArray )
{
    LogUtil.logIt( msg );
    Role role;
    Map<PRA, PRA> praTestResults = PRATestData.getPRAs( uraArray );

    try
    {
        DelAccessMgr delAccessMgr = DelAccessMgrFactory.createInstance( TestUtils.getContext() );
        AccessMgr accessMgr = ( AccessMgr ) delAccessMgr;
        int i = 0;
        for ( String[] aUsr : uaArray )
        {
            User aUser = UserTestData.getUser( aUsr );
            Session session = accessMgr.createSession( aUser, false );
            assertNotNull( session );
            for ( String[] prm : pArray )
            {
                PermObj pObj = PermTestData.getObj( prm );
                i++;
                for ( String[] rle : rArray )
                {
                    role = RoleTestData.getRole( rle );
                    String methodName;
                    boolean result;
                    if ( op == GRANT_OP.GRANT )
                    {
                        result = delAccessMgr.canGrant( session, role, new Permission( pObj.getObjName(), "" ) );
                        methodName = ".canGrantPerms";
                    }
                    else
                    {
                        result = delAccessMgr.canRevoke( session, role, new Permission( pObj.getObjName(), "" ) );
                        methodName = ".canRevokePerms";
                    }

                    List<UserAdminRole> aRoles = session.getAdminRoles();
                    assertNotNull( aRoles );
                    assertTrue( CLS_NM + methodName + " Admin User invalid number of roles", aRoles.size() == 1 );
                    UserAdminRole aRole = aRoles.get( 0 );
                    PRA sourceUra = new PRA( aRole.getName(), pObj.getOu(), role.getName(), result );
                    PRA targetUra = praTestResults.get( sourceUra );
                    assertTrue( CLS_NM + methodName + " cannot find target PRA admin role [" + sourceUra.getArole()
                        + " pou [" + sourceUra.getPou() + "] role [" + sourceUra.getUrole() + "] Result ["
                        + sourceUra.isCanAssign() + "] actual result [" + result + "]", targetUra != null );
                    LOG.debug( methodName + " failed target PRA admin role [" + targetUra.getArole()
                        + " pou [" + targetUra.getPou() + "] role [" + targetUra.getUrole() + "] target result ["
                        + targetUra.isCanAssign() + "] actual result [" + result + "]" );
                }
            }
        }
    }
    catch ( SecurityException ex )
    {
        LOG.error( "canGrantPerms op [" + op + "] caught SecurityException rc=" + ex.getErrorId()
            + ", msg=" + ex.getMessage(), ex );
        fail( ex.getMessage() );
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:71,代码来源:DelegatedMgrImplTest.java


示例18: 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.createSession方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。