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:
committed by
Josh Cummings
parent
9fe8949883
commit
e66369f6c6
+3
@@ -18,6 +18,7 @@ package org.springframework.security.authentication.jaas;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.SpringSecurityCoreVersion;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
@@ -37,6 +38,8 @@ public final class JaasGrantedAuthority implements GrantedAuthority {
|
||||
private final Principal principal;
|
||||
|
||||
public JaasGrantedAuthority(String role, Principal principal) {
|
||||
Assert.notNull(role, "role cannot be null");
|
||||
Assert.notNull(principal, "principal cannot be null");
|
||||
this.role = role;
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.authentication.jaas;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import org.springframework.security.authentication.jaas.JaasGrantedAuthority;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clement Ng
|
||||
*
|
||||
*/
|
||||
public class JaasGrantedAuthorityTests {
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void authorityWithNullRoleFailsAssertion() throws Exception {
|
||||
assertThatThrownBy(() -> new JaasGrantedAuthority(null, null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("role cannot be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void authorityWithNullPrincipleFailsAssertion() throws Exception {
|
||||
assertThatThrownBy(() -> new JaasGrantedAuthority("role", null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("principal cannot be null");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user