Search in sources :

Example 36 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class RolesPermissionServiceFacadeWebTier method hasUserAccessForActivity.

@Override
public boolean hasUserAccessForActivity(Short activityID) throws Exception {
    boolean result = false;
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    try {
        for (Short roleId : mifosUser.getRoleIds()) {
            RoleBO role = legacyRolesPermissionsDao.getRole(roleId);
            if (role.getActivityIds().contains(activityID) || null == activityID) {
                result = true;
                break;
            }
        }
    } catch (PersistenceException e) {
        throw new RolesPermissionException(e);
    }
    return result;
}
Also used : PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosUser(org.mifos.security.MifosUser) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 37 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class MifosDaoAuthenticationProvider method additionalAuthenticationChecks.

@Override
protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    MifosUser user = (MifosUser) userDetails;
    if (authentication.getCredentials() == null) {
        throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
    }
    String presentedPassword = authentication.getCredentials().toString();
    boolean isPasswordValid = passwordHashing.verifyPassword(presentedPassword, user.getPasswordAsBytes());
    if (!isPasswordValid) {
        throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
    }
}
Also used : MifosUser(org.mifos.security.MifosUser) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException)

Example 38 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class RepayLoanActionStrutsTest method setMifosUserFromContext.

private void setMifosUserFromContext() {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUser(userContext.getId(), userContext.getBranchId(), userContext.getLevelId(), new ArrayList<Short>(userContext.getRoles()), userContext.getName(), "".getBytes(), true, true, true, true, new ArrayList<GrantedAuthority>(), userContext.getLocaleId());
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 39 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class ApplyAdjustmentActionStrutsTest method setUpSecurityContext.

private void setUpSecurityContext() {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser mifosUser = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(mifosUser, mifosUser);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 40 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class ApplyChargeActionStrutsTest method testUpdateSuccess.

@Test
public void testUpdateSuccess() {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    createInitialObjects();
    accountBO = getLoanAccount(client, meeting);
    setRequestPathInfo("/applyChargeAction.do");
    addRequestParameter("method", "update");
    addRequestParameter("chargeType", IS_PENALTY_TYPE + ":" + FEE_ID + ":" + IS_NOT_RATE_TYPE);
    addRequestParameter("charge", "18");
    addRequestParameter("accountId", accountBO.getAccountId().toString());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    //        verifyForward("loanDetails_success");
    verifyNoActionErrors();
    verifyNoActionMessages();
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Aggregations

MifosUser (org.mifos.security.MifosUser)205 UserContext (org.mifos.security.util.UserContext)134 MifosRuntimeException (org.mifos.core.MifosRuntimeException)88 BusinessRuleException (org.mifos.service.BusinessRuleException)74 ArrayList (java.util.ArrayList)52 AccountException (org.mifos.accounts.exceptions.AccountException)52 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)44 PersistenceException (org.mifos.framework.exceptions.PersistenceException)43 ServiceException (org.mifos.framework.exceptions.ServiceException)43 CustomerBO (org.mifos.customers.business.CustomerBO)38 Authentication (org.springframework.security.core.Authentication)38 SecurityContext (org.springframework.security.core.context.SecurityContext)38 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)38 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)36 Money (org.mifos.framework.util.helpers.Money)35 LocalDate (org.joda.time.LocalDate)33 LoanBO (org.mifos.accounts.loan.business.LoanBO)33 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)29 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)26