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 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 spring-boot by spring-projects.
the class UserInfoTokenServices method extractAuthentication.
private OAuth2Authentication extractAuthentication(Map<String, Object> map) {
Object principal = getPrincipal(map);
List<GrantedAuthority> authorities = this.authoritiesExtractor.extractAuthorities(map);
OAuth2Request request = new OAuth2Request(null, this.clientId, null, true, null, null, null, null, null);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(principal, "N/A", authorities);
token.setDetails(map);
return new OAuth2Authentication(request, token);
}
use of org.springframework.security.core.GrantedAuthority in project camel by apache.
the class SpringSecurityAuthorizationPolicyTest method createAuthenticationToken.
private Authentication createAuthenticationToken(String username, String password, String... roles) {
Authentication authToken;
if (roles != null && roles.length > 0) {
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(roles.length);
for (String role : roles) {
authorities.add(new SimpleGrantedAuthority(role));
}
authToken = new UsernamePasswordAuthenticationToken(username, password, authorities);
} else {
authToken = new UsernamePasswordAuthenticationToken(username, password);
}
return authToken;
}
Aggregations