I am trying to create a custom Condition for my confluence Plugin, which should only show a web-item to a specified group. The group/s should later be changeable through an admin.
I found an answer to my question here: https://community.atlassian.com/t5/Answers-Developer-Questions/How-can-i-control-web-item-condition/qaq-p/471832 but if I expect a UserManager in the constructor, I get this error message:
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.atlassian.sal.api.user.UserManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.atlassian.sal.api.user.UserManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
My Condition:
public class UserAuthorisationGroup extends BaseConfluenceCondition{
private Logger logger = Logger.getLogger(UserAuthorisationGroup.class);
private UserManager userManager;
public UserAuthorisationGroup(UserManager userManager){
this.userManager = userManager;
}
@Override
protected boolean shouldDisplay(WebInterfaceContext context) {
if(this.currentUserIsAuthenticated(userManager)) {
return true;
}
return false;
}
public boolean currentUserIsAuthenticated(UserManager userManager) {
return userManager.isUserInGroup(userManager.getRemoteUserKey(), "testgroup");
}
}
How can I get the UserManager inside this class?
Is it even possible to get a UserManager inside a condition, or do I have to use a different approach to check the group?
I found an answer and it's as simple, as I expected:
@Scanned
public class UserAuthorisationGroup extends BaseConfluenceCondition{
@ComponentImport
private UserManager userManager;
public UserAuthorisationGroup(UserManager userManager) {
this.userManager = userManager;
}
@Override
protected boolean shouldDisplay(WebInterfaceContext context) {
if(this.currentUserIsAuthenticated(userManager)) {
return true;
}
return false;
}
public boolean currentUserIsAuthenticated(UserManager userManager) {
return userManager.isUserInGroup(userManager.getRemoteUserKey(), "authorisiert");
}
}
I just had to add a ComponentImport annotation and a Scanned annotation.
Only if anyone stumbles over this question.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.