Search in sources :

Example 1 with JacksonConfigContext

use of com.nexblocks.authguard.config.JacksonConfigContext in project AuthGuard by AuthGuard.

the class SecurePasswordProviderTest method parsesWithPreviousVersions.

@Test
void parsesWithPreviousVersions() {
    final ObjectNode configRoot = new ObjectNode(JsonNodeFactory.instance).put("algorithm", "bcrypt").put("validFor", "5d").put("version", 2);
    final ObjectNode bcryptConfig = new ObjectNode(JsonNodeFactory.instance);
    configRoot.set("bcrypt", bcryptConfig);
    final ObjectNode previousPasswordConfig = new ObjectNode(JsonNodeFactory.instance).put("algorithm", "scrypt").put("validFor", "5d").put("version", 1);
    final ObjectNode scryptConfig = new ObjectNode(JsonNodeFactory.instance);
    previousPasswordConfig.set("scrypt", scryptConfig);
    final ArrayNode previousVersions = new ArrayNode(JsonNodeFactory.instance).add(previousPasswordConfig);
    configRoot.set("previousVersions", previousVersions);
    final ConfigContext configContext = new JacksonConfigContext(configRoot);
    final SecurePasswordProvider provider = new SecurePasswordProvider(configContext);
    assertThat(provider.getCurrentVersion()).isEqualTo(2);
    assertThat(provider.getPreviousVersions().get(1)).isInstanceOf(SCryptPassword.class);
}
Also used : JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Test(org.junit.jupiter.api.Test)

Example 2 with JacksonConfigContext

use of com.nexblocks.authguard.config.JacksonConfigContext in project AuthGuard by AuthGuard.

the class SecurePasswordProviderTest method parsesWithoutPreviousVersions.

@Test
void parsesWithoutPreviousVersions() {
    final ObjectNode configRoot = new ObjectNode(JsonNodeFactory.instance).put("algorithm", "bcrypt").put("validFor", "5d");
    final ObjectNode bcryptConfig = new ObjectNode(JsonNodeFactory.instance);
    configRoot.set("bcrypt", bcryptConfig);
    final ConfigContext configContext = new JacksonConfigContext(configRoot);
    final SecurePasswordProvider provider = new SecurePasswordProvider(configContext);
    assertThat(provider.getCurrentVersion()).isEqualTo(1);
}
Also used : JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Test(org.junit.jupiter.api.Test)

Example 3 with JacksonConfigContext

use of com.nexblocks.authguard.config.JacksonConfigContext in project AuthGuard by AuthGuard.

the class SessionProviderTest method sessionsConfig.

private ConfigContext sessionsConfig() {
    final ObjectNode configNode = new ObjectNode(JsonNodeFactory.instance);
    configNode.put("randomSize", 128).put("lifeTime", "20m");
    return new JacksonConfigContext(configNode);
}
Also used : JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 4 with JacksonConfigContext

use of com.nexblocks.authguard.config.JacksonConfigContext in project AuthGuard by AuthGuard.

the class MessageBusTest method setup.

@BeforeAll
void setup() {
    final ObjectNode configNode = new ObjectNode(JsonNodeFactory.instance);
    configNode.set("channels", new ArrayNode(JsonNodeFactory.instance).add("accounts").add("auth"));
    final ConfigContext configContext = new JacksonConfigContext(configNode);
    messageBus = new MessageBus(new RxPublisherFactory(), configContext);
}
Also used : JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RxPublisherFactory(com.nexblocks.authguard.emb.rxjava.RxPublisherFactory) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ConfigContext(com.nexblocks.authguard.config.ConfigContext) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with JacksonConfigContext

use of com.nexblocks.authguard.config.JacksonConfigContext in project AuthGuard by AuthGuard.

the class AutoSubscribersTest method subscribe.

@Test
void subscribe() {
    final ObjectNode configRoot = new ObjectNode(JsonNodeFactory.instance);
    final ArrayNode allowed = new ArrayNode(JsonNodeFactory.instance).add("com.nexblocks.authguard.emb.AutoSubscribersTest.ToBeSubscribed").add("com.nexblocks.authguard.emb.AutoSubscribersTest.NotToBeSubscribed");
    configRoot.set("subscribers", allowed);
    final MessageBus messageBus = Mockito.mock(MessageBus.class);
    final ToBeSubscribed toBeSubscribed = new ToBeSubscribed();
    final NotToBeSubscribed notToBeSubscribed = new NotToBeSubscribed();
    final ConfigContext configContext = new JacksonConfigContext(configRoot);
    final AutoSubscribers autoSubscribers = new AutoSubscribers(messageBus, ImmutableSet.of(toBeSubscribed, notToBeSubscribed), configContext);
    autoSubscribers.subscribe();
    Mockito.verify(messageBus, Mockito.times(1)).subscribe("test", toBeSubscribed);
    Mockito.verify(messageBus, Mockito.never()).subscribe(Mockito.any(), Mockito.eq(notToBeSubscribed));
}
Also used : JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 JacksonConfigContext (com.nexblocks.authguard.config.JacksonConfigContext)5 ConfigContext (com.nexblocks.authguard.config.ConfigContext)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 Test (org.junit.jupiter.api.Test)3 RxPublisherFactory (com.nexblocks.authguard.emb.rxjava.RxPublisherFactory)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1