Skip to content

Commit f435a3f

Browse files
committed
UY-1184 outdated credential handling moved to AuthenticationUI
also improved info message handling after change
1 parent 314593b commit f435a3f

File tree

8 files changed

+79
-45
lines changed

8 files changed

+79
-45
lines changed

engine/src/main/java/pl/edu/icm/unity/engine/authn/InteractiveAuthneticationProcessorImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public PostAuthenticationStepDecision processFirstFactorResult(AuthenticationRes
143143
AuthenticationProcessor.extractParticipants(result), sessionReinitializer, httpResponse);
144144

145145
setLastIdpCookie(httpResponse, stepContext.authnOptionId, stepContext.endpointPath);
146-
log.info("Successful authentication after first factor for {}", result);
147146
return PostAuthenticationStepDecision.completed();
148147
}
149148

engine/src/main/java/pl/edu/icm/unity/engine/authz/InternalAuthorizationManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public boolean isSelf(long subject)
281281

282282
private Set<AuthzCapability> getRoleCapabilities(Set<AuthzRole> roles, boolean selfAccess)
283283
{
284-
Set<AuthzCapability> ret = new HashSet<AuthzCapability>();
284+
Set<AuthzCapability> ret = new HashSet<>();
285285
for (AuthzRole role: roles)
286286
Collections.addAll(ret, role.getCapabilities(selfAccess));
287287
return ret;

web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationUI.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ protected void appInit(final VaadinRequest request)
126126
formLauncher, sandboxRouter, inputTranslationEngine,
127127
getSandboxServletURLForAssociation());
128128
authenticationUI = ColumnInstantAuthenticationScreen.getInstance(msg, imageAccessService, config, endpointDescription,
129-
this::showOutdatedCredentialDialog,
130129
new CredentialResetLauncherImpl(),
131130
this::showRegistration,
132131
cancelHandler, idsMan, execService,
@@ -140,6 +139,7 @@ protected void appInit(final VaadinRequest request)
140139

141140
private void loadInitialState()
142141
{
142+
LOG.debug("Loading initial state of authentication UI");
143143
WrappedSession session = VaadinSession.getCurrent().getSession();
144144
PostAuthenticationDecissionWithContext postAuthnStepDecision = (PostAuthenticationDecissionWithContext) session
145145
.getAttribute(RemoteRedirectedAuthnResponseProcessingFilter.DECISION_SESSION_ATTRIBUTE);
@@ -158,35 +158,37 @@ private void loadInitialState()
158158
}
159159
} else
160160
{
161-
setContent(authenticationUI);
161+
if (isUserAuthenticatedWithOutdatedCredential())
162+
showOutdatedCredentialDialog();
163+
else
164+
setContent(authenticationUI);
162165
}
163166
}
164167

165-
166168
/**
167169
* We may end up in authentication UI also after being properly logged in,
168170
* when the credential is outdated. The credential change dialog must be displayed then.
169171
*/
170-
private boolean showOutdatedCredentialDialog()
172+
private boolean isUserAuthenticatedWithOutdatedCredential()
171173
{
172174
WrappedSession vss = VaadinSession.getCurrent().getSession();
173175
LoginSession ls = (LoginSession) vss.getAttribute(LoginToHttpSessionBinder.USER_SESSION_KEY);
174-
if (ls != null && ls.isUsedOutdatedCredential())
175-
{
176-
CredentialChangeConfiguration uiConfig = new CredentialChangeConfiguration(
177-
config.getValue(VaadinEndpointProperties.AUTHN_LOGO),
178-
getFirstColumnWidth(),
179-
config.getBooleanValue(VaadinEndpointProperties.CRED_RESET_COMPACT));
180-
181-
182-
OutdatedCredentialController outdatedCredentialController = outdatedCredentialDialogFactory.getObject();
183-
outdatedCredentialController.init(uiConfig, authnProcessor, this::resetToFreshAuthenticationScreen);
184-
setContent(outdatedCredentialController.getComponent());
185-
return true;
186-
}
187-
return false;
176+
return ls != null && ls.isUsedOutdatedCredential();
188177
}
189178

