How to implement a Jira plugin that limit account name allowed at SignUp?

I want to write a Jira plugin that force people to use a certain username pattern when they register their accounts in Jira.

This is happening inside the form is displayed at `/secure/Signup!default.jspa` and is based on `$JIRA_INSTALL/atlassian-jira/views/signup.jsp` view.

Still, I have no idea what to put inside the plugin in order to make it fail, and also I do not want to go the easy way and implement this in JavaScript on the client, not because of security, just because I want a solution that does not brake when you upgrade Jira.

Update: I found that DefaultUserService.java - still I'm not sure how to implement this in a plugin and preferably writing a minimal amount of code.

Probably what I need is to throw a CreateExeption from inside the plugin, but what to implement inside the plugin to throw this?

2 answers

1 accepted

0 votes
Accepted answer

Because I don't want to loose my customization each time I'm doing a Jira update, I ended up writing a jQuery check. I know, it is not safe but it is better than loosing changes on updates.

You have to overwrite the Signup WebAction as described in this tutorial: http://www.j-tricks.com/1/post/2010/10/extending-jira-actions.html

In this case it should be the following definition in your atlassian-plugin.xml:

<webwork1 key="new-signup" name="New Signup" class="java.lang.Object">
        <actions>
            <action name="com.foo.bar.NewSignup" alias="Signup">
                <view name="success">/views/signup-success.jsp</view>
                <view name="limitexceeded">/views/signup-limitexceeded.jsp</view>
                <view name="alreadyloggedin">/views/signup-alreadyloggedin.jsp</view>
                <view name="error">/views/signup.jsp</view>
                <view name="input">/views/signup.jsp</view>
                <view name="modebreach">/views/modebreach.jsp</view>
                <view name="systemerror">/views/signup-systemerror.jsp</view>
            </action>
        </actions>
    </webwork1>

Then you have to extend com.atlassian.jira.web.action.user.Signup and validate the username:

@Override
    protected void doValidation() {

        if (getUsername().matches("mypattern")){
            addError("username", getText("mytext"));
        }

        super.doValidation();
    }

Then the user sees a red error message at the username field.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,667 views 18 21
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you