question: public Set < AccessRight > applyAccessRights ( AppContext ctx , Set < AccessRight > accessRights , Set < AccessRight > newAccessRights ) { Set < AccessRight > rightsToAdd = new HashSet < AccessRight > ( ) ; Set < AccessRight > rightsToRemove = new HashSet < AccessRight > ( ) ; Set < AccessRight > rights = new HashSet < AccessRight > ( accessRights ) ; User user = ctx . getUser ( ) ; for ( AccessRight newRight : newAccessRights ) { if ( ! accessRights . contains ( newRight ) ) { if ( hasRole ( user , newAccessRights , newRight . getRole ( ) ) ) { rightsToAdd . add ( newRight ) ; } else { throw new InvalidCredentialsAPIException ( "Insufficient privileges : " + newRight . getRole ( ) + " required" , ctx . isNoError ( ) ) ; } } } if ( ! newAccessRights . isEmpty ( ) ) { for ( AccessRight right : accessRights ) { if ( ! newAccessRights . contains ( right ) ) { if ( hasRole ( user , newAccessRights , right . getRole ( ) ) ) { rightsToRemove . add ( right ) ; } else { throw new InvalidCredentialsAPIException ( "Insufficient privileges " + right . getRole ( ) + " required" , ctx . isNoError ( ) ) ; } } } } rights . addAll ( rightsToAdd ) ; rights . removeAll ( rightsToRemove ) ; return rights ; }
target:  Compute the access rights to apply based on the current user rights.<br>