-
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.
Intermediate work commit - feature incomplete
- Loading branch information
Showing
15 changed files
with
298 additions
and
5 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
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/beacon/BeaconDetail.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,21 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.beacon; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public class BeaconDetail { | ||
| private String msgType = "TIERBEACON"; | ||
| private String msgName = "TIER"; | ||
| private String msgVersion = "1.0"; | ||
|
|
||
| private String tbProduct; | ||
| private String tbProductVersion; | ||
| private String tbTIERRelease; | ||
| private String tbMaintainer = "Unicon"; | ||
|
|
||
| private ShibuiDetail shibui; | ||
| } | ||
|
|
||
| // "tbProduct": "ShibUI (shibui.beacon.productName)", | ||
| // "tbProductVersion": "1.17.4 (can we get this from the app?)", | ||
| // "tbTIERRelease": "(if the TAP container: 1.17.4; if the Unicon package, INTERNAL_1.17.4)", |
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/beacon/ShibuiDetail.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,21 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.beacon; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public class ShibuiDetail { | ||
|
|
||
|
|
||
| // "shibui": { | ||
| // "authMechanisms": [ | ||
| // "pac4j-saml" | ||
| // ], | ||
| // "numberOfMetadataSources": 25, | ||
| // "numberOfMetadataProviders": 3, | ||
| // "numberOfFilters": 0, | ||
| // "dailyLogins": 12, | ||
| // "numberOfGroups": 15, | ||
| // "numberOfRoles": 5, | ||
| // "installationID": "4813c762-4a90-40a2-9c01-81bf67647da4" | ||
| // } | ||
| } |
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 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 javax.persistence.EntityExistsException; | ||
| import javax.transaction.Transactional; | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.domain; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.Id; | ||
|
|
||
| @Data | ||
| @Entity | ||
| public class BeaconConfiguration { | ||
| @Id | ||
| private int id = 1; | ||
|
|
||
| private String installationId; | ||
|
|
||
| private String sendCron; | ||
|
|
||
| /** | ||
| * 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> { | ||
|
|
||
| } |
25 changes: 25 additions & 0 deletions
25
...d/src/main/java/edu/internet2/tier/shibboleth/admin/ui/scheduled/BeaconReportingTask.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,25 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.scheduled; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.service.IBeaconDataService; | ||
| import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock; | ||
| import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Configuration | ||
| @ConditionalOnProperty(name = "shibui.beacon.enabled", matchIfMissing=true) | ||
| @EnableSchedulerLock(defaultLockAtMostFor = "${shibui.maxTask.lockTime:30m}") | ||
| public class BeaconReportingTask { | ||
| @Autowired | ||
| IBeaconDataService dataService; | ||
|
|
||
| @Scheduled(cron="#{@getBeaconCronValue}") | ||
| @SchedulerLock(name = "generateEntityDescriptorFiles") | ||
| @Transactional(readOnly = true) | ||
| public void generateEntityDescriptorFiles() { | ||
|
|
||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
...d/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/BeaconDataServiceImpl.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,33 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import edu.internet2.tier.shibboleth.admin.ui.beacon.BeaconDetail; | ||
| import lombok.SneakyThrows; | ||
| import org.springframework.boot.actuate.info.InfoEndpoint; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class BeaconDataServiceImpl implements IBeaconDataService { | ||
| private ObjectMapper mapper; | ||
| private String productName; | ||
| private String version; | ||
|
|
||
| public BeaconDataServiceImpl(String productName, InfoEndpoint info) { | ||
| mapper = new ObjectMapper(); | ||
| mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // skip any null values | ||
|
|
||
| this.productName = productName; | ||
| version = info.info().get("build") == null ? "unknown" : ((Map)info.info().get("build")).get("version").toString(); | ||
| } | ||
|
|
||
| @Override | ||
| @SneakyThrows | ||
| public String getBeaconData() throws JsonProcessingException { | ||
| BeaconDetail detail = new BeaconDetail(); | ||
| detail.setTbProduct(productName); | ||
| detail.setTbProductVersion(version); | ||
| return mapper.writeValueAsString(detail); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/IBeaconDataService.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,7 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
|
||
| public interface IBeaconDataService { | ||
| String getBeaconData() throws JsonProcessingException; | ||
| } |
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
Oops, something went wrong.