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();
82 public boolean supportsRealm(String user);
84 public void addSupportedRealm(String r);
91 * Get Identity information based on userID
96 public Identity getIdentity(AuthzTrans trans, String id) throws OrganizationException;
100 * Does the ID pass Organization Standards
102 * Return a Blank (empty) String if empty, otherwise, return a "\n" separated list of
103 * reasons why it fails
108 public String isValidID(AuthzTrans trans, String id);
111 * Return a Blank (empty) String if empty, otherwise, return a "\n" separated list of
112 * reasons why it fails
114 * Identity is passed in to allow policies regarding passwords that are the same as user ID
116 * any entries for "prev" imply a reset
122 public String isValidPassword(final AuthzTrans trans, final String id, final String password, final String ... prev);
125 * Return a list of Strings denoting Organization Password Rules, suitable for posting on a WebPage with <p>
127 public String[] getPasswordRules();
134 public boolean isValidCred(final AuthzTrans trans, final String id);
137 * If response is Null, then it is valid. Otherwise, the Organization specific reason is returned.
144 * @throws OrganizationException
146 public String validate(AuthzTrans trans, Policy policy, Executor executor, String ... vars) throws OrganizationException;
149 * Does your Company distinguish essential permission structures by kind of Identity?
150 * i.e. Employee, Contractor, Vendor
153 public Set<String> getIdentityTypes();
157 PasswordExpiration(2),
161 Notify(int id) {this.id = id;}
162 public int getValue() {return id;}
163 public static Notify from(int type) {
164 for (Notify t : Notify.values()) {
173 public enum Response{
177 ERR_NotificationFailure,
180 public enum Expiration {
193 CREATE_MECHID_BY_PERM_ONLY,
196 MAY_EXTEND_CRED_EXPIRES,
197 MAY_APPLY_DEFAULT_REALM
201 * Notify a User of Action or Info
205 * @param users (separated by commas)
206 * @param ccs (separated by commas)
210 public Response notify(AuthzTrans trans, Notify type, String url, String ids[], String ccs[], String summary, Boolean urgent);
213 * (more) generic way to send an email
222 public int sendEmail(AuthzTrans trans, List<String> toList, List<String> ccList, String subject, String body, Boolean urgent) throws OrganizationException;
227 * Authz support services will ask the Organization Object at startup when it should
228 * kickoff Validation processes given particular types.
230 * This allows the Organization to express Policy
232 * Turn off Validation behavior by returning "null"
235 public Date whenToValidate(Notify type, Date lastValidated);
241 * Given a Calendar item of Start (or now), set the Expiration Date based on the Policy
244 * For instance, "Passwords expire in 3 months"
246 * The Extra Parameter is used by certain Orgs.
248 * For Password, the extra is UserID, so it can check the User Type
254 public GregorianCalendar expiration(GregorianCalendar gc, Expiration exp, String ... extra);
257 * Get Email Warning timing policies
260 public EmailWarnings emailWarningPolicy();
268 public List<Identity> getApprovers(AuthzTrans trans, String user) throws OrganizationException ;
276 public Response notifyRequest(AuthzTrans trans, String user, Approval type, List<User> approvers);
283 public String getApproverType();
286 * startOfDay - define for company what hour of day business starts (specifically for password and other expiration which
287 * were set by Date only.)
291 public int startOfDay();
294 * implement this method to support any IDs that can have multiple entries in the cred table
295 * NOTE: the combination of ID/expiration date/(encryption type when implemented) must be unique.
296 * Since expiration date is based on startOfDay for your company, you cannot create many
297 * creds for the same ID in the same day.
301 public boolean canHaveMultipleCreds(String id);
305 public void setTestMode(boolean dryRun);
307 public static final Organization NULL = new Organization()
309 private final GregorianCalendar gc = new GregorianCalendar(1900, 1, 1);
310 private final List<Identity> nullList = new ArrayList<>();
311 private final Set<String> nullStringSet = new HashSet<>();
312 private String[] nullStringArray = new String[0];
313 private final Identity nullIdentity = new Identity() {
314 List<String> nullUser = new ArrayList<>();
316 public String type() {
321 public String mayOwn() {
322 return N_A; // negative case
326 public boolean isFound() {
336 public String fullID() {
341 public String email() {
346 public List<String> delegate() {
350 public String fullName() {
354 public Organization org() {
358 public String firstName() {
362 public boolean isPerson() {
367 public Identity responsibleTo() {
372 public String getName() {
377 public String getRealm() {
382 public boolean supportsRealm(String r) {
387 public void addSupportedRealm(String r) {
391 public String getDomain() {
396 public Identity getIdentity(AuthzTrans trans, String id) {
401 public String isValidID(final AuthzTrans trans, String id) {
406 public String isValidPassword(final AuthzTrans trans, final String user, final String password, final String... prev) {
411 public Set<String> getIdentityTypes() {
412 return nullStringSet;
416 public Response notify(AuthzTrans trans, Notify type, String url,
417 String[] users, String[] ccs, String summary, Boolean urgent) {
418 return Response.ERR_NotImplemented;
422 public int sendEmail(AuthzTrans trans, List<String> toList, List<String> ccList,
423 String subject, String body, Boolean urgent) throws OrganizationException {
428 public Date whenToValidate(Notify type, Date lastValidated) {
433 public GregorianCalendar expiration(GregorianCalendar gc,
434 Expiration exp, String... extra) {
439 public List<Identity> getApprovers(AuthzTrans trans, String user)
440 throws OrganizationException {
445 public String getApproverType() {
450 public int startOfDay() {
455 public boolean canHaveMultipleCreds(String id) {
460 public boolean isValidCred(final AuthzTrans trans, final String id) {
465 public String validate(AuthzTrans trans, Policy policy, Executor executor, String ... vars)
466 throws OrganizationException {
467 return "Null Organization rejects all Policies";
471 public boolean isTestEnv() {
476 public void setTestMode(boolean dryRun) {
480 public EmailWarnings emailWarningPolicy() {
481 return new EmailWarnings() {
484 public long credEmailInterval()
486 return 604800000L; // 7 days in millis 1000 * 86400 * 7
490 public long roleEmailInterval()
492 return 604800000L; // 7 days in millis 1000 * 86400 * 7
496 public long apprEmailInterval() {
497 return 259200000L; // 3 days in millis 1000 * 86400 * 3
501 public long credExpirationWarning()
503 return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds
507 public long roleExpirationWarning()
509 return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds
513 public long emailUrgentWarning()
515 return( 1209600000L ); // Two weeks, in milliseconds 1000 * 86400 * 14 in milliseconds
522 public String[] getPasswordRules() {
523 return nullStringArray;