Hi,
I am confused about communcation mechanism between JIAR software(Not Cloud) and Plugin Module.
For example:
I intend to utilize Servlet Filter Plugin to monitor user behaviors by checking some urls. During that process, I need to some information, such as projects, roles and so on. I could achive that by calling rest api, but it means http been used between Plugin and JIAR software, is it correct?
Somebody could please give me more information?
Thanks in advance.
Hi,
you can inject the dependencies or use static ComponentAccessor methods to get ProjectManager, UserManager and so on.
Could you please give me more info about communcation mechanism between JIAR software(Not Cloud) and Plugin Module?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You register your servlet-filter in atlassian-plugin.xml, then implements javax.servlet.Filter interface. So now you have access to servletRequest (HttpServletRequest), servletResponse and filterChain objects. E.g. you can also get current user by
ApplicationUser loggedUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is very crucial clue, thank you very much.
Could you please give me more inforamtion, such as sample code?
thanks for your support.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please take a look:
public class SprintServletFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
RequestWrapper requestWrapper = new RequestWrapper(httpServletRequest);
ApplicationUser loggedUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
filterChain.doFilter(requestWrapper, servletResponse);
String requestBody = new String(requestWrapper.getRawData());
JsonObject jsonObject = new JsonParser().parse(requestBody).getAsJsonObject();
JsonElement jsonElement = jsonObject.get("sprintId");
if (!jsonElement.isJsonNull()) {
Long sprintId = jsonElement.getAsLong();
}
}
@Override
public void destroy() {
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks.
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() the result is null, and I tried isLoggedInUser() return false , getUser() return null
I don't know how to deal it, :(.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What do you have inside atlassian-plugin.xml?
Example:
<servlet-filter name="Sprint Servlet" key="sprintServlet"
class="com.xxx.plugins.jira.filter.SprintServletFilter"
location="before-decoration" weight="200">
<description>Tackle sprint events</description>
<url-pattern>/rest/greenhopper/1.0/sprint/*</url-pattern>
</servlet-filter>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks , I have fixed this issue by changing location="after-encoding" to location="before-decoration" .
Maybe the user info not been injected on the top of chain, I guess
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.