Added implementation of GrantedAuthoritiesContainer to allow refactoring of duplication in various preauth details classes

This commit is contained in:
Luke Taylor 2008-03-22 19:29:13 +00:00
parent 2ea94e2cc9
commit 162933155e
1 changed files with 27 additions and 0 deletions

View File

@ -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();
}
}