Skip to content

Commit

Permalink
SHIBUI-2584
Browse files Browse the repository at this point in the history
Correcting/updating the scheduler. Additional debug logging setup when data is sent.
  • Loading branch information
chasegawa committed Jul 6, 2023
1 parent f996848 commit 20a04a7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import edu.internet2.tier.shibboleth.admin.util.EntityDescriptorConversionUtils;
import edu.internet2.tier.shibboleth.admin.util.LuceneUtility;
import edu.internet2.tier.shibboleth.admin.util.ModelRepresentationConversions;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import org.apache.lucene.analysis.Analyzer;
Expand Down Expand Up @@ -82,11 +83,13 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Random;

@Configuration
@Import(SearchConfiguration.class)
@ComponentScan(basePackages = "{ edu.internet2.tier.shibboleth.admin.ui.service }")
@EnableConfigurationProperties({CustomPropertiesConfiguration.class, ShibUIConfiguration.class})
@Slf4j
public class CoreShibUiConfiguration {
@Bean
public OpenSamlObjects openSamlObjects() {
Expand Down Expand Up @@ -276,8 +279,21 @@ public LockProvider lockProvider(DataSource dataSource) {
@Bean
public String getBeaconCronValue(BeaconConfigurationRepository repo)
{
Optional<BeaconConfiguration> bc = repo.findById(1);
return bc.isPresent() ? bc.get().getSendCron() : "0 3 * * * *";
Optional<BeaconConfiguration> obc = repo.findById(1);
BeaconConfiguration bc;
if (obc.isEmpty()) {
//set random cron in db
BeaconConfiguration newbc = new BeaconConfiguration();
Random rand = new Random();
String cron = "0 " + rand.nextInt(60) + " " + rand.nextInt(4) + " * * ?";
newbc.setSendCron(cron);
repo.save(newbc);
bc = repo.findById(1).get();
} else {
bc = obc.get();
}
log.info("Scheduling beacon cron: {}", bc.getSendCron());
return bc.getSendCron();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void configure(HttpSecurity http) throws Exception {
.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and()
.authorizeRequests()
.antMatchers("/unsecured/**/*","/entities/**/*", "/health").permitAll()
.antMatchers("/unsecured/**/*","/entities/**/*", "/health", "/api/beacon/send").permitAll()
.anyRequest().hasAnyRole(acceptedAuthenticationRoles)
.and()
.exceptionHandling().accessDeniedHandler((request, response, accessDeniedException) -> response.sendRedirect("/unsecured/error.html"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public ResponseEntity<?> getDetail() throws JsonProcessingException {
return ResponseEntity.ok(service.getBeaconData());
}

@PostMapping("/send")
// This should be a POST, but to make it easier to hit, this is a GET
@GetMapping("/send")
public ResponseEntity<?> forceSendBeaconData() {
beaconReporter.sendBeaconData();
return ResponseEntity.ok("Manual push of beacon data completed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ public class BeaconReportingTask {
public void sendBeaconData() {
endpointUrls.forEach(url -> {
try {
String dataOutput = dataService.getBeaconData();
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
try (OutputStream os = con.getOutputStream()) {
byte[] input = dataService.getBeaconData().getBytes(StandardCharsets.UTF_8);
byte[] input = dataOutput.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
log.info("TIER Beacon data sent to {} with response code: {}", url, con.getResponseCode());
log.debug("TIER Beacon data load: {}", dataOutput);
}
catch (IOException e) {
e.printStackTrace();
Expand Down

0 comments on commit 20a04a7

Please sign in to comment.