Search in sources :

Example 6 with EventBus

use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.

the class RadiusRequestHandlerTest method testRunReject.

/**
     * Test that when run is called with an RejectAllHandler that the resultant promise returns a RadiusResponse
     * containing an ACCESS_REJECT packet.
     *
     * @throws InterruptedException - when an interrupt occurs.
     * @throws RadiusProcessingException - when something goes wrong processing a RADIUS packet.
     * @throws UnknownHostException - if the host can't be determined
     */
@Test(enabled = true)
public void testRunReject() throws UnknownHostException, InterruptedException, RadiusProcessingException {
    // given
    final RadiusRequestContext reqCtx = mock(RadiusRequestContext.class);
    final ClientConfig clientConfig = mock(ClientConfig.class);
    String url = "forgerock.org";
    InetSocketAddress socketAddress = new InetSocketAddress(Inet4Address.getByName(url), 6836);
    when(reqCtx.getClientConfig()).thenReturn(clientConfig);
    when(reqCtx.getSource()).thenReturn(socketAddress);
    when(clientConfig.getName()).thenReturn("TestConfig");
    when(clientConfig.getAccessRequestHandlerClass()).thenReturn(RejectAllHandler.class);
    final ByteBuffer bfr = Utils.toBuffer(res);
    final PromiseImpl<RadiusResponse, RadiusProcessingException> promise = PromiseImpl.create();
    EventBus eventBus = new EventBus();
    AccessRequestHandlerFactory accessRequestHandlerFactory = mock(AccessRequestHandlerFactory.class);
    when(accessRequestHandlerFactory.getAccessRequestHandler(reqCtx)).thenReturn(new RejectAllHandler());
    final RadiusRequestHandler handler = new RadiusRequestHandler(accessRequestHandlerFactory, reqCtx, bfr, promise, promise, eventBus);
    handler.run();
    // when
    final RadiusResponse result = promise.getOrThrow();
    // then
    assertThat(result.getResponsePacket().getType()).isEqualTo(PacketType.ACCESS_REJECT);
    verify(reqCtx, times(1)).send(isA(AccessReject.class));
}
Also used : RejectAllHandler(org.forgerock.openam.radius.server.spi.handlers.RejectAllHandler) InetSocketAddress(java.net.InetSocketAddress) EventBus(org.forgerock.guava.common.eventbus.EventBus) ByteBuffer(java.nio.ByteBuffer) AccessReject(org.forgerock.openam.radius.common.AccessReject) ClientConfig(org.forgerock.openam.radius.server.config.ClientConfig) Test(org.testng.annotations.Test)

Example 7 with EventBus

use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.

the class RadiusRequestHandlerTest method testRun.

/**
     * Test that when run is called with an AcceptAllHandler then the RadiusAuthResponse contains a success code and an
     * AcceptResponse is sent.
     *
     * @throws InterruptedException - when an interrupt occurs.
     * @throws RadiusProcessingException - when something goes wrong processing a RADIUS packet.
     * @throws UnknownHostException - if the host can't be determined
     */
