Polish messaging generics and imports

This commit is contained in:
Rob Winch 2014-09-16 14:31:06 -05:00
parent b6fcde880a
commit b717333707
10 changed files with 15 additions and 13 deletions

View File

@ -24,8 +24,9 @@ import org.springframework.security.core.Authentication;
/**
* The default implementation of {@link SecurityExpressionHandler} which uses a {@link MessageSecurityExpressionRoot}.
*
* @since 4.0
* @param <T> the type for the body of the Message
*
* @since 4.0
* @author Rob Winch
*/
public class DefaultMessageSecurityExpressionHandler<T> extends AbstractSecurityExpressionHandler<Message<T>> {

View File

@ -20,7 +20,6 @@ import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.messaging.access.intercept.DefaultMessageSecurityMetadataSource;
import org.springframework.security.messaging.access.intercept.MessageSecurityMetadataSource;
import org.springframework.security.messaging.util.matcher.MessageMatcher;
import org.springframework.security.messaging.util.matcher.SimpDestinationMessageMatcher;
import java.util.Arrays;
import java.util.Collection;
@ -66,7 +65,7 @@ public final class ExpressionBasedMessageSecurityMetadataSourceFactory {
* @return the {@link MessageSecurityMetadataSource} to use. Cannot be null.
*/
public static MessageSecurityMetadataSource createExpressionMessageMetadataSource(LinkedHashMap<MessageMatcher<?>,String> matcherToExpression) {
DefaultMessageSecurityExpressionHandler handler = new DefaultMessageSecurityExpressionHandler();
DefaultMessageSecurityExpressionHandler<Object> handler = new DefaultMessageSecurityExpressionHandler<Object>();
LinkedHashMap<MessageMatcher<?>, Collection<ConfigAttribute>> matcherToAttrs = new LinkedHashMap<MessageMatcher<?>, Collection<ConfigAttribute>>();

View File

@ -26,6 +26,7 @@ import org.springframework.util.Assert;
* @since 4.0
* @author Rob Winch
*/
@SuppressWarnings("serial")
class MessageExpressionConfigAttribute implements ConfigAttribute {
private final Expression authorizeExpression;

View File

@ -35,7 +35,7 @@ import java.util.Collection;
* @author Rob Winch
*/
public class MessageExpressionVoter<T> implements AccessDecisionVoter<Message<T>> {
private SecurityExpressionHandler<Message<T>> expressionHandler = new DefaultMessageSecurityExpressionHandler();
private SecurityExpressionHandler<Message<T>> expressionHandler = new DefaultMessageSecurityExpressionHandler<T>();
public int vote(Authentication authentication, Message<T> message, Collection<ConfigAttribute> attributes) {
assert authentication != null;

View File

@ -27,7 +27,7 @@ import org.springframework.security.core.Authentication;
*/
final class MessageSecurityExpressionRoot extends SecurityExpressionRoot {
public MessageSecurityExpressionRoot(Authentication authentication, Message message) {
public MessageSecurityExpressionRoot(Authentication authentication, Message<?> message) {
super(authentication);
}
}

View File

@ -44,6 +44,7 @@ public final class DefaultMessageSecurityMetadataSource implements MessageSecuri
this.messageMap = messageMap;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
final Message message = (Message) object;
for (Map.Entry<MessageMatcher<?>, Collection<ConfigAttribute>> entry : messageMap.entrySet()) {

View File

@ -35,7 +35,7 @@ public interface MessageMatcher<T> {
/**
* Matches every {@link Message}
*/
MessageMatcher ANY_MESSAGE = new MessageMatcher<Object>() {
MessageMatcher<Object> ANY_MESSAGE = new MessageMatcher<Object>() {
public boolean matches(Message<? extends Object> message) {
return true;
}

View File

@ -27,13 +27,11 @@ import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.access.intercept.InterceptorStatusToken;
import org.springframework.security.access.intercept.RunAsManager;
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@ -119,6 +117,7 @@ public class ChannelSecurityInterceptorTests {
}
@SuppressWarnings("unchecked")
@Test
public void preSendPostSendRunAs() throws Exception {
when(source.getAttributes(message)).thenReturn(attrs);
@ -138,6 +137,7 @@ public class ChannelSecurityInterceptorTests {
interceptor.afterSendCompletion(message, channel, true, null);
}
@SuppressWarnings("unchecked")
@Test
public void preSendFinallySendRunAs() throws Exception {
when(source.getAttributes(message)).thenReturn(attrs);

View File

@ -36,11 +36,11 @@ import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(MockitoJUnitRunner.class)
public class DefaultMessageSecurityMetadataSourceTests {
@Mock
MessageMatcher matcher1;
MessageMatcher<Object> matcher1;
@Mock
MessageMatcher matcher2;
MessageMatcher<Object> matcher2;
@Mock
Message message;
Message<?> message;
@Mock
Authentication authentication;

View File

@ -29,7 +29,7 @@ public class SecurityContextChannelInterceptorTests {
@Mock
Principal principal;
MessageBuilder messageBuilder;
MessageBuilder<String> messageBuilder;
Authentication authentication;