0
votes

I have done an installation of WSO2 API Manager 2.5.0.

I am customizing the Publisher portal by creating a new subtheme and editing .jag files. Everything is OK until here.

I would like to show elements depending on user role. My first question is: Can I get the rol of the user logged in Publisher portal in jag files?

I couldnt find the way, so I have thought a walkaround: send a request to the RESTful API for WSO2 API Manager - Publisher. The problem is I cannot find (on the documentation) a method that return the roles of a user.

My second question is: There is some method to return the roles of a user?

I know the solution of use Publisher APIS, but they are deprecated, and anyway I have tested it, and it always return true even when the user has not assigned the role.

Ask me more information if you need. Thanks in advance.

1

1 Answers

1
votes

One possible solution is to invoke a java method exposed from the APIUtil class. The method you are looking from this util class would be the getListOfRoles method which has the following signature.

public static String[] getListOfRoles(String username) throws APIManagementException;

Or alternatively you can use the below method which does not throw any error, but rather return an empty array on an error situation.

public static String[] getListOfRolesQuietly(String username);

So to use this method in your jaggery file, you can use this using the following approach

var roleList = Packages.org.wso2.carbon.apimgt.impl.utils.APIUtil.getListOfRoles(userName);

The above should return a string array of roles in your jaggery file using which you could proceed with next steps. If you check other jaggery files found in Store or Publisher apps, the above approach is how you import a java class into the jaggery file and use it.

The APIUtil class is available in here : https://github.com/wso2/carbon-apimgt/blob/1.2.5/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java#L2420