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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

User in group/s condition Confluence Web-item

Edited

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

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
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

239 views 4 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you