SEBSERV-34 fixed
This commit is contained in:
parent
7a8cdf0ee3
commit
88df75c6dc
3 changed files with 59 additions and 28 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
package ch.ethz.seb.sebserver.gui.content;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.rap.rwt.RWT;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
|
@ -83,43 +84,72 @@ public class LoginPage implements TemplateComposer {
|
|||
.getAuthorizationContext(RWT.getUISession().getHttpSession());
|
||||
|
||||
button.addListener(SWT.Selection, event -> {
|
||||
final String username = loginName.getText();
|
||||
try {
|
||||
|
||||
final boolean loggedIn = authorizationContext.login(
|
||||
username,
|
||||
loginPassword.getText());
|
||||
|
||||
if (loggedIn) {
|
||||
// Set users locale on page after successful login
|
||||
this.i18nSupport.setSessionLocale(
|
||||
authorizationContext
|
||||
.getLoggedInUser()
|
||||
.getOrThrow().language);
|
||||
|
||||
pageContext.forwardToMainPage();
|
||||
|
||||
} else {
|
||||
loginError(pageContext, "sebserver.login.failed.message");
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log.error("Unexpected error while trying to login with user: {}", username, e);
|
||||
loginError(pageContext, "Unexpected Error. Please call an Administrator");
|
||||
}
|
||||
login(
|
||||
pageContext,
|
||||
loginName.getText(),
|
||||
loginPassword.getText(),
|
||||
authorizationContext);
|
||||
});
|
||||
loginName.addListener(SWT.KeyDown, event -> {
|
||||
if (event.character == '\n' || event.character == '\r') {
|
||||
loginPassword.setFocus();
|
||||
if (StringUtils.isNotBlank(loginPassword.getText())) {
|
||||
login(
|
||||
pageContext,
|
||||
loginName.getText(),
|
||||
loginPassword.getText(),
|
||||
authorizationContext);
|
||||
} else {
|
||||
loginPassword.setFocus();
|
||||
}
|
||||
}
|
||||
});
|
||||
loginPassword.addListener(SWT.KeyDown, event -> {
|
||||
if (event.character == '\n' || event.character == '\r') {
|
||||
button.setFocus();
|
||||
if (StringUtils.isNotBlank(loginName.getText())) {
|
||||
login(
|
||||
pageContext,
|
||||
loginName.getText(),
|
||||
loginPassword.getText(),
|
||||
authorizationContext);
|
||||
} else {
|
||||
loginName.setFocus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void login(
|
||||
final PageContext pageContext,
|
||||
final String loginName,
|
||||
final CharSequence loginPassword,
|
||||
final SEBServerAuthorizationContext authorizationContext) {
|
||||
|
||||
final String username = loginName;
|
||||
try {
|
||||
|
||||
final boolean loggedIn = authorizationContext.login(
|
||||
username,
|
||||
loginPassword);
|
||||
|
||||
if (loggedIn) {
|
||||
// Set users locale on page after successful login
|
||||
this.i18nSupport.setSessionLocale(
|
||||
authorizationContext
|
||||
.getLoggedInUser()
|
||||
.getOrThrow().language);
|
||||
|
||||
pageContext.forwardToMainPage();
|
||||
|
||||
} else {
|
||||
loginError(pageContext, "sebserver.login.failed.message");
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log.error("Unexpected error while trying to login with user: {}", username, e);
|
||||
loginError(pageContext, "Unexpected Error. Please call an Administrator");
|
||||
}
|
||||
}
|
||||
|
||||
private void loginError(
|
||||
final PageContext pageContext,
|
||||
final String message) {
|
||||
|
|
|
@ -48,6 +48,7 @@ import ch.ethz.seb.sebserver.gbl.model.user.UserInfo;
|
|||
import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Utils;
|
||||
|
||||
@Lazy
|
||||
@Component
|
||||
|
@ -183,13 +184,13 @@ public class OAuth2AuthorizationContextHolder implements AuthorizationContextHol
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean login(final String username, final String password) {
|
||||
public boolean login(final String username, final CharSequence password) {
|
||||
if (!this.valid || this.isLoggedIn()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.resource.setUsername(username);
|
||||
this.resource.setPassword(password);
|
||||
this.resource.setPassword(Utils.toString(password));
|
||||
|
||||
log.debug("Trying to login for user: {}", username);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public interface SEBServerAuthorizationContext {
|
|||
* @param username the username for login
|
||||
* @param password the password for login
|
||||
* @return */
|
||||
boolean login(String username, String password);
|
||||
boolean login(String username, CharSequence password);
|
||||
|
||||
/** Requests a logout on SEB Server webservice if a user is currently logged in
|
||||
* This uses OAuth 2 and Springs OAuth2RestTemplate to make a revoke token request for the
|
||||
|
|
Loading…
Reference in a new issue