Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(saml): Set allowedAccounts info #1856

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.netflix.spinnaker.gate.security.saml;

import com.netflix.spinnaker.gate.security.AllowedAccountsSupport;
import com.netflix.spinnaker.gate.services.AuthenticationService;
import com.netflix.spinnaker.security.User;
import java.util.Collection;
Expand All @@ -25,6 +26,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.GrantedAuthority;
Expand All @@ -45,6 +47,8 @@ public class ResponseAuthenticationConverter
private final ObjectFactory<UserRolesExtractor> userRolesExtractorFactory;
private final ObjectFactory<AuthenticationService> authenticationServiceFactory;

@Autowired AllowedAccountsSupport allowedAccountsSupport;

@Override
public PreAuthenticatedAuthenticationToken convert(ResponseToken source) {
UserIdentifierExtractor userIdentifierExtractor = userIdentifierExtractorFactory.getObject();
Expand All @@ -69,6 +73,8 @@ public PreAuthenticatedAuthenticationToken convert(ResponseToken source) {
Set<String> roles = userRolesExtractor.getRoles(principal);
user.setRoles(roles);

user.setAllowedAccounts(allowedAccountsSupport.filterAllowedAccounts(userid, roles));

if (!CollectionUtils.isEmpty(properties.getRequiredRoles())) {
var requiredRoles = Set.copyOf(properties.getRequiredRoles());
// check for at least one common role in both sets
Expand Down