179+
private void showOutdatedCredentialDialog()
180+
{
181+
CredentialChangeConfiguration uiConfig = new CredentialChangeConfiguration(
182+
config.getValue(VaadinEndpointProperties.AUTHN_LOGO),
183+
getFirstColumnWidth(),
184+
config.getBooleanValue(VaadinEndpointProperties.CRED_RESET_COMPACT));
185+
186+
OutdatedCredentialController outdatedCredentialController = outdatedCredentialDialogFactory.getObject();
187+
outdatedCredentialController.init(uiConfig, authnProcessor, this::resetToFreshAuthenticationScreen);
188+
setContent(outdatedCredentialController.getComponent());
189+
}
190+
191+
190192
private float getFirstColumnWidth()
191193
{
192194
Iterator<String> columnKeys = config.getStructuredListKeys(AUTHN_COLUMNS_PFX).iterator();

web-common/src/main/java/pl/edu/icm/unity/webui/authn/column/ColumnInstantAuthenticationScreen.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.List;
1111
import java.util.Optional;
1212
import java.util.function.Function;
13-
import java.util.function.Supplier;
1413

1514
import org.apache.logging.log4j.Logger;
1615

@@ -37,8 +36,8 @@
3736
import pl.edu.icm.unity.engine.api.authn.InteractiveAuthenticationProcessor;
3837
import pl.edu.icm.unity.engine.api.authn.InteractiveAuthenticationProcessor.PostAuthenticationStepDecision;
3938
import pl.edu.icm.unity.engine.api.authn.PartialAuthnState;
40-
import pl.edu.icm.unity.engine.api.authn.UnsuccessfulAuthenticationCounter;
4139
import pl.edu.icm.unity.engine.api.authn.RemoteAuthenticationResult.UnknownRemotePrincipalResult;
40+
import pl.edu.icm.unity.engine.api.authn.UnsuccessfulAuthenticationCounter;
4241
import pl.edu.icm.unity.engine.api.server.HTTPRequestContext;
4342
import pl.edu.icm.unity.engine.api.utils.ExecutorsService;
4443
import pl.edu.icm.unity.types.authn.AuthenticationOptionKey;
@@ -73,7 +72,6 @@ public class ColumnInstantAuthenticationScreen extends CustomComponent implement
7372
private final ImageAccessService imageAccessService;
7473
private final VaadinEndpointProperties config;
7574
private final ResolvedEndpoint endpointDescription;
76-
private final Supplier<Boolean> outdatedCredentialDialogLauncher;
7775
private final Runnable registrationLayoutLauncher;
7876
private final boolean enableRegistration;
7977
private final CancelHandler cancelHandler;
@@ -99,7 +97,6 @@ public class ColumnInstantAuthenticationScreen extends CustomComponent implement
9997
protected ColumnInstantAuthenticationScreen(MessageSource msg, ImageAccessService imageAccessService,
10098
VaadinEndpointProperties config,
10199
ResolvedEndpoint endpointDescription,
102-
Supplier<Boolean> outdatedCredentialDialogLauncher,
103100
CredentialResetLauncher credentialResetLauncher,
104101
Runnable registrationLayoutLauncher, CancelHandler cancelHandler,
105102
EntityManagement idsMan,
@@ -112,7 +109,6 @@ protected ColumnInstantAuthenticationScreen(MessageSource msg, ImageAccessServic
112109
this.msg = msg;
113110
this.config = config;
114111
this.endpointDescription = endpointDescription;
115-
this.outdatedCredentialDialogLauncher = outdatedCredentialDialogLauncher;
116112
this.credentialResetLauncher = credentialResetLauncher;
117113
this.registrationLayoutLauncher = registrationLayoutLauncher;
118114
this.cancelHandler = cancelHandler;
@@ -129,7 +125,6 @@ protected ColumnInstantAuthenticationScreen(MessageSource msg, ImageAccessServic
129125
public static ColumnInstantAuthenticationScreen getInstance(MessageSource msg, ImageAccessService imageAccessService,
130126
VaadinEndpointProperties config,
131127
ResolvedEndpoint endpointDescription,
132-
Supplier<Boolean> outdatedCredentialDialogLauncher,
133128
CredentialResetLauncher credentialResetLauncher,
134129
Runnable registrationLayoutLauncher, CancelHandler cancelHandler,
135130
EntityManagement idsMan,
@@ -140,7 +135,7 @@ public static ColumnInstantAuthenticationScreen getInstance(MessageSource msg, I
140135
InteractiveAuthenticationProcessor interactiveAuthnProcessor)
141136
{
142137
ColumnInstantAuthenticationScreen instance = new ColumnInstantAuthenticationScreen(msg,
143-
imageAccessService, config, endpointDescription, outdatedCredentialDialogLauncher,
138+
imageAccessService, config, endpointDescription,
144139
credentialResetLauncher, registrationLayoutLauncher, cancelHandler, idsMan, execService,
145140
enableRegistration, unknownUserDialogProvider, localeChoice, flows,
146141
interactiveAuthnProcessor);
@@ -176,12 +171,6 @@ protected final void init()
176171
topLevelLayout.setComponentAlignment(authnOptionsComponent, Alignment.MIDDLE_CENTER);
177172

178173
log.debug("Authn screen init finished loading authenticators");
179-
180-
if (outdatedCredentialDialogLauncher.get())
181-
{
182-
log.info("Launched outdated credential dialog");
183-
return;
184-
}
185174
}
186175

187176
/**

web-common/src/main/java/pl/edu/icm/unity/webui/authn/extensions/PasswordRetrieval.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ private void triggerAuthentication()
204204

205205
if (password.equals(""))
206206
{
207-
NotificationPopup.showError(msg.getMessage("AuthenticationUI.authnErrorTitle"),
207+
NotificationPopup.showErrorAutoClosing(msg.getMessage("AuthenticationUI.authnErrorTitle"),
208208
msg.getMessage("WebPasswordRetrieval.noPassword"));
209209
} else if (username.equals(""))
210210
{
211-
NotificationPopup.showError(msg.getMessage("AuthenticationUI.authnErrorTitle"),
211+
NotificationPopup.showErrorAutoClosing(msg.getMessage("AuthenticationUI.authnErrorTitle"),
212212
msg.getMessage("WebPasswordRetrieval.noUser"));
213213
} else
214214
{

web-common/src/main/java/pl/edu/icm/unity/webui/authn/outdated/OutdatedCredentialController.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,21 @@ private CredentialDefinition getCredentialDefinition()
127127

128128
private void afterCredentialUpdate(boolean changed)
129129
{
130-
finishHandler.run();
131-
authnProcessor.logout(true);
130+
ui.setEnabled(false);
132131
if (changed)
133132
{
134-
NotificationPopup.showSuccess(msg.getMessage("OutdatedCredentialDialog.finalOK"),
135-
msg.getMessage("OutdatedCredentialDialog.finalInfo"));
133+
NotificationPopup.showWarningAutoClosing(msg.getMessage("OutdatedCredentialDialog.finalOK"),
134+
msg.getMessage("OutdatedCredentialDialog.finalInfo"), this::cleanup);
136135
} else
137136
{
138-
NotificationPopup.showError(msg.getMessage("OutdatedCredentialDialog.finalError"),
139-
msg.getMessage("OutdatedCredentialDialog.finalInfoNotChanged"));
137+
NotificationPopup.showWarningAutoClosing(msg.getMessage("OutdatedCredentialDialog.finalError"),
138+
msg.getMessage("OutdatedCredentialDialog.finalInfoNotChanged"), this::cleanup);
140139
}
141140
}
141+
142+
private void cleanup()
143+
{
144+
finishHandler.run();
145+
authnProcessor.logout(true);
146+
}
142147
}

web-common/src/main/java/pl/edu/icm/unity/webui/common/NotificationPopup.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,57 @@ public static void showError(String caption, String description)
5454
ValoTheme.NOTIFICATION_CLOSABLE);
5555
}
5656

57+
public static void showWarningAutoClosing(String caption, String description, Runnable afterCloseHandler)
58+
{
59+
showAutoClosing(getWarningNotificationPlain(caption, description), Position.MIDDLE_CENTER, afterCloseHandler);
60+
}
61+
62+
public static void showErrorAutoClosing(String caption, String description, Runnable afterCloseHandler)
63+
{
64+
showAutoClosing(getErrorNotificationPlain(caption, description), Position.TOP_CENTER, afterCloseHandler);
65+
}
66+
67+
public static void showAssistiveAutoClosing(String caption, String description)
68+
{
69+
showAutoClosing(getAssistiveNotificationPlain(caption, description), Position.TOP_CENTER, () -> {});
70+
}
71+
5772
public static void showErrorAutoClosing(String caption, String description)
5873
{
59-
Notification notification = new Notification(caption, description, Type.ERROR_MESSAGE);
60-
notification.setIcon(Images.error.getResource());
74+
showAutoClosing(getErrorNotificationPlain(caption, description), Position.TOP_CENTER, () -> {});
75+
}
76+
77+
private static void showAutoClosing(Notification notification, Position position, Runnable afterCloseHandler)
78+
{
6179
notification.setDelayMsec((int)NOTIFICATION_AUTOCLOSE_AFTER.toMillis());
6280
StringBuilder sb = new StringBuilder(notification.getStyleName());
6381
sb.append(" ").append(Styles.veryLargeIcon.toString());
64-
notification.setPosition(Position.TOP_CENTER);
82+
notification.setPosition(position);
83+
notification.addCloseListener(e -> afterCloseHandler.run());
6584
notification.show(Page.getCurrent());
6685
}
6786

87+
private static Notification getWarningNotificationPlain(String caption, String description)
88+
{
89+
Notification notification = new Notification(caption, description, Type.WARNING_MESSAGE);
90+
notification.setIcon(Images.info.getResource());
91+
return notification;
92+
}
93+
94+
private static Notification getAssistiveNotificationPlain(String caption, String description)
95+
{
96+
Notification notification = new Notification(caption, description, Type.ASSISTIVE_NOTIFICATION);
97+
notification.setIcon(Images.info.getResource());
98+
return notification;
99+
}
100+
101+
private static Notification getErrorNotificationPlain(String caption, String description)
102+
{
103+
Notification notification = new Notification(caption, description, Type.ERROR_MESSAGE);
104+
notification.setIcon(Images.error.getResource());
105+
return notification;
106+
}
107+
68108
public static void showError(ControllerException exception)
69109
{
70110
if (exception.getType() == pl.edu.icm.unity.webui.exceptions.ControllerException.Type.ERROR)

web-common/src/main/java/pl/edu/icm/unity/webui/sandbox/SandboxAuthenticationScreen.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class SandboxAuthenticationScreen extends ColumnInstantAuthenticationScreen
7777
prepareConfigurationBasingOnEndpoint(config.getProperties(), title) :
7878
prepareFreshConfigurationWithAllOptions(title, authenticators),
7979
endpointDescription,
80-
() -> false,
8180
new NoOpCredentialRestLauncher(),
8281
() -> {},
8382
cancelHandler, idsMan,

0 commit comments

Comments
 (0)