HPE Morpheus Enterprise Software
1858778 Members
2955 Online
110392 Solutions
New Discussion

Re: Calling a function exposed by HTTP route results in a 403 error

 
DP_Nico
HPE Pro

Calling a function exposed by HTTP route results in a 403 error

Hi,

I want to expose groovy methods to the javascript part of the plugin using HTTP routes.
when calling the exposed method from javascript with the following code I get a 403 error:

(function () {
    $(document).on('shown.bs.tab', '[href="#morpheus-tab-plugin-lb"]', function (e) {
        console.log("TEST");
        $.ajax({
            type: "GET",
            url: "${createLink(controller: 'reverseTextController', action: '/reverseTask/json')}"
          }).done(function(data) {
              console.log("DONE")
          });
    });
}());

Any idea?

Thanks,
Nico



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
19 REPLIES 19
Not applicable

Re: Calling a function exposed by HTTP route results in a 403 error

Any chance you could share your plugin code and we can take a look?

DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

Still the same result unfortunately



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Not applicable

Re: Calling a function exposed by HTTP route results in a 403 error

ok the docs arent clear here you have to append /plugin/ to the route so in your case you will do

/plugin/reverseTask/example

DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

So, tried now with 5.5.0 release and plugin api version v0.13.1 and I get the same error.

Any idea?



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

I shared the code via teams with Chris Bunge last week.



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Not applicable

Re: Calling a function exposed by HTTP route results in a 403 error

I was able to take a look at your plugin code and run it locally. Give the following a try:

  1. In LBCustomTabPlugin.groovy you should define your own permissions… for example
@Override
public List<Permission> getPermissions() {
	Permission permission = new Permission('LB Custom Tab Plugin', 'lbCustomTabPlugin', [Permission.AccessType.full])
	return [permission];
}
  1. Change CustomTabController.groovy getRoutes() to:
List<Route> getRoutes() {
  [
    Route.build("/reverseTask/example", "example", Permission.build("lbCustomTabPlugin", "full")), 
    Route.build("/reverseTask/json", "json", Permission.build("lbCustomTabPlugin", "full"))
  ]
}

Notice the change on Permissions.build to use the new Permission defined as lbCustomTabPlugin

Before you were using Permissions.build("admin","full"). There is no admin permission in the system so it would never route.

Also, after you upload the plugin, make sure you logout and login again to make sure your user’s permissions are recalculated.

Not applicable

Re: Calling a function exposed by HTTP route results in a 403 error

Morpheus v5.5.0 will need to be used as this is the first version that uses morpheus-plugin-api v0.13.1 (the version where the bug was fixed)

Not applicable

Re: Calling a function exposed by HTTP route results in a 403 error

which version of the plugin api are you using, this is a bug that was fixed last February.

DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

Issue is resolved.

Thanks everyone



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Not applicable

Re: Calling a function exposed by HTTP route results in a 403 error

groovy code is not interpreted in JavaScript, you are going to need to use the path you specified in your plugin in directly in the JavaScript rather than expecting it to be interpreted.

if you have

List<Route> getRoutes() {
[
Route.build('reverseText/json', 'myFuncThatReturnsJSON', Permission.build("admin", "full"))
]
}

so instead of:

url: "${createLink(controller: 'reverseTextController', action: 'myFuncThatReturnsJSON')}"

you should just do

url: "/reverseText/json"
DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

That gets me further to this error:
[http-nio-127.0.0.1-8080-exec-4] MissingMethodException occurred when processing request: [GET] /plugin/reverseTask/json No signature of method: com.morpheusdata.core.PluginManager.handleRoute() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, com.morpheusdata.views.ViewModel...) values: [/reverseTask/json, com.morpheusdata.views.ViewModel@459e7a6c, ...] Possible solutions: handleRoute(java.lang.String, com.morpheusdata.views.ViewModel, java.util.List). Stacktrace follows: groovy.lang.MissingMethodException: No signature of method: com.morpheusdata.core.PluginManager.handleRoute() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, com.morpheusdata.views.ViewModel...) values: [/reverseTask/json, com.morpheusdata.views.ViewModel@459e7a6c, ...] Possible solutions: handleRoute(java.lang.String, com.morpheusdata.views.ViewModel, java.util.List) at com.morpheus.plugin.PluginManagerService.handleRoute(PluginManagerService.groovy:212) at com.morpheus.PluginManagerController.route(PluginManagerController.groovy:25) at com.morpheus.remote.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:20) [9 skipped] [36 skipped]

My Method to handle the route:

def json(ViewModel<Map> model){}


I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Not applicable

Re: Calling a function exposed by HTTP route results in a 403 error

You need to use Morpheus v5.5.0 if you are using plugin api version v0.13.1

DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

Thanks, still gives me a HTTP 403 but now with a json output: “{
“error”: “access denied”
}”



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Not applicable

Re: Calling a function exposed by HTTP route results in a 403 error

do you have the required permissions you set in the route? (admin, full)

DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

yes,

/**
* Defines two Routes with the builder method
* @return
*/
List getRoutes() {
[
Route.build("/reverseTask/example", “example”, Permission.build(“admin”, “full”)),
Route.build("/reverseTask/json", “json”, Permission.build(“admin”, “full”))
]
}



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

@Andy_Warner

I used com.morpheusdata:morpheus-plugin-api:0.12.0 previously.
Updated now to Version 0.13.1.
Similar error:

[http-nio-127.0.0.1-8080-exec-10] MissingMethodException occurred when processing request: [GET] /plugin/reverseTask/json No signature of method: com.morpheusdata.core.PluginManager.handleRoute() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, com.morpheusdata.views.ViewModel...) values: [/reverseTask/json, com.morpheusdata.views.ViewModel@1c628645, ...] Possible solutions: handleRoute(java.lang.String, com.morpheusdata.views.ViewModel, java.util.List). Stacktrace follows: groovy.lang.MissingMethodException: No signature of method: com.morpheusdata.core.PluginManager.handleRoute() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, com.morpheusdata.views.ViewModel...) values: [/reverseTask/json, com.morpheusdata.views.ViewModel@1c628645, ...] Possible solutions: handleRoute(java.lang.String, com.morpheusdata.views.ViewModel, java.util.List) at com.morpheus.plugin.PluginManagerService.handleRoute(PluginManagerService.groovy:212) at com.morpheus.PluginManagerController.route(PluginManagerController.groovy:25) at com.morpheus.remote.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:20) [9 skipped] [36 skipped]


I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

with Morpheus v5.4.6 and plugin api version v.0.13.1 the recent error is gone but I am now back to the 403 error I started the thread with.
What am I missing?



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
DP_Nico
HPE Pro

Re: Calling a function exposed by HTTP route results in a 403 error

Ok, is there a solution for the LTS branch? As I need to use LTS releases.



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
kwc1
Established Member

Re: Calling a function exposed by HTTP route results in a 403 error

We are also experiencing error 403.

Not able to get the controller working.

Our custom permission has been created and was being used in the controller (getRoutes).

The plugin was uploaded in the master tenant. And we could see the custom permission in that tenant.

But we are using the custom plugin in the sub-tenant. And that custom permission is NOT appearing in the sub-tenant! And I think because of this, we are experiencing error 403, which indicates insufficient permissions.