/** Grant all permissions for the role names on this application */ protected void grantAppRoles( UsergridAuthorizationInfo info, EntityManager em, UUID applicationId, TokenInfo token, Set<String> rolenames ) throws Exception { Map<String, Role> app_roles = em.getRolesWithTitles( rolenames ); for ( String rolename : rolenames ) { if ( ( app_roles != null ) && ( token != null ) ) { Role role = app_roles.get( rolename ); if ( ( role != null ) && ( role.getInactivity() > 0 ) && ( token.getInactive() > role .getInactivity() ) ) { continue; } } Set<String> permissions = em.getRolePermissions( rolename ); grant( info, applicationId, permissions ); role( info, "application-role:".concat( applicationId.toString() ).concat( ":" ).concat( rolename ) ); } } }
assertEquals( name1, existing.getName() ); assertEquals( title1, existing.getTitle() ); assertEquals( inactivity1, existing.getInactivity().longValue() ); assertEquals( name2, existing.getName() ); assertEquals( title2, existing.getTitle() ); assertEquals( inactivity2, existing.getInactivity().longValue() );
/** * Create the role with the action and info and test it's created successfully * * @param action the action to take */ private void createAndTestRoles( ServiceAction action, String roleName, String roleTitle, long inactivity ) throws Exception { app.put( "name", roleName ); app.put( "title", roleTitle ); app.put( "inactivity", inactivity ); // test creating a new role ServiceResults results = app.testRequest( action, 1, "roles" ); // check the results Entity roleEntity = results.getEntities().get( 0 ); assertEquals( roleName, roleEntity.getProperty( "name" ) ); assertEquals( roleTitle, roleEntity.getProperty( "title" ) ); assertEquals( inactivity, roleEntity.getProperty( "inactivity" ) ); // check the role is correct at the application level Map<String, Role> roles = app.getRolesWithTitles( Collections.singleton( roleName ) ); Role role = roles.get( roleName ); assertNotNull( role ); assertEquals( roleName, role.getName() ); assertEquals( roleTitle, role.getTitle() ); assertEquals( inactivity, role.getInactivity().longValue() ); }