1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.cadi.lur.test;
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertFalse;
26 import static junit.framework.Assert.assertTrue;
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;
34 import java.util.TreeSet;
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;
46 public class JU_LocalLur {
49 public void test() throws IOException {
50 final Symm symmetric = Symm.baseCrypt().obtain();
52 ByteArrayOutputStream baos = new ByteArrayOutputStream();
53 baos.write(Symm.ENC.getBytes());
54 symmetric.enpass("<pass>", baos);
55 PropAccess ta = new PropAccess() {
57 public String decrypt(String encrypted, boolean anytext) throws IOException {
58 return symmetric.depass(encrypted);
62 public String encrypt(String unencrypted) throws IOException {
63 return symmetric.enpass(unencrypted);
68 Lur ml = up = new LocalLur(ta,"myname:groupA,groupB","admin:myname,yourname;suser:hisname,hername,m1234%"+baos.toString());
71 // Permission admin = new LocalPermission("admin");
72 // Permission suser = new LocalPermission("suser");
75 // assertTrue(ml.fish(new JUPrincipal("myname"),admin));
76 // assertTrue(ml.fish(new JUPrincipal("hisname"),admin));
77 // assertFalse(ml.fish(new JUPrincipal("noname"),admin));
78 // assertTrue(ml.fish(new JUPrincipal("itsname"),suser));
79 // assertTrue(ml.fish(new JUPrincipal("hername"),suser));
80 // assertFalse(ml.fish(new JUPrincipal("myname"),suser));
82 // // Check validate password
83 // assertTrue(up.validate("m1234",Type.PASSWORD, "<pass>".getBytes()));
84 // assertFalse(up.validate("m1234",Type.PASSWORD, "badPass".getBytes()));
87 Set<String> set = new TreeSet<String>();
88 List<Permission> perms = new ArrayList<Permission>();
89 ml.fishAll(new JUPrincipal("myname"), perms);
90 for(Permission p : perms) {
93 // assertEquals("[admin, groupA, groupB]",set.toString());
94 UsersDump.write(System.out, up);
99 // Simplistic Principal for testing purposes
100 private static class JUPrincipal implements Principal {
102 public JUPrincipal(String name) {
106 public String getName() {