Search in sources :

Example 61 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class LinkBeanTest method shouldCheckLinkAndCallResetPassword.

@Test
public void shouldCheckLinkAndCallResetPassword() {
    User testUser = new User();
    testUser.setLogin("testUser");
    testUser.setActive(true);
    Link testLink = new Link();
    testLink.setLink("linkTest");
    testLink.setUser("testUser");
    testLink.setInsertDate(new Date());
    doReturn(Arrays.asList(testLink)).when(sutMock).getLinksWithLink("linkTest");
    doReturn(testUser).when(sutMock).getUserByName(testLink.getUser());
    doReturn("changedPassword").when(sutMock).resetPassword(testUser);
    String result = sutMock.checkLinkAndResetPassword(testLink.getLink());
    assertThat(result, equalTo("Tu nueva contraseña es: <b>changedPassword</b></br> <p>Se te pedirá que la modifiques al entrar por primera vez.</p>"));
}
Also used : User(com.autentia.tnt.businessobject.User) Link(com.autentia.tnt.businessobject.Link) Date(java.util.Date) Test(org.junit.Test)

Example 62 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class LinkBeanTest method shouldDismissPasswordResetRequestWithNonExistentUser.

@Test
public void shouldDismissPasswordResetRequestWithNonExistentUser() {
    sutMock.setName("testName");
    doReturn(new User()).when(userManager).getUserByLogin("testName");
    String result = sutMock.passwordResetRequest();
    verify(sutMock, never()).sendMail((Link) any(), any());
    assertThat(result, equalTo("emailSentFailed"));
}
Also used : User(com.autentia.tnt.businessobject.User) Test(org.junit.Test)

Example 63 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class UserDAO method searchByLogin.

/**
 * Get a user given her login.
 * @return the user
 * @param login login of user
 * @throws com.autentia.tnt.dao.DataNotFoundException if user does not exist
 * @throws com.autentia.tnt.dao.DataIntegrityException if user is duplicated (bad thing)
 * @throws com.autentia.tnt.dao.DataAccException if something fails accesind DB
 */
public User searchByLogin(String login) throws DataAccException, DataNotFoundException, DataIntegrityException {
    UserSearch search = new UserSearch();
    search.setLogin(login);
    List<User> found = super.search(User.class, search, null);
    if (found.size() == 0) {
        throw new DataNotFoundException(User.class, search);
    } else if (found.size() > 1) {
        throw new DataIntegrityException(User.class, "duplicate login '" + login + "'");
    } else {
        return found.get(0);
    }
}
Also used : DataNotFoundException(com.autentia.tnt.dao.DataNotFoundException) User(com.autentia.tnt.businessobject.User) DataIntegrityException(com.autentia.tnt.dao.DataIntegrityException) UserSearch(com.autentia.tnt.dao.search.UserSearch)

Example 64 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class AuthenticationManager method loadUserByUsername.

/**
 * Load a User for ACEGI given its user name
 *
 * @param username user name
 * @throws org.acegisecurity.userdetails.UsernameNotFoundException
 * @throws org.springframework.dao.DataAccessException
 * @return the user object description as specified by ACEGI
 */
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    try {
        Version db = Version.getDatabaseVersion();
        Version code = Version.getApplicationVersion();
        if (db.compareTo(code, Version.MINOR) == 0) {
            log.info("loadUserByUsername - getting user " + username + " using Hibernate");
            User user = userDAO.searchByLogin(username);
            GrantedAuthority[] auths = userRolesService.getAuthorities(user);
            if (log.isDebugEnabled()) {
                StringBuilder sb = new StringBuilder();
                for (GrantedAuthority auth : auths) {
                    sb.append(auth);
                    sb.append(" ");
                }
                log.debug("loadUserByUsername - user roles: " + sb);
            }
            final Principal principal = new Principal(user, auths);
            // setting user preferred Locale
            final SettingSearch s = new SettingSearch();
            s.setName(SettingPath.GENERAL_PREFERRED_LOCALE);
            s.setOwnerId(user.getId());
            final List<Setting> vals = settings.search(s, null);
            final Setting val = (vals != null && vals.size() > 0) ? vals.get(0) : null;
            if (val != null) {
                final Locale local = new Locale(val.getValue());
                principal.setLocale(local);
            }
            return principal;
        } else {
            log.info("loadUserByUsername - getting user " + username + " using JDBC");
            return jdbcSearchByLogin(username);
        }
    } catch (SecException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new DataRetrievalFailureException("Error getting roles for user: " + username, e);
    } catch (DataIntegrityException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new DataIntegrityViolationException("Inconsistent user name: " + username, e);
    } catch (DataNotFoundException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new UsernameNotFoundException("User not found: " + username, e);
    } catch (DataAccException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new DataRetrievalFailureException("Error getting user: " + username, e);
    } catch (SQLException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new DataRetrievalFailureException("Error getting user: " + username, e);
    }
}
Also used : Locale(java.util.Locale) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) DataNotFoundException(com.autentia.tnt.dao.DataNotFoundException) User(com.autentia.tnt.businessobject.User) DataAccException(com.autentia.tnt.dao.DataAccException) SecException(com.autentia.tnt.manager.security.exception.SecException) SQLException(java.sql.SQLException) DataIntegrityException(com.autentia.tnt.dao.DataIntegrityException) GrantedAuthority(org.acegisecurity.GrantedAuthority) Setting(com.autentia.tnt.businessobject.Setting) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Version(com.autentia.tnt.version.Version) SettingSearch(com.autentia.tnt.dao.search.SettingSearch) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException)

Example 65 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class AuthenticationManagerLdapImpl method resetPasswordExternal.

public String resetPasswordExternal(User user, String[] rnd0, String[] rnd1, String[] rnd2, String[] rnd3, String[] rnd4) {
    String changedPassword = generateRandomPassword(rnd0, rnd1, rnd2, rnd3, rnd4);
    Principal principal = SpringUtils.getPrincipalAdmin();
    final User userAdmin = principal.getUser();
    userAdmin.setDn(ConfigurationUtil.getDefault().getLdapAdminDn());
    userAdmin.setLdapPassword(ConfigurationUtil.getDefault().getLdapAdminPassword());
    changePassword(user, changedPassword, userAdmin);
    activateLdapUserPasswordResetFlag(user, userAdmin);
    return changedPassword;
}
Also used : User(com.autentia.tnt.businessobject.User)

Aggregations

User (com.autentia.tnt.businessobject.User)70 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)17 SortCriteria (com.autentia.tnt.dao.SortCriteria)15 SelectItem (javax.faces.model.SelectItem)11 UserDAO (com.autentia.tnt.dao.hibernate.UserDAO)10 Date (java.util.Date)9 Link (com.autentia.tnt.businessobject.Link)6 UserSearch (com.autentia.tnt.dao.search.UserSearch)5 Attributes (javax.naming.directory.Attributes)5 BasicAttributes (javax.naming.directory.BasicAttributes)5 Activity (com.autentia.tnt.businessobject.Activity)4 Attribute (javax.naming.directory.Attribute)4 BasicAttribute (javax.naming.directory.BasicAttribute)4 GlobalHourReport (com.autentia.tnt.businessobject.GlobalHourReport)3 GlobalHoursReportBean (com.autentia.tnt.bean.activity.GlobalHoursReportBean)2 Commissioning (com.autentia.tnt.businessobject.Commissioning)2 Objective (com.autentia.tnt.businessobject.Objective)2 Occupation (com.autentia.tnt.businessobject.Occupation)2 DataIntegrityException (com.autentia.tnt.dao.DataIntegrityException)2