Added null checks and tests to constructors

RequestKey, JaasGrantedAuthority, and SwitchUserGrantedAuthority
assume certain final members are non-null.

Issue: gh-6892
This commit is contained in:
Clement Ng
2019-05-28 19:35:06 -07:00
committed by Josh Cummings
parent 9fe8949883
commit e66369f6c6
6 changed files with 123 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package org.springframework.security.web.access.intercept;
import org.springframework.util.Assert;
/**
* @author Luke Taylor
* @since 2.0
@@ -28,6 +30,7 @@ public class RequestKey {
}
public RequestKey(String url, String method) {
Assert.notNull(url, "url cannot be null");
this.url = url;
this.method = method;
}

View File

@@ -19,6 +19,7 @@ package org.springframework.security.web.authentication.switchuser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.SpringSecurityCoreVersion;
import org.springframework.util.Assert;
/**
* Custom {@code GrantedAuthority} used by
@@ -44,6 +45,8 @@ public final class SwitchUserGrantedAuthority implements GrantedAuthority {
// ===================================================================================================
public SwitchUserGrantedAuthority(String role, Authentication source) {
Assert.notNull(role, "role cannot be null");
Assert.notNull(source, "source cannot be null");
this.role = role;
this.source = source;
}