Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

User in group/s condition Confluence Web-item

Ramon Segmüller October 14, 2020

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?

1 answer

1 accepted

0 votes
Answer accepted
Ramon Segmüller October 14, 2020

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events