Skip to content

Commit

Permalink
wip retour des events pour spoc
Browse files Browse the repository at this point in the history
  • Loading branch information
CChemin committed Oct 19, 2023
1 parent 022fa16 commit a527f97
Show file tree
Hide file tree
Showing 21 changed files with 927 additions and 74 deletions.
13 changes: 0 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,11 @@
<artifactId>sugoi-api-jms-store-provider</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-log</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-webhook</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-metrics</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-jms-utils</artifactId>
Expand Down Expand Up @@ -328,9 +317,7 @@
<module>sugoi-api-rest-services</module>
<module>sugoi-api-rest-old-services</module>
<module>sugoi-api-rest-commons-services</module>
<module>sugoi-api-event-log</module>
<module>sugoi-api-event-webhook</module>
<module>sugoi-api-event-metrics</module>
<module>sugoi-api-converter</module>
<module>sugoi-api-distribution</module>
<module>sugoi-api-file-config-provider</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,16 @@ public class EventKeysConfig {
private EventKeysConfig() {}

public static final String REALM = "realm";
public static final String REALM_NAME = "realmName";
public static final String USERSTORAGE = "userStorage";
public static final String ORGANIZATION = "organization";
public static final String ORGANIZATION_ID = "organizationId";
public static final String ORGANIZATION_FILTER = "organizationFilter";

public static final String APPLICATION = "application";
public static final String APPLICATION_ID = "applicationId";
public static final String APPLICATION_NAME = "appName";
public static final String APPLICATION_FILTER = "applicationFilter";

public static final String GROUP = "group";
public static final String GROUP_ID = "groupId";
public static final String GROUP_NAME = "groupName";
public static final String GROUP_FILTER = "groupFilter";

public static final String HABILITATION = "habilitation";
public static final String HABILITATION_ID = "habilitationId";
public static final String HABILITATION_NAME = "habilitationName";
public static final String HABILITATION_FILTER = "habilitationFilter";

public static final String USER = "user";
public static final String USER_ID = "userId";
public static final String USER_NAME = "userName";
public static final String USER_MAIL = "userMail";
public static final String USER_FILTER = "userFilter";
public static final String USER_PROPERTIES = "userProperties";

public static final String MAILS = "mails";
public static final String ADDRESS = "address";
public static final String PROPERTIES = "properties";

public static final String PAGEABLE = "pageable";
public static final String PAGEABLE_RESULT = "pageableResult";
public static final String TYPE_RECHERCHE = "typeRecherche";
public static final String SENDMODES = "sendModes";

public static final String MUST_CHANGE_PASSWORD = "mustChangePassword";
public static final String PASSWORD_CHANGE_REQUEST = "pcr";
public static final String PASSWORD = "password";

public static final String ERROR = "error";

public static final String ATTRIBUTE_KEY = "attribute-key";
public static final String ATTRIBUTE_VALUE = "attribute-value";

public static final String TYPE = "type";

public static final String NEW_PASSWORD = "new-password";
public static final String OLD_PASSWORD = "old-password";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.insee.sugoi.core.event.model;

import java.util.Map;
import org.springframework.context.ApplicationEvent;

public class SugoiEvent extends ApplicationEvent {

private static final long serialVersionUID = 1L;

private SugoiEventTypeEnum eventType;

private String realm;

private String userStorage;

private Map<String, Object> properties;

public SugoiEvent(
String realm, String storage, SugoiEventTypeEnum eventType, Map<String, Object> properties) {
super(eventType);
this.realm = realm;
this.userStorage = storage;
this.eventType = eventType;
this.properties = properties;
}

public SugoiEventTypeEnum getEventType() {
return eventType;
}

public String getRealm() {
return realm;
}

public String getUserStorage() {
return userStorage;
}

public Map<String, Object> getProperties() {
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.insee.sugoi.core.event.model;

public enum SugoiEventTypeEnum {
CHANGE_PASSWORD,
REINIT_PASSWORD,
SEND_LOGIN,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.insee.sugoi.core.event.publisher;

import fr.insee.sugoi.core.event.model.SugoiEvent;
import fr.insee.sugoi.core.event.model.SugoiEventTypeEnum;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

@Component
public class SugoiEventPublisher {
@Autowired private ApplicationEventPublisher applicationEventPublisher;

public void publishCustomEvent(
final String realm,
final String storage,
final SugoiEventTypeEnum eventType,
final Map<String, Object> properties) {
SugoiEvent sugoiEvent = new SugoiEvent(realm, storage, eventType, properties);
applicationEventPublisher.publishEvent(sugoiEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package fr.insee.sugoi.core.service.impl;

import fr.insee.sugoi.core.event.configuration.EventKeysConfig;
import fr.insee.sugoi.core.event.model.SugoiEventTypeEnum;
import fr.insee.sugoi.core.event.publisher.SugoiEventPublisher;
import fr.insee.sugoi.core.model.ProviderRequest;
import fr.insee.sugoi.core.model.ProviderResponse;
import fr.insee.sugoi.core.realm.RealmProvider;
Expand Down Expand Up @@ -47,6 +49,8 @@ public class CredentialsServiceImpl implements CredentialsService {

@Autowired private PasswordService passwordService;

@Autowired private SugoiEventPublisher sugoiEventPublisher;

@Autowired private RealmProvider realmProvider;

@Autowired private UserService userService;
Expand Down Expand Up @@ -90,7 +94,8 @@ public ProviderResponse reinitPassword(
getPasswordIntConfiguration(
userStorageProperties, PasswordPolicyConstants.CREATE_PASSWORD_SIZE));

return storeProvider
ProviderResponse response =
storeProvider
.getWriterStore(realm, userStorage)
.reinitPassword(
userId,
Expand All @@ -99,6 +104,17 @@ public ProviderResponse reinitPassword(
templateProperties,
webserviceTag,
providerRequest);
sugoiEventPublisher.publishCustomEvent(
realm,
userStorage,
SugoiEventTypeEnum.REINIT_PASSWORD,
Map.ofEntries(
Map.entry(EventKeysConfig.PROPERTIES, templateProperties),
Map.entry(EventKeysConfig.MAILS, computeReceiverMails(templateProperties, user)),
Map.entry(EventKeysConfig.USER, user),
Map.entry(EventKeysConfig.WEBSERVICE_TAG, webserviceTag != null ? webserviceTag : ""),
Map.entry(EventKeysConfig.PASSWORD, password)));
return response;
}

@Override
Expand All @@ -111,6 +127,7 @@ public ProviderResponse changePassword(
String webserviceTag,
Map<String, String> templateProperties,
ProviderRequest providerRequest) {

User user = userService.findById(realm, userStorage, userId, false);

Map<RealmConfigKeys, List<String>> userStorageProperties =
Expand All @@ -124,7 +141,8 @@ public ProviderResponse changePassword(
boolean newPasswordIsValid = validatePassword(newPassword, userStorageProperties);

if (newPasswordIsValid) {
return storeProvider
ProviderResponse providerResponse =
storeProvider
.getWriterStore(realm, userStorage)
.changePassword(
userId,
Expand All @@ -133,6 +151,19 @@ public ProviderResponse changePassword(
webserviceTag,
templateProperties,
providerRequest);
sugoiEventPublisher.publishCustomEvent(
realm,
userStorage,
SugoiEventTypeEnum.CHANGE_PASSWORD,
Map.ofEntries(
Map.entry(EventKeysConfig.NEW_PASSWORD, newPassword),
Map.entry(EventKeysConfig.OLD_PASSWORD, newPassword),
Map.entry(EventKeysConfig.USER_ID, userId),
Map.entry(EventKeysConfig.PROPERTIES, templateProperties),
Map.entry(EventKeysConfig.MAILS, computeReceiverMails(templateProperties, user)),
Map.entry(
EventKeysConfig.WEBSERVICE_TAG, webserviceTag != null ? webserviceTag : "")));
return providerResponse;
} else {
throw new PasswordPolicyNotMetException("New password is not valid");
}
Expand Down Expand Up @@ -163,7 +194,7 @@ public ProviderResponse initPassword(
} else {
throw new PasswordPolicyNotMetException("New password is not valid");
}
}
}

@Override
public boolean validateCredential(
Expand All @@ -180,7 +211,16 @@ public boolean sendLogin(
Map<String, String> templateProperties,
String webhookTag) {
try {
userService.findById(realm, userStorage, id, false);
User user = userService.findById(realm, userStorage, id, false);
sugoiEventPublisher.publishCustomEvent(
realm,
userStorage,
SugoiEventTypeEnum.SEND_LOGIN,
Map.ofEntries(
Map.entry(EventKeysConfig.MAILS, computeReceiverMails(templateProperties, user)),
Map.entry(EventKeysConfig.WEBSERVICE_TAG, webhookTag != null ? webhookTag : ""),
Map.entry(EventKeysConfig.USER, user),
Map.entry(EventKeysConfig.PROPERTIES, templateProperties)));
return true;
} catch (Exception e) {
return false;
Expand Down
10 changes: 0 additions & 10 deletions sugoi-api-distribution/sugoi-api-distribution-jar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,11 @@
<artifactId>sugoi-api-core</artifactId>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-log</artifactId>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-webhook</artifactId>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-metrics</artifactId>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-rest-services</artifactId>
Expand Down
10 changes: 0 additions & 10 deletions sugoi-api-distribution/sugoi-api-distribution-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,11 @@
<artifactId>sugoi-api-jms-store-provider</artifactId>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-log</artifactId>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-webhook</artifactId>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-metrics</artifactId>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-seealso-http</artifactId>
Expand Down
44 changes: 44 additions & 0 deletions sugoi-api-event-webhook/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sugoi-api-event-webhook</artifactId>
<name>sugoi-api-event-webhook</name>
<description>event listener which produce webhook</description>

<dependencies>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>

<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit a527f97

Please sign in to comment.