Skip to content

Commit 314593b

Browse files
committed
UY-1175 remote reg allow using authenticator with regular input profile.
Fix DryRun step component, Fix Account Association
1 parent e8268ae commit 314593b

File tree

9 files changed

+104
-18
lines changed

9 files changed

+104
-18
lines changed

engine-api/src/main/java/pl/edu/icm/unity/engine/api/authn/remote/AuthenticationTriggeringContext.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package pl.edu.icm.unity.engine.api.authn.remote;
66

77
import pl.edu.icm.unity.engine.api.authn.PartialAuthnState;
8+
import pl.edu.icm.unity.engine.api.authn.sandbox.SandboxAuthnEvent;
89
import pl.edu.icm.unity.engine.api.authn.sandbox.SandboxAuthnRouter;
910
import pl.edu.icm.unity.types.authn.AuthenticationOptionKey;
1011
import pl.edu.icm.unity.types.registration.RegistrationForm;
@@ -32,13 +33,13 @@ private AuthenticationTriggeringContext(boolean rememberMeSet,
3233
this.authenticationOptionKey = authenticationOptionKey;
3334
}
3435

35-
public static AuthenticationTriggeringContext registrationTriggeredAuthn(RegistrationForm form,
36-
String invitationCode,
37-
AuthenticationOptionKey authenticationOptionKey)
36+
public static AuthenticationTriggeringContext registrationTriggeredAuthn(RegistrationForm form,
37+
String invitationCode, AuthenticationOptionKey authenticationOptionKey)
3838
{
3939
if (form == null)
4040
throw new IllegalArgumentException("Form must be set in registration triggered remote authn");
41-
return new AuthenticationTriggeringContext(false, null, form, invitationCode, null, authenticationOptionKey);
41+
return new AuthenticationTriggeringContext(false, null, form, invitationCode, new MockSandboxAuthnRouter(),
42+
authenticationOptionKey);
4243
}
4344

4445

@@ -90,4 +91,22 @@ public String toString()
9091
"AuthenticationTriggeringContext [rememberMeSet=%s, firstFactorAuthnState=%s, form=%s, invitationCode=%s]",
9192
rememberMeSet, firstFactorAuthnState, form, invitationCode);
9293
}
94+
95+
private static final class MockSandboxAuthnRouter implements SandboxAuthnRouter
96+
{
97+
@Override
98+
public void addListener(AuthnResultListener listener)
99+
{
100+
}
101+
102+
@Override
103+
public void removeListener(AuthnResultListener listener)
104+
{
105+
}
106+
107+
@Override
108+
public void fireEvent(SandboxAuthnEvent event)
109+
{
110+
}
111+
}
93112
}

engine-api/src/main/java/pl/edu/icm/unity/engine/api/authn/sandbox/SandboxAuthenticationResult.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package pl.edu.icm.unity.engine.api.authn.sandbox;
66

77
import pl.edu.icm.unity.engine.api.authn.AuthenticationResult;
8+
import pl.edu.icm.unity.engine.api.authn.RemoteAuthenticationResult;
89

910
public class SandboxAuthenticationResult implements AuthenticationResult
1011
{
@@ -66,5 +67,11 @@ public String toString()
6667
return baseResult.toString();
6768
}
6869

70+
@Override
71+
public RemoteAuthenticationResult asRemote()
72+
{
73+
return baseResult.asRemote();
74+
}
75+
6976

7077
}

engine-api/src/main/java/pl/edu/icm/unity/engine/api/translation/in/InputTranslationEngine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ public interface InputTranslationEngine
3838

3939
MappedIdentity getExistingIdentity(MappingResult result);
4040

