Search in sources :

Example 1 with SettingSearch

use of com.autentia.tnt.dao.search.SettingSearch in project TNTConcept by autentia.

the class SettingManager method get.

/**
 * Get a property's persistent object
 *
 * @param propertyPath
 *            property path
 * @param returnNewIfNotExists
 *            return a newly created object if it does not exist (null
 *            otherwise)
 * @return the Setting object which stores the property in database (if it
 *         exists) or a new Setting or null
 *
 *         Paco changed the visibility of this method... (ask him why)
 */
public Setting get(String propertyPath, boolean returnNewIfNotExists) {
    SettingSearch s = new SettingSearch();
    s.setName(propertyPath);
    s.setOwnerId(AuthenticationManager.getDefault().getCurrentPrincipal().getUser().getId());
    List<Setting> vals = settingDAO.search(s, null);
    if (vals.size() > 0) {
        return vals.get(0);
    } else if (returnNewIfNotExists) {
        Setting val = new Setting();
        val.setName(propertyPath);
        return val;
    } else {
        return null;
    }
}
Also used : SettingSearch(com.autentia.tnt.dao.search.SettingSearch) Setting(com.autentia.tnt.businessobject.Setting)

Example 2 with SettingSearch

use of com.autentia.tnt.dao.search.SettingSearch 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)

Aggregations

Setting (com.autentia.tnt.businessobject.Setting)2 SettingSearch (com.autentia.tnt.dao.search.SettingSearch)2 User (com.autentia.tnt.businessobject.User)1 DataAccException (com.autentia.tnt.dao.DataAccException)1 DataIntegrityException (com.autentia.tnt.dao.DataIntegrityException)1 DataNotFoundException (com.autentia.tnt.dao.DataNotFoundException)1 SecException (com.autentia.tnt.manager.security.exception.SecException)1 Version (com.autentia.tnt.version.Version)1 SQLException (java.sql.SQLException)1 Locale (java.util.Locale)1 GrantedAuthority (org.acegisecurity.GrantedAuthority)1 UsernameNotFoundException (org.acegisecurity.userdetails.UsernameNotFoundException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 DataRetrievalFailureException (org.springframework.dao.DataRetrievalFailureException)1