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

How do I add a security check to my custom searcher?

tommy guo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 16, 2013

In side my searcher I wish to use the following code to see if the user is in a specfic group:

JiraAuthenticationContext myAuth = ComponentManager.getInstance().getJiraAuthenticationContext();

String thisUser = myAuth.getLoggedInUser().getName();

boolean isUserBanned = (userUtil.getGroupNamesForUser(thisUser).contains("Banned"));

If he is in this group (if isUserBanned == true) I want my searcher to return no results when the search is performed, but how do I add this logic into my class which extends the SelectSearcher class?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
tommy guo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 17, 2013

I have resolved this issue. The answer lied in writing a new Clause Validator i.e.:

public

class MySelectCustomFieldValidator implements ClauseValidator

{

...

}

and then using this class in the init(CustomField field) function of the MySelectSearcher class via:

this

.customFieldSearcherClauseHandler = new SimpleCustomFieldContextValueGeneratingClauseHandler(

componentFactory.createObject(MySelectCustomFieldValidator.class, field) , ......);

<font></font>

<font></font>

0 votes
tommy guo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 17, 2013

I've tried extending the parent class instead of the SelectSearch class

(

MySelectSearcher

extends AbstractInitializationCustomFieldSearcher

implements

CustomFieldSearcher, SortableCustomFieldSearcher, CustomFieldStattable {

........

)

However the problem is that although I defined all the functions necessary and the search template is in fact working the security check is only ever run once when the search template for the field of interest is changed. I've tried adding the security check to each of the six functions in the class (i.e. getSearchInformation() , getSearchRenderer() , etc) but again the cehck does not occur at the time the search is actually conducted. Any advice/help would be IMMENSELY appreciated.

0 votes
tommy guo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 17, 2013

Can I use the view.vm or search.vm files in the templates folder to make it such that if the isUserBanned function returns true the search view is altered?

TAGS
AUG Leaders

Atlassian Community Events