Skip to content

Commit

Permalink
notifier + invitation link creation
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Apr 29, 2023
1 parent 8c3425e commit 3176ac9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public static SelfRegistrationPolicyType getSelfRegistrationPolicy(SecurityPolic
return selfRegistrationPolicy;
}

public static SelfRegistrationPolicyType getInvitationPolicy(SecurityPolicyType securityPolicyType) {
RegistrationsPolicyType flowPolicy = securityPolicyType.getFlow();
SelfRegistrationPolicyType invitationPolicy = null;
if (flowPolicy != null) {
invitationPolicy = flowPolicy.getInvitation();
}

return invitationPolicy;
}

public static AuthenticationSequenceType findSequenceByIdentifier(@NotNull SecurityPolicyType securityPolicy, String identifier) {
if (StringUtils.isEmpty(identifier)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,8 @@ List<ObjectReferenceType> getMembersAsReferences(String orgOid)

String createPasswordResetLink(UserType userType);

String createInvitationLink(UserType userType);

/**
* Returns a link where given work item can be completed.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,26 @@ public String createPasswordResetLink(UserType userType) {
return createTokenConfirmationLink(SchemaConstants.PASSWORD_RESET_CONFIRMATION_PREFIX, userType);
}

public String createInvitationLink(UserType userType) {
SecurityPolicyType securityPolicy = resolveSecurityPolicy(userType.asPrismObject());
if (securityPolicy != null && securityPolicy.getAuthentication() != null
&& securityPolicy.getAuthentication().getSequence() != null &&
!securityPolicy.getAuthentication().getSequence().isEmpty()) {
SelfRegistrationPolicyType invitationPolicy = SecurityPolicyUtil.getInvitationPolicy(securityPolicy);
if (invitationPolicy != null) {
String invitationSequenceName = invitationPolicy.getAdditionalAuthenticationSequence();
if (invitationSequenceName != null) {
String prefix = createPrefixLinkByAuthSequence(SchemaConstants.CHANNEL_INVITATION_URI, invitationSequenceName,
securityPolicy.getAuthentication().getSequence());
if (prefix != null) {
return createTokenConfirmationLink(prefix, userType);
}
}
}
}
return createTokenConfirmationLink(SchemaConstants.AUTH_MODULE_PREFIX + SchemaConstants.CHANNEL_INVITATION_URI, userType);
}

@Override
public @Nullable String createWorkItemCompletionLink(@NotNull WorkItemId workItemId) {
String publicHttpUrlPattern = getPublicHttpUrlPattern();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ protected String getBody(ModelEvent event, AccountActivationNotifierType configu

StringBuilder body = new StringBuilder();
String message = "Your accounts was successfully created. To activate your accounts, please click on the link below.";
body.append(message).append("\n\n").append(createConfirmationLink(getUser(event), configuration, result)).append("\n\n");
body.append(message).append("\n\n").append(createConfirmationLink(getUser(event), configuration, event.getChannel(),
result)).append("\n\n");

FocusType owner = (FocusType) event.getRequesteeObject();
String userOrOwner = owner instanceof UserType ? "User" : "Owner";
Expand Down Expand Up @@ -153,7 +154,7 @@ private List<ShadowType> getShadowsToActivate(ModelEvent modelEvent) {
}

@Override
public String getConfirmationLink(UserType userType) {
public String getConfirmationLink(UserType userType, String channel) {
return getMidpointFunctions().createAccountActivationLink(userType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public Class<ModelEvent> getEventType() {
return ModelEvent.class;
}

public String getConfirmationLink(UserType userType) {
public String getConfirmationLink(UserType userType, String channel) {
throw new UnsupportedOperationException("Please implement in concrete notifier");
}

String createConfirmationLink(UserType userType, N config, OperationResult result) {
String createConfirmationLink(UserType userType, N config, String channel, OperationResult result) {

RegistrationConfirmationMethodType confirmationMethod = config.getConfirmationMethod();
if (confirmationMethod == null) {
Expand All @@ -54,7 +54,7 @@ String createConfirmationLink(UserType userType, N config, OperationResult resul
try {
switch (confirmationMethod) {
case LINK:
return getConfirmationLink(userType);
return getConfirmationLink(userType, channel);
case PIN:
throw new UnsupportedOperationException("PIN confirmation not supported yes");
// return getNonce(userType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ protected String getBody(ModelEvent event, PasswordResetNotifierType generalNoti
OperationResult result) {
UserType userType = getUser(event);
return "Did you request password reset? If yes, click on the link below \n\n"
+ createConfirmationLink(userType, generalNotifierType, result);
+ createConfirmationLink(userType, generalNotifierType, event.getChannel(), result);
}

@Override
public String getConfirmationLink(UserType userType) {
public String getConfirmationLink(UserType userType, String channel) {
return getMidpointFunctions().createPasswordResetLink(userType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected boolean checkApplicability(ModelEvent event, RegistrationConfirmationN
} else if (event.getFocusDeltas().isEmpty()) {
LOGGER.trace("No user deltas in event, exiting.");
return false;
} else if (SchemaConstants.CHANNEL_SELF_REGISTRATION_URI.equals(event.getChannel())) {
} else if (isSelfRegistrationChannel(event.getChannel()) || isInvitationChannel(event.getChannel())) {
LOGGER.trace("Found change from registration channel.");
return true;
} else {
Expand Down Expand Up @@ -86,7 +86,7 @@ protected String getBody(ModelEvent event, RegistrationConfirmationNotifierType
messageBuilder.append(userType.getGivenName()).append(",\n")
.append("your account was successfully created. To activate your account click on the following confiramtion link. ")
.append("\n")
.append(createConfirmationLink(userType, configuration, result))
.append(createConfirmationLink(userType, configuration, event.getChannel(), result))
.append("\n\n")
.append("After your account is activated, use following credentials to log in: \n")
.append("username: ")
Expand All @@ -98,7 +98,21 @@ protected String getBody(ModelEvent event, RegistrationConfirmationNotifierType
}

@Override
public String getConfirmationLink(UserType userType) {
return getMidpointFunctions().createRegistrationConfirmationLink(userType);
public String getConfirmationLink(UserType userType, String channel) {
if (isSelfRegistrationChannel(channel)) {
return getMidpointFunctions().createRegistrationConfirmationLink(userType);
}
if (isInvitationChannel(channel)) {
return getMidpointFunctions().createInvitationLink(userType);
}
return null;
}

private boolean isSelfRegistrationChannel(String channel) {
return SchemaConstants.CHANNEL_SELF_REGISTRATION_URI.equals(channel);
}

private boolean isInvitationChannel(String channel) {
return SchemaConstants.CHANNEL_INVITATION_URI.equals(channel);
}
}

0 comments on commit 3176ac9

Please sign in to comment.