use of org.mifos.dto.domain.LoginDto in project head by mifos.
the class LoginServiceFacadeWebTier method login.
@Override
public LoginDto login(String username, String password) {
PersonnelBO user = this.personnelDao.findPersonnelByUsername(username);
if (user == null) {
throw new UsernameNotFoundException(LoginConstants.KEYINVALIDUSER);
}
MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
List<ValueListElement> localeList = personnelServiceFacade.getDisplayLocaleList();
Locale preferredLocale = new Locale(configMgr.getString(LANGUAGE_CODE), configMgr.getString(COUNTRY_CODE));
String listElement = "[" + preferredLocale.toString() + "]";
Short localeId = user.getPreferredLocale();
for (ValueListElement element : localeList) {
if (element.getName().contains(listElement)) {
localeId = element.getId().shortValue();
break;
}
}
user.setPreferredLocale(localeId);
UserContext userContext = new UserContext();
userContext.setPreferredLocale(preferredLocale);
userContext.setLocaleId(localeId);
userContext.setId(user.getPersonnelId());
userContext.setName(user.getDisplayName());
userContext.setLevel(user.getLevelEnum());
userContext.setRoles(user.getRoles());
userContext.setLastLogin(user.getLastLogin());
userContext.setPasswordChanged(user.getPasswordChanged());
userContext.setBranchId(user.getOffice().getOfficeId());
userContext.setBranchGlobalNum(user.getOffice().getGlobalOfficeNum());
userContext.setOfficeLevelId(user.getOffice().getLevel().getId());
user.updateDetails(userContext);
try {
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(user);
user.login(password);
this.personnelDao.save(user);
this.transactionHelper.commitTransaction();
boolean isPasswordExpired = new LocalDate(user.getPasswordExpirationDate()).isBefore(new LocalDate());
return new LoginDto(user.getPersonnelId(), user.getOffice().getOfficeId(), user.isPasswordChanged(), isPasswordExpired);
} catch (ApplicationException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.dto.domain.LoginDto in project head by mifos.
the class MifosAuthenticationSuccessHandler method determineTargetUrl.
@Override
protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response) {
String targetUrl = super.determineTargetUrl(request, response);
LoginDto loginActivity = (LoginDto) request.getAttribute("activityDto");
if (!loginActivity.isPasswordChanged()) {
targetUrl = "/changePassword.ftl?username=" + request.getAttribute("username");
}
if (loginActivity.isPasswordExpired()) {
targetUrl = "/changePassword.ftl?expired=true&username=" + request.getAttribute("username");
}
return targetUrl;
}
use of org.mifos.dto.domain.LoginDto in project head by mifos.
the class MifosLegacyUsernamePasswordAuthenticationFilter method handleLegacySuccessfulAuthentication.
private void handleLegacySuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, final String username, final String password) {
try {
FlowManager flowManager = new FlowManager();
String flowKey = String.valueOf(new DateTimeService().getCurrentDateTime().getMillis());
flowManager.addFLow(flowKey, new Flow(), this.getFilterName());
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
request.getSession(false).setAttribute(Constants.FLOWMANAGER, flowManager);
request.getSession(false).setAttribute(Constants.RANDOMNUM, new Random().nextLong());
boolean flag = AccountingRules.getSimpleAccountingStatus();
request.getSession(false).setAttribute("accountingActivationStatus", flag);
LoginDto loginActivity = loginServiceFacade.login(username, password);
PersonnelBO user = ApplicationContextProvider.getBean(LegacyPersonnelDao.class).findPersonnelById(loginActivity.getUserId());
SitePreferenceHelper sitePreferenceHelper = new SitePreferenceHelper();
sitePreferenceHelper.setSitePreferenceCookie(SitePreferenceType.getSitePreference(user.getSitePreference()), response);
ActivityContext activityContext = new ActivityContext(Short.valueOf("0"), user.getOffice().getOfficeId(), user.getPersonnelId());
request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, activityContext);
request.setAttribute("activityDto", loginActivity);
Short localeId = user.getPreferredLocale();
Locale preferredLocale = Localization.getInstance().getLocaleById(localeId);
UserContext userContext = new UserContext();
userContext.setPreferredLocale(preferredLocale);
userContext.setLocaleId(localeId);
userContext.setId(user.getPersonnelId());
userContext.setName(user.getDisplayName());
userContext.setLevel(user.getLevelEnum());
userContext.setRoles(user.getRoles());
userContext.setLastLogin(user.getLastLogin());
userContext.setPasswordChanged(user.getPasswordChanged());
userContext.setBranchId(user.getOffice().getOfficeId());
userContext.setBranchGlobalNum(user.getOffice().getGlobalOfficeNum());
userContext.setOfficeLevelId(user.getOffice().getLevel().getId());
request.setAttribute(Constants.USERCONTEXT, userContext);
request.getSession(false).setAttribute(Constants.USERCONTEXT, userContext);
request.removeAttribute("CURRENT_LOCALE_ID");
request.setAttribute("CURRENT_LOCALE_ID", localeId);
if (loginActivity.isPasswordChanged()) {
HttpSession hs = request.getSession(false);
hs.setAttribute(Constants.USERCONTEXT, userContext);
hs.setAttribute(Globals.LOCALE_KEY, userContext.getCurrentLocale());
} else {
flowManager.addObjectToFlow(flowKey, Constants.TEMPUSERCONTEXT, userContext);
}
if (loginActivity.isPasswordChanged()) {
flowManager.removeFlow((String) request.getAttribute(Constants.CURRENTFLOWKEY));
request.setAttribute(Constants.CURRENTFLOWKEY, null);
}
} catch (ApplicationException e1) {
throw new MifosRuntimeException(e1);
}
}
Aggregations