73c579bc7ac68dfa9a615ab82123378a4989be62
[aaf/authz.git] / authz-defOrg / src / main / java / com / osaaf / defOrg / Identities.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\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
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \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
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.osaaf.defOrg;\r
25 \r
26 import java.io.File;\r
27 import java.io.IOException;\r
28 \r
29 import com.att.authz.local.AbsData;\r
30 import com.att.authz.local.DataFile.Token.Field;\r
31 \r
32 /*\r
33  * Example User Data file, which can be modified for many different kinds of Data Feeds.\r
34  * \r
35  * Note: This has shown to be extremely effective in AT&T, an acknowledged very large organizations, \r
36  *           because there is no need to synchronize records.  AAF simply receives a Data Feed in Organization\r
37  *               defined intervals.  (You might want to check for validity, such as size, etc), then is copied into\r
38  *               Data Directory.  You will want to do so first creating a "lock" file.  Assuming the File name is "users.dat",\r
39  *               the Lock File is "users.lock".  \r
40  * \r
41  *               After the movement of the Datafile into place, it is best to remove the Index File, then remove the lock file.\r
42  * \r
43  *               Note, Any AAF Programs needing this data WILL wait on the Lock file, so you should get fresh Data files\r
44  *       in a "stage" directory, from WEB, or wherever, and then, after it is correct, do the following as fast as feasible.\r
45  *       \r
46  *              a) lock\r
47  *          b) copy from stage\r
48  *          c) remove idx\r
49  *          d) unlock\r
50  * \r
51  *           If the Index File is either non-existent or out of date from the Data File, it will be reindexed, which\r
52  *               has proven to be a very quick function, even with large numbers of entries.\r
53  * \r
54  * This Sample Feed is set for a file with delimiter of "|".  512 is maximum expected line length. The "0" is the\r
55  *       field offset for the "key" to the record,  which, for user, should be the unique Organization Identity.\r
56  *       \r
57  */\r
58 public class Identities extends AbsData {\r
59         public final static Data NO_DATA = new Data();\r
60         \r
61         public Identities(File users) {\r
62                 super(users,'|',512,0);\r
63         }\r
64 \r
65         /*\r
66          * Example Field Layout.  note, in this example, Application IDs and People IDs are mixed.  You may want to split\r
67          *   out AppIDs, choose your own status indicators, or whatever you use.\r
68          * 0 - unique ID\r
69          * 1 - full name\r
70          * 2 - first name\r
71          * 3 - last name\r
72          * 4 - phone\r
73          * 5 - official email\r
74          * 6 - employment status e=employee, c=contractor, a=application, n=no longer with company\r
75          * 7 - responsible to (i.e Supervisor for People, or AppOwner, if it's an App ID)\r
76          */\r
77         public static class Data {\r
78                 public final String id;\r
79                 public final String name;\r
80                 public final String fname;\r
81                 public final String lname;\r
82                 public final String phone;\r
83                 public final String email;\r
84                 public final String status;\r
85                 public final String responsibleTo;\r
86                 \r
87                 private Data(Field f) {\r
88                         f.reset();\r
89                         id=f.next();\r
90                         name=f.next();\r
91                         fname=f.next();\r
92                         lname=f.next();\r
93                         phone=f.next();\r
94                         email=f.next();\r
95                         status=f.next();\r
96                         responsibleTo =f.next();\r
97                 }\r
98                 \r
99                 private Data() {\r
100                         id = name = fname = lname =\r
101                         phone = email = status = responsibleTo \r
102                         = "";\r
103                 }\r
104 \r
105                 public String toString() {\r
106                         return  id + '|' +\r
107                                         name + '|' +\r
108                                         lname + '|' +\r
109                                         fname + '|' +\r
110                                         phone + '|' +\r
111                                         email + '|' +\r
112                                         status + '|' +\r
113                                         responsibleTo;\r
114                 }\r
115                 \r
116                 // Here, make up your own Methods which help you easily determine your Organization's structure\r
117                 // in your Organization Object\r
118         public boolean hasStatus(String possible) {\r
119             return possible.contains(status);\r
120             }\r
121 \r
122             public boolean isEmployee() {\r
123                     return "e".equals(status);\r
124             }\r
125         \r
126             public boolean isContractor() {\r
127                     return "c".equals(status);\r
128             }\r
129         \r
130             public boolean isApplication() {\r
131                     return "a".equals(status);\r
132             }\r
133         }\r
134         \r
135     public Data find(Object key,Reuse r) throws IOException {\r
136         r.getFieldData().reset();\r
137         // These are new, to allow for Thread Safety\r
138         int rec = ti.find(key,r.getTokenData(),r.getFieldData(),0);\r
139         if(rec<0) {\r
140             return null;\r
141         }\r
142         r.getTokenData().pos(rec);\r
143         return new Data(r.getFieldData());\r
144     }\r
145 }\r