fd8e357578539e2baa24dc2909e8d008067d9b49
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / lur / test / JU_LocalLur.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * * ===========================================================================
7  * * Licensed under the Apache License, Version 2.0 (the "License");
8  * * you may not use this file except in compliance with the License.
9  * * You may obtain a copy of the License at
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
13  *  * Unless required by applicable law or agreed to in writing, software
14  * * distributed under the License is distributed on an "AS IS" BASIS,
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * * See the License for the specific language governing permissions and
17  * * limitations under the License.
18  * * ============LICENSE_END====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.cadi.lur.test;
23
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertFalse;
26 import static junit.framework.Assert.assertTrue;
27
28 import java.io.ByteArrayOutputStream;
29 import java.io.IOException;
30 import java.security.Principal;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Set;
34 import java.util.TreeSet;
35
36 import org.junit.Test;
37 import org.onap.aaf.cadi.Lur;
38 import org.onap.aaf.cadi.Permission;
39 import org.onap.aaf.cadi.PropAccess;
40 import org.onap.aaf.cadi.Symm;
41 import org.onap.aaf.cadi.CredVal.Type;
42 import org.onap.aaf.cadi.config.UsersDump;
43 import org.onap.aaf.cadi.lur.LocalLur;
44 import org.onap.aaf.cadi.lur.LocalPermission;
45
46 public class JU_LocalLur {
47
48         @Test
49         public void test() throws IOException {
50                 Symm symmetric = Symm.baseCrypt().obtain();
51                 LocalLur up;
52                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
53                 baos.write(Symm.ENC.getBytes());
54                 symmetric.enpass("<pass>", baos);
55                 PropAccess ta = new PropAccess();
56                 Lur ml = up = new LocalLur(ta,"myname:groupA,groupB","admin:myname,yourname;suser:hisname,hername,m1234%"+baos.toString());
57
58                 
59 //              Permission admin = new LocalPermission("admin");
60 //              Permission suser = new LocalPermission("suser");
61 //              
62 //              // Check User fish
63 //              assertTrue(ml.fish(new JUPrincipal("myname"),admin));
64 //              assertTrue(ml.fish(new JUPrincipal("hisname"),admin));
65 //              assertFalse(ml.fish(new JUPrincipal("noname"),admin));
66 //              assertTrue(ml.fish(new JUPrincipal("itsname"),suser));
67 //              assertTrue(ml.fish(new JUPrincipal("hername"),suser));
68 //              assertFalse(ml.fish(new JUPrincipal("myname"),suser));
69 //              
70 //              // Check validate password
71 //              assertTrue(up.validate("m1234",Type.PASSWORD, "<pass>".getBytes()));
72 //              assertFalse(up.validate("m1234",Type.PASSWORD, "badPass".getBytes()));
73 //              
74                 // Check fishAll
75                 Set<String> set = new TreeSet<String>();
76                 List<Permission> perms = new ArrayList<Permission>();
77                 ml.fishAll(new JUPrincipal("myname"), perms);
78                 for(Permission p : perms) {
79                         set.add(p.getKey());
80                 }
81 //              assertEquals("[admin, groupA, groupB]",set.toString());
82                 UsersDump.write(System.out, up);
83                 System.out.flush();
84                 
85         }
86         
87         // Simplistic Principal for testing purposes
88         private static class JUPrincipal implements Principal {
89                 private String name;
90                 public JUPrincipal(String name) {
91                         this.name = name;
92                 }
93 //              @Override
94                 public String getName() {
95                         return name;
96                 }
97         }
98
99
100
101         
102         
103 }