2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.it;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
32 import java.io.IOException;
33 import java.util.LinkedList;
34 import java.util.List;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mockito;
40 import org.onap.clamp.authorization.AuthorizationController;
41 import org.onap.clamp.clds.service.SecureServicePermission;
42 import org.onap.clamp.util.PrincipalUtils;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
45 import org.springframework.security.core.Authentication;
46 import org.springframework.security.core.GrantedAuthority;
47 import org.springframework.security.core.authority.SimpleGrantedAuthority;
48 import org.springframework.security.core.context.SecurityContext;
49 import org.springframework.security.core.userdetails.User;
50 import org.springframework.test.context.junit4.SpringRunner;
53 * Test CldsDAO calls through CldsModel and CldsEvent. This really test the DB
54 * and stored procedures.
56 @RunWith(SpringRunner.class)
58 public class AuthorizationControllerItCase {
60 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(AuthorizationControllerItCase.class);
61 private Authentication authentication;
62 private List<GrantedAuthority> authList = new LinkedList<GrantedAuthority>();
65 * Setup the variable before the tests execution.
68 * In case of issues when opening the files
71 public void setupBefore() throws IOException {
72 authList.add(new SimpleGrantedAuthority("permission-type-cl-manage|dev|*"));
73 authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read"));
74 authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update"));
75 authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read"));
76 authList.add(new SimpleGrantedAuthority("permission-type-template|dev|update"));
77 authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*"));
78 authList.add(new SimpleGrantedAuthority("permission-type-cl-event|dev|*"));
80 authentication = new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList);
84 public void testIsUserPermittedNoException() {
85 SecurityContext securityContext = Mockito.mock(SecurityContext.class);
86 Mockito.when(securityContext.getAuthentication()).thenReturn(authentication);
87 PrincipalUtils.setSecurityContext(securityContext);
89 AuthorizationController auth = new AuthorizationController();
90 assertTrue(auth.isUserPermittedNoException(new SecureServicePermission("permission-type-cl","dev","read")));
91 assertTrue(auth.isUserPermittedNoException(new SecureServicePermission("permission-type-cl-manage","dev","DEPLOY")));
92 assertTrue(auth.isUserPermittedNoException(new SecureServicePermission("permission-type-filter-vf","dev","12345-55555-55555-5555")));
93 assertFalse(auth.isUserPermittedNoException(new SecureServicePermission("permission-type-cl","test","read")));