Skip to content

Instantly share code, notes, and snippets.

@DemkaAge
Last active August 29, 2015 13:58
Show Gist options
  • Save DemkaAge/10237347 to your computer and use it in GitHub Desktop.
Save DemkaAge/10237347 to your computer and use it in GitHub Desktop.
Авторизация. Тестовый проект.
package ru.brbpm.lecm.wm.login.client;
import com.google.common.base.Strings;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.*;
import ru.brbpm.lecm.wm.styles.client.MainStyleResources;
import ru.brbpm.lecm.wm.styles.client.StandardStyleResources;
public class LoginController extends PopupPanel implements EntryPoint {
private static LoginUiBinder ourUiBinder = GWT.create(LoginUiBinder.class);
private static Messages messages = GWT.create(Messages.class);
@UiField(provided = true)
MainStyleResources res;
@UiField(provided = true)
FormPanel formPanel;
@UiField
TextBox userEdit;
@UiField
PasswordTextBox passwordEdit;
public LoginController() {
res = GWT.create(MainStyleResources.class);
StandardStyleResources standard = GWT.create(StandardStyleResources.class);
res.styles().ensureInjected();
standard.styles().ensureInjected();
String targetIFrame = null;
formPanel = new FormPanel(targetIFrame);
formPanel.setAction("j_security_check");
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setEncoding(FormPanel.ENCODING_URLENCODED);
setWidget(ourUiBinder.createAndBindUi(this));
}
public void onModuleLoad() {
center();
}
@UiHandler("clearButton")
void clickClear(ClickEvent event) {
clearCredentials();
}
@UiHandler("enterButton")
void clickLogin(ClickEvent event) {
proceedLogin();
}
private void proceedLogin() {
String username = userEdit.getValue();
String password = passwordEdit.getValue();
if (!Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password)) {
try {
formPanel.submit();
} catch (Exception e) {
GWT.log("EXCEPTION", e);
}
}
}
@UiHandler("passwordEdit")
void passwordKeyPressed(KeyDownEvent event) {
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
proceedLogin();
}
}
private void clearCredentials() {
userEdit.setValue("");
passwordEdit.setValue("");
userEdit.setFocus(true);
}
interface LoginUiBinder extends UiBinder<Widget, LoginController> {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>gateway</servlet-name>
<servlet-class>ru.brbpm.lecm.webapp.server.GatewayServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>gateway</servlet-name>
<url-pattern>*.rpc</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>MainWebapp.html</welcome-file>
</welcome-file-list>
<error-page>
<location>/Error.html</location>
</error-page>
<security-role>
<description>Все пользователи</description>
<role-name>Everyone</role-name>
</security-role>
<security-role>
<description>Все авторизованные пользователи</description>
<role-name>Users</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>Unrestricted</web-resource-name>
<url-pattern>/Error.html</url-pattern>
<url-pattern>/images/*</url-pattern>
<url-pattern>/Login/*</url-pattern>
<url-pattern>/Login.html</url-pattern>
<url-pattern>/LoginError.html</url-pattern>
<url-pattern>/MainWebapp.css</url-pattern>
<url-pattern>/version.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Everyone</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Restricted</web-resource-name>
<url-pattern>/*</url-pattern>
<url-pattern>/MainWebapp.html</url-pattern>
<url-pattern>/MainWebapp/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Users</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/Login.html</form-login-page>
<form-error-page>/LoginError.html</form-error-page>
</form-login-config>
</login-config>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment