// Path: mujina-idp/src/main/java/mujina/idp/FederatedUserAuthenticationToken.java
// @Getter
// @Setter
// public class FederatedUserAuthenticationToken extends UsernamePasswordAuthenticationToken {
// 
//   private Map<String, List<String>> attributes = new TreeMap<>();
// 
//   public FederatedUserAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
//     super(principal, credentials, authorities);
//   }
// 
//   public FederatedUserAuthenticationToken clone() {
//     FederatedUserAuthenticationToken clone = new FederatedUserAuthenticationToken(getPrincipal(), getCredentials(), getAuthorities());
//     clone.setAttributes(attributes);
//     return clone;
//   }
// }


import mujina.idp.FederatedUserAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import static java.util.stream.Collectors.toList;
    LOG.info("Request to set attribute {} to {}", name, values);
    configuration().getAttributes().put(name, values);
  }

  @PutMapping("/attributes/{name:.+}/{userName:.+}")
  public void setAttributeForUser(@PathVariable String name, @PathVariable String userName,
                                  @RequestBody List<String> values) {
    LOG.info("Request to set attribute {} to {} for user {}", name, values, userName);
    configuration().getUsers().stream().filter(userAuthenticationToken -> userAuthenticationToken.getName().equals
      (userName)).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("User %s first " +
      "must be created", userName))).getAttributes().put(name, values);
  }

  @DeleteMapping("/attributes/{name:.+}")
  public void removeAttribute(@PathVariable String name) {
    LOG.info("Request to remove attribute {}", name);
    configuration().getAttributes().remove(name);
  }

  @DeleteMapping("/attributes/{name:.+}/{userName:.+}")
  public void removeAttributeForUser(@PathVariable String name, @PathVariable String userName) {
    LOG.info("Request to remove attribute {} for user {}", name, userName);
    configuration().getUsers().stream().filter(userAuthenticationToken -> userAuthenticationToken.getName().equals
      (userName)).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("User %s first " +
      "must be created", userName))).getAttributes().remove(name);
  }

  @PutMapping("/users")
  public void addUser(@RequestBody User user) {
    LOG.info("Request to add user {}", user);
// Path: mujina-idp/src/main/java/mujina/idp/FederatedUserAuthenticationToken.java
// @Getter
// @Setter
// public class FederatedUserAuthenticationToken extends UsernamePasswordAuthenticationToken {
// 
//   private Map<String, List<String>> attributes = new TreeMap<>();
// 
//   public FederatedUserAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
//     super(principal, credentials, authorities);
//   }
// 
//   public FederatedUserAuthenticationToken clone() {
//     FederatedUserAuthenticationToken clone = new FederatedUserAuthenticationToken(getPrincipal(), getCredentials(), getAuthorities());
//     clone.setAttributes(attributes);
//     return clone;
//   }
// }


// Path: mujina-idp/src/main/java/mujina/api/IdpController.java
import mujina.idp.FederatedUserAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import static java.util.stream.Collectors.toList;

    LOG.info("Request to set attribute {} to {}", name, values);
    configuration().getAttributes().put(name, values);
  }

  @PutMapping("/attributes/{name:.+}/{userName:.+}")
  public void setAttributeForUser(@PathVariable String name, @PathVariable String userName,
                                  @RequestBody List<String> values) {
    LOG.info("Request to set attribute {} to {} for user {}", name, values, userName);
    configuration().getUsers().stream().filter(userAuthenticationToken -> userAuthenticationToken.getName().equals
      (userName)).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("User %s first " +
      "must be created", userName))).getAttributes().put(name, values);
  }

  @DeleteMapping("/attributes/{name:.+}")
  public void removeAttribute(@PathVariable String name) {
    LOG.info("Request to remove attribute {}", name);
    configuration().getAttributes().remove(name);
  }

  @DeleteMapping("/attributes/{name:.+}/{userName:.+}")
  public void removeAttributeForUser(@PathVariable String name, @PathVariable String userName) {
    LOG.info("Request to remove attribute {} for user {}", name, userName);
    configuration().getUsers().stream().filter(userAuthenticationToken -> userAuthenticationToken.getName().equals
      (userName)).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("User %s first " +
      "must be created", userName))).getAttributes().remove(name);
  }

  @PutMapping("/users")
  public void addUser(@RequestBody User user) {
    LOG.info("Request to add user {}", user);
    FederatedUserAuthenticationToken userAuthenticationToken = new FederatedUserAuthenticationToken(