Search in sources :

Example 1 with AuthProvider

use of de.symeda.sormas.api.AuthProvider in project SORMAS-Project by hzi-braunschweig.

the class StartupShutdownService method syncUsers.

/**
 * Synchronizes all active users with the external Authentication Provider if User Sync at startup is enabled and supported.
 *
 * @see AuthProvider#isUserSyncSupported()
 * @see AuthProvider#isUserSyncAtStartupEnabled()
 */
private void syncUsers() {
    AuthProvider authProvider = AuthProvider.getProvider(configFacade);
    if (!authProvider.isUserSyncSupported()) {
        logger.info("Active Authentication Provider {} doesn't support user sync", authProvider.getName());
        return;
    }
    if (!authProvider.isUserSyncAtStartupEnabled()) {
        logger.info("User sync at startup is disabled. Enable this in SORMAS properties if the active Authentication Provider supports it");
        return;
    }
    List<User> users = userService.getAllActive();
    for (User user : users) {
        syncUser(user);
    }
    logger.info("User synchronization finalized");
}
Also used : User(de.symeda.sormas.backend.user.User) AuthProvider(de.symeda.sormas.api.AuthProvider)

Example 2 with AuthProvider

use of de.symeda.sormas.api.AuthProvider in project SORMAS-Project by hzi-braunschweig.

the class UserFacadeEjbTest method testGetValidLoginRoles.

@Test
public void testGetValidLoginRoles() {
    AuthProvider authProvider = mock(AuthProvider.class);
    MockedStatic<AuthProvider> mockAuthProvider = mockStatic(AuthProvider.class);
    Mockito.when(AuthProvider.getProvider(any())).thenReturn(authProvider);
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, SURVEILLANCE_SUPERVISOR);
    String password = getUserFacade().resetPassword(user.getUuid());
    Set<UserRole> validLoginRoles = getUserFacade().getValidLoginRoles(user.getUserName(), password);
    assertThat(validLoginRoles, containsInAnyOrder(SURVEILLANCE_SUPERVISOR));
    user.setActive(false);
    getUserFacade().saveUser(user);
    validLoginRoles = getUserFacade().getValidLoginRoles(user.getUserName(), password);
    assertThat(validLoginRoles, nullValue());
    // Important: release static mock.
    mockAuthProvider.closeOnDemand();
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) UserRole(de.symeda.sormas.api.user.UserRole) UserDto(de.symeda.sormas.api.user.UserDto) AuthProvider(de.symeda.sormas.api.AuthProvider) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with AuthProvider

use of de.symeda.sormas.api.AuthProvider in project SORMAS-Project by hzi-braunschweig.

the class UserServiceTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    AuthProvider authProvider = mock(AuthProvider.class);
    mockAuthProvider = mockStatic(AuthProvider.class);
    assertNotNull(mockAuthProvider);
    Mockito.when(AuthProvider.getProvider(any())).thenReturn(authProvider);
}
Also used : AuthProvider(de.symeda.sormas.api.AuthProvider) BeforeClass(org.junit.BeforeClass)

Aggregations

AuthProvider (de.symeda.sormas.api.AuthProvider)3 UserDto (de.symeda.sormas.api.user.UserDto)1 UserRole (de.symeda.sormas.api.user.UserRole)1 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)1 User (de.symeda.sormas.backend.user.User)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1