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));
}
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);
}
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);
}
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());
}
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, ","));
}
Aggregations