Skip to content

Commit

Permalink
autorun components via ApplicationRunner interface
Browse files Browse the repository at this point in the history
  • Loading branch information
philippst committed Oct 22, 2019
1 parent 552e40f commit 40d0bee
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ Fehler und Verbesserungsvorschläge können gerne als [Github Issue](https://git
oder Pull Request eingestellt werden. Wir freuen uns über Mitwirkung!

Kontakt: [email protected]

## Ausfuehrung

```
# Normale Ausfuehrung der LDAP Synchronisation
java -jar -Dspring.profiles.active=prod ldap-sync-1.2.0.jar
# Zusaetzlich mit Ausgabe von verwaisten Benutzern (in keiner Berechtigungsgruppe) in LDAP Verzeichnis
java -jar -Dspring.profiles.active=prod ldap-sync-1.2.0.jar --orphaned
```
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'de.pfadfinden.mv'
version = '1.1.0'
version = '1.2.0'
description = 'Sync tool of BdP membership administration and user directory'

sourceCompatibility = '1.8'
Expand Down
35 changes: 2 additions & 33 deletions src/main/java/de/pfadfinden/mv/LdapSyncApplication.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,13 @@
package de.pfadfinden.mv;

import de.pfadfinden.mv.command.CommandGruppen;
import de.pfadfinden.mv.command.CommandGruppierungen;
import de.pfadfinden.mv.command.CommandOrphanedPersons;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class LdapSyncApplication implements CommandLineRunner {

private final static Logger logger = LoggerFactory.getLogger(LdapSyncApplication.class);

private CommandGruppierungen commandGruppierungen;
private CommandGruppen commandGruppen;
private CommandOrphanedPersons commandOrphanedPersons;

public LdapSyncApplication(CommandGruppierungen commandGruppierungen,
CommandGruppen commandGruppen,
CommandOrphanedPersons commandOrphanedPersons) {
this.commandGruppierungen = commandGruppierungen;
this.commandGruppen = commandGruppen;
this.commandOrphanedPersons = commandOrphanedPersons;
}
public class LdapSyncApplication {

public static void main(String[] args) {
SpringApplication.run(LdapSyncApplication.class, args);
System.exit(SpringApplication.exit(SpringApplication.run(LdapSyncApplication.class, args)));
}

@Override
public void run(String... args) {

logger.info("Start MV LDAP Sync");

this.commandGruppierungen.exec();
this.commandGruppen.exec();
// this.commandOrphanedPersons.exec();

System.exit(0);
}
}
10 changes: 8 additions & 2 deletions src/main/java/de/pfadfinden/mv/command/CommandGruppen.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Date;
Expand All @@ -26,7 +29,8 @@
import java.util.Set;

@Component
public class CommandGruppen {
@Order(20)
public class CommandGruppen implements ApplicationRunner {
private final Logger logger = LoggerFactory.getLogger(CommandGruppen.class);

private final CommandIdentitaet commandIdentitaet;
Expand All @@ -44,7 +48,8 @@ public CommandGruppen(CommandIdentitaet commandIdentitaet,
this.ldapEntryService = ldapEntryService;
}

public void exec() {
@Override
public void run(ApplicationArguments args) {
List<SyncBerechtigungsgruppe> syncBerechtigungsgruppeList = this.syncService.getSyncGruppen();

for(SyncBerechtigungsgruppe berechtigungsgruppe : syncBerechtigungsgruppeList) {
Expand Down Expand Up @@ -134,4 +139,5 @@ private void updateBerechtigungsgruppe(SyncBerechtigungsgruppe berechtigungsgrup
logger.error(modifyResponse.getLdapResult().getDiagnosticMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
import org.apache.directory.api.util.GeneralizedTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Component
public class CommandGruppierungen {
@Order(10)
public class CommandGruppierungen implements ApplicationRunner {
private final Logger logger = LoggerFactory.getLogger(CommandGruppierungen.class);

private IcaService icaService;
Expand All @@ -32,7 +36,8 @@ public CommandGruppierungen(IcaService icaService, LdapEntryService ldapEntrySer
this.ldapEntryService = ldapEntryService;
}

public void exec() {
@Override
public void run(ApplicationArguments args) {
List<IcaGruppierung> icaGruppierungList = this.icaService.getGruppierungen();
for(IcaGruppierung icaGruppierung : icaGruppierungList){
execGruppierung(icaGruppierung);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/de/pfadfinden/mv/command/CommandOrphanedPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import de.pfadfinden.mv.service.LdapEntryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CommandOrphanedPersons {
@Order(50)
public class CommandOrphanedPersons implements ApplicationRunner {
private final Logger logger = LoggerFactory.getLogger(CommandOrphanedPersons.class);

private final LdapEntryService ldapEntryService;
Expand All @@ -18,8 +22,14 @@ public CommandOrphanedPersons(LdapEntryService ldapEntryService) {
this.ldapEntryService = ldapEntryService;
}

public void exec() {
@Override
public void run(ApplicationArguments args) {
if(args.containsOption("orphaned")) this.logOrphanedPersons();
}

private void logOrphanedPersons() {
List<IcaIdentitaet> identitaetList = ldapEntryService.findOrphanedPersons();
identitaetList.forEach(icaIdentitaet -> logger.info("Orphaned User: {} {}",icaIdentitaet.getIcaId(),icaIdentitaet.getCn()));
}

}

0 comments on commit 40d0bee

Please sign in to comment.