use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class SimbaGatewayTest method authenticate_WhenPrincipalWasNotSet_ReturnsAbsentPrincipal.
@Test
public void authenticate_WhenPrincipalWasNotSet_ReturnsAbsentPrincipal() throws Exception {
SimbaCredentials credentials = mock(SimbaCredentials.class);
RequestData requestData = mock(RequestData.class);
when(credentials.asRequestData()).thenReturn(requestData);
Client authenticationServiceMock = setupSimbaServiceToReturnASimbaAuthenticationService();
String principal = "simbaUsername";
String ssoToken = "ssotoken";
ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.ADD_PARAMETER_TO_TARGET).withPrincipal(principal).withSsoToken(new SSOToken(ssoToken)).build();
when(authenticationServiceMock.processRequest(requestData, SimbaGateway.SESSION_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
Optional<SimbaPrincipal> simbaPrincipal = simbaGateway.authenticate(credentials);
assertThat(simbaPrincipal.isPresent()).isFalse();
}
use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class SimbaGatewayTest method authenticate_WhenPrincipalWasSet_ReturnPrincipal.
@Test
public void authenticate_WhenPrincipalWasSet_ReturnPrincipal() throws Exception {
SimbaCredentials credentials = mock(SimbaCredentials.class);
RequestData requestData = mock(RequestData.class);
when(credentials.asRequestData()).thenReturn(requestData);
Client authenticationServiceMock = setupSimbaServiceToReturnASimbaAuthenticationService();
String principal = "simbaUsername";
String token = "token";
ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.DO_FILTER_AND_SET_PRINCIPAL).withPrincipal(principal).withSsoToken(new SSOToken(token)).build();
when(authenticationServiceMock.processRequest(requestData, SESSION_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
Optional<SimbaPrincipal> simbaPrincipal = simbaGateway.authenticate(credentials);
assertThat(simbaPrincipal.get()).isEqualTo(new SimbaPrincipal(principal, token));
}
use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class SimbaCredentialsTest method asRequestData_ReturnsRequestDataFromInternals.
@Test
public void asRequestData_ReturnsRequestDataFromInternals() throws Exception {
Map<String, String> requestHeaders = Maps.newHashMap();
requestHeaders.put(HttpHeaders.WWW_AUTHENTICATE, "auth-string");
Map<String, String> requestParameters = Maps.newHashMap();
requestParameters.put("format", "timeseries");
SimbaCredentials simbaCredentials = new SimbaCredentialsBuilderForTests().withRequestUrl(SimbaCredentialsBuilderForTests.REQUESTURL + "?format=timeseries").withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsotoken("123456").withIsLoginRequest(true).build();
RequestData expected = new RequestDataBuilderForTests().withHostServerName(HOSTSERVERNAME).withRequestMethod(HTTP_METHOD).withRequestUrl(REQUESTURL + "?format=timeseries").withSimbaWebURL(SIMBAWEBURL).withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsoToken(new SSOToken("123456")).withLoginRequest(true).build();
RequestData actual = simbaCredentials.asRequestData();
assertThat(actual).isEqualTo(expected);
}
use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class EnterApplicationCommandTest method doFilterAndFinishOnExecute.
@Test
public void doFilterAndFinishOnExecute() throws Exception {
SSOToken ssoToken = new SSOToken();
when(chainContextMock.getRequestSSOToken()).thenReturn(ssoToken);
State state = enterApplicationCommand.execute(chainContextMock);
assertThat(state).isEqualTo(State.FINISH);
verify(chainContextMock).activateAction(ActionType.DO_FILTER_AND_SET_PRINCIPAL);
verify(auditLogEventFactory).createEventForAuthenticationForSuccess(chainContextMock, AuditMessages.ENTER_APPLICATION);
verify(auditMock).log(any(AuditLogEvent.class));
}
use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class SimbaGatewayTest method login.
@Test
public void login() throws Exception {
Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
ContainerRequest containerRequestMock = mock(ContainerRequest.class);
SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
RequestData requestData = mock(RequestData.class);
SSOToken expectedSSOToken = new SSOToken("token");
ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.MAKE_COOKIE).withSsoToken(expectedSSOToken).build();
when(simbaCredentialsFactoryMock.create(containerRequestMock, false)).thenReturn(simbaCredentials);
when(simbaCredentials.asRequestData()).thenReturn(requestData);
when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
Optional<String> actualSSOToken = simbaGateway.login(containerRequestMock);
assertThat(actualSSOToken.isPresent()).isTrue();
assertThat(actualSSOToken.get()).isEqualTo(expectedSSOToken.getToken());
}
Aggregations