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());
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations