Search in sources :

Example 1 with ClientSession

use of com.tyndalehouse.step.core.models.ClientSession in project step by STEPBible.

the class BibleControllerTest method testGetBibleVersions.

/**
 * tests that we call correct method
 */
@Test
public void testGetBibleVersions() {
    final ClientSession clientSessionMock = mock(ClientSession.class);
    when(clientSessionMock.getLocale()).thenReturn(Locale.getDefault());
    when(this.clientSessionProvider.get()).thenReturn(clientSessionMock);
    // do test
    this.testController.getModules("true");
    verify(this.bibleInformation).getAvailableModules(true, null, Locale.getDefault());
}
Also used : ClientSession(com.tyndalehouse.step.core.models.ClientSession) Test(org.junit.Test)

Example 2 with ClientSession

use of com.tyndalehouse.step.core.models.ClientSession in project step by STEPBible.

the class StepServletConfig method configureJSword.

/**
 * Configure JSword.
 */
private void configureJSword() {
    BookName.setFullBookName(false);
    final Provider<ClientSession> provider = this.injector.getProvider(ClientSession.class);
    ConfigEntry.setConfigValueInterceptor(this.injector.getInstance(ConfigValueInterceptor.class));
    // set the locale resolution
    LocaleProviderManager.setLocaleProvider(new LocaleProvider() {

        @Override
        public Locale getUserLocale() {
            try {
                return provider.get().getLocale();
            } catch (final ProvisionException ex) {
                return Locale.ENGLISH;
            }
        }
    });
    if (Boolean.TRUE.equals(Boolean.getBoolean("step.development"))) {
        TransformingSAXEventProvider.setDevelopmentMode(true);
    }
}
Also used : Locale(java.util.Locale) ProvisionException(com.google.inject.ProvisionException) ConfigValueInterceptor(org.crosswire.jsword.book.sword.ConfigValueInterceptor) ClientSession(com.tyndalehouse.step.core.models.ClientSession) LocaleProvider(org.crosswire.jsword.internationalisation.LocaleProvider)

Example 3 with ClientSession

use of com.tyndalehouse.step.core.models.ClientSession in project step by STEPBible.

the class RequestUtils method validateSession.

/**
 * validates a session
 *
 * @param sessionProvider provides the client session
 */
public static void validateSession(final Provider<ClientSession> sessionProvider) {
    LOGGER.warn("Attempting to validate session from external call");
    try {
        final ClientSession clientSession = sessionProvider.get();
        final String requiredPassword = System.getProperty("step.setup.password");
        if (StringUtils.isNotBlank(requiredPassword)) {
            // check request has this parameter
            if (!requiredPassword.equals(clientSession.getParam("step.setup.password"))) {
                LOGGER.warn("DENYING ACCESS");
                throw new StepInternalException("This functionality is not available");
            }
        }
        final String ipAddress = clientSession.getIpAddress();
        final InetAddress addr = InetAddress.getByName(ipAddress);
        // Check if the address is a valid special local or loop back
        if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) {
            return;
        }
        // Check if the address is defined on any interface
        try {
            if (NetworkInterface.getByInetAddress(addr) != null) {
                return;
            }
        } catch (final SocketException e) {
            LOGGER.warn("Socket error: ", e);
        }
        LOGGER.warn("DENYING ACCESS TO IP ADDRESS [{}]", ipAddress);
        throw new StepInternalException("This functionality is not available");
    } catch (final UnknownHostException e) {
        throw new StepInternalException("Failed to initialise ip addresses", e);
    }
}
Also used : SocketException(java.net.SocketException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) UnknownHostException(java.net.UnknownHostException) ClientSession(com.tyndalehouse.step.core.models.ClientSession) InetAddress(java.net.InetAddress)

Example 4 with ClientSession

use of com.tyndalehouse.step.core.models.ClientSession in project step by STEPBible.

the class LoaderTest method setUp.

/**
 * sets up the test path for entities
 */
@Before
public void setUp() {
    this.entityManager = new TestEntityManager();
    final ClientSession session = mock(ClientSession.class);
    when(this.clientSessionProvider.get()).thenReturn(session);
    when(session.getLocale()).thenReturn(Locale.ENGLISH);
}
Also used : ClientSession(com.tyndalehouse.step.core.models.ClientSession) TestEntityManager(com.tyndalehouse.step.core.data.entities.impl.TestEntityManager) Before(org.junit.Before)

Example 5 with ClientSession

use of com.tyndalehouse.step.core.models.ClientSession in project step by STEPBible.

the class LanguageServiceImplTest method setUp.

/**
 * Sets up the test mocks
 */
@Before
public void setUp() {
    final ClientSession clientSession = mock(ClientSession.class);
    when(this.clientSessionProvider.get()).thenReturn(clientSession);
    when(clientSession.getLocale()).thenReturn(Locale.ENGLISH);
}
Also used : ClientSession(com.tyndalehouse.step.core.models.ClientSession) Before(org.junit.Before)

Aggregations

ClientSession (com.tyndalehouse.step.core.models.ClientSession)8 Before (org.junit.Before)3 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 ProvisionException (com.google.inject.ProvisionException)1 TestEntityManager (com.tyndalehouse.step.core.data.entities.impl.TestEntityManager)1 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)1 StepCoreModule (com.tyndalehouse.step.core.guice.StepCoreModule)1 BibleInformationService (com.tyndalehouse.step.core.service.BibleInformationService)1 Timed (com.yammer.metrics.annotation.Timed)1 InetAddress (java.net.InetAddress)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 Locale (java.util.Locale)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ConfigValueInterceptor (org.crosswire.jsword.book.sword.ConfigValueInterceptor)1 LocaleProvider (org.crosswire.jsword.internationalisation.LocaleProvider)1 Test (org.junit.Test)1