mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-03 10:53:49 +00:00
added a first version of a simple UserStatusPanel. The displayed logout button won't work as long as we use basic authentication.
This commit is contained in:
1 parent
d6b7eb2e03
commit
550ef49668
5 files changed
+114
-3
No files matched your search
+4
-2
@@ -18,6 +18,7 @@ import com.sap.sailing.gwt.ui.leaderboard.LeaderboardPanel;
|
||||
import com.sap.sailing.gwt.ui.leaderboard.LeaderboardSettings;
|
||||
import com.sap.sailing.gwt.ui.leaderboard.LeaderboardSettingsFactory;
|
||||
import com.sap.sailing.gwt.ui.shared.EventDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.panels.UserStatusPanel;
|
||||
|
||||
public class AdminConsoleEntryPoint extends AbstractEntryPoint implements EventRefresher {
|
||||
private Set<EventDisplayer> eventDisplayers;
|
||||
@@ -26,11 +27,12 @@ public class AdminConsoleEntryPoint extends AbstractEntryPoint implements EventR
|
||||
public void onModuleLoad() {
|
||||
super.onModuleLoad();
|
||||
RootPanel rootPanel = RootPanel.get();
|
||||
rootPanel.setSize("95%", "95%");
|
||||
rootPanel.setSize("100%", "100%");
|
||||
|
||||
rootPanel.add(new UserStatusPanel(userManagementService, this));
|
||||
TabPanel tabPanel = new TabPanel();
|
||||
tabPanel.setAnimationEnabled(true);
|
||||
rootPanel.add(tabPanel, 10, 10);
|
||||
rootPanel.add(tabPanel); //, 10, 10);
|
||||
tabPanel.setSize("95%", "95%");
|
||||
|
||||
eventDisplayers = new HashSet<EventDisplayer>();
|
||||
|
||||
+3
-1
@@ -8,6 +8,8 @@ import com.sap.sailing.gwt.ui.shared.UserDTO;
|
||||
public interface UserManagementService extends RemoteService {
|
||||
|
||||
public boolean isUserInRole(String userRole);
|
||||
|
||||
|
||||
public void logoutUser();
|
||||
|
||||
public UserDTO getUser();
|
||||
}
|
||||
+2
@@ -9,4 +9,6 @@ public interface UserManagementServiceAsync {
|
||||
|
||||
void getUser(AsyncCallback<UserDTO> callback);
|
||||
|
||||
void logoutUser(AsyncCallback<Void> callback);
|
||||
|
||||
}
|
||||
+10
@@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.sap.sailing.gwt.ui.client.UserManagementService;
|
||||
@@ -23,6 +24,15 @@ public class UserManagementServiceImpl extends RemoteServiceServlet implements
|
||||
return getThreadLocalRequest().isUserInRole(userRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logoutUser() {
|
||||
HttpSession session = getThreadLocalRequest().getSession();
|
||||
if(session != null) {
|
||||
session.invalidate();
|
||||
session = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDTO getUser() {
|
||||
HttpServletRequest threadLocalRequest = getThreadLocalRequest();
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package com.sap.sailing.gwt.ui.shared.panels;
|
||||
|
||||
import com.google.gwt.dom.client.Style;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.sap.sailing.gwt.ui.client.ErrorReporter;
|
||||
import com.sap.sailing.gwt.ui.client.UserManagementServiceAsync;
|
||||
import com.sap.sailing.gwt.ui.shared.UserDTO;
|
||||
|
||||
public class UserStatusPanel extends FlowPanel {
|
||||
|
||||
private UserDTO user;
|
||||
|
||||
private final Label userNameLabel;
|
||||
|
||||
private final Label userNameText;
|
||||
|
||||
private final Label userRolesText;
|
||||
|
||||
private final Button logoutButton;
|
||||
|
||||
public UserStatusPanel(final UserManagementServiceAsync userManagementService, final ErrorReporter errorReporter) {
|
||||
super();
|
||||
|
||||
userNameLabel = new Label("User:");
|
||||
userNameText = new Label("");
|
||||
userRolesText = new Label("");
|
||||
user = null;
|
||||
|
||||
logoutButton = new Button("Logout");
|
||||
|
||||
userManagementService.getUser(new AsyncCallback<UserDTO>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
errorReporter.reportError("Could not read user: " + caught.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(UserDTO result) {
|
||||
updateUser(result);
|
||||
}
|
||||
});
|
||||
|
||||
logoutButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent click) {
|
||||
userManagementService.logoutUser(
|
||||
new AsyncCallback<Void>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
errorReporter.reportError("Error during logout of the user: " + caught.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
errorReporter.reportError("Basic authentication does not support a server side 'Logout'. Please close the browser to logout.");
|
||||
// Window.Location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
addFloatingWidget(userNameLabel);
|
||||
addFloatingWidget(userNameText);
|
||||
addFloatingWidget(userRolesText);
|
||||
add(logoutButton);
|
||||
|
||||
updateUser(user);
|
||||
}
|
||||
|
||||
private void addFloatingWidget(Widget w) {
|
||||
w.getElement().getStyle().setFloat(Style.Float.LEFT);
|
||||
w.getElement().getStyle().setPadding(3, Style.Unit.PX);
|
||||
add(w);
|
||||
}
|
||||
|
||||
private void updateUser(UserDTO newUser) {
|
||||
this.user = newUser;
|
||||
|
||||
if(user != null) {
|
||||
userNameText.setText(user.principalName);
|
||||
userRolesText.setText(user.roles.toString());
|
||||
logoutButton.setEnabled(true);
|
||||
} else {
|
||||
userNameText.setText("Unknown");
|
||||
userRolesText.setText("Unknown");
|
||||
logoutButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user