-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in merge/shibui-2576 (pull request #659)
Merge/shibui 2576 Approved-by: Chad Redman
- Loading branch information
Showing
43 changed files
with
663 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...hibboleth/admin/ui/configuration/postprocessors/BeaconConfigurationStartupProcessing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.configuration.postprocessors; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.domain.BeaconConfiguration; | ||
| import edu.internet2.tier.shibboleth.admin.ui.repository.BeaconConfigurationRepository; | ||
| import jakarta.persistence.EntityExistsException; | ||
| import jakarta.transaction.Transactional; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.context.event.ContextRefreshedEvent; | ||
| import org.springframework.context.event.EventListener; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.UUID; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
|
|
||
| /** | ||
| * This approach for running logic waits until after the Spring context has been initialized. | ||
| * We will always use an ID of 1 for the beaconConfiguration, so if the data doesn't exist, we can try to write the data. If the | ||
| * data exists, we don't need to do anything. | ||
| * | ||
| * Because multiple instances could be starting at the same time, we must account for a save "losing" to another entity - that's ok | ||
| * and if we get an exception because the entity with the id already exists, we can just bail out. | ||
| */ | ||
| @Component | ||
| public class BeaconConfigurationStartupProcessing { | ||
| @Autowired | ||
| BeaconConfigurationRepository beaconRepo; | ||
|
|
||
| @EventListener | ||
| @Transactional | ||
| public void onApplicationEvent(ContextRefreshedEvent event) { | ||
| // If there is nothing in the db, create the entry to use going forward | ||
| if (beaconRepo.count() == 0) { | ||
| String appId = event.getApplicationContext().getEnvironment().getProperty("shibui.beacon.installationID"); | ||
| BeaconConfiguration bc = new BeaconConfiguration(); | ||
| bc.setInstallationId(StringUtils.isBlank(appId) ? UUID.randomUUID().toString() : appId); | ||
|
|
||
| String cronDef = event.getApplicationContext().getEnvironment().getProperty("shibui.beacon.send.cron"); | ||
|
|
||
| // If not set, set a random time between 12AM-4AM | ||
| if (StringUtils.isBlank(cronDef)) { | ||
| int randomMin = ThreadLocalRandom.current().nextInt(0, 60); | ||
| int randomHour = ThreadLocalRandom.current().nextInt(0, 5); | ||
| cronDef = "" + randomMin + " " + randomHour + " * * * *"; | ||
| } | ||
|
|
||
| bc.setSendCron(cronDef); | ||
|
|
||
| try { | ||
| beaconRepo.save(bc); | ||
| } | ||
| catch (EntityExistsException ignore) { | ||
| // Race between startup instances - as long as one of them won... | ||
| } | ||
| } | ||
| // if the entry exists, check that the cron timing hasn't changed | ||
| else { | ||
| String cronDef = event.getApplicationContext().getEnvironment().getProperty("shibui.beacon.send.cron"); | ||
| if (StringUtils.isNotBlank(cronDef)) { | ||
| BeaconConfiguration bc = beaconRepo.getReferenceById(1); | ||
| if (StringUtils.isNotBlank(cronDef) && !cronDef.equals(bc.getSendCron())) { | ||
| bc.setSendCron(cronDef); | ||
| beaconRepo.save(bc); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
...end/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/BeaconController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.controller; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import edu.internet2.tier.shibboleth.admin.ui.scheduled.BeaconReportingTask; | ||
| import edu.internet2.tier.shibboleth.admin.ui.service.IBeaconDataService; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Profile({"dev", "very-dangerous"}) | ||
| @RestController | ||
| @RequestMapping(value = "/api/beacon") | ||
| public class BeaconController { | ||
| @Autowired | ||
| BeaconReportingTask beaconReporter; | ||
|
|
||
| @Autowired | ||
| private IBeaconDataService service; | ||
|
|
||
| @GetMapping(value = "/detail") | ||
| public ResponseEntity<?> getDetail() throws JsonProcessingException { | ||
| return ResponseEntity.ok(service.getBeaconData()); | ||
| } | ||
|
|
||
| @PostMapping("/send") | ||
| public ResponseEntity<?> forceSendBeaconData() { | ||
| beaconReporter.sendBeaconData(); | ||
| return ResponseEntity.ok("Manual push of beacon data completed"); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/domain/BeaconConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.domain; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Transient; | ||
| import lombok.Data; | ||
| import lombok.Setter; | ||
|
|
||
| @Data | ||
| @Entity | ||
| public class BeaconConfiguration { | ||
| @Id | ||
| private int id = 1; | ||
|
|
||
| private String installationId; | ||
|
|
||
| private String sendCron; | ||
|
|
||
| // Comma separated list of the auth mechanisms used. | ||
| @Setter | ||
| @Transient | ||
| private static String authMechanisms = "unset"; | ||
|
|
||
| public static String getAuthMechanisms() { | ||
| return authMechanisms; | ||
| } | ||
|
|
||
| /** | ||
| * enforce that id will only ever be 1 | ||
| */ | ||
| public void setId(int ignored) { | ||
| this.id = 1; | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
...java/edu/internet2/tier/shibboleth/admin/ui/repository/BeaconConfigurationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.repository; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.domain.BeaconConfiguration; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface BeaconConfigurationRepository extends JpaRepository<BeaconConfiguration, Integer> { | ||
|
|
||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
...end/src/main/java/edu/internet2/tier/shibboleth/admin/ui/repository/FilterRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.repository; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.domain.filters.MetadataFilter; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.CrudRepository; | ||
|
|
||
| public interface FilterRepository extends CrudRepository<MetadataFilter, Long> { | ||
| MetadataFilter findByResourceId(String resourceId); | ||
| } | ||
|
|
||
| @Query("SELECT COUNT(f) FROM MetadataFilter f WHERE f.filterEnabled = true") | ||
| int getActiveFilterCount(); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.