mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
Moved AuthenticationManager to sse.security.ui
This commit is contained in:
1 parent
ea2f788e3e
commit
8e46d3d0e8
17 files changed
+28
-21
No files matched your search
+33
@@ -0,0 +1,33 @@
|
||||
package com.sap.sse.security.ui.authentication;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
import com.sap.sse.security.ui.authentication.app.AuthenticationContext;
|
||||
|
||||
public class AuthenticationContextEvent extends GwtEvent<AuthenticationContextEvent.Handler> {
|
||||
public static final Type<Handler> TYPE = new Type<AuthenticationContextEvent.Handler>();
|
||||
|
||||
private final AuthenticationContext ctx;
|
||||
|
||||
public interface Handler extends EventHandler {
|
||||
void onUserChangeEvent(AuthenticationContextEvent event);
|
||||
}
|
||||
|
||||
public AuthenticationContextEvent(AuthenticationContext ctx) {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
public AuthenticationContext getCtx() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<Handler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatch(Handler handler) {
|
||||
handler.onUserChangeEvent(this);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.sap.sse.security.ui.authentication;
|
||||
|
||||
import com.sap.sse.security.ui.authentication.app.AuthenticationContext;
|
||||
import com.sap.sse.security.ui.shared.UserDTO;
|
||||
|
||||
public interface AuthenticationManager {
|
||||
|
||||
AuthenticationContext getAuthenticationContext();
|
||||
void didLogin(UserDTO user);
|
||||
void didLogout();
|
||||
void refreshUser();
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package com.sap.sse.security.ui.authentication;
|
||||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sap.sse.security.ui.authentication.app.AuthenticationContext;
|
||||
import com.sap.sse.security.ui.authentication.app.AuthenticationContextImpl;
|
||||
import com.sap.sse.security.ui.client.UserManagementServiceAsync;
|
||||
import com.sap.sse.security.ui.client.UserStatusEventHandler;
|
||||
import com.sap.sse.security.ui.client.WithSecurity;
|
||||
import com.sap.sse.security.ui.shared.SuccessInfo;
|
||||
import com.sap.sse.security.ui.shared.UserDTO;
|
||||
|
||||
public class AuthenticationManagerImpl implements AuthenticationManager {
|
||||
private final WithSecurity clientFactory;
|
||||
private AuthenticationContext uCtx = new AuthenticationContextImpl();
|
||||
private final EventBus eventBus;
|
||||
|
||||
public AuthenticationManagerImpl(final WithSecurity clientFactory, final EventBus eventBus) {
|
||||
this.clientFactory = clientFactory;
|
||||
this.eventBus = eventBus;
|
||||
clientFactory.getUserService().addUserStatusEventHandler(new UserStatusEventHandler() {
|
||||
@Override
|
||||
public void onUserStatusChange(UserDTO user) {
|
||||
uCtx = new AuthenticationContextImpl(user);
|
||||
eventBus.fireEvent(new AuthenticationContextEvent(uCtx));
|
||||
}
|
||||
});
|
||||
eventBus.addHandler(AuthenticationRequestEvent.TYPE, new AuthenticationRequestEvent.Handler() {
|
||||
@Override
|
||||
public void onUserManagementRequestEvent(AuthenticationRequestEvent event) {
|
||||
if (!event.isLogin()) {
|
||||
clientFactory.getUserManagementService().logout(new AsyncCallback<SuccessInfo>() {
|
||||
@Override
|
||||
public void onSuccess(SuccessInfo result) {
|
||||
didLogout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
didLogout();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthenticationContext getAuthenticationContext() {
|
||||
return uCtx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didLogout() {
|
||||
uCtx = new AuthenticationContextImpl();
|
||||
clientFactory.getUserService().updateUser(true);
|
||||
eventBus.fireEvent(new AuthenticationRequestEvent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didLogin(UserDTO user) {
|
||||
uCtx = new AuthenticationContextImpl(user);
|
||||
clientFactory.getUserService().updateUser(true);
|
||||
eventBus.fireEvent(new AuthenticationContextEvent(uCtx));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUser() {
|
||||
clientFactory.getUserManagementService().getCurrentUser(new AsyncCallback<UserDTO>() {
|
||||
@Override
|
||||
public void onSuccess(UserDTO result) {
|
||||
didLogin(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO change to package private or remove
|
||||
public UserManagementServiceAsync getUserManagementService() {
|
||||
return clientFactory.getUserManagementService();
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.sap.sse.security.ui.authentication;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
public class AuthenticationRequestEvent extends GwtEvent<AuthenticationRequestEvent.Handler> {
|
||||
public static final Type<Handler> TYPE = new Type<AuthenticationRequestEvent.Handler>();
|
||||
|
||||
public interface Handler extends EventHandler {
|
||||
void onUserManagementRequestEvent(AuthenticationRequestEvent event);
|
||||
}
|
||||
|
||||
private final boolean login;
|
||||
|
||||
public AuthenticationRequestEvent() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public AuthenticationRequestEvent(boolean login) {
|
||||
super();
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public boolean isLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<Handler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatch(Handler handler) {
|
||||
handler.onUserManagementRequestEvent(this);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user