diff --git a/core/src/main/java/org/springframework/security/GrantedAuthoritiesContainerImpl.java b/core/src/main/java/org/springframework/security/GrantedAuthoritiesContainerImpl.java new file mode 100644 index 0000000000..ef603c810a --- /dev/null +++ b/core/src/main/java/org/springframework/security/GrantedAuthoritiesContainerImpl.java @@ -0,0 +1,27 @@ +package org.springframework.security; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.springframework.util.Assert; + +public class GrantedAuthoritiesContainerImpl implements MutableGrantedAuthoritiesContainer { + private List authorities; + + public void setGrantedAuthorities(GrantedAuthority[] newAuthorities) { + this.authorities = new ArrayList(newAuthorities.length); + authorities.addAll(Arrays.asList(newAuthorities)); + } + + public GrantedAuthority[] getGrantedAuthorities() { + Assert.notNull(authorities, "Granted authorities have not been set"); + return (GrantedAuthority[]) authorities.toArray(new GrantedAuthority[authorities.size()]); + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("Authorities: ").append(authorities); + return sb.toString(); + } +}