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.org;
24 import java.io.IOException;
25 import java.util.List;
27 import org.onap.aaf.auth.env.AuthzTrans;
28 import org.onap.aaf.auth.local.AbsData.Reuse;
29 import org.onap.aaf.auth.org.Organization;
30 import org.onap.aaf.auth.org.OrganizationException;
31 import org.onap.aaf.auth.org.Organization.Identity;
32 import org.onap.aaf.cadi.config.Config;
33 import org.onap.aaf.org.Identities.Data;
36 * Org Users are essential representations of Identities within the Org. Since this is a highly individual
37 * thing for most Orgs, i.e. some use LDAP, some need feed, some use something else, this object will allow
38 * the Organization to connect to their own Identity systems...
42 public class DefaultOrgIdentity implements Identity {
43 private static final String CONTRACTOR = "c";
44 private static final String EMPLOYEE = "e";
45 private static final String APPLICATION = "a";
46 private static final String NON_ACTIVE = "n";
48 private final static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);
50 private DefaultOrg org;
53 private AuthzTrans trans;
55 public DefaultOrgIdentity(AuthzTrans trans, String key, DefaultOrg dorg) throws OrganizationException {
60 org.identities.open(trans, TIMEOUT);
62 Reuse r = org.identities.reuse();
63 int at = key.indexOf(dorg.atDomain);
66 search = key.substring(0,at);
70 identity = org.identities.find(search, r);
72 identity = Identities.NO_DATA;
75 org.identities.close(trans);
77 } catch (IOException e) {
78 throw new OrganizationException(e);
83 public boolean equals(Object b) {
84 if(b instanceof DefaultOrgIdentity) {
85 return identity.id.equals(((DefaultOrgIdentity)b).identity.id);
92 public int hashCode() {
93 return identity.hashCode();
102 public String fullID() {
103 return identity.id+'@'+org.getDomain();
107 public String type() {
108 switch(identity.status) {
109 case EMPLOYEE: return DefaultOrg.Types.Employee.name();
110 case CONTRACTOR: return DefaultOrg.Types.Contractor.name();
111 case APPLICATION: return DefaultOrg.Types.Application.name();
112 case NON_ACTIVE: return DefaultOrg.Types.NotActive.name();
119 public Identity responsibleTo() throws OrganizationException {
120 if("".equals(identity.responsibleTo) && isFound()) { // cover the situation of Top Dog... reports to no-one.
123 return org.getIdentity(trans, identity.responsibleTo);
128 public List<String> delegate() {
129 //NOTE: implement Delegate system, if desired
130 return DefaultOrg.NULL_DELEGATES;
134 public String email() {
135 return identity.email;
139 public String fullName() {
140 return identity.name;
144 public String firstName() {
145 return identity.fname;
149 public String mayOwn() {
150 // Assume only Employees are responsible for Resources.
151 if(identity.status==null|| identity.status.length()==0) {
152 return "Identity must have valid status";
153 } else if(EMPLOYEE.equals(identity.status)) {
154 return null; // This is "Yes, is Responsible"
156 return "Reponsible Party must be an Employee";
161 public boolean isFound() {
162 return identity!=Identities.NO_DATA; // yes, object comparison intended
166 public boolean isPerson() {
167 return !identity.status.equals(APPLICATION);
171 public Organization org() {