Trying to use <condition class="com.atlassian.bitbucket.web.conditions.IsLoggedInCondition"/>

I’m finishing up a new bitbucket plugin and trying to add conditions to the defined in the atlassian-plugin.xml file, so that it only displays if several conditions are met…

<web-item key="project-plugin-tab" name="Project Secret" section="bitbucket.project.settings.panel/project-settings-addons-section" weight="30">
   	<conditions type="AND">
   	  <condition class="myclass.utilities.ValidLicenseCondition"/>
	  <condition class="com.atlassian.bitbucket.web.conditions.IsLoggedInCondition"/>
	  <condition class="com.atlassian.bitbucket.web.conditions.HasProjectPermissionCondition">
     			<param name="permission">PROJECT_ADMIN</param>
 	  </condition>
	</conditions>
...
..
</web-item>

It the spring scanner finds myclass condition, but fails to find IsLoggedInCondition, not sure about the HasProjectPermission, I think it fails before it checks for that one…

[INFO] [talledLocalContainer] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.atlassian.bitbucket.web.conditions.IsLoggedInCondition': Unsatisfied dependency expressed through constructor argument with index 0 of type [com.atlassian.bitbucket.auth.AuthenticationContext]: : No qualifying bean of type [com.atlassian.bitbucket.auth.AuthenticationContext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.atlassian.bitbucket.auth.AuthenticationContext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
I will also note that i am using the newest way to do component imports, where as i have none in my atlassian-plugin.xml, and a limited number in "src/main/resources/META-INFO/atlassian-plugins-components-imports.xml"

I see com.atlassian.bitbucket.auth.AuthenticationContext, is suppose to be part of the constructor for IsLoggedInCondition. Am I missing a maven dependency, or component-import. Its an Atlassian class so I can’t really see/modify it…

My guess is that you’re hitting a bug in the osgi layer (with the new approach) which is slightly disconcerting for me. I don’t usually use the IsLoggedInCondition since I like to write my own (and then be able to use my own unit tests to express my own behavior - you know in case Atlassian changes the behavior…)

2 suggestions:

  1. Take a look at the section in the pom.xml and make sure that either * or com.atlassian.bitbucket.auth.* is in there.
  2. As a workaround would be to try to create a dummy class:
@Component
public class MyDummyClass
{
    @ComponentImport
    private final AuthenticationContext;

    @Inject
    public MyDummyClass(final AuthenticationContext authenticationContext)
    {}
} 

The above should cause the Spring Scanner to create the proper import statements. It’s the nuclear option but it should work… If it does - please file a bug over at the BSERV project on jira.atlassian.com.

1 Like

Stumbled over this problem as well and can confirm the workaround via a ‘dummy’ component import class. An apparently independent analysis and confirmation of the workaround can be found in the accepted solution to Using conditions from bitbucket-web-common.

There is a long standing bug report for a slight variation of this (same underlying problem, slightly different missing component): BSERV-3810 When using Condition class in atlassian-plugin.xml, transitive dependency beans are not implicitly included