41+
void preprocess(MappingResult result) throws EngineException;
42+
4143
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,21 @@ public PostAuthenticationStepDecision processFirstFactorSandboxAuthnResult(Sandb
231231
{
232232
authnState = basicAuthnProcessor.processPrimaryAuthnResult(result, stepContext.selectedAuthnFlow, null);
233233
assertNotFailed(authnState.getPrimaryResult());
234-
} catch (AuthenticationException e)
234+
} catch (UnknownRemoteUserException e)
235+
{
236+
sandboxRouter.fireEvent(new SandboxAuthnEvent(result.sandboxAuthnInfo, null,
237+
httpRequest.getSession() != null ? httpRequest.getSession().getId() : null));
238+
return PostAuthenticationStepDecision.completed();
239+
}
240+
241+
catch (AuthenticationException e)
235242
{
236243
sandboxRouter.fireEvent(new SandboxAuthnEvent(
237-
RemoteSandboxAuthnContext.failedAuthn(
238-
result.sandboxAuthnInfo.getAuthnException().orElse(e),
239-
result.sandboxAuthnInfo.getLogs(),
244+
RemoteSandboxAuthnContext.failedAuthn(result.sandboxAuthnInfo.getAuthnException().orElse(e),
245+
result.sandboxAuthnInfo.getLogs(),
240246
result.sandboxAuthnInfo.getRemotePrincipal()
241-
.map(RemotelyAuthenticatedPrincipal::getAuthnInput).orElse(null)),
242-
null,
243-
httpRequest.getSession().getId()));
247+
.map(RemotelyAuthenticatedPrincipal::getAuthnInput).orElse(null)),
248+
null, httpRequest.getSession().getId()));
244249
return interpretAuthnException(e, httpRequest, machineDetails.getIp());
245250
}
246251

engine/src/main/java/pl/edu/icm/unity/engine/authn/remote/RemoteAuthnResponseProcessorImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ private PostAuthenticationStepDecision processResponseInSandboxMode(RedirectedAu
7777
HttpServletRequest httpRequest,
7878
AuthenticationTriggeringContext triggeringContext)
7979
{
80+
8081
SandboxAuthenticationResult authnResult = executeVerificatorInSandboxMode(
8182
authnContext::processAnswer, triggeringContext);
83+
if (triggeringContext.isRegistrationTriggered())
84+
{
85+
return authnProcessor.processRemoteRegistrationResult(authnResult,
86+
authnContext.getAuthenticationStepContext(),
87+
authnContext.getInitialLoginMachine(),
88+
httpRequest);
89+
}
90+
8291
return processSandboxAuthenticationResult(authnContext, httpRequest, authnResult);
8392
}
8493

engine/src/main/java/pl/edu/icm/unity/engine/authn/remote/RemoteAuthnResultTranslatorImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ public RemoteAuthenticationResult getTranslatedResult(RemotelyAuthenticatedInput
113113
throw new RemoteAuthenticationException("The mapping of the remotely authenticated " +
114114
"principal to a local representation failed", e);
115115
}
116-
return dryRun ? assembleDryRunAuthenticationResult(remotePrincipal) :
116+
return dryRun ? assembleDryRunAuthenticationResult(remotePrincipal, registrationForm, allowAssociation) :
117117
assembleAuthenticationResult(remotePrincipal, registrationForm, allowAssociation);
118118
}
119119

120-
private RemoteAuthenticationResult assembleDryRunAuthenticationResult(RemotelyAuthenticatedPrincipal remotePrincipal)
120+
private RemoteAuthenticationResult assembleDryRunAuthenticationResult(RemotelyAuthenticatedPrincipal remotePrincipal,
121+
String registrationForm, boolean allowAssociation)
121122
{
122123
AuthenticatedEntity authenticatedEntity = null;
123124
if (remotePrincipal.getLocalMappedPrincipal() != null)
@@ -129,6 +130,9 @@ private RemoteAuthenticationResult assembleDryRunAuthenticationResult(RemotelyAu
129130
{
130131
log.debug("Exception resolving remote principal", e);
131132
}
133+
} else
134+
{
135+
return handleUnknownUser(remotePrincipal, registrationForm, allowAssociation);
132136
}
133137
return RemoteAuthenticationResult.successfulPartial(remotePrincipal, authenticatedEntity);
134138
}
@@ -217,6 +221,7 @@ public final RemotelyAuthenticatedPrincipal translateRemoteInput(RemotelyAuthent
217221
result.addIdentity(new MappedIdentity(IdentityEffectMode.REQUIRE_MATCH,
218222
presetIdParam, null));
219223
}
224+
trEngine.preprocess(result);
220225
if (!dryRun)
221226
trEngine.process(result);
222227

