Skip to content

Commit fdf7746

Browse files
committed
UY-1175 CR-505 fixes
1 parent f435a3f commit fdf7746

File tree

4 files changed

+41
-43
lines changed

4 files changed

+41
-43
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,4 @@ public interface InputTranslationEngine
3737
Entity resolveMappedIdentity(MappedIdentity checked) throws EngineException;
3838

3939
MappedIdentity getExistingIdentity(MappingResult result);
40-
41-
void preprocess(MappingResult result) throws EngineException;
42-
4340
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ public PostAuthenticationStepDecision processFirstFactorSandboxAuthnResult(Sandb
235235
sandboxRouter.fireEvent(new SandboxAuthnEvent(result.sandboxAuthnInfo, null,
236236
httpRequest.getSession() != null ? httpRequest.getSession().getId() : null));
237237
return PostAuthenticationStepDecision.completed();
238-
}
239-
240-
catch (AuthenticationException e)
238+
} catch (AuthenticationException e)
241239
{
242240
sandboxRouter.fireEvent(new SandboxAuthnEvent(
243241
RemoteSandboxAuthnContext.failedAuthn(result.sandboxAuthnInfo.getAuthnException().orElse(e),
@@ -252,8 +250,8 @@ public PostAuthenticationStepDecision processFirstFactorSandboxAuthnResult(Sandb
252250
return PostAuthenticationStepDecision.goToSecondFactor(new SecondFactorDetail(authnState));
253251

254252
AuthenticatedEntity authnEntity = basicAuthnProcessor.finalizeAfterPrimaryAuthentication(authnState, false);
255-
sandboxRouter.fireEvent(new SandboxAuthnEvent(result.sandboxAuthnInfo, authnEntity,
256-
httpRequest.getSession().getId()));
253+
sandboxRouter.fireEvent(
254+
new SandboxAuthnEvent(result.sandboxAuthnInfo, authnEntity, httpRequest.getSession().getId()));
257255
return PostAuthenticationStepDecision.completed();
258256
}
259257

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
import org.apache.logging.log4j.Logger;
1515
import org.springframework.beans.factory.annotation.Autowired;
16+
import org.springframework.beans.factory.annotation.Qualifier;
1617
import org.springframework.stereotype.Component;
1718

1819
import eu.unicore.util.configuration.ConfigurationException;
1920
import pl.edu.icm.unity.base.utils.Log;
21+
import pl.edu.icm.unity.engine.api.EntityManagement;
2022
import pl.edu.icm.unity.engine.api.authn.AuthenticatedEntity;
2123
import pl.edu.icm.unity.engine.api.authn.AuthenticationResult;
2224
import pl.edu.icm.unity.engine.api.authn.RemoteAuthenticationException;
@@ -32,12 +34,14 @@
3234
import pl.edu.icm.unity.engine.api.translation.in.MappedGroup;
3335
import pl.edu.icm.unity.engine.api.translation.in.MappedIdentity;
3436
import pl.edu.icm.unity.engine.api.translation.in.MappingResult;
37+
import pl.edu.icm.unity.engine.translation.ExecutionBreakException;
3538
import pl.edu.icm.unity.engine.translation.in.InputTranslationProfile;
3639
import pl.edu.icm.unity.engine.translation.in.InputTranslationProfileRepository;
3740
import pl.edu.icm.unity.exceptions.EngineException;
3841
import pl.edu.icm.unity.exceptions.IllegalIdentityValueException;
3942
import pl.edu.icm.unity.store.api.tx.Transactional;
4043
import pl.edu.icm.unity.types.basic.Attribute;
44+
import pl.edu.icm.unity.types.basic.Entity;
4145
import pl.edu.icm.unity.types.basic.EntityParam;
4246
import pl.edu.icm.unity.types.basic.IdentityParam;
4347
import pl.edu.icm.unity.types.basic.IdentityTaV;
@@ -51,18 +55,20 @@ class RemoteAuthnResultTranslatorImpl implements RemoteAuthnResultTranslator
5155
private final IdentityResolver identityResolver;
5256
private final InputTranslationEngine trEngine;
5357
private final InputTranslationActionsRegistry actionsRegistry;
54-
58+
private final EntityManagement idsMan;
5559

5660
@Autowired
5761
RemoteAuthnResultTranslatorImpl(IdentityResolver identityResolver,
5862
InputTranslationProfileRepository profileRepo,
5963
InputTranslationEngine trEngine,
60-
InputTranslationActionsRegistry actionsRegistry)
64+
InputTranslationActionsRegistry actionsRegistry,
65+
@Qualifier("insecure") EntityManagement idsMan)
6166
{
6267
this.identityResolver = identityResolver;
6368
this.inputProfileRepo = profileRepo;
6469
this.trEngine = trEngine;
6570
this.actionsRegistry = actionsRegistry;
71+
this.idsMan = idsMan;
6672
}
6773

6874
@Override
@@ -72,7 +78,6 @@ public RemoteAuthenticationResult getTranslatedResult(RemotelyAuthenticatedInput
7278
String registrationForm, boolean allowAssociation)
7379
throws RemoteAuthenticationException
7480
{
75-
7681
TranslationProfile translationProfile;
7782
try
7883
{
@@ -132,7 +137,7 @@ private RemoteAuthenticationResult assembleDryRunAuthenticationResult(RemotelyAu
132137
}
133138
} else
134139
{
135-
return handleUnknownUser(remotePrincipal, registrationForm, allowAssociation);
140+
return handleUnknownUser(remotePrincipal, registrationForm, allowAssociation);
136141
}
137142
return RemoteAuthenticationResult.successfulPartial(remotePrincipal, authenticatedEntity);
138143
}
@@ -221,7 +226,7 @@ public final RemotelyAuthenticatedPrincipal translateRemoteInput(RemotelyAuthent
221226
result.addIdentity(new MappedIdentity(IdentityEffectMode.REQUIRE_MATCH,
222227
presetIdParam, null));
223228
}
224-
trEngine.preprocess(result);
229+
setMappingToExistingEntity(result);
225230
if (!dryRun)
226231
trEngine.process(result);
227232

@@ -236,6 +241,34 @@ public final RemotelyAuthenticatedPrincipal translateRemoteInput(RemotelyAuthent
236241
ret.setCreationTime(Instant.now());
237242
return ret;
238243
}
244+
245+
private void setMappingToExistingEntity(MappingResult result) throws EngineException
246+
{
247+
Entity existing = null;
248+
for (MappedIdentity checked : result.getIdentities())
249+
{
250+
try
251+
{
252+
Entity found = idsMan.getEntity(new EntityParam(checked.getIdentity()));
253+
if (existing != null && !existing.getId().equals(found.getId()))
254+
{
255+
log.warn("Identity was mapped to two different entities: " + existing + " and "
256+
+ found);
257+
throw new ExecutionBreakException();
258+
}
259+
existing = found;
260+
result.addAuthenticatedWith(checked.getIdentity().getValue());
261+
} catch (IllegalArgumentException e)
262+
{
263+
log.trace("Identity " + checked + " not found in DB, details of exception follows", e);
264+
}
265+
}
266+
if (existing != null)
267+
{
268+
result.setMappedToExistingEntity(new EntityParam(existing.getId()));
269+
}
270+
}
271+
239272
private List<IdentityTaV> extractIdentities(MappingResult input)
240273
{
241274
List<MappedIdentity> identities = input.getIdentities();

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,35 +76,6 @@ public InputTranslationEngineImpl(@Qualifier("insecure") EntityManagement idsMan
7676
this.groupsMan = groupsMan;
7777
this.attrTypeHelper = attrTypeHelper;
7878
}
79-
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-
}
10879

10980
@Override
11081
public void process(MappingResult result) throws EngineException
@@ -209,7 +180,6 @@ private EntityParam processIdentities(MappingResult result, Set<Attribute> proce
209180
throw new ExecutionBreakException();
210181
}
211182
existing = found;
212-
//result.addAuthenticatedWith(checked.getIdentity().getValue());
213183
} catch (IllegalArgumentException e)
214184
{
215185
log.trace("Identity " + checked + " not found in DB, details of exception follows", e);

0 commit comments

Comments
 (0)