Problem with IsUserInRole

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Problem with IsUserInRole

    Hey,

    I'm building a web app with need some security.
    For that i'm using an already defined database which handle user password
    group membership and functionnality
    par group or user.

    So i filled the list of functionnality the user is allowed to use in the roles
    param of cfloginuser.

    This seem to work well until i need to dynamicaly check the autorisation.

    Ex if i use

    <cfset fct="36">

    <cfif (IsUserInRole(#fct#))>
    test
    </cfif>

    everything is fine, i got the correct output if the user as the functionnality
    36
    but if the varaible come from an SQL query then everything failed.
    Example of what i mean:
    <cfquery name="fonction" datasource="si">
    SELECT * FROM fonctionnalite
    WHERE num_rubrique=#rubrique.num#
    </cfquery>
    <cfloop query="fonction">

    <cfif (IsUserInRole(#fonction.num#))>
    is authorized
    </cfif>
    </cfloop>

    Any idea of how and/or why ?

    PS: I'm using CFMX version 6,1,0,63958 hosted on linux

    bplessis Guest

  2. Similar Questions and Discussions

    1. contribute problem - access denied file may not existpermission problem
      Recieving the following error message - "access denied file may not exist , or there could be a permission problem" this happened this morning ,...
    2. IsUserInRole
      :Q All, is there a problem with the CF MX7 documentation within DreamWeaver? The updated on-line CF Function Reference in DreamWeaver MX 2004 states...
    3. IsUserInRole()
      Hi, All: Is it possible to use the IsUserInRole() function to use two groups or is it just one? I've tried several different ways to accomplish...
    4. Uploading problem = weird warning (was: access denied problem.....)
      Hi, I had a problem where my upload form was not working on our production server but was working on two other servers, after checking the...
    5. Problem with Apache Web Server config file and PHP (please give advice on what problem may be me)
      HI: Can anyone refer me to someone that can help with the problem below. I installed Apache Web Server on my laptop which has Windows XP. I...
  3. #2

    Default Re: Problem with IsUserInRole


    Well if using string instead of number everything work.
    I'd prefer number altough but ...
    bplessis Guest

  4. #3

    Default Re: Problem with IsUserInRole

    Don't put # signs around your variable And no error will occur.


    <cfif IsUserInRole(fonction.num)>
    is authorized
    </cfif>
    SamCurren Guest

  5. #4

    Default Re: Problem with IsUserInRole


    Nope, not better.

    Altough it work with or without '#' when using libelle (string)
    Nothing work when using the id (number).

    Weird.

    bplessis Guest

  6. #5

    Default Re: Problem with IsUserInRole

    Can we see the complete CFLOGIN code? What it looks like to me is you are
    looping over the IsUserInRole call, so the value of fonction.num will change
    with each row retrieved. And I'm sure you know you assign roles to users with
    <cfloginuser>. Now a more optimal way to do this is to create a list from the
    retrieved records, then pass the list to <cfloginuser>: <cfquery
    name='fonction' datasource='si'> SELECT * FROM fonctionnalite WHERE
    num_rubrique=#rubrique.num# </cfquery> <cfloginuser name='#j_username#'
    password='#j_password#' roles='#valueList(fonction.num)#> Now your
    IsUserInRole should work properly. Remember you can only check against one role
    at a time, so you may need an IF-ELSE block to go through all of the possible
    roles. HTH,

    Sarge Guest

  7. #6

    Default Re: Problem with IsUserInRole

    Here is the <cflogin> code. Mostly taken from some snippet in the livedoc site.

    PS: I do loop on some row and apply IsUserInRole on result but it's to
    dynamicaly generate the application menu.


    <cflogin>
    <cfif NOT IsDefined("cflogin")>
    <cfinclude template="loginform.cfm">
    <cfabort>
    <cfelse>
    <cfif cflogin.name IS "" OR cflogin.password IS "">
    <cfoutput>
    <H2>You must enter text in both the User Name and Password
    fields</H2>
    </cfoutput>
    <cfinclude template="loginform.cfm">
    <cfabort>
    <cfelse>

    <!--- search login number --->
    <cfquery name="loginQuery" dataSource="sidys">
    SELECT login, num, num_groupe
    FROM log_personne
    WHERE pass='#cflogin.password#'
    AND login='#cflogin.name#'
    </cfquery>
    <!--- obtain groups --->
    <cfquery name="groupQuery" dataSource="sidys">
    SELECT num, nom
    FROM groupe
    WHERE num='#loginQuery.num_groupe#'
    </cfquery>

    <!--- query list of roles --->
    <cfquery name="droits" datasource="sidys">
    SELECT num_fonctionnalite AS fct, libelle
    ....
    UNION
    SELECT num_fonctionnalite AS fct, libelle
    ......
    </cfquery>

    <cfif loginQuery.num NEQ "">
    <cfloginuser name = "#cflogin.name#" password =
    "#cflogin.password#"
    roles = "#ValueList(droits.libelle)#" />
    <cfelse>
    <cfoutput>
    <H2>Your login information is not valid.<br>
    Please Try again</H2>
    </cfoutput>
    <cfinclude template="loginform.cfm">
    <cfabort>
    </cfif>
    </cfif>
    </cfif>
    </cflogin>

    bplessis Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139