engine/src/main/java/pl/edu/icm/unity/engine/translation/in/InputTranslationEngineImpl.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,35 @@ public InputTranslationEngineImpl(@Qualifier("insecure") EntityManagement idsMan
7777
this.attrTypeHelper = attrTypeHelper;
7878
}
7979

80+
81+
@Override
82+
public void preprocess(MappingResult result) throws EngineException
83+
{
84+
Entity existing = null;
85+
for (MappedIdentity checked : result.getIdentities())
86+
{
87+
try
88+
{
89+
Entity found = idsMan.getEntity(new EntityParam(checked.getIdentity()));
90+
if (existing != null && !existing.getId().equals(found.getId()))
91+
{
92+
log.warn("Identity was mapped to two different entities: " + existing + " and "
93+
+ found);
94+
throw new ExecutionBreakException();
95+
}
96+
existing = found;
97+
result.addAuthenticatedWith(checked.getIdentity().getValue());
98+
} catch (IllegalArgumentException e)
99+
{
100+
log.trace("Identity " + checked + " not found in DB, details of exception follows", e);
101+
}
102+
}
103+
if (existing != null)
104+
{
105+
result.setMappedToExistingEntity(new EntityParam(existing.getId()));
106+
}
107+
}
108+
80109
@Override
81110
public void process(MappingResult result) throws EngineException
82111
{
@@ -180,7 +209,7 @@ private EntityParam processIdentities(MappingResult result, Set<Attribute> proce
180209
throw new ExecutionBreakException();
181210
}
182211
existing = found;
183-
result.addAuthenticatedWith(checked.getIdentity().getValue());
212+
//result.addAuthenticatedWith(checked.getIdentity().getValue());
184213
} catch (IllegalArgumentException e)
185214
{
186215
log.trace("Identity " + checked + " not found in DB, details of exception follows", e);

web-common/src/main/java/pl/edu/icm/unity/webui/association/atlogin/MergeUnknownWithExistingConfirmationStep.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,26 @@ class MergeUnknownWithExistingConfirmationStep extends AbstractConfirmationStep
3737
void setAuthenticatedUser(AuthenticatedEntity ae)
3838
{
3939
locallyAuthenticatedEntity = ae;
40-
introLabel.setHtmlValue("MergeUnknownWithExistingConfirmationStep.info",
41-
unknownUser.getRemoteIdPName(),
42-
locallyAuthenticatedEntity.getAuthenticatedWith().get(0));
40+
if (ae != null)
41+
{
42+
introLabel.setHtmlValue("MergeUnknownWithExistingConfirmationStep.info", unknownUser.getRemoteIdPName(),
43+
locallyAuthenticatedEntity.getAuthenticatedWith().get(0));
44+
} else
45+
{
46+
introLabel.setHtmlValue("MergeUnknownWithExistingConfirmationStep.errorNotExistingIdentity");
47+
//block finish button
48+
errorComponent.setVisible(true);
49+
}
4350
}
4451

4552
@Override
4653
protected void merge()
4754
{
4855
if (locallyAuthenticatedEntity == null)
56+
{
57+
NotificationPopup.showError(msg.getMessage("ConnectId.ConfirmStep.mergeFailed"), "");
4958
return;
59+
}
5060
EntityParam existing = new EntityParam(locallyAuthenticatedEntity.getEntityId());
5161
try
5262
{

web-console/src/main/java/io/imunity/webconsole/translationProfile/dryrun/DryRunStepComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class DryRunStepComponent extends CustomComponent
9393
void handle(SandboxAuthnEvent event)
9494
{
9595
RemoteSandboxAuthnContext ctx = (RemoteSandboxAuthnContext) event.ctx;
96-
if (ctx.getAuthnException() == null)
96+
if (!ctx.getAuthnException().isPresent())
9797
{
9898
authnResultLabel.setValue(msg.getMessage("DryRun.DryRunStepComponent.authnResultLabel.success"));
9999
authnResultLabel.setStyleName(Styles.success.toString());

0 commit comments

Comments
 (0)