Search in sources :

Example 41 with GrantedAuthority

use of org.springframework.security.core.GrantedAuthority in project spring-security by spring-projects.

the class NestedLdapAuthoritiesPopulatorTests method testGroovyDudeJDevelopersAuthorities.

@Test
public void testGroovyDudeJDevelopersAuthorities() {
    DirContextAdapter ctx = new DirContextAdapter("uid=groovydude,ou=people,dc=springframework,dc=org");
    Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx, "groovydude");
    assertThat(authorities).hasSize(4);
    assertThat(authorities).isEqualTo(Arrays.asList(javaDevelopers, circularJavaDevelopers, jDevelopers, groovyDevelopers));
}
Also used : GrantedAuthority(org.springframework.security.core.GrantedAuthority) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) Test(org.junit.Test)

Example 42 with GrantedAuthority

use of org.springframework.security.core.GrantedAuthority 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 43 with GrantedAuthority

use of org.springframework.security.core.GrantedAuthority in project head by mifos.

the class CustomerNotesActionStrutsTest 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 44 with GrantedAuthority

use of org.springframework.security.core.GrantedAuthority in project head by mifos.

the class PersonnelDaoHibernate method findAuthenticatedUserByUsername.

@SuppressWarnings("unchecked")
@Override
public MifosUser findAuthenticatedUserByUsername(String username) {
    PersonnelBO user = findPersonnelByUsername(username);
    if (user == null) {
        return null;
    }
    Set<Short> activityIds = new HashSet<Short>();
    Set<Short> roleIds = new HashSet<Short>();
    for (PersonnelRoleEntity personnelRole : user.getPersonnelRoles()) {
        RoleBO role = personnelRole.getRole();
        roleIds.add(role.getId());
        activityIds.addAll(role.getActivityIds());
    }
    byte[] password = user.getEncryptedPassword();
    boolean enabled = user.isActive();
    boolean accountNonExpired = !user.isLocked();
    boolean credentialsNonExpired = true;
    boolean accountNonLocked = !user.isLocked();
    List<GrantedAuthority> authorities = getGrantedActivityAuthorities(activityIds);
    return new MifosUser(user.getPersonnelId(), user.getOffice().getOfficeId(), user.getLevelEnum().getValue(), new ArrayList<Short>(roleIds), username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities, user.getPreferredLocale());
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersonnelRoleEntity(org.mifos.customers.personnel.business.PersonnelRoleEntity) GrantedAuthority(org.springframework.security.core.GrantedAuthority) MifosUser(org.mifos.security.MifosUser) HashSet(java.util.HashSet) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 45 with GrantedAuthority

use of org.springframework.security.core.GrantedAuthority in project vaadin-samples by xpoft.

the class MainView method enter.

@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
    User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    List<String> roles = new ArrayList<String>();
    for (GrantedAuthority grantedAuthority : user.getAuthorities()) {
        roles.add(grantedAuthority.getAuthority());
    }
    usernameLabel.setValue(user.getUsername());
    rolesLabel.setValue(StringUtils.join(roles, ","));
}
Also used : User(org.springframework.security.core.userdetails.User) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList)

Aggregations

GrantedAuthority (org.springframework.security.core.GrantedAuthority)188 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)90 Authentication (org.springframework.security.core.Authentication)55 ArrayList (java.util.ArrayList)43 Test (org.junit.Test)42 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)37 HashSet (java.util.HashSet)27 UserDetails (org.springframework.security.core.userdetails.UserDetails)16 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)15 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)11 Before (org.junit.Before)10 SecurityContext (org.springframework.security.core.context.SecurityContext)10 User (org.springframework.security.core.userdetails.User)10 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)10 DefaultGrantedAuthority (eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority)9 List (java.util.List)9 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)9 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)8