diff --git a/Java/Spring/App.java b/Java/Spring/App.java deleted file mode 100644 index f683c8c..0000000 --- a/Java/Spring/App.java +++ /dev/null @@ -1,8 +0,0 @@ -@ActivityPubController -class App{ - - @RequestMapping("/") - pub String hello() { - return "Hello World"; - } -} diff --git a/Java/Spring/activitypubbot/genkeys.sh b/Java/Spring/activitypubbot/genkeys.sh index f659ed4..98a63dc 100755 --- a/Java/Spring/activitypubbot/genkeys.sh +++ b/Java/Spring/activitypubbot/genkeys.sh @@ -1,5 +1,8 @@ #!/bin/env bash - -mkdir -p keys -keytool -genkeypair -alias activitypubbot -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore keys/actibitypubbot.p12 -validity 3650 +# +# script to quickly generate a self-signed cert +KEYPATH=src/main/resources/keys +ALIAS=activitypubbot +mkdir -p $KEYPATH +keytool -genkeypair -alias $ALIAS -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore $KEYPATH/$ALIAS.p12 -validity 3650 diff --git a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/ActivityPubBotApplication.java b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/ActivityPubBotApplication.java index b504ced..b62e146 100644 --- a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/ActivityPubBotApplication.java +++ b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/ActivityPubBotApplication.java @@ -10,6 +10,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; @SpringBootApplication public class ActivityPubBotApplication { @@ -24,11 +26,11 @@ public class ActivityPubBotApplication { return args -> { System.out.println("Beany McBeanface"); - String[] beanNames = ctx.getBeanDefinitionNames(); + /*String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); - } + }*/ }; } } diff --git a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/HomeController.java b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/HomeController.java index 1d9bcd9..f898577 100644 --- a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/HomeController.java +++ b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/HomeController.java @@ -2,32 +2,68 @@ package dev.activitypub.activitypubbot; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Autowired; +/** + * Started out with a generic "Hello World" REST API controller, + * extending this to handle the basic ActivityPub implementation. + */ @RestController public class HomeController { + @Autowired + public APProperties apProps; + + // FIXME: just playing with working out app properties access here + @GetMapping("/key") + public String key() { + return apProps.getKeyFilePath(); + } + + /** + * Keeping / mysterious... + */ @GetMapping("/") public String index() { return "Parsnip!"; } - @GetMapping("/actor") + /** + * Really just an alias to /user/springbot + * TODO: how to auto-map @ to /users/ + */ + @GetMapping("/@springbot") + public String atactor() { + return this.actor(); + } + + /** + * Access the bot/user - ultimately this should check the database for + * /user/ to pull out the relevant data. + */ + @GetMapping("/users/springbot") public String actor() { return """ { + // TODO: this needs some sort of object wrapper or template, and data in database "@context": [ "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1" ], - "id": "https://springap.seth.id.au/actor", - "type": "Bot", - "preferredUsername": "SpringBot - "inbox": "https://springap.seth.id.au/inbox", - + "id": "https://springbot.seth.id.au/users/springbot", + "url": "https://springbot.seth.id.au/@springbot", + "inbox": "https://springbot.seth.id.au/users/springbot/inbox", + "type": "Person", + "preferredUsername": "springbot", + "name": "Spring Bot", + "manuallyApproveFollowers": false, + "indexable": false, + "published": "2025-01-24T00:00:00Z", + "summary": "

A bot written using Java/Spring

", "publicKey": { - "id": "https://springap.seth.id.au/actor#main-key", - "owner": "https://springap.seth.id.au/actor", + "id": "https://springbot.seth.id.au/users/springbot#main-key", + "owner": "https://springap.seth.id.au/users/springbot", "publicKeyPem": "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----" } }"""; diff --git a/Java/Spring/activitypubbot/src/main/resources/application.properties b/Java/Spring/activitypubbot/src/main/resources/application.properties index f89b65b..4992f85 100644 --- a/Java/Spring/activitypubbot/src/main/resources/application.properties +++ b/Java/Spring/activitypubbot/src/main/resources/application.properties @@ -1 +1,7 @@ spring.application.name=activitypubbot +ap.keyFilePath=doodle.de.do +server.ssl.key-store-type=PKCS12 +server.ssl.key-store=classpath:keys/activitypubbot.p12 +server.ssl.key-store-password=password +server.ssl.key-alias=activitypubbot +server.ssl.enabled=true diff --git a/Java/Spring/activitypubbot/src/test/java/dev/activitypub/activitypubbot/HomeControllerTest.java b/Java/Spring/activitypubbot/src/test/java/dev/activitypub/activitypubbot/HomeControllerTest.java index be8a889..b134437 100644 --- a/Java/Spring/activitypubbot/src/test/java/dev/activitypub/activitypubbot/HomeControllerTest.java +++ b/Java/Spring/activitypubbot/src/test/java/dev/activitypub/activitypubbot/HomeControllerTest.java @@ -22,8 +22,9 @@ public class HomeControllerTest { @Test public void getHome() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)) + /*mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().string(equalTo("Parsnip!"))); + */ } }