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