{
  "category": "User Attribute Based",
  "name": "Role Based",
  "img": "./images/user.gif",
  "code": [
    "function onInitialRequest(context) {",
    "   executeStep({",
    "       id: '1',",
    "       on: {",
    "           success: function (context) {",
    "               var isAdmin = hasRole(context, 'admin');",
    "               Log.info('--------------- Has Admin ' + isAdmin);",
    "               if (isAdmin) {",
    "                   executeStep({id: '2'});",
    "	                executeStep({id: '3'});",
    "               }",
    "           }",
    "       }",
    "   });",
    "}"
  ],
  "help": "Define conditional authentication based on user role.",
  "helpLink": "https://docs.wso2.com/display/IS560/WSO2+Identity+Server+Documentation"
}

{
  "category": "User Attribute Based",
  "name": "Role Based",
  "img": "./images/user.gif",
  "code": [
    "function onInitialRequest(context) {",
    "   executeStep({",
    "       id: '1',",
    "       on: {",
    "           success: function (context) {",
    "               // Extracting authenticated subject from the first step",
    "               var user = context.steps[1].subject;",
    "               // Checking if the user is assigned for the given role",
    "               var isAdmin = hasRole(user, 'ROLE-NAME-PLACEHOLDER');",
    "               Log.info(user.username + ' Has Admin Role: ' + isAdmin);",
    "               if (isAdmin) {",
    "                   executeStep({id: '2'});",
    "	                executeStep({id: '3'});",
    "               }",
    "           }",
    "       }",
    "   });",
    "}"
  ],
  "help": "Define conditional authentication based on user role.",
  "helpLink": "https://docs.wso2.com/display/IS560/WSO2+Identity+Server+Documentation"
}

Fix casting issue in the role based template
Fix casting issue in the role based template

The template causes a class casting exception as the hasRole function is refactored to accept authenticated user instead of the context object. This commit fixes the issue by updating the template to pass the user instead of context.