use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class JsonPostClient method parseResponse.
/**
* Parses the responce to an object.
*
* @param resp JSON string
* @return
*/
protected JavaScriptObject parseResponse(String callbackName, String resp) {
// trims the whitespace
resp = resp.trim();
// short comparing
if ((callbackName + "(null);").equalsIgnoreCase(resp)) {
return null;
}
// if starts with callbackName( and ends with ) or ); - wrapped, must be unwrapped
RegExp re = RegExp.compile("^" + callbackName + "\\((.*)\\)|\\);$");
MatchResult result = re.exec(resp);
if (result != null) {
resp = result.getGroup(1);
}
// if response = null - return null
if (resp.equals("null")) {
return null;
}
// normal object
JavaScriptObject jso = JsonUtils.parseJson(resp);
return jso;
}
use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class RegistrarFormItemGenerator method generateUsernameBox.
/**
* Generates the username textbox
* @return
*/
private Widget generateUsernameBox() {
final TextBox tbox = new ExtendedTextBox();
tbox.setMaxLength(TEXT_BOX_MAX_LENGTH);
strValueBox = tbox;
tbox.setText(strValue);
tbox.getElement().setClassName("apptextbox" + counter++);
setCutCopyPasteHandler("apptextbox" + counter);
setVariableWidth(tbox);
// if username not empty - disable
if (!tbox.getValue().equalsIgnoreCase("")) {
tbox.setEnabled(false);
// do not check prefilled logins
inputChecker = getDefaultInputChecker();
} else {
// get namespace
if (item.getPerunDestinationAttribute() != null && !item.getPerunDestinationAttribute().isEmpty()) {
final String loginNamespace = item.getPerunDestinationAttribute().substring(PERUN_ATTRIBUTE_LOGIN_NAMESPACE_POSITION);
// check if login is new
inputChecker = new FormInputChecker() {
private boolean validating = false;
private boolean valid = true;
private Map<String, Boolean> validMap = new HashMap<String, Boolean>();
public boolean isValid(boolean forceNewValidation) {
// if not new, don't force
if (!forceNewValidation)
return valid;
final String str = tbox.getValue();
// missing?
valid = (!(item.isRequired() && str.equals("")));
if (!valid) {
statusCellWrapper.setWidget(new FormInputStatusWidget(ApplicationMessages.INSTANCE.missingValue(), Status.ERROR));
return false;
}
// length
valid = checkLength();
if (!valid) {
return false;
}
valid = checkValueRegex();
// regex check
if (!valid) {
return false;
}
// force check for base REGEX used in login attribute module
RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
boolean match = regExp.test(str);
if (!match)
return false;
// has already checked it?
if (validMap.containsKey(str)) {
valid = validMap.get(str);
if (valid) {
statusCellWrapper.setWidget(new FormInputStatusWidget(ApplicationMessages.INSTANCE.usernameAvailable(), Status.OK));
} else {
statusCellWrapper.setWidget(new FormInputStatusWidget(ApplicationMessages.INSTANCE.usernameNotAvailable(), Status.ERROR));
}
return valid;
}
// check login
validating = true;
statusCellWrapper.setWidget(new FormInputStatusWidget(ApplicationMessages.INSTANCE.validating(), Status.LOADING));
// check login
new IsLoginAvailable(loginNamespace, str, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// store result for the requested login
BasicOverlayType bo = jso.cast();
validMap.put(str, bo.getBoolean());
if (!str.equals(strValueBox.getValue())) {
// value changed before request finished, don't update the valid value
return;
}
valid = bo.getBoolean();
validating = false;
if (valid) {
statusCellWrapper.setWidget(new FormInputStatusWidget(ApplicationMessages.INSTANCE.usernameAvailable(), Status.OK));
} else {
statusCellWrapper.setWidget(new FormInputStatusWidget(ApplicationMessages.INSTANCE.usernameNotAvailable(), Status.ERROR));
}
validationTrigger.triggerValidation();
}
@Override
public void onError(PerunError error) {
if (!str.equals(strValueBox.getValue())) {
// value changed before request finished, don't update the valid value
return;
}
if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
validMap.put(str, false);
statusCellWrapper.setWidget(new FormInputStatusWidget("Login has invalid syntax." + error.getErrorInfo(), Status.ERROR));
} else {
// generic error
statusCellWrapper.setWidget(new FormInputStatusWidget("Unable to check if login is available!", Status.ERROR));
}
validating = false;
validationTrigger.triggerValidation();
}
}).retrieveData();
// check login end
valid = false;
return false;
}
public boolean isValidating() {
return validating;
}
public boolean useDefaultOkMessage() {
return false;
}
};
} else {
// Username has no "login-namespace"
// prevent such malformed applications from submission
tbox.setEnabled(false);
tbox.setValue("Wrong form item configuration !!");
inputChecker = new FormInputChecker() {
@Override
public boolean isValid(boolean forceNewValidation) {
return false;
}
@Override
public boolean isValidating() {
return false;
}
@Override
public boolean useDefaultOkMessage() {
return false;
}
};
}
}
return tbox;
}
use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class Utils method clearFederationCookies.
/**
* Clear all cookies provided by federation IDP in user's browser.
*/
public static void clearFederationCookies() {
final String SHIBBOLETH_COOKIE_FORMAT = "^_shib.+$";
// retrieves all the cookies
Collection<String> cookies = Cookies.getCookieNames();
// regexp
RegExp regExp = RegExp.compile(SHIBBOLETH_COOKIE_FORMAT);
for (String cookie : cookies) {
// shibboleth cookie?
MatchResult matcher = regExp.exec(cookie);
// equivalent to regExp.test(inputStr);
boolean matchFound = (matcher != null);
if (matchFound) {
// remove it
Cookies.removeCookieNative(cookie, "/");
}
}
}
use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class CreateServiceMemberInVoTabItem method draw.
public Widget draw() {
titleWidget.setText("Create service member");
final TabItem tab = this;
// draw the main tab
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
final ExtendedTextBox serviceUserName = new ExtendedTextBox();
final ExtendedTextBox serviceUserEmail = new ExtendedTextBox();
final ExtendedTextBox serviceUserLogin = new ExtendedTextBox();
final ExtendedPasswordBox serviceUserPassword = new ExtendedPasswordBox();
final ExtendedPasswordBox serviceUserPassword2 = new ExtendedPasswordBox();
final ListBox namespace = new ListBox();
final ExtendedTextBox certDN = new ExtendedTextBox();
final ExtendedTextBox cacertDN = new ExtendedTextBox();
final String serviceType = "SERVICE";
serviceUserPassword.getTextBox().setWidth("200px");
serviceUserPassword2.getTextBox().setWidth("200px");
final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (serviceUserName.getTextBox().getValue().trim().isEmpty()) {
serviceUserName.setError("Name can't be empty!");
return false;
}
serviceUserName.setOk();
return true;
}
};
serviceUserName.setValidator(nameValidator);
final ExtendedTextBox.TextBoxValidator loginValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (namespace.getSelectedIndex() == 0) {
// do not validate if namespace is not selected
serviceUserLogin.getTextBox().setValue(null);
serviceUserLogin.setOk();
return true;
}
if (serviceUserLogin.getTextBox().getValue().trim().isEmpty()) {
serviceUserLogin.setError("Login can't be empty!");
return false;
}
RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
boolean match = regExp.test(serviceUserLogin.getTextBox().getValue().trim());
if (!match) {
serviceUserLogin.setError("Invalid format!");
return false;
}
if (serviceUserLogin.isProcessing() || serviceUserLogin.isHardError()) {
// keep original message
return false;
}
serviceUserLogin.setOk();
return true;
}
};
serviceUserLogin.setValidator(loginValidator);
final ExtendedTextBox.TextBoxValidator emailValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!JsonUtils.isValidEmail(serviceUserEmail.getTextBox().getValue().trim())) {
serviceUserEmail.setError("Wrong email format!");
return false;
}
serviceUserEmail.setOk();
return true;
}
};
serviceUserEmail.setValidator(emailValidator);
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (serviceUserPassword.getTextBox().getValue().trim().equals("")) {
serviceUserPassword.setError("Password can't be empty!");
return false;
}
// einfra check
if ("einfra".equals(namespace.getSelectedValue())) {
RegExp regExp2 = RegExp.compile("^[\\x20-\\x7E]{1,}$");
if (regExp2.exec(serviceUserPassword.getTextBox().getValue()) == null) {
serviceUserPassword.setError("Password <b>can`t contain accented characters (diacritics)</b> or non-printing and control characters!");
return false;
}
// check on login in password if login is longer than 2 chars
// TODO - check for name/surname too
String pass = serviceUserPassword.getTextBox().getValue();
String login = serviceUserLogin.getTextBox().getValue();
if (login.length() > 2) {
if (Utils.normalizeString(pass).contains(Utils.normalizeString(login)) || Utils.normalizeString(pass).contains(Utils.normalizeString(Utils.reverseString((login))))) {
serviceUserPassword.setError("Password <b>can't contain login, name or surname</b>, not even backwards!");
return false;
}
}
// Check that password contains at least 3 of 4 character groups
RegExp regExpDigit = RegExp.compile("^.*[0-9].*$");
RegExp regExpLower = RegExp.compile("^.*[a-z].*$");
RegExp regExpUpper = RegExp.compile("^.*[A-Z].*$");
// FIXME - are those correct printable specific chars?
RegExp regExpSpec = RegExp.compile("^.*[\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E].*$");
int matchCounter = 0;
if (regExpDigit.exec(serviceUserPassword.getTextBox().getValue()) != null)
matchCounter++;
if (regExpLower.exec(serviceUserPassword.getTextBox().getValue()) != null)
matchCounter++;
if (regExpUpper.exec(serviceUserPassword.getTextBox().getValue()) != null)
matchCounter++;
if (regExpSpec.exec(serviceUserPassword.getTextBox().getValue()) != null)
matchCounter++;
if (matchCounter < 3) {
serviceUserPassword.setError("Password must consist of <b>at least 3 of 4</b> character groups<ul><li>lower-case letters</li><li>upper-case letters</li><li>digits</li><li>special characters</li></ul>");
return false;
}
// check length
if (serviceUserPassword.getTextBox().getValue().length() < 10) {
serviceUserPassword.setError("Password must be <b>at least 10 characters</b> long!");
return false;
}
}
if (!serviceUserPassword.getTextBox().getValue().equals(serviceUserPassword2.getTextBox().getValue())) {
serviceUserPassword.setOk();
serviceUserPassword2.setError("Password in both textboxes must be the same!");
return false;
}
serviceUserPassword.setOk();
return true;
}
};
serviceUserPassword.setValidator(validator);
final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!serviceUserPassword2.getTextBox().getValue().equals(serviceUserPassword.getTextBox().getValue())) {
serviceUserPassword2.setError("Password in both textboxes must be the same!");
return false;
} else {
serviceUserPassword2.setOk();
return true;
}
}
};
serviceUserPassword2.setValidator(validator2);
/*
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (serviceUserPassword.getTextBox().getValue().trim().isEmpty()) {
serviceUserPassword.setError("Password can't be empty !");
return false;
} else if (!serviceUserPassword.getTextBox().getValue().equals(serviceUserPassword2.getTextBox().getValue())) {
serviceUserPassword.setError("Password in both textboxes must be the same !");
return false;
} else {
serviceUserPassword.setOk();
serviceUserPassword2.setOk();
return true;
}
}
};
serviceUserPassword.setValidator(validator);
final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (serviceUserPassword2.getTextBox().getValue().trim().isEmpty()) {
serviceUserPassword2.setError("Password can't be empty !");
return false;
} else if (!serviceUserPassword2.getTextBox().getValue().equals(serviceUserPassword.getTextBox().getValue())) {
serviceUserPassword2.setError("Password in both textboxes must be the same !");
return false;
} else {
serviceUserPassword2.setOk();
serviceUserPassword.setOk();
return true;
}
}
};
serviceUserPassword2.setValidator(validator2);
*/
final ExtendedTextBox.TextBoxValidator certDNValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if ((certDN.getTextBox().getValue().trim().isEmpty() && cacertDN.getTextBox().getValue().trim().isEmpty()) || (!certDN.getTextBox().getValue().trim().isEmpty() && !cacertDN.getTextBox().getValue().trim().isEmpty())) {
certDN.setOk();
cacertDN.setOk();
return true;
} else {
if (certDN.getTextBox().getValue().trim().isEmpty()) {
certDN.setError("Value can't be empty!");
}
if (cacertDN.getTextBox().getValue().trim().isEmpty()) {
cacertDN.setError("Value can't be empty!");
}
}
return false;
}
};
certDN.setValidator(certDNValidator);
cacertDN.setValidator(certDNValidator);
// make value empty
namespace.addItem("Not selected", "");
for (String name : Utils.getSupportedPasswordNamespaces()) {
namespace.addItem(name.toUpperCase(), name);
}
final FlexTable layout = new FlexTable();
layout.setCellPadding(5);
layout.setHTML(0, 0, "<h3>1. Create service identity</h3>");
layout.getFlexCellFormatter().setColSpan(0, 0, 3);
layout.setHTML(1, 0, "<strong>Member's name: </strong>");
layout.setWidget(1, 1, serviceUserName);
layout.setHTML(2, 0, "<strong>Member's email: </strong>");
layout.setWidget(2, 1, serviceUserEmail);
layout.setHTML(3, 0, "<strong>Namespace: </strong>");
layout.setWidget(3, 1, namespace);
layout.setHTML(4, 0, "<strong>Login: </strong>");
layout.setWidget(4, 1, serviceUserLogin);
final Label label = new Label("You will be assigned with available login");
label.setVisible(false);
layout.setWidget(5, 0, label);
layout.getFlexCellFormatter().setStyleName(5, 0, "inputFormInlineComment");
layout.getFlexCellFormatter().setColSpan(5, 0, 2);
layout.setHTML(6, 0, "<strong>Subject DN: </strong>");
layout.setWidget(6, 1, certDN);
layout.setHTML(7, 0, "<strong>Issuer DN: </strong>");
layout.setWidget(7, 1, cacertDN);
final FlexTable firstTabLayout = new FlexTable();
firstTabLayout.setSize("100%", "100%");
firstTabLayout.setVisible(false);
final AddRemoveItemsTable<User> itemsTable = new AddRemoveItemsTable<User>(true);
itemsTable.addItem(session.getUser());
final VerticalPanel secondTabPanel = new VerticalPanel();
secondTabPanel.setSize("100%", "100%");
secondTabPanel.setVisible(false);
mainTab.add(layout);
mainTab.add(firstTabLayout);
mainTab.add(secondTabPanel);
// disable login by default (first option)
serviceUserLogin.getTextBox().setEnabled(false);
final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.addIcon(), new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
// check
if (!namespace.getSelectedValue().equals("mu") && namespace.getSelectedIndex() != 0 && !loginValidator.validateTextBox())
return;
if (!nameValidator.validateTextBox())
return;
if (!emailValidator.validateTextBox())
return;
if (!certDNValidator.validateTextBox())
return;
// change to lager tab
session.getTabManager().changeStyleOfInnerTab(true);
// first tab panel
firstTabLayout.setHTML(0, 0, "<h3>2. Associate real users</h3>");
firstTabLayout.getFlexCellFormatter().setColSpan(0, 0, 2);
layout.setVisible(false);
firstTabLayout.setVisible(true);
final FindUsersInVo callback = new FindUsersInVo();
// Service users can't own another Service or Guest (Sponsored) account.
callback.hideService(true);
// HORIZONTAL MENU
TabMenu tabMenu = new TabMenu();
// get the table
final CellTable<User> table = callback.getTable();
// search textbox
ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
callback.searchFor(text, voId);
searchString = text;
}
}, ButtonTranslation.INSTANCE.searchUsers());
final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.arrowRightIcon());
cb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
// check
if (itemsTable.getList().isEmpty()) {
new Confirm("No user associated", new HTML("You must associate at least one real user to service member."), true).show();
return;
}
// create member + user
CreateSpecificMember request = new CreateSpecificMember(JsonCallbackEvents.disableButtonEvents(cb, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
final Member member = jso.cast();
for (User u : itemsTable.getList()) {
if (u.getId() == session.getUser().getId()) {
// set local authz if one of associated users is us
session.addEditableUser(member.getUserId());
}
}
if (namespace.getSelectedIndex() == 0) {
// we didn't set login, hence skip password setting
session.getTabManager().closeTab(tab, true);
return;
}
// change to small tab
session.getTabManager().changeStyleOfInnerTab(false);
secondTabPanel.add(new HTML("<h3>3.Set password for: " + serviceUserLogin.getTextBox().getValue().trim() + "</h3>"));
final CustomButton button = new CustomButton("Set password", SmallIcons.INSTANCE.keyIcon());
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
if (!validator.validateTextBox() || !validator2.validateTextBox()) {
// one of input boxes for passwords is wrong
return;
}
final String namespaceValue = namespace.getSelectedValue();
if ("mu".equals(namespaceValue)) {
final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// validate member when all kerberos logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
req2.validateMemberAsync(member);
}
}));
// validate login returned from account generation
req.validatePassword(member.getUserId(), login, namespaceValue);
// show assigned login
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
}
@Override
public void onError(PerunError error) {
UiElements.generateError(error, "Saving login failed", "You were assigned with login <b>" + login + "</b> in namespace MU but saving it to user failed. <b>Please copy your login and contact support at <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">" + Utils.perunReportEmailAddress() + "</a>.</b>");
// validate member when all logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
req2.validateMemberAsync(member);
}
}));
setLogin.setLogin(member.getUserId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
RichMember rm = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
req.generateAccount(namespaceValue, serviceUserPassword.getTextBox().getValue(), params);
}
}));
get.retrieveData();
} else {
// create password which sets also user ext sources
CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// validate member when all kerberos logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
req2.validateMemberAsync(member);
}
}));
req.createPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue, serviceUserPassword.getTextBox().getValue());
}
}
});
final CustomButton skipButton = new CustomButton("Skip", SmallIcons.INSTANCE.arrowRightIcon());
skipButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
final String namespaceValue = namespace.getSelectedValue();
if ("mu".equals(namespaceValue)) {
final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// validate member when all kerberos logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
req2.validateMemberAsync(member);
}
}));
// validate login returned from account generation
req.validatePassword(member.getUserId(), login, namespaceValue);
// show assigned login
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
}
@Override
public void onError(PerunError error) {
// validate member when all logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
req2.validateMemberAsync(member);
}
}));
setLogin.setLogin(member.getUserId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
RichMember rm = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
req.generateAccount(namespaceValue, null, params);
}
}));
get.retrieveData();
} else {
CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(skipButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// validate member when all kerberos logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(skipButton, tab, true));
req2.validateMemberAsync(member);
}
}));
// set empty password for service member if "skipped"
req.createRandomPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue);
}
}
});
FlexTable ft = new FlexTable();
ft.setStyleName("inputFormFlexTable");
ft.setWidth("400px");
ft.setHTML(0, 0, "Password:");
ft.setWidget(0, 1, serviceUserPassword);
ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
ft.setHTML(1, 0, "Re-type password:");
ft.setWidget(1, 1, serviceUserPassword2);
ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
if ("einfra".equals(namespace.getSelectedValue())) {
ft.setHTML(2, 0, "Password must <ul><li>contain only printing (non-accented) characters<li>be at least 10 characters long<li>consist of at least 3 of 4 character groups<ul><li>lower-case letters<li>upper-case letters<li>digits<li>special characters</ul></ul>");
} else {
ft.setHTML(2, 0, "Please <b>avoid using accented characters</b>. It might not be supported by all backend components and services.");
}
ft.getFlexCellFormatter().setColSpan(2, 0, 2);
ft.getCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
ft.setWidget(3, 1, skipButton);
ft.getFlexCellFormatter().addStyleName(3, 1, "align-right");
ft.setWidget(4, 1, button);
ft.getFlexCellFormatter().addStyleName(4, 1, "align-right");
secondTabPanel.add(ft);
// hide 2nd panel
firstTabLayout.setVisible(false);
// show 3rd panel
secondTabPanel.setVisible(true);
}
}));
request.createMember(voId, serviceUserName.getTextBox().getValue().trim(), serviceUserEmail.getTextBox().getValue().trim(), itemsTable.getList(), namespace.getValue(namespace.getSelectedIndex()), serviceUserLogin.getTextBox().getValue().trim(), certDN.getTextBox().getValue().trim(), cacertDN.getTextBox().getValue().trim(), serviceType);
}
});
// we have ourselves already assigned
// cb.setEnabled(false);
CustomButton button = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected users to service member");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
ArrayList<User> list = callback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// skip self
ArrayList<User> list2 = new ArrayList<User>();
for (User user : list) {
if (user != null && user.getId() != session.getUser().getId()) {
list2.add(user);
}
}
itemsTable.addItems(list2);
cb.setEnabled(true);
callback.clearTableSelectedSet();
}
}
});
button.setEnabled(false);
tabMenu.addWidget(button);
JsonUtils.addTableManagedButton(callback, table, button);
// add finish button to menu
tabMenu.addWidget(cb);
// if some text has been searched before
if (!searchString.equals("")) {
searchBox.getTextBox().setText(searchString);
callback.searchFor(searchString, voId);
}
final ScrollPanel sp = new ScrollPanel(table);
table.addStyleName("perun-table");
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(sp, 350, tab);
firstTabLayout.setWidget(1, 0, tabMenu);
firstTabLayout.setWidget(2, 0, sp);
firstTabLayout.setHTML(1, 1, "<h3>To be associated:</h3>");
firstTabLayout.setWidget(2, 1, itemsTable);
firstTabLayout.getFlexCellFormatter().setWidth(2, 0, "75%");
firstTabLayout.getFlexCellFormatter().setWidth(2, 1, "25%");
firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 1, HasVerticalAlignment.ALIGN_TOP);
firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_TOP);
// actions when added items or removed items
itemsTable.setEvents(new AddRemoveItemsTable.HandleItemsAction<User>() {
@Override
public void onAdd(User object) {
cb.setEnabled(true);
}
@Override
public void onRemove(User object) {
if (object.equals(session.getUser())) {
itemsTable.addItem(object);
UiElements.generateInfo("Can't remove yourself", "<p>You can't remove yourself yet. You wouldn't be able to finish service member configuration. Please remove yourself afterwards.");
}
if (itemsTable.getList().isEmpty()) {
cb.setEnabled(false);
}
}
});
}
});
// check login availability
serviceUserLogin.getTextBox().addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent keyUpEvent) {
if (keyUpEvent.isDownArrow() || keyUpEvent.isUpArrow() || keyUpEvent.isLeftArrow() || keyUpEvent.isRightArrow()) {
// do not trigger when no text input
return;
}
final String login = serviceUserLogin.getTextBox().getValue().trim();
final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
// trigger new validation on checked input or if previously was hard error
if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
BasicOverlayType bo = jso.cast();
serviceUserLogin.setProcessing(false);
if (!bo.getBoolean()) {
serviceUserLogin.setHardError("Login is already in use!");
} else {
serviceUserLogin.removeHardError();
loginValidator.validateTextBox();
}
}
}
@Override
public void onLoadingStart() {
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
serviceUserLogin.removeHardError();
serviceUserLogin.setProcessing(true);
}
}
@Override
public void onError(PerunError error) {
// response is relevant to current value
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
serviceUserLogin.setProcessing(false);
String text = error.getErrorInfo();
text = text.split(":", 2)[1];
text = (text == null || text.isEmpty()) ? error.getErrorInfo() : text;
serviceUserLogin.setHardError(text);
} else {
// generic error
serviceUserLogin.setProcessing(false);
serviceUserLogin.setHardError("Unable to check if login is available!");
}
}
}
}).retrieveData();
}
}
});
namespace.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (namespace.getSelectedIndex() == 0) {
// do not set login
serviceUserLogin.getTextBox().setEnabled(false);
serviceUserLogin.getTextBox().setValue(null);
loginValidator.validateTextBox();
label.setVisible(false);
} else if (namespace.getSelectedValue().equals("mu")) {
serviceUserLogin.getTextBox().setEnabled(false);
label.setVisible(true);
} else {
serviceUserLogin.getTextBox().setEnabled(true);
label.setVisible(false);
}
if (namespace.getSelectedIndex() != 0) {
// do not check login if not desired to set
final String login = serviceUserLogin.getTextBox().getValue().trim();
final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
serviceUserLogin.setProcessing(false);
BasicOverlayType bo = jso.cast();
if (!bo.getBoolean()) {
serviceUserLogin.setHardError("Login is already in use!");
} else {
serviceUserLogin.removeHardError();
loginValidator.validateTextBox();
}
}
}
@Override
public void onLoadingStart() {
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
serviceUserLogin.removeHardError();
serviceUserLogin.setProcessing(true);
loginValidator.validateTextBox();
}
}
@Override
public void onError(PerunError error) {
// response is relevant to current value
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
serviceUserLogin.setProcessing(false);
String text = error.getErrorInfo();
text = text.split(":", 2)[1];
text = (text == null || text.isEmpty()) ? error.getErrorInfo() : text;
serviceUserLogin.setHardError(text);
} else {
// generic error
serviceUserLogin.setProcessing(false);
serviceUserLogin.setHardError("Unable to check if login is available!");
}
}
}
}).retrieveData();
}
}
}
});
if (session.isPerunAdmin()) {
layout.setWidget(9, 0, cb);
layout.getFlexCellFormatter().setHorizontalAlignment(9, 0, HasHorizontalAlignment.ALIGN_RIGHT);
layout.getFlexCellFormatter().setColSpan(9, 0, 2);
} else {
layout.setWidget(8, 0, cb);
layout.getFlexCellFormatter().setHorizontalAlignment(8, 0, HasHorizontalAlignment.ALIGN_RIGHT);
layout.getFlexCellFormatter().setColSpan(8, 0, 2);
}
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class JsonUtils method stringFormat.
/**
* Replacement for String.format in Java
* @param format Source format
*/
public static String stringFormat(final String format, final Object... args) {
final RegExp regex = RegExp.compile("%[a-z]");
final SplitResult split = regex.split(format);
final StringBuffer msg = new StringBuffer();
for (int pos = 0; pos < split.length() - 1; pos += 1) {
msg.append(split.get(pos));
msg.append(args[pos].toString());
}
msg.append(split.get(split.length() - 1));
return msg.toString();
}
Aggregations