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
|
|
@ -1,8 +0,0 @@
|
||||||
@ActivityPubController
|
|
||||||
class App{
|
|
||||||
|
|
||||||
@RequestMapping("/")
|
|
||||||
pub String hello() {
|
|
||||||
return "Hello World";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
#!/bin/env bash
|
#!/bin/env bash
|
||||||
|
#
|
||||||
mkdir -p keys
|
# script to quickly generate a self-signed cert
|
||||||
keytool -genkeypair -alias activitypubbot -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore keys/actibitypubbot.p12 -validity 3650
|
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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ActivityPubBotApplication {
|
public class ActivityPubBotApplication {
|
||||||
|
|
@ -24,11 +26,11 @@ public class ActivityPubBotApplication {
|
||||||
return args -> {
|
return args -> {
|
||||||
System.out.println("Beany McBeanface");
|
System.out.println("Beany McBeanface");
|
||||||
|
|
||||||
String[] beanNames = ctx.getBeanDefinitionNames();
|
/*String[] beanNames = ctx.getBeanDefinitionNames();
|
||||||
Arrays.sort(beanNames);
|
Arrays.sort(beanNames);
|
||||||
for (String beanName : beanNames) {
|
for (String beanName : beanNames) {
|
||||||
System.out.println(beanName);
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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
|
@RestController
|
||||||
public class HomeController {
|
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("/")
|
@GetMapping("/")
|
||||||
public String index() {
|
public String index() {
|
||||||
return "Parsnip!";
|
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() {
|
public String actor() {
|
||||||
return """
|
return """
|
||||||
{
|
{
|
||||||
|
// TODO: this needs some sort of object wrapper or template, and data in database
|
||||||
"@context": [
|
"@context": [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
"https://w3id.org/security/v1"
|
"https://w3id.org/security/v1"
|
||||||
],
|
],
|
||||||
|
|
||||||
"id": "https://springap.seth.id.au/actor",
|
"id": "https://springbot.seth.id.au/users/springbot",
|
||||||
"type": "Bot",
|
"url": "https://springbot.seth.id.au/@springbot",
|
||||||
"preferredUsername": "SpringBot
|
"inbox": "https://springbot.seth.id.au/users/springbot/inbox",
|
||||||
"inbox": "https://springap.seth.id.au/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": {
|
"publicKey": {
|
||||||
"id": "https://springap.seth.id.au/actor#main-key",
|
"id": "https://springbot.seth.id.au/users/springbot#main-key",
|
||||||
"owner": "https://springap.seth.id.au/actor",
|
"owner": "https://springap.seth.id.au/users/springbot",
|
||||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----"
|
"publicKeyPem": "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----"
|
||||||
}
|
}
|
||||||
}""";
|
}""";
|
||||||
|
|
|
||||||
|
|
@ -1 +1,7 @@
|
||||||
spring.application.name=activitypubbot
|
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
|
@Test
|
||||||
public void getHome() throws Exception {
|
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(status().isOk())
|
||||||
.andExpect(content().string(equalTo("Parsnip!")));
|
.andExpect(content().string(equalTo("Parsnip!")));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue