Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mpdz2 649 e mail notification #44

Merged
merged 15 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pom.xml
markostreich marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

<!-- Test -->

<dependency>
Expand All @@ -87,6 +92,18 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
markostreich marked this conversation as resolved.
Show resolved Hide resolved

<!-- LDAP Test -->
<dependency>
<groupId>org.springframework.ldap</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ZammadGroupDTO {

Expand All @@ -22,6 +26,6 @@ public class ZammadGroupDTO {
private String lhmobjectid;
@JsonProperty("updated_at")
private String updatedAt;


}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package de.muenchen.zammad.ldap.domain;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@AllArgsConstructor
@NoArgsConstructor
public class ZammadUserDTO {

private String id;
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/de/muenchen/zammad/ldap/service/Validation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package de.muenchen.zammad.ldap.service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
markostreich marked this conversation as resolved.
Show resolved Hide resolved

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import de.muenchen.zammad.ldap.tree.LdapOuNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@RequiredArgsConstructor
public class Validation {

@Value(value = "${sync.message.from}")
private String from = "noreply@test.com";

@Value(value = "${sync.message.to}")
private String to = "test@test.com";

@Value(value = "${sync.message.subject}")
private String subject = "Ooops ... test error occurred.";

private final JavaMailSender javaMailSender;

void checkOuBases(List<String> ldapSyncDistinguishedNames, Map<String, LdapOuNode> ldapShadetrees) {

try {

if (ldapShadetrees.size() != ldapSyncDistinguishedNames.size()) {

var trees = Arrays.asList(ldapShadetrees.keySet().toArray());
var differences = ldapSyncDistinguishedNames.stream().filter(element -> !trees.contains(element)).toList();

var sb = new StringBuilder();
sb.append(System.lineSeparator() + System.lineSeparator());
markostreich marked this conversation as resolved.
Show resolved Hide resolved
sb.append(
" !!! No ldap nodes for all ouBases found. Please check the ouBase(s) (ldap distinguished name) availability. Maybe part of a distinguished name was renamed in ldap :");
sb.append(System.lineSeparator());
differences.forEach(dn -> {
sb.append(" !!! - ");
sb.append(dn);
sb.append(System.lineSeparator());
});

log.error(sb.toString());

var message = new SimpleMailMessage();
message.setFrom(from);
message.setSubject(subject);
message.setTo(to);
message.setText(sb.toString());

javaMailSender.send(message);

}

} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
markostreich marked this conversation as resolved.
Show resolved Hide resolved
}
}
26 changes: 14 additions & 12 deletions src/main/java/de/muenchen/zammad/ldap/service/ZammadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
@Slf4j
public class ZammadService {

private final RestTemplate restTemplate = new RestTemplate();
private static final String AUTHORIZATION = "Authorization";

private final RestTemplate restTemplate = new RestTemplate();

private final ZammadProperties zammadProperties;

Expand All @@ -32,7 +34,7 @@ public ZammadService(ZammadProperties zammadProperties) {

public List<ZammadGroupDTO> getZammadGroups() {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

boolean found = true;
int i = 0;
Expand All @@ -55,7 +57,7 @@ public List<ZammadGroupDTO> getZammadGroups() {

public ZammadGroupDTO updateZammadGroup(ZammadGroupDTO zammadGroupDTO) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadGroupDTO> requestEntity = new HttpEntity<>(zammadGroupDTO, headers);

Expand All @@ -69,7 +71,7 @@ public ZammadGroupDTO updateZammadGroup(ZammadGroupDTO zammadGroupDTO) {

public String deleteZammadGroup(String id) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadGroupDTO> requestEntity = new HttpEntity<>(headers);

Expand All @@ -81,7 +83,7 @@ public String deleteZammadGroup(String id) {

public ZammadGroupDTO createZammadGroup(ZammadGroupDTO zammadGroupDTO) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadGroupDTO> requestEntity = new HttpEntity<>(zammadGroupDTO, headers);

Expand All @@ -99,7 +101,7 @@ public ZammadGroupDTO createZammadGroup(ZammadGroupDTO zammadGroupDTO) {

public List<ZammadUserDTO> getZammadUsers() {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

boolean found = true;
int i = 0;
Expand All @@ -121,7 +123,7 @@ public List<ZammadUserDTO> getZammadUsers() {

public ZammadUserDTO updateZammadUser(ZammadUserDTO zammadUserDTO) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadUserDTO> requestEntity = new HttpEntity<>(zammadUserDTO, headers);

Expand All @@ -135,7 +137,7 @@ public ZammadUserDTO updateZammadUser(ZammadUserDTO zammadUserDTO) {

public ZammadUserDTO createZammadUser(ZammadUserDTO zammadUserDTO) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadUserDTO> requestEntity = new HttpEntity<>(zammadUserDTO, headers);

Expand All @@ -147,7 +149,7 @@ public ZammadUserDTO createZammadUser(ZammadUserDTO zammadUserDTO) {

public String deleteZammadUser(String id) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadUserDTO> requestEntity = new HttpEntity<>(headers);

Expand All @@ -159,7 +161,7 @@ public String deleteZammadUser(String id) {

public ZammadRoleDTO getZammadRole(int id) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadRoleDTO> requestEntity = new HttpEntity<>(headers);

Expand All @@ -171,7 +173,7 @@ public ZammadRoleDTO getZammadRole(int id) {

public List<ZammadRoleDTO> getZammadRoles() {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadRoleDTO> requestEntity = new HttpEntity<>(headers);

Expand All @@ -183,7 +185,7 @@ public List<ZammadRoleDTO> getZammadRoles() {

public ZammadRoleDTO updateZammadRole(ZammadRoleDTO zammadRoleDTO) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", zammadProperties.getToken());
headers.add(AUTHORIZATION, zammadProperties.getToken());

HttpEntity<ZammadRoleDTO> requestEntity = new HttpEntity<>(zammadRoleDTO, headers);

Expand Down
Loading
Loading