use of org.springframework.extensions.webscripts.servlet.WebScriptServletResponse in project alfresco-remote-api by Alfresco.
the class BlockingRemoteUserMapper method prepareMockResponse.
private WebScriptServletResponse prepareMockResponse() {
HttpServletResponse mockHttpResponse = mock(HttpServletResponse.class);
WebScriptServletResponse mockResponse = mock(WebScriptServletResponse.class);
when(mockResponse.getHttpServletResponse()).thenReturn(mockHttpResponse);
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
if (args != null && args.length == 1) {
setStatusCode = -1;
try {
setStatusCode = (int) args[0];
} catch (Exception e) {
logger.error("Could not get the status code: " + e.getMessage(), e);
}
}
return null;
}
}).when(mockHttpResponse).setStatus(anyInt());
return mockResponse;
}
use of org.springframework.extensions.webscripts.servlet.WebScriptServletResponse in project alfresco-remote-api by Alfresco.
the class RemoteAuthenticatorFactoryTest method testLogInWithNonExistingPerson.
@Test
public void testLogInWithNonExistingPerson() {
// Random non existing person
final String username = GUID.generate();
// Mock a request with a username in the header
HttpServletRequest mockHttpRequest = mock(HttpServletRequest.class);
when(mockHttpRequest.getHeader("X-Alfresco-Remote-User")).thenReturn(username);
when(mockHttpRequest.getScheme()).thenReturn("http");
WebScriptServletRequest mockRequest = mock(WebScriptServletRequest.class);
when(mockRequest.getHttpServletRequest()).thenReturn(mockHttpRequest);
HttpServletResponse mockHttpResponse = mock(HttpServletResponse.class);
WebScriptServletResponse mockResponse = mock(WebScriptServletResponse.class);
when(mockResponse.getHttpServletResponse()).thenReturn(mockHttpResponse);
Authenticator authenticator = remoteUserAuthenticatorFactory.create(mockRequest, mockResponse);
assertTrue("The non existing user should be authenticated.", authenticator.authenticate(RequiredAuthentication.user, false));
assertTrue("The user should be auto created.", personService.personExists(username));
}
use of org.springframework.extensions.webscripts.servlet.WebScriptServletResponse in project alfresco-remote-api by Alfresco.
the class ResponseWriter method setContentInfoOnResponse.
/**
* Sets the response headers with any information we know about the content
*
* @param res WebScriptResponse
* @param contentInfo Content Information
*/
default void setContentInfoOnResponse(WebScriptResponse res, ContentInfo contentInfo) {
if (contentInfo != null) {
// Set content info on the response
res.setContentType(contentInfo.getMimeType());
res.setContentEncoding(contentInfo.getEncoding());
if (res instanceof WrappingWebScriptResponse) {
WrappingWebScriptResponse wrappedRes = ((WrappingWebScriptResponse) res);
res = wrappedRes.getNext();
}
if (res instanceof WebScriptServletResponse) {
WebScriptServletResponse servletResponse = (WebScriptServletResponse) res;
if (contentInfo.getLength() > 0) {
if (contentInfo.getLength() > 0 && contentInfo.getLength() < Integer.MAX_VALUE) {
servletResponse.getHttpServletResponse().setContentLength((int) contentInfo.getLength());
}
}
if (contentInfo.getLocale() != null) {
servletResponse.getHttpServletResponse().setLocale(contentInfo.getLocale());
}
}
}
}
use of org.springframework.extensions.webscripts.servlet.WebScriptServletResponse in project alfresco-remote-api by Alfresco.
the class RemoteAuthenticatorFactoryTest method testDisabledUser.
@Test
public void testDisabledUser() throws Exception {
final String username = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {
@Override
public String execute() throws Throwable {
return AuthenticationUtil.runAs(new RunAsWork<String>() {
@Override
public String doWork() throws Exception {
return createPerson(false);
}
}, AuthenticationUtil.SYSTEM_USER_NAME);
}
}, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
return AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
// Mock a request with a username in the header
HttpServletRequest mockHttpRequest = mock(HttpServletRequest.class);
when(mockHttpRequest.getHeader("X-Alfresco-Remote-User")).thenReturn(username);
when(mockHttpRequest.getScheme()).thenReturn("http");
WebScriptServletRequest mockRequest = mock(WebScriptServletRequest.class);
when(mockRequest.getHttpServletRequest()).thenReturn(mockHttpRequest);
HttpServletResponse mockHttpResponse = mock(HttpServletResponse.class);
WebScriptServletResponse mockResponse = mock(WebScriptServletResponse.class);
when(mockResponse.getHttpServletResponse()).thenReturn(mockHttpResponse);
Authenticator authenticator = remoteUserAuthenticatorFactory.create(mockRequest, mockResponse);
assertFalse(authenticator.authenticate(RequiredAuthentication.user, false));
return null;
}
}, AuthenticationUtil.SYSTEM_USER_NAME);
}
}, false, true);
}
use of org.springframework.extensions.webscripts.servlet.WebScriptServletResponse in project alfresco-remote-api by Alfresco.
the class RemoteAuthenticatorFactoryTest method testEnabledUser.
@Test
public void testEnabledUser() throws Exception {
final String username = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {
@Override
public String execute() throws Throwable {
return AuthenticationUtil.runAs(new RunAsWork<String>() {
@Override
public String doWork() throws Exception {
return createPerson(true);
}
}, AuthenticationUtil.SYSTEM_USER_NAME);
}
}, false, true);
// Mock a request with a username in the header
HttpServletRequest mockHttpRequest = mock(HttpServletRequest.class);
when(mockHttpRequest.getHeader("X-Alfresco-Remote-User")).thenReturn(username);
when(mockHttpRequest.getScheme()).thenReturn("http");
WebScriptServletRequest mockRequest = mock(WebScriptServletRequest.class);
when(mockRequest.getHttpServletRequest()).thenReturn(mockHttpRequest);
HttpServletResponse mockHttpResponse = mock(HttpServletResponse.class);
WebScriptServletResponse mockResponse = mock(WebScriptServletResponse.class);
when(mockResponse.getHttpServletResponse()).thenReturn(mockHttpResponse);
Authenticator authenticator = remoteUserAuthenticatorFactory.create(mockRequest, mockResponse);
assertTrue(authenticator.authenticate(RequiredAuthentication.user, false));
}
Aggregations