@Test(enabled = true)
public void testRun() throws UnknownHostException, InterruptedException, RadiusProcessingException {
    // given
    final RadiusRequestContext reqCtx = mock(RadiusRequestContext.class);
    final ClientConfig clientConfig = mock(ClientConfig.class);
    String url = "forgerock.org";
    InetSocketAddress socketAddress = new InetSocketAddress(Inet4Address.getByName(url), 6836);
    when(reqCtx.getClientConfig()).thenReturn(clientConfig);
    when(reqCtx.getSource()).thenReturn(socketAddress);
    when(clientConfig.getName()).thenReturn("TestConfig");
    final ByteBuffer bfr = Utils.toBuffer(res);
    final PromiseImpl<RadiusResponse, RadiusProcessingException> promise = PromiseImpl.create();
    EventBus eventBus = new EventBus();
    AccessRequestHandlerFactory accessRequestHandlerFactory = mock(AccessRequestHandlerFactory.class);
    when(accessRequestHandlerFactory.getAccessRequestHandler(reqCtx)).thenReturn(new AcceptAllHandler());
    final RadiusRequestHandler handler = new RadiusRequestHandler(accessRequestHandlerFactory, reqCtx, bfr, promise, promise, eventBus);
    handler.run();
    // when
    final RadiusResponse result = promise.getOrThrow();
    // then
    assertThat(result.getResponsePacket().getType()).isEqualTo(PacketType.ACCESS_ACCEPT);
    verify(reqCtx, times(1)).send(isA(AccessAccept.class));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EventBus(org.forgerock.guava.common.eventbus.EventBus) AcceptAllHandler(org.forgerock.openam.radius.server.spi.handlers.AcceptAllHandler) ByteBuffer(java.nio.ByteBuffer) ClientConfig(org.forgerock.openam.radius.server.config.ClientConfig) AccessAccept(org.forgerock.openam.radius.common.AccessAccept) Test(org.testng.annotations.Test)

Example 8 with EventBus

use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.

the class RadiusServerEventRegistrarTest method packetProcessed.

/**
     * Test the following method.
     *
     * @see org.forgerock.openam.radius.server.monitoring.RadiusServerEventRegistrar#packetProcessed
     */
@Test(enabled = true)
public void packetProcessed() {
    // Given
    EventBus eventBus = new EventBus();
    final RadiusServerEventRegistrar eventRegistrar = new RadiusServerEventRegistrar(eventBus);
    // When
    eventRegistrar.packetProcessed();
    // Then
    assertThat(eventRegistrar.getNumberOfPacketsProcessed()).isEqualTo(1);
}
Also used : EventBus(org.forgerock.guava.common.eventbus.EventBus) Test(org.testng.annotations.Test)

Example 9 with EventBus

use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.

the class RadiusServerEventRegistrarTest method packetReceived.

/**
     * Test the following method.
     *
     * @see org.forgerock.openam.radius.server.monitoring.RadiusServerEventRegistrar#packetReceived
     */
@Test(enabled = true)
public void packetReceived() {
    // Given
    EventBus eventBus = new EventBus();
    final RadiusServerEventRegistrar eventRegistrar = new RadiusServerEventRegistrar(eventBus);
    // When
    eventRegistrar.packetReceived();
    // Then
    assertThat(eventRegistrar.getNumberOfPacketsRecieved()).isEqualTo(1);
}
Also used : EventBus(org.forgerock.guava.common.eventbus.EventBus) Test(org.testng.annotations.Test)

Example 10 with EventBus

use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.

the class RadiusServerEventRegistrarTest method packetAccepted.

/**
     * Test the following method.
     *
     * @see org.forgerock.openam.radius.server.monitoring.RadiusServerEventRegistrar#packetAccepted
     */
@Test(enabled = true)
public void packetAccepted() {
    // Given
    EventBus eventBus = new EventBus();
    final RadiusServerEventRegistrar eventRegistrar = new RadiusServerEventRegistrar(eventBus);
    // When
    eventRegistrar.packetAccepted();
    // Then
    assertThat(eventRegistrar.getNumberOfAcceptedPackets()).isEqualTo(1);
}
Also used : EventBus(org.forgerock.guava.common.eventbus.EventBus) Test(org.testng.annotations.Test)

Aggregations

EventBus (org.forgerock.guava.common.eventbus.EventBus)10 Test (org.testng.annotations.Test)10 InetSocketAddress (java.net.InetSocketAddress)3 ByteBuffer (java.nio.ByteBuffer)3 ClientConfig (org.forgerock.openam.radius.server.config.ClientConfig)3 Packet (org.forgerock.openam.radius.common.Packet)2 AuthContext (com.sun.identity.authentication.AuthContext)1 Status (com.sun.identity.authentication.AuthContext.Status)1 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)1 Properties (java.util.Properties)1 Callback (javax.security.auth.callback.Callback)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 AccessAccept (org.forgerock.openam.radius.common.AccessAccept)1 AccessReject (org.forgerock.openam.radius.common.AccessReject)1 AccessRequest (org.forgerock.openam.radius.common.AccessRequest)1 AttributeSet (org.forgerock.openam.radius.common.AttributeSet)1 Authenticator (org.forgerock.openam.radius.common.Authenticator)1 UserNameAttribute (org.forgerock.openam.radius.common.UserNameAttribute)1 UserPasswordAttribute (org.forgerock.openam.radius.common.UserPasswordAttribute)1