Initial working skeleton/prototype that merely returns a hard-coded actor
This commit is contained in:
parent
cf6e536aca
commit
d2760742b6
6 changed files with 62 additions and 22 deletions
|
|
@ -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);
|
||||
}
|
||||
}*/
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 @<user> to /users/<user>
|
||||
*/
|
||||
@GetMapping("/@springbot")
|
||||
public String atactor() {
|
||||
return this.actor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the bot/user - ultimately this should check the database for
|
||||
* /user/<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": "<p>A bot written using Java/Spring</p>",
|
||||
"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-----"
|
||||
}
|
||||
}""";
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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!")));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue