public void updateUser(String username, AppUser userShell) { AppUser userEntity = getUserByUsername(username); String oldEmailAddress = userEntity.getEmailAddress(); String oldPassword = userEntity.getPassword(); copyProperties(userShell, userEntity); String newEmailAddress = userEntity.getEmailAddress(); String newPassword = userEntity.getPassword(); if (changed(oldPassword, newPassword)) { validatePassword(newPassword); hashPassword(userEntity); } validateEntity(userEntity); if (changed(oldEmailAddress, newEmailAddress)) { checkEmailAddressIsNotRegistered(newEmailAddress); updateCurrentPrincipal(userEntity, newEmailAddress); } userDao.merge(userEntity); }
public void actionPerformed(ActionEvent evt) { // String sPassword = m_actionuser.getPassword(); if (m_actionuser.authenticate()) { // p'adentro directo, no tiene password openAppView(m_actionuser); } else { // comprobemos la clave antes de entrar... String sPassword = JPasswordDialog.showEditPassword( JRootApp.this, AppLocal.getIntString("Label.Password"), m_actionuser.getName(), m_actionuser.getIcon()); if (sPassword != null) { if (m_actionuser.authenticate(sPassword)) { openAppView(m_actionuser); } else { MessageInf msg = new MessageInf( MessageInf.SGN_WARNING, AppLocal.getIntString("message.BadPassword")); msg.show(JRootApp.this); } } } }
private void setUserProperties(AppUser user) { user.setEnabled(false); user.setRole(Role.ROLE_USER); user.setDateTimeCreated(clock.now()); user.setEmailValidationKey(getEmailValidationKey(user)); }
public ArrayList<SmallPrayer> getTodayServices() { ArrayList<String> services = new ArrayList<String>(); AppUser appUserInstance = AppUser.getInstance(); ArrayList<DailyEvents> dailyEvents = appUserInstance.getCurrentCommunity().getDailyEvents(); Calendar calendar = Calendar.getInstance(); String day = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)); String month = String.valueOf(calendar.get(Calendar.MONTH) + 1); String year = String.valueOf(calendar.get(Calendar.YEAR)); if (Integer.valueOf(day) < 10) day = "0" + day; if (Integer.valueOf(month) < 10) month = "0" + month; String todayDateString = String.valueOf( String.valueOf(day) + "/" + String.valueOf(month) + "/" + String.valueOf(year)); for (int i = 0; i < dailyEvents.size(); i++) { DailyEvents singleDay = dailyEvents.get(i); if (todayDateString.equals(singleDay.getDate())) { if (singleDay.getPrayers().size() > 0) { return singleDay.getPrayers().get(0).getSmallPrayers(); } } } return null; }
public void createUser(AppUser user) { checkEmailAddressIsNotRegistered(user.getEmailAddress()); validatePassword(user.getPassword()); hashPassword(user); setUserProperties(user); validateEntity(user); userDao.persist(user); validationEmailSender.send(user); }
public Post getRecentConversation() { AppUser appUserInstance = AppUser.getInstance(); ArrayList<Post> posts = appUserInstance.getCurrentCommunity().getCommunityPosts(); if (posts != null) { if (posts.size() > 0) { Post item = posts.get(0); return item; } } return null; }
public boolean enableUserByValidationKey(String emailValidationKey) { AppUser user = userDao.findByEmailValidationKey(emailValidationKey); boolean emailKeyExists = user != null; if (emailKeyExists) { user.setEnabled(true); user.setEmailValidationKey(null); userDao.merge(user); } return emailKeyExists; }
private String getEmailValidationKey(AppUser user) { String randomString = RandomStringUtils.randomAlphanumeric(EMAIL_VALIDATION_KEY_LENGTH); String hashedUsername = DigestUtils.md2Hex(user.getEmailAddress()); return randomString + hashedUsername; }
public void executeTask(String sTaskClass) { m_appview.waitCursorBegin(); if (m_appuser.hasPermission(sTaskClass)) { try { ProcessAction myProcess = (ProcessAction) m_appview.getBean(sTaskClass); // execute the proces try { MessageInf m = myProcess.execute(); if (m != null) { // si devuelve un mensaje, lo muestro JMessageDialog.showMessage(JPrincipalApp.this, m); } } catch (BasicException eb) { // Si se produce un error lo muestro. JMessageDialog.showMessage(JPrincipalApp.this, new MessageInf(eb)); } } catch (BeanFactoryException e) { JMessageDialog.showMessage( JPrincipalApp.this, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("Label.LoadError"), e)); } } else { // No hay permisos para ejecutar la accion... JMessageDialog.showMessage( JPrincipalApp.this, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.notpermissions"))); } m_appview.waitCursorEnd(); }
private void copyProperties(AppUser userShell, AppUser userEntity) { userEntity.setFirstName(userShell.getFirstName()); userEntity.setLastName(userShell.getLastName()); userEntity.setEmailAddress(userShell.getEmailAddress()); if (passwordChanged(userShell)) { userEntity.setPassword(userShell.getPassword()); } }
public void showTask(String sTaskClass) { m_appview.waitCursorBegin(); if (m_appuser.hasPermission(sTaskClass)) { JPanelView m_jMyView = (JPanelView) m_aCreatedViews.get(sTaskClass); // cierro la antigua if (m_jLastView == null || (m_jMyView != m_jLastView && m_jLastView.deactivate())) { // Construct the new view if (m_jMyView == null) { // Is the view prepared m_jMyView = m_aPreparedViews.get(sTaskClass); if (m_jMyView == null) { // The view is not prepared. Try to get as a Bean... try { m_jMyView = (JPanelView) m_appview.getBean(sTaskClass); } catch (BeanFactoryException e) { m_jMyView = new JPanelNull(m_appview, e); } } m_jPanelContainer.add(m_jMyView.getComponent(), sTaskClass); m_aCreatedViews.put(sTaskClass, m_jMyView); } // ejecuto la tarea try { m_jMyView.activate(); } catch (BasicException e) { JMessageDialog.showMessage( this, new MessageInf( MessageInf.SGN_WARNING, AppLocal.getIntString("message.notactive"), e)); } // se tiene que mostrar el panel m_jLastView = m_jMyView; showView(sTaskClass); // Y ahora que he cerrado la antigua me abro yo String sTitle = m_jMyView.getTitle(); m_jPanelTitle.setVisible(sTitle != null); m_jTitle.setText(sTitle); } } else { // No hay permisos para ejecutar la accion... JMessageDialog.showMessage( this, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.notpermissions"))); } m_appview.waitCursorEnd(); }
private void updateCurrentPrincipal(AppUser user, String newEmailAddress) { Authentication originalAuth = SecurityContextHolder.getContext().getAuthentication(); UserDetails originalUserDetails = (UserDetails) originalAuth.getPrincipal(); UserDetails newUserDetails = new User(newEmailAddress, user.getPassword(), originalUserDetails.getAuthorities()); Authentication newAuth = new UsernamePasswordAuthenticationToken( newUserDetails, newUserDetails.getPassword(), newUserDetails.getAuthorities()); SecurityContextHolder.getContext().setAuthentication(newAuth); }
public JSONObject toJson() { JSONObject JSONObjectShoppingList = new JSONObject(); JSONArray JSONArrayListEntry = new JSONArray(); JSONArray JSONArrayUser = new JSONArray(); try { JSONObjectShoppingList.put("id", id).put("name", name).put("status", status); for (ListEntry le : this.listEntry) { JSONArrayListEntry.put(le.toJson()); } for (AppUser user : this.userList) { JSONArrayUser.put(user.toJson()); } JSONObjectShoppingList.put("listEntry", JSONArrayListEntry); JSONObjectShoppingList.put("user", JSONArrayUser); } catch (JSONException ex) { Logger.getLogger(ShoppingList.class.getName()).log(Level.SEVERE, null, ex); } return JSONObjectShoppingList; }
public SearchBean() { HttpServletRequest hsr = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); javax.servlet.http.HttpServletResponse response = (javax.servlet.http.HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); String term = hsr.getParameter("q").trim(); if (term.length() < 1) { try { response.sendRedirect("/"); } catch (Exception ex) { } } BiblePassage passage = BiblePassage.parse(term, CachedData.getBibleBooks(), true); if (passage != null) { try { response.sendRedirect("/bible/" + passage.getUrl()); } catch (Exception ex) { } } else { if (!term.contains(" ")) { String baseWord = Topic.getBaseWord(term); Topic topic = Topic.loadByBaseWord(baseWord); if (topic != null) { try { response.sendRedirect("/topics/" + topic.getUrl()); } catch (Exception ex) { } } } else { int verseId = TextSearch.findMatch(term); passage = BiblePassage.load(verseId, verseId); passage.populateVerses(AppUser.getCurrent().TranslationId); try { response.sendRedirect("/bible/" + passage.getUrl()); } catch (Exception ex) { } } } }
/** Creates new form JPrincipalApp */ public JPrincipalApp(JRootApp appview, AppUser appuser) { m_appview = appview; m_appuser = appuser; m_dlSystem = (DataLogicSystem) m_appview.getBean("com.openbravo.pos.forms.DataLogicSystemCreate"); // Cargamos los permisos del usuario m_appuser.fillPermissions(m_dlSystem); m_principalnotificator = new JPrincipalNotificator(); m_actionfirst = null; m_jLastView = null; m_aPreparedViews = new HashMap<String, JPanelView>(); m_aCreatedViews = new HashMap<String, JPanelView>(); initComponents(); // m_jPanelTitle.setUI(new GradientUI()); m_jPanelTitle.setBorder(RoundedBorder.createGradientBorder()); m_jPanelTitle.setVisible(false); // Anado el panel nulo m_jPanelContainer.add(new JPanel(), "<NULL>"); showView("<NULL>"); try { ScriptMenu menu = new ScriptMenu(); ScriptEngine eng = ScriptFactory.getScriptEngine(ScriptFactory.BEANSHELL); eng.put("menu", menu); eng.eval(m_dlSystem.getResourceAsText("Menu.Root")); m_jPanelLeft.setViewportView(menu.getTaskPane()); } catch (ScriptException e) { e.printStackTrace(); // Error Message } }
/** * Obtiene la información del usuario en la aplicación. * * @param userAuthId Identificador del usuario en el Sistema Gestor de Usuarios. * @param userAuthType Tipo de usuario. * @param userName Nombre del usuario * @param remoteIpAddress Dirección IP del usuario. * @return Información del usuario en la aplicación. * @throws AppUserException si ocurre algún error en la validación */ public AppUser getAppUser( String userAuthId, String userAuthType, String userName, String remoteIpAddress, String entity, String sessionAdm) throws AppUserException, ArchivoModelException { if (logger.isDebugEnabled()) logger.debug( "getAppUser: userAuthId=[" + userAuthId + "], userAuthType=[" + userAuthType + "], remoteIpAddress=[" + remoteIpAddress + "]"); // Obtener el engine de base de datos DbEngine engine = null; String dataSourceName = ConfiguracionSistemaArchivoFactory.getConfiguracionSistemaArchivo() .getConfiguracionGeneral() .getDataSourceName(); String dbFactoryClass = ConfiguracionSistemaArchivoFactory.getConfiguracionSistemaArchivo() .getConfiguracionGeneral() .getDBFactoryClass(); if (StringUtils.isNotEmpty(entity)) { dataSourceName = MultiEntityUtil.composeDsName(dataSourceName, entity); } try { if (ConfigConstants.getInstance().getEntidadRequerida()) { // Buscar el datasource en el contexto if (dataSourceName != null) { Context context = new InitialContext(); if (context != null) { DataSource dataSource = (DataSource) context.lookup(dataSourceName); engine = new DbEngine(dataSource, dbFactoryClass); } } } else { engine = DataSourceEngine.getDbEngine(dataSourceName, dbFactoryClass); } } catch (NamingException e) { throw new ArchivoModelException(DbEngine.class, "createWithEntity", e.getMessage()); } catch (ArchivoModelException e) { throw e; } // Usuario AppUser user = new AppUser(); user.setExternalUserId(userAuthId); user.setUserType(userAuthType); user.setIp(remoteIpAddress); user.setEngine(engine); user.setEntity(entity); // Si es un administrador copiar el nombre del usuario if (StringUtils.isNotEmpty(sessionAdm)) { user.setName(userName); } // Comprobar la existencia del usuario en el Sistema de Archivo checkUser(user, sessionAdm); // Añadir los permisos del usuario addUserPermissions(user); // Añadir los grupos del usuario addUserGroups(user); // Establecer el nivel de auditoría setLogLevel(user); // Añadir la información de la organización setOrganizationInfo(user, entity); // Añadir las listas de control de acceso del usuario setAccessControlLists(user); return user; }
private boolean passwordChanged(AppUser userShell) { return userShell.getPassword() != null && !userShell.getPassword().trim().isEmpty(); }
public AppUserAction(AppUser user) { m_actionuser = user; putValue(Action.SMALL_ICON, m_actionuser.getIcon()); putValue(Action.NAME, m_actionuser.getName()); }
private void hashPassword(AppUser user) { String encryptedPassword = getPasswordEncoder().encode(user.getPassword()); user.setPassword(encryptedPassword); }