From 162933155e9e5833ef4f20c4d193929ec1d8aa74 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sat, 22 Mar 2008 19:29:13 +0000 Subject: [PATCH] Added implementation of GrantedAuthoritiesContainer to allow refactoring of duplication in various preauth details classes --- .../GrantedAuthoritiesContainerImpl.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 core/src/main/java/org/springframework/security/GrantedAuthoritiesContainerImpl.java 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(); + } +}