use of com.netflix.spinnaker.fiat.permissions.ExternalUser in project fiat by spinnaker.
the class RolesController method putUserPermission.
@RequestMapping(value = "/{userId:.+}", method = RequestMethod.PUT)
public void putUserPermission(@PathVariable String userId, @RequestBody @NonNull List<String> externalRoles) {
List<Role> convertedRoles = externalRoles.stream().map(extRole -> new Role().setSource(Role.Source.EXTERNAL).setName(extRole)).collect(Collectors.toList());
ExternalUser extUser = new ExternalUser().setId(ControllerSupport.convert(userId)).setExternalRoles(convertedRoles);
try {
UserPermission userPermission = permissionsResolver.resolveAndMerge(extUser);
log.debug("Updated user permissions (userId: {}, roles: {}, suppliedExternalRoles: {})", userId, userPermission.getRoles().stream().map(Role::getName).collect(Collectors.toList()), externalRoles);
permissionsRepository.put(userPermission);
} catch (PermissionResolutionException pre) {
throw new UserPermissionModificationException(pre);
}
}
use of com.netflix.spinnaker.fiat.permissions.ExternalUser in project fiat by spinnaker.
the class LdapUserRolesProvider method loadRoles.
@Override
public List<Role> loadRoles(ExternalUser user) {
String userId = user.getId();
log.debug("loadRoles for user " + userId);
if (StringUtils.isEmpty(configProps.getGroupSearchBase())) {
return new ArrayList<>();
}
String fullUserDn = getUserFullDn(userId);
if (fullUserDn == null) {
// Likely a service account
log.debug("fullUserDn is null for {}", userId);
return new ArrayList<>();
}
String[] params = new String[] { fullUserDn, userId };
if (log.isDebugEnabled()) {
log.debug(new StringBuilder("Searching for groups using ").append("\ngroupSearchBase: ").append(configProps.getGroupSearchBase()).append("\ngroupSearchFilter: ").append(configProps.getGroupSearchFilter()).append("\nparams: ").append(StringUtils.join(params, " :: ")).append("\ngroupRoleAttributes: ").append(configProps.getGroupRoleAttributes()).toString());
}
// Copied from org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator.
Set<String> userRoles = ldapTemplate.searchForSingleAttributeValues(configProps.getGroupSearchBase(), configProps.getGroupSearchFilter(), params, configProps.getGroupRoleAttributes());
log.debug("Got roles for user " + userId + ": " + userRoles);
return userRoles.stream().map(role -> new Role(role).setSource(Role.Source.LDAP)).collect(Collectors.toList());
}
Aggregations