public boolean checkPermission ( Principal user , int operation ) { if ( tc . isEntryEnabled ( ) ) SibTr . entry ( tc , "checkPermission" , new Object [ ] { user , new Integer ( operation ) } ) ; boolean allowed = false ; if ( operation == 1 ) // a publish operation { // check whether permission has been granted to special group Everyone. // We can do this before we check whether the user is authenticated if ( accumGroupAllowedToPublish . size ( ) > 0 && accumGroupAllowedToPublish . contains ( everyone ) ) { allowed = true ; } // Now check whether the user is authenticated, ie we have a username else if ( user . getName ( ) != null && user . getName ( ) . length ( ) > 0 ) { // User is authenticated // Check user list next if ( accumUsersAllowedToPublish . size ( ) > 0 && accumUsersAllowedToPublish . contains ( user ) ) { allowed = true ; } else // Now check the groups { if ( accumGroupAllowedToPublish . size ( ) > 0 ) { // user hasn't been granted access directly, check the groups // check for AllAuthenticated first if ( accumGroupAllowedToPublish . contains ( allAuthenticated ) ) { allowed = true ; } else { Iterator itr = accumGroupAllowedToPublish . iterator ( ) ; while ( itr . hasNext ( ) ) { Group group = ( Group ) itr . next ( ) ; if ( group . isMember ( user ) ) { allowed = true ; break ; } } // eof while } } } } } else // a subscribe operation { // check whether permission has been granted to special group Everyone. // We can do this before we check whether the user is authenticated if ( accumGroupAllowedToSubscribe . size ( ) > 0 && accumGroupAllowedToSubscribe . contains ( everyone ) ) { allowed = true ; } // Now check whether the user is authenticated, ie we have a username else if ( user . getName ( ) != null && user . getName ( ) . length ( ) > 0 ) { // User is authenticated // Check user list next if ( accumUsersAllowedToSubscribe . size ( ) > 0 && accumUsersAllowedToSubscribe . contains ( user ) ) { allowed = true ; } else // Now check the groups { if ( accumGroupAllowedToSubscribe . size ( ) > 0 ) { // user hasn't been granted access directly, check the groups // check for AllAuthenticated first if ( accumGroupAllowedToSubscribe . contains ( allAuthenticated ) ) { allowed = true ; } else { Iterator itr = accumGroupAllowedToSubscribe . iterator ( ) ; while ( itr . hasNext ( ) ) { Group group = ( Group ) itr . next ( ) ; if ( group . isMember ( user ) ) { allowed = true ; break ; } } } } } } } if ( tc . isEntryEnabled ( ) ) SibTr . exit ( tc , "checkPermission" , new Boolean ( allowed ) ) ; return allowed ; }
Method checkPermission Used to determine whether a user is allowed to perform a particular operation .