use of org.springframework.security.core.GrantedAuthority in project vft-capture by videofirst.
the class EncryptedLockOutSupportAuthenticationProvider method getAuthorities.
// Private methods
private Collection<? extends GrantedAuthority> getAuthorities(String role) {
Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority(role));
return Collections.unmodifiableSet(authorities);
}
use of org.springframework.security.core.GrantedAuthority in project CzechIdMng by bcvsolutions.
the class AuthorizationPolicyDeletePermissionsChangeProcessor method process.
@Override
public EventResult<IdmAuthorizationPolicyDto> process(EntityEvent<IdmAuthorizationPolicyDto> event) {
IdmAuthorizationPolicyDto entity = event.getContent();
Set<GrantedAuthority> currentRolePermissions = service.getEnabledRoleAuthorities(null, entity.getRole());
Set<GrantedAuthority> persistedRolePermissions = service.getEnabledPersistedRoleAuthorities(null, entity.getRole());
//
if (!currentRolePermissions.equals(persistedRolePermissions)) {
updateIdentitiesAuthChangeInRole(entity.getRole());
}
//
return new DefaultEventResult<>(event, this);
}
use of org.springframework.security.core.GrantedAuthority in project CzechIdMng by bcvsolutions.
the class DefaultIdmAuthorizationPolicyService method getGrantedAuthorities.
@Override
@Transactional(readOnly = true)
public Set<GrantedAuthority> getGrantedAuthorities(UUID identityId, List<IdmAuthorizationPolicyDto> policies) {
final Set<GrantedAuthority> authorities = new HashSet<>();
// find all active policies and return their authority by authorizable type
for (IdmAuthorizationPolicyDto policy : policies) {
// evaluate policy permissions - authorities are eveluated on null entity
String groupPermission = policy.getGroupPermission();
Set<String> baseAuthorities = getAuthorizationManager().getAuthorities(identityId, policy);
//
if (IdmGroupPermission.APP.getName().equals(groupPermission) || (StringUtils.isEmpty(groupPermission) && baseAuthorities.contains(IdmBasePermission.ADMIN.getName()))) {
// admin
return Sets.newHashSet(new DefaultGrantedAuthority(IdmGroupPermission.APP.getName(), IdmBasePermission.ADMIN.getName()));
}
if (StringUtils.isEmpty(groupPermission)) {
if (baseAuthorities.contains(IdmBasePermission.ADMIN.getName())) {
// all groups => synonym to APP_ADMIN
authorities.add(new DefaultGrantedAuthority(IdmGroupPermission.APP.getName(), IdmBasePermission.ADMIN.getName()));
} else {
// some base permission only
moduleService.getAvailablePermissions().forEach(availableGroupPermission -> {
if (IdmGroupPermission.APP != availableGroupPermission) {
// app is wildcard only - skipping
for (String permission : baseAuthorities) {
authorities.add(new DefaultGrantedAuthority(availableGroupPermission.getName(), permission));
}
;
}
});
}
} else if (baseAuthorities.contains(IdmBasePermission.ADMIN.getName())) {
authorities.add(new DefaultGrantedAuthority(groupPermission, IdmBasePermission.ADMIN.getName()));
} else {
for (String permission : baseAuthorities) {
authorities.add(new DefaultGrantedAuthority(groupPermission, permission));
}
;
}
}
//
return authorities;
}
use of org.springframework.security.core.GrantedAuthority in project CzechIdMng by bcvsolutions.
the class TestAppAuthenticationFilter method authorize.
@Override
public boolean authorize(String token, HttpServletRequest request, HttpServletResponse response) {
try {
Optional<Jwt> jwt = HttpFilterUtils.parseToken(token);
if (!jwt.isPresent()) {
return false;
}
Map<String, Object> claims = verifyTokenAndGetClaims(jwt.get());
String userName = (String) claims.get(HttpFilterUtils.JWT_USER_NAME);
IdmIdentityDto identity = identityService.getByUsername(userName);
// not important - either new refreshed token or data are returned to user
DateTime expiration = null;
Collection<GrantedAuthority> authorities = null;
if (shouldGrantAuthoritiesForPath(request.getServletPath())) {
authorities = grantedAuthoritiesFactory.getGrantedAuthoritiesForIdentity(identity.getId());
} else {
authorities = new ArrayList<>();
}
IdmJwtAuthentication ija = new IdmJwtAuthentication(identity, expiration, authorities, EntityUtils.getModule(this.getClass()));
SecurityContextHolder.getContext().setAuthentication(ija);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of org.springframework.security.core.GrantedAuthority in project CzechIdMng by bcvsolutions.
the class JwtAuthenticationMapper method fromDto.
/**
* Converts dto to authentication.
*
* @param dto
* @return
*/
public IdmJwtAuthentication fromDto(IdmJwtAuthenticationDto dto) {
Assert.notNull(dto);
//
Collection<DefaultGrantedAuthorityDto> authorities = dto.getAuthorities();
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
if (authorities != null) {
for (DefaultGrantedAuthorityDto a : authorities) {
grantedAuthorities.add(new DefaultGrantedAuthority(a.getAuthority()));
}
}
IdmJwtAuthentication authentication = new IdmJwtAuthentication(new IdmIdentityDto(dto.getCurrentIdentityId(), dto.getCurrentUsername()), new IdmIdentityDto(dto.getOriginalIdentityId(), dto.getOriginalUsername()), dto.getExpiration(), dto.getIssuedAt(), grantedAuthorities, dto.getFromModule());
return authentication;
}
Aggregations