use of org.sonar.api.security.UserDetails in project sonarqube by SonarSource.
the class RealmAuthenticatorTest method fail_to_authenticate_when_external_authentication_fails.
@Test
public void fail_to_authenticate_when_external_authentication_fails() throws Exception {
executeStartWithoutGroupSync();
when(externalUsersProvider.doGetUserDetails(any(ExternalUsersProvider.Context.class))).thenReturn(new UserDetails());
when(authenticator.doAuthenticate(any(Authenticator.Context.class))).thenReturn(false);
expectedException.expect(authenticationException().from(Source.realm(BASIC, REALM_NAME)).withLogin(LOGIN).andNoPublicMessage());
expectedException.expectMessage("Realm returned authenticate=false");
try {
underTest.authenticate(LOGIN, PASSWORD, request, BASIC);
} finally {
verifyZeroInteractions(authenticationEvent);
}
}
use of org.sonar.api.security.UserDetails in project sonarqube by SonarSource.
the class RealmAuthenticatorTest method fail_to_authenticate_when_any_exception_is_thrown.
@Test
public void fail_to_authenticate_when_any_exception_is_thrown() throws Exception {
executeStartWithoutGroupSync();
String expectedMessage = "emulating exception in doAuthenticate";
doThrow(new IllegalArgumentException(expectedMessage)).when(authenticator).doAuthenticate(any(Authenticator.Context.class));
when(externalUsersProvider.doGetUserDetails(any(ExternalUsersProvider.Context.class))).thenReturn(new UserDetails());
expectedException.expect(authenticationException().from(Source.realm(BASIC_TOKEN, REALM_NAME)).withLogin(LOGIN).andNoPublicMessage());
expectedException.expectMessage(expectedMessage);
try {
underTest.authenticate(LOGIN, PASSWORD, request, BASIC_TOKEN);
} finally {
verifyZeroInteractions(authenticationEvent);
}
}
use of org.sonar.api.security.UserDetails in project sonarqube by SonarSource.
the class RealmAuthenticatorTest method login_is_used_when_no_name_provided.
@Test
public void login_is_used_when_no_name_provided() throws Exception {
executeStartWithoutGroupSync();
when(authenticator.doAuthenticate(any(Authenticator.Context.class))).thenReturn(true);
UserDetails userDetails = new UserDetails();
userDetails.setEmail("email");
when(externalUsersProvider.doGetUserDetails(any(ExternalUsersProvider.Context.class))).thenReturn(userDetails);
when(userIdentityAuthenticator.authenticate(any(UserIdentity.class), any(IdentityProvider.class), any(Source.class))).thenReturn(USER);
underTest.authenticate(LOGIN, PASSWORD, request, BASIC);
verify(userIdentityAuthenticator).authenticate(userIdentityArgumentCaptor.capture(), identityProviderArgumentCaptor.capture(), sourceCaptor.capture());
assertThat(identityProviderArgumentCaptor.getValue().getName()).isEqualTo("sonarqube");
verify(authenticationEvent).loginSuccess(request, LOGIN, Source.realm(BASIC, REALM_NAME));
}
use of org.sonar.api.security.UserDetails in project sonarqube by SonarSource.
the class RealmAuthenticatorTest method authenticate_with_sonarqube_identity_provider.
@Test
public void authenticate_with_sonarqube_identity_provider() throws Exception {
executeStartWithoutGroupSync();
when(authenticator.doAuthenticate(any(Authenticator.Context.class))).thenReturn(true);
UserDetails userDetails = new UserDetails();
userDetails.setName("name");
userDetails.setEmail("email");
when(externalUsersProvider.doGetUserDetails(any(ExternalUsersProvider.Context.class))).thenReturn(userDetails);
when(userIdentityAuthenticator.authenticate(any(UserIdentity.class), any(IdentityProvider.class), any(Source.class))).thenReturn(USER);
underTest.authenticate(LOGIN, PASSWORD, request, BASIC);
verify(userIdentityAuthenticator).authenticate(userIdentityArgumentCaptor.capture(), identityProviderArgumentCaptor.capture(), sourceCaptor.capture());
assertThat(identityProviderArgumentCaptor.getValue().getKey()).isEqualTo("sonarqube");
assertThat(identityProviderArgumentCaptor.getValue().getName()).isEqualTo("sonarqube");
assertThat(identityProviderArgumentCaptor.getValue().getDisplay()).isNull();
assertThat(identityProviderArgumentCaptor.getValue().isEnabled()).isTrue();
verify(authenticationEvent).loginSuccess(request, LOGIN, Source.realm(BASIC, REALM_NAME));
}
use of org.sonar.api.security.UserDetails in project sonarqube by SonarSource.
the class RealmAuthenticatorTest method use_login_if_user_details_contains_no_name.
@Test
public void use_login_if_user_details_contains_no_name() throws Exception {
executeStartWithoutGroupSync();
when(authenticator.doAuthenticate(any(Authenticator.Context.class))).thenReturn(true);
UserDetails userDetails = new UserDetails();
userDetails.setName(null);
when(externalUsersProvider.doGetUserDetails(any(ExternalUsersProvider.Context.class))).thenReturn(userDetails);
when(userIdentityAuthenticator.authenticate(any(UserIdentity.class), any(IdentityProvider.class), any(Source.class))).thenReturn(USER);
underTest.authenticate(LOGIN, PASSWORD, request, BASIC);
verify(userIdentityAuthenticator).authenticate(userIdentityArgumentCaptor.capture(), identityProviderArgumentCaptor.capture(), sourceCaptor.capture());
assertThat(userIdentityArgumentCaptor.getValue().getName()).isEqualTo(LOGIN);
verify(authenticationEvent).loginSuccess(request, LOGIN, Source.realm(BASIC, REALM_NAME));
}
Aggregations