2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 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====================================================
22 package org.onap.aaf.auth.org;
24 import java.util.ArrayList;
25 import java.util.Date;
26 import java.util.GregorianCalendar;
27 import java.util.HashSet;
28 import java.util.List;
31 import org.onap.aaf.auth.env.AuthzTrans;
36 * There is Organizational specific information required which we have extracted to a plugin
38 * It supports using Company Specific User Directory lookups, as well as supporting an
39 * Approval/Validation Process to simplify control of Roles and Permissions for large organizations
40 * in lieu of direct manipulation by a set of Admins.
45 public interface Organization {
46 public static final String N_A = "n/a";
48 public interface Identity {
50 public String fullID() throws OrganizationException; // Fully Qualified ID (includes Domain of Organization)
51 public String type(); // Must be one of "IdentityTypes", see below
52 public Identity responsibleTo() throws OrganizationException; // Chain of Command, or Application ID Sponsor
53 public List<String> delegate(); // Someone who has authority to act on behalf of Identity
54 public String email();
55 public String fullName();
56 public String firstName();
58 * If Responsible entity, then String returned is "null" meaning "no Objection".
59 * If String exists, it is the Policy objection text setup by the entity.
62 public String mayOwn(); // Is id passed belong to a person suitable to be Responsible for content Management
63 public boolean isFound(); // Is Identity found in Identity stores
64 public boolean isPerson(); // Whether a Person or a Machine (App)
65 public Organization org(); // Organization of Identity
71 * Name of Organization, suitable for Logging
74 public String getName();
77 * Realm, for use in distinguishing IDs from different systems/Companies
80 public String getRealm();
85 * Get Identity information based on userID
90 public Identity getIdentity(AuthzTrans trans, String id) throws OrganizationException;
94 * Does the ID pass Organization Standards
96 * Return a Blank (empty) String if empty, otherwise, return a "\n" separated list of
97 * reasons why it fails
102 public String isValidID(AuthzTrans trans, String id);
105 * Return a Blank (empty) String if empty, otherwise, return a "\n" separated list of
106 * reasons why it fails
108 * Identity is passed in to allow policies regarding passwords that are the same as user ID
110 * any entries for "prev" imply a reset
116 public String isValidPassword(final AuthzTrans trans, final String id, final String password, final String ... prev);
119 * Return a list of Strings denoting Organization Password Rules, suitable for posting on a WebPage with <p>
121 public String[] getPasswordRules();
128 public boolean isValidCred(final AuthzTrans trans, final String id);
131 * If response is Null, then it is valid. Otherwise, the Organization specific reason is returned.
138 * @throws OrganizationException
140 public String validate(AuthzTrans trans, Policy policy, Executor executor, String ... vars) throws OrganizationException;
143 * Does your Company distinguish essential permission structures by kind of Identity?
144 * i.e. Employee, Contractor, Vendor
147 public Set<String> getIdentityTypes();
151 PasswordExpiration(2),
155 Notify(int id) {this.id = id;}
156 public int getValue() {return id;}
157 public static Notify from(int type) {
158 for(Notify t : Notify.values()) {
167 public enum Response{
171 ERR_NotificationFailure,
174 public enum Expiration {
187 CREATE_MECHID_BY_PERM_ONLY,
190 MAY_EXTEND_CRED_EXPIRES,
191 MAY_APPLY_DEFAULT_REALM
195 * Notify a User of Action or Info
199 * @param users (separated by commas)
200 * @param ccs (separated by commas)
204 public Response notify(AuthzTrans trans, Notify type, String url, String ids[], String ccs[], String summary, Boolean urgent);
207 * (more) generic way to send an email
216 public int sendEmail(AuthzTrans trans, List<String> toList, List<String> ccList, String subject, String body, Boolean urgent) throws OrganizationException;
221 * Authz support services will ask the Organization Object at startup when it should
222 * kickoff Validation processes given particular types.
224 * This allows the Organization to express Policy
226 * Turn off Validation behavior by returning "null"
229 public Date whenToValidate(Notify type, Date lastValidated);
235 * Given a Calendar item of Start (or now), set the Expiration Date based on the Policy
238 * For instance, "Passwords expire in 3 months"
240 * The Extra Parameter is used by certain Orgs.
242 * For Password, the extra is UserID, so it can check the User Type
248 public GregorianCalendar expiration(GregorianCalendar gc, Expiration exp, String ... extra);
251 * Get Email Warning timing policies
254 public EmailWarnings emailWarningPolicy();
262 public List<Identity> getApprovers(AuthzTrans trans, String user) throws OrganizationException ;
270 public Response notifyRequest(AuthzTrans trans, String user, Approval type, List<User> approvers);
277 public String getApproverType();
280 * startOfDay - define for company what hour of day business starts (specifically for password and other expiration which
281 * were set by Date only.)
285 public int startOfDay();
288 * implement this method to support any IDs that can have multiple entries in the cred table
289 * NOTE: the combination of ID/expiration date/(encryption type when implemented) must be unique.
290 * Since expiration date is based on startOfDay for your company, you cannot create many
291 * creds for the same ID in the same day.
295 public boolean canHaveMultipleCreds(String id);
299 public void setTestMode(boolean dryRun);
301 public static final Organization NULL = new Organization()
303 private final GregorianCalendar gc = new GregorianCalendar(1900, 1, 1);
304 private final List<Identity> nullList = new ArrayList<Identity>();
305 private final Set<String> nullStringSet = new HashSet<String>();
306 private String[] nullStringArray = new String[0];
307 private final Identity nullIdentity = new Identity() {
308 List<String> nullUser = new ArrayList<String>();
310 public String type() {
315 public String mayOwn() {
316 return N_A; // negative case
320 public boolean isFound() {
330 public String fullID() {
335 public String email() {
340 public List<String> delegate() {
344 public String fullName() {
348 public Organization org() {
352 public String firstName() {
356 public boolean isPerson() {
361 public Identity responsibleTo() {
366 public String getName() {
371 public String getRealm() {
376 public String getDomain() {
381 public Identity getIdentity(AuthzTrans trans, String id) {
386 public String isValidID(final AuthzTrans trans, String id) {
391 public String isValidPassword(final AuthzTrans trans, final String user, final String password, final String... prev) {
396 public Set<String> getIdentityTypes() {
397 return nullStringSet;
401 public Response notify(AuthzTrans trans, Notify type, String url,
402 String[] users, String[] ccs, String summary, Boolean urgent) {
403 return Response.ERR_NotImplemented;
407 public int sendEmail(AuthzTrans trans, List<String> toList, List<String> ccList,
408 String subject, String body, Boolean urgent) throws OrganizationException {
413 public Date whenToValidate(Notify type, Date lastValidated) {
418 public GregorianCalendar expiration(GregorianCalendar gc,
419 Expiration exp, String... extra) {
424 public List<Identity> getApprovers(AuthzTrans trans, String user)
425 throws OrganizationException {
430 public String getApproverType() {
435 public int startOfDay() {
440 public boolean canHaveMultipleCreds(String id) {
445 public boolean isValidCred(final AuthzTrans trans, final String id) {
450 public String validate(AuthzTrans trans, Policy policy, Executor executor, String ... vars)
451 throws OrganizationException {
452 return "Null Organization rejects all Policies";
456 public boolean isTestEnv() {
461 public void setTestMode(boolean dryRun) {
465 public EmailWarnings emailWarningPolicy() {
466 return new EmailWarnings() {
469 public long credEmailInterval()
471 return 604800000L; // 7 days in millis 1000 * 86400 * 7
475 public long roleEmailInterval()
477 return 604800000L; // 7 days in millis 1000 * 86400 * 7
481 public long apprEmailInterval() {
482 return 259200000L; // 3 days in millis 1000 * 86400 * 3
486 public long credExpirationWarning()
488 return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds
492 public long roleExpirationWarning()
494 return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds
498 public long emailUrgentWarning()
500 return( 1209600000L ); // Two weeks, in milliseconds 1000 * 86400 * 14 in milliseconds
507 public String[] getPasswordRules() {
508 return nullStringArray;