From 43854a9e3310ff7a92257d16c4fc0a8321eaec68 Mon Sep 17 00:00:00 2001 From: sg481n Date: Thu, 3 Aug 2017 17:27:34 -0400 Subject: [PATCH] =?utf8?q?=C2=A0[AAF-21]=20Initial=20code=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I63d7d499bbd46f500b5f5a4db966166f613f327a Signed-off-by: sg481n --- authz-batch/.gitignore | 4 + authz-batch/pom.xml | 256 ++ authz-batch/src/main/config/authBatch.props | 36 + authz-batch/src/main/config/log4j.properties | 84 + authz-batch/src/main/java/com/att/authz/Batch.java | 471 +++ .../main/java/com/att/authz/BatchException.java | 33 + .../src/main/java/com/att/authz/CassBatch.java | 58 + .../src/main/java/com/att/authz/FileCassBatch.java | 53 + .../src/main/java/com/att/authz/JobChange.java | 743 ++++ .../java/com/att/authz/UserRoleDataGeneration.java | 100 + .../main/java/com/att/authz/actions/Action.java | 11 + .../main/java/com/att/authz/actions/ActionDAO.java | 43 + .../java/com/att/authz/actions/ActionPuntDAO.java | 45 + .../java/com/att/authz/actions/CredDelete.java | 31 + .../main/java/com/att/authz/actions/CredPrint.java | 38 + .../main/java/com/att/authz/actions/CredPunt.java | 47 + .../src/main/java/com/att/authz/actions/Email.java | 113 + .../java/com/att/authz/actions/EmailPrint.java | 51 + .../main/java/com/att/authz/actions/FADelete.java | 52 + .../main/java/com/att/authz/actions/FAPrint.java | 23 + .../src/main/java/com/att/authz/actions/Key.java | 8 + .../main/java/com/att/authz/actions/Message.java | 33 + .../src/main/java/com/att/authz/actions/URAdd.java | 39 + .../main/java/com/att/authz/actions/URDelete.java | 35 + .../com/att/authz/actions/URFutureApprove.java | 83 + .../java/com/att/authz/actions/URFuturePrint.java | 28 + .../main/java/com/att/authz/actions/URPrint.java | 24 + .../main/java/com/att/authz/actions/URPunt.java | 46 + .../authz/entryConverters/AafEntryConverter.java | 28 + .../authz/entryConverters/CredEntryConverter.java | 29 + .../authz/entryConverters/NsEntryConverter.java | 27 + .../authz/entryConverters/PermEntryConverter.java | 24 + .../authz/entryConverters/RoleEntryConverter.java | 23 + .../entryConverters/UserRoleEntryConverter.java | 26 + .../main/java/com/att/authz/helpers/Approver.java | 44 + .../main/java/com/att/authz/helpers/Creator.java | 23 + .../src/main/java/com/att/authz/helpers/Cred.java | 142 + .../main/java/com/att/authz/helpers/Future.java | 99 + .../java/com/att/authz/helpers/InputIterator.java | 51 + .../main/java/com/att/authz/helpers/MiscID.java | 169 + .../src/main/java/com/att/authz/helpers/NS.java | 134 + .../java/com/att/authz/helpers/Notification.java | 273 ++ .../main/java/com/att/authz/helpers/NsAttrib.java | 88 + .../src/main/java/com/att/authz/helpers/Perm.java | 124 + .../src/main/java/com/att/authz/helpers/Role.java | 125 + .../main/java/com/att/authz/helpers/UserRole.java | 133 + .../java/com/att/authz/reports/ApprNotify.java | 107 + .../main/java/com/att/authz/reports/CheckCred.java | 90 + .../main/java/com/att/authz/reports/CheckNS.java | 425 +++ .../java/com/att/authz/reports/CheckRolePerm.java | 164 + .../main/java/com/att/authz/reports/CheckUR.java | 74 + .../main/java/com/att/authz/reports/Expiring.java | 235 ++ .../main/java/com/att/authz/reports/NSDump.java | 136 + authz-batch/src/main/scripts/SyncV1V2 | 17 + authz-batch/src/main/scripts/SyncV1V2daily | 17 + authz-batch/src/main/scripts/SyncV2V1 | 17 + authz-batch/src/main/scripts/SyncV2V1daily | 17 + authz-batch/src/main/scripts/V1daily | 46 + authz-batch/src/main/scripts/V2daily | 46 + authz-batch/src/main/scripts/aafbch | 21 + authz-batch/src/main/scripts/run_batch | 16 + authz-cass/.gitignore | 5 + authz-cass/pom.xml | 155 + authz-cass/src/main/cql/ecomp.cql | 118 + authz-cass/src/main/cql/init.cql | 212 ++ .../src/main/java/com/att/dao/AbsCassDAO.java | 497 +++ .../src/main/java/com/att/dao/Bytification.java | 32 + authz-cass/src/main/java/com/att/dao/CIDAO.java | 52 + .../src/main/java/com/att/dao/Cacheable.java | 35 + authz-cass/src/main/java/com/att/dao/Cached.java | 198 + .../src/main/java/com/att/dao/CachedDAO.java | 229 ++ .../src/main/java/com/att/dao/CassAccess.java | 220 ++ .../src/main/java/com/att/dao/CassDAOImpl.java | 328 ++ authz-cass/src/main/java/com/att/dao/DAO.java | 44 + .../src/main/java/com/att/dao/DAOException.java | 53 + authz-cass/src/main/java/com/att/dao/DAO_RO.java | 71 + authz-cass/src/main/java/com/att/dao/Loader.java | 215 ++ authz-cass/src/main/java/com/att/dao/Streamer.java | 33 + .../src/main/java/com/att/dao/Touchable.java | 28 + .../java/com/att/dao/aaf/cached/CachedCertDAO.java | 56 + .../java/com/att/dao/aaf/cached/CachedCredDAO.java | 68 + .../java/com/att/dao/aaf/cached/CachedNSDAO.java | 35 + .../java/com/att/dao/aaf/cached/CachedPermDAO.java | 126 + .../java/com/att/dao/aaf/cached/CachedRoleDAO.java | 108 + .../com/att/dao/aaf/cached/CachedUserRoleDAO.java | 117 + .../java/com/att/dao/aaf/cass/ApprovalDAO.java | 206 + .../main/java/com/att/dao/aaf/cass/ArtiDAO.java | 267 ++ .../java/com/att/dao/aaf/cass/CacheInfoDAO.java | 464 +++ .../java/com/att/dao/aaf/cass/CacheableData.java | 37 + .../main/java/com/att/dao/aaf/cass/CertDAO.java | 244 ++ .../main/java/com/att/dao/aaf/cass/CredDAO.java | 258 ++ .../java/com/att/dao/aaf/cass/DelegateDAO.java | 139 + .../main/java/com/att/dao/aaf/cass/FutureDAO.java | 183 + .../main/java/com/att/dao/aaf/cass/HistoryDAO.java | 237 ++ .../main/java/com/att/dao/aaf/cass/Namespace.java | 152 + .../src/main/java/com/att/dao/aaf/cass/NsDAO.java | 541 +++ .../main/java/com/att/dao/aaf/cass/NsSplit.java | 63 + .../src/main/java/com/att/dao/aaf/cass/NsType.java | 75 + .../main/java/com/att/dao/aaf/cass/PermDAO.java | 502 +++ .../main/java/com/att/dao/aaf/cass/RoleDAO.java | 412 ++ .../src/main/java/com/att/dao/aaf/cass/Status.java | 89 + .../java/com/att/dao/aaf/cass/UserRoleDAO.java | 320 ++ .../main/java/com/att/dao/aaf/hl/CassExecutor.java | 75 + .../src/main/java/com/att/dao/aaf/hl/Function.java | 1575 ++++++++ .../main/java/com/att/dao/aaf/hl/PermLookup.java | 185 + .../src/main/java/com/att/dao/aaf/hl/Question.java | 1087 ++++++ .../java/com/att/dao/session/SessionFilter.java | 142 + .../java/com/att/authz/cass/hl/JU_Question.java | 501 +++ .../src/test/java/com/att/dao/JU_Cached.java | 126 + .../src/test/java/com/att/dao/JU_CachedDAO.java | 64 + .../src/test/java/com/att/dao/JU_CassAccess.java | 74 + .../src/test/java/com/att/dao/JU_CassDAOImpl.java | 96 + .../src/test/java/com/att/dao/JU_DAOException.java | 50 + .../test/java/com/att/dao/aaf/test/AbsJUCass.java | 201 + .../java/com/att/dao/aaf/test/JU_ApprovalDAO.java | 149 + .../test/java/com/att/dao/aaf/test/JU_ArtiDAO.java | 139 + .../java/com/att/dao/aaf/test/JU_Bytification.java | 268 ++ .../java/com/att/dao/aaf/test/JU_CacheInfoDAO.java | 66 + .../test/java/com/att/dao/aaf/test/JU_CertDAO.java | 106 + .../test/java/com/att/dao/aaf/test/JU_CredDAO.java | 253 ++ .../java/com/att/dao/aaf/test/JU_DelegateDAO.java | 109 + .../java/com/att/dao/aaf/test/JU_FastCalling.java | 92 + .../java/com/att/dao/aaf/test/JU_HistoryDAO.java | 156 + .../test/java/com/att/dao/aaf/test/JU_NsDAO.java | 188 + .../test/java/com/att/dao/aaf/test/JU_NsType.java | 61 + .../test/java/com/att/dao/aaf/test/JU_PermDAO.java | 177 + .../test/java/com/att/dao/aaf/test/JU_RoleDAO.java | 140 + .../java/com/att/dao/aaf/test/NS_ChildUpdate.java | 74 + authz-cass/src/test/resources/cadi.properties | 53 + authz-certman/.gitignore | 5 + authz-certman/pom.xml | 179 + authz-certman/src/main/config/certman.props | 25 + authz-certman/src/main/config/log4j.properties | 79 + .../src/main/config/lrm-authz-certman.xml | 83 + .../java/com/att/authz/cm/api/API_Artifact.java | 130 + .../main/java/com/att/authz/cm/api/API_Cert.java | 100 + .../src/main/java/com/att/authz/cm/ca/AppCA.java | 357 ++ .../src/main/java/com/att/authz/cm/ca/CA.java | 84 + .../src/main/java/com/att/authz/cm/ca/DevlCA.java | 227 ++ .../main/java/com/att/authz/cm/cert/BCFactory.java | 169 + .../main/java/com/att/authz/cm/cert/CSRMeta.java | 330 ++ .../java/com/att/authz/cm/cert/StandardFields.java | 30 + .../main/java/com/att/authz/cm/data/CertDrop.java | 28 + .../main/java/com/att/authz/cm/data/CertRenew.java | 28 + .../main/java/com/att/authz/cm/data/CertReq.java | 51 + .../main/java/com/att/authz/cm/data/CertResp.java | 66 + .../main/java/com/att/authz/cm/facade/Facade.java | 162 + .../java/com/att/authz/cm/facade/Facade1_0.java | 47 + .../com/att/authz/cm/facade/FacadeFactory.java | 43 + .../java/com/att/authz/cm/facade/FacadeImpl.java | 493 +++ .../main/java/com/att/authz/cm/mapper/Mapper.java | 53 + .../java/com/att/authz/cm/mapper/Mapper1_0.java | 246 ++ .../java/com/att/authz/cm/service/CMService.java | 515 +++ .../java/com/att/authz/cm/service/CertManAPI.java | 286 ++ .../main/java/com/att/authz/cm/service/Code.java | 46 + .../com/att/authz/cm/validation/Validator.java | 166 + .../java/com/att/authz/cm/api/JU_API_Artifact.java | 109 + .../java/com/att/authz/cm/api/JU_API_Cert.java | 109 + .../test/java/com/att/authz/cm/ca/JU_AppCA.java | 287 ++ .../test/java/com/att/authz/cm/ca/JU_DevlCA.java | 287 ++ .../java/com/att/authz/cm/cert/JU_BCFactory.java | 132 + .../java/com/att/authz/cm/cert/JU_CSRMeta.java | 96 + .../java/com/att/authz/cm/data/JU_CertReq.java | 88 + .../com/att/authz/cm/facade/JU_FacadeImpl.java | 195 + .../com/att/authz/cm/validation/JU_Validator.java | 101 + authz-client/.gitignore | 5 + authz-client/pom.xml | 208 + authz-client/src/main/xsd/aaf_2_0.xsd | 467 +++ authz-client/src/main/xsd/certman_1_0.xsd | 131 + authz-cmd/.gitignore | 5 + authz-cmd/aafcli.sh | 9 + authz-cmd/etc/log4j.properties | 55 + authz-cmd/pom.xml | 177 + authz-cmd/src/main/assemble/authz-cmd.xml | 48 + authz-cmd/src/main/assemble/swm.xml | 35 + authz-cmd/src/main/config/log4j.properties | 55 + authz-cmd/src/main/config/logging.props | 38 + authz-cmd/src/main/java/com/att/cmd/AAFcli.java | 723 ++++ authz-cmd/src/main/java/com/att/cmd/BaseCmd.java | 70 + authz-cmd/src/main/java/com/att/cmd/BasicAuth.java | 57 + authz-cmd/src/main/java/com/att/cmd/Cmd.java | 499 +++ authz-cmd/src/main/java/com/att/cmd/Help.java | 113 + .../main/java/com/att/cmd/MessageException.java | 47 + authz-cmd/src/main/java/com/att/cmd/Param.java | 39 + authz-cmd/src/main/java/com/att/cmd/Version.java | 46 + .../src/main/java/com/att/cmd/mgmt/Cache.java | 34 + .../src/main/java/com/att/cmd/mgmt/Clear.java | 86 + authz-cmd/src/main/java/com/att/cmd/mgmt/Deny.java | 102 + authz-cmd/src/main/java/com/att/cmd/mgmt/Log.java | 111 + authz-cmd/src/main/java/com/att/cmd/mgmt/Mgmt.java | 38 + .../src/main/java/com/att/cmd/mgmt/SessClear.java | 84 + .../src/main/java/com/att/cmd/mgmt/Session.java | 34 + authz-cmd/src/main/java/com/att/cmd/ns/Admin.java | 106 + authz-cmd/src/main/java/com/att/cmd/ns/Attrib.java | 115 + authz-cmd/src/main/java/com/att/cmd/ns/Create.java | 128 + authz-cmd/src/main/java/com/att/cmd/ns/Delete.java | 90 + .../src/main/java/com/att/cmd/ns/Describe.java | 96 + authz-cmd/src/main/java/com/att/cmd/ns/List.java | 170 + .../src/main/java/com/att/cmd/ns/ListActivity.java | 81 + .../java/com/att/cmd/ns/ListAdminResponsible.java | 79 + .../src/main/java/com/att/cmd/ns/ListByName.java | 105 + .../src/main/java/com/att/cmd/ns/ListChildren.java | 82 + .../java/com/att/cmd/ns/ListNsKeysByAttrib.java | 89 + .../src/main/java/com/att/cmd/ns/ListUsers.java | 54 + .../main/java/com/att/cmd/ns/ListUsersInRole.java | 129 + .../java/com/att/cmd/ns/ListUsersWithPerm.java | 128 + authz-cmd/src/main/java/com/att/cmd/ns/NS.java | 47 + .../src/main/java/com/att/cmd/ns/Responsible.java | 111 + .../src/main/java/com/att/cmd/perm/Create.java | 165 + .../src/main/java/com/att/cmd/perm/Delete.java | 90 + .../src/main/java/com/att/cmd/perm/Describe.java | 102 + .../src/main/java/com/att/cmd/perm/Grant.java | 151 + authz-cmd/src/main/java/com/att/cmd/perm/List.java | 129 + .../main/java/com/att/cmd/perm/ListActivity.java | 77 + .../src/main/java/com/att/cmd/perm/ListByNS.java | 72 + .../src/main/java/com/att/cmd/perm/ListByName.java | 70 + .../src/main/java/com/att/cmd/perm/ListByRole.java | 73 + .../src/main/java/com/att/cmd/perm/ListByUser.java | 76 + authz-cmd/src/main/java/com/att/cmd/perm/Perm.java | 44 + .../src/main/java/com/att/cmd/perm/Rename.java | 103 + .../main/java/com/att/cmd/role/CreateDelete.java | 132 + .../src/main/java/com/att/cmd/role/Describe.java | 96 + authz-cmd/src/main/java/com/att/cmd/role/List.java | 169 + .../main/java/com/att/cmd/role/ListActivity.java | 76 + .../src/main/java/com/att/cmd/role/ListByNS.java | 73 + .../main/java/com/att/cmd/role/ListByNameOnly.java | 73 + .../src/main/java/com/att/cmd/role/ListByPerm.java | 79 + .../src/main/java/com/att/cmd/role/ListByRole.java | 70 + .../src/main/java/com/att/cmd/role/ListByUser.java | 146 + authz-cmd/src/main/java/com/att/cmd/role/Role.java | 41 + authz-cmd/src/main/java/com/att/cmd/role/User.java | 171 + authz-cmd/src/main/java/com/att/cmd/user/Cred.java | 153 + authz-cmd/src/main/java/com/att/cmd/user/Delg.java | 136 + authz-cmd/src/main/java/com/att/cmd/user/List.java | 122 + .../main/java/com/att/cmd/user/ListActivity.java | 81 + .../main/java/com/att/cmd/user/ListApprovals.java | 104 + .../main/java/com/att/cmd/user/ListDelegates.java | 95 + .../main/java/com/att/cmd/user/ListForCreds.java | 99 + .../java/com/att/cmd/user/ListForPermission.java | 104 + .../main/java/com/att/cmd/user/ListForRoles.java | 93 + authz-cmd/src/main/java/com/att/cmd/user/Role.java | 158 + authz-cmd/src/main/java/com/att/cmd/user/User.java | 38 + authz-cmd/src/main/scripts/aaflogin | 199 + authz-cmd/src/test/java/com/att/cmd/JU_AAFCli.java | 90 + .../src/test/java/com/att/cmd/JU_BaseCmd.java | 57 + .../src/test/java/com/att/cmd/JU_BasicAuth.java | 49 + authz-cmd/src/test/java/com/att/cmd/JU_Help.java | 69 + .../src/test/java/com/att/cmd/JU_Version.java | 58 + .../src/test/java/com/att/cmd/mgmt/JU_Clear.java | 63 + .../src/test/java/com/att/cmd/mgmt/JU_Log.java | 63 + .../test/java/com/att/cmd/mgmt/JU_SessClear.java | 63 + .../src/test/java/com/att/cmd/ns/JU_Admin.java | 71 + .../src/test/java/com/att/cmd/ns/JU_Attrib.java | 71 + .../src/test/java/com/att/cmd/ns/JU_Create.java | 71 + .../src/test/java/com/att/cmd/ns/JU_Delete.java | 72 + .../src/test/java/com/att/cmd/ns/JU_Describe.java | 72 + .../test/java/com/att/cmd/ns/JU_ListActivity.java | 68 + .../com/att/cmd/ns/JU_ListAdminResponsible.java | 68 + .../test/java/com/att/cmd/ns/JU_ListByName.java | 68 + .../test/java/com/att/cmd/ns/JU_ListChildren.java | 68 + .../java/com/att/cmd/ns/JU_ListNsKeysByAttrib.java | 68 + .../java/com/att/cmd/ns/JU_ListUsersInRole.java | 68 + .../java/com/att/cmd/ns/JU_ListUsersWithPerm.java | 68 + .../test/java/com/att/cmd/ns/JU_Responsible.java | 66 + .../src/test/java/com/att/cmd/perm/JU_Create.java | 68 + .../src/test/java/com/att/cmd/perm/JU_Delete.java | 68 + .../test/java/com/att/cmd/perm/JU_Describe.java | 68 + .../src/test/java/com/att/cmd/perm/JU_Grant.java | 68 + .../java/com/att/cmd/perm/JU_ListActivity.java | 69 + .../test/java/com/att/cmd/perm/JU_ListByNS.java | 69 + .../test/java/com/att/cmd/perm/JU_ListByName.java | 69 + .../test/java/com/att/cmd/perm/JU_ListByRole.java | 69 + .../test/java/com/att/cmd/perm/JU_ListByUser.java | 69 + .../src/test/java/com/att/cmd/perm/JU_Rename.java | 68 + .../java/com/att/cmd/role/JU_CreateDelete.java | 67 + .../test/java/com/att/cmd/role/JU_Describe.java | 67 + .../java/com/att/cmd/role/JU_ListActivity.java | 68 + .../test/java/com/att/cmd/role/JU_ListByNS.java | 68 + .../java/com/att/cmd/role/JU_ListByNameOnly.java | 68 + .../test/java/com/att/cmd/role/JU_ListByPerm.java | 68 + .../test/java/com/att/cmd/role/JU_ListByRole.java | 68 + .../test/java/com/att/cmd/role/JU_ListByUser.java | 68 + .../src/test/java/com/att/cmd/role/JU_User.java | 68 + .../src/test/java/com/att/cmd/user/JU_Cred.java | 115 + .../src/test/java/com/att/cmd/user/JU_Delg.java | 80 + .../java/com/att/cmd/user/JU_ListActivity.java | 68 + .../java/com/att/cmd/user/JU_ListApprovals.java | 68 + .../java/com/att/cmd/user/JU_ListDelegates.java | 68 + .../java/com/att/cmd/user/JU_ListForCreds.java | 68 + .../com/att/cmd/user/JU_ListForPermission.java | 68 + .../java/com/att/cmd/user/JU_ListForRoles.java | 68 + .../src/test/java/com/att/cmd/user/JU_Role.java | 67 + authz-core/.gitignore | 5 + authz-core/pom.xml | 148 + .../src/main/java/com/att/authz/common/Define.java | 51 + .../src/main/java/com/att/authz/env/AuthzEnv.java | 265 ++ .../main/java/com/att/authz/env/AuthzTrans.java | 71 + .../java/com/att/authz/env/AuthzTransFilter.java | 165 + .../java/com/att/authz/env/AuthzTransImpl.java | 198 + .../com/att/authz/env/AuthzTransOnlyFilter.java | 89 + .../src/main/java/com/att/authz/env/NullTrans.java | 225 ++ .../main/java/com/att/authz/layer/FacadeImpl.java | 39 + .../src/main/java/com/att/authz/layer/Result.java | 326 ++ .../src/main/java/com/att/authz/local/AbsData.java | 215 ++ .../main/java/com/att/authz/local/DataFile.java | 186 + .../main/java/com/att/authz/local/TextIndex.java | 253 ++ .../main/java/com/att/authz/org/EmailWarnings.java | 35 + .../src/main/java/com/att/authz/org/Executor.java | 36 + .../main/java/com/att/authz/org/Organization.java | 491 +++ .../com/att/authz/org/OrganizationException.java | 54 + .../com/att/authz/org/OrganizationFactory.java | 148 + .../main/java/com/att/authz/server/AbsServer.java | 150 + authz-core/src/main/java/com/att/cache/Cache.java | 196 + .../src/main/java/com/att/cssa/rserv/Acceptor.java | 170 + .../java/com/att/cssa/rserv/CachingFileAccess.java | 477 +++ .../main/java/com/att/cssa/rserv/CodeSetter.java | 54 + .../src/main/java/com/att/cssa/rserv/Content.java | 116 + .../src/main/java/com/att/cssa/rserv/HttpCode.java | 112 + .../main/java/com/att/cssa/rserv/HttpMethods.java | 31 + .../src/main/java/com/att/cssa/rserv/Match.java | 212 ++ .../src/main/java/com/att/cssa/rserv/Pair.java | 44 + .../src/main/java/com/att/cssa/rserv/RServlet.java | 156 + .../src/main/java/com/att/cssa/rserv/Route.java | 143 + .../main/java/com/att/cssa/rserv/RouteReport.java | 35 + .../src/main/java/com/att/cssa/rserv/Routes.java | 91 + .../main/java/com/att/cssa/rserv/TransFilter.java | 137 + .../java/com/att/cssa/rserv/TransOnlyFilter.java | 78 + .../main/java/com/att/cssa/rserv/TypedCode.java | 269 ++ .../src/main/java/com/att/cssa/rserv/Version.java | 94 + .../main/java/com/att/cssa/rserv/doc/ApiDoc.java | 43 + .../test/java/com/att/authz/common/JU_Define.java | 64 + .../test/java/com/att/authz/env/JU_AuthzEnv.java | 70 + .../com/att/authz/env/JU_AuthzTransFilter.java | 81 + .../java/com/att/authz/env/JU_AuthzTransImpl.java | 74 + .../com/att/authz/env/JU_AuthzTransOnlyFilter.java | 50 + .../test/java/com/att/authz/env/JU_NullTrans.java | 47 + .../test/java/com/att/authz/layer/JU_Result.java | 54 + .../test/java/com/att/authz/local/JU_DataFile.java | 69 + .../java/com/att/authz/local/JU_TextIndex.java | 52 + .../att/authz/org/JU_OrganizationException.java | 49 + .../com/att/authz/org/JU_OrganizationFactory.java | 64 + .../com/att/cssa/rserv/JU_CachingFileAccess.java | 50 + .../java/com/att/cssa/rserv/JU_CodeSetter.java | 68 + .../src/test/java/com/att/cssa/rserv/JU_Pair.java | 46 + .../test/java/com/att/cssa/rserv/JU_Routes.java | 70 + .../test/java/com/att/cssa/rserv/JU_TypedCode.java | 52 + .../test/java/com/att/cssa/rserv/JU_Version.java | 58 + .../com/att/cssa/rserv/test/JU_BetterMatch.java | 167 + .../java/com/att/cssa/rserv/test/JU_Content.java | 133 + authz-defOrg/.gitignore | 5 + authz-defOrg/pom.xml | 82 + .../src/main/java/com/osaaf/defOrg/DefaultOrg.java | 597 +++ .../java/com/osaaf/defOrg/DefaultOrgIdentity.java | 147 + .../java/com/osaaf/defOrg/DefaultOrgWarnings.java | 65 + .../src/main/java/com/osaaf/defOrg/Identities.java | 145 + .../java/com/osaaf/defOrd/test/JU_Identities.java | 113 + .../test/java/com/osaaf/defOrg/JU_DefaultOrg.java | 103 + .../com/osaaf/defOrg/JU_DefaultOrgIdentity.java | 72 + .../com/osaaf/defOrg/JU_DefaultOrgWarnings.java | 84 + .../test/java/com/osaaf/defOrg/JU_Identities.java | 113 + authz-fs/.gitignore | 5 + authz-fs/pom.xml | 163 + authz-fs/src/main/config/FileServer.props | 20 + authz-fs/src/main/config/log4j.properties | 91 + authz-fs/src/main/config/lrm-authz-fs.xml | 83 + authz-fs/src/main/data/test.html | 43 + .../src/main/java/com/att/authz/fs/FileServer.java | 156 + .../test/java/com/att/authz/fs/JU_FileServer.java | 84 + authz-gui/.gitignore | 5 + authz-gui/pom.xml | 232 ++ authz-gui/src/main/config/authGUI.props | 34 + authz-gui/src/main/config/log4j.properties | 57 + authz-gui/src/main/config/lrm-authz-gui.xml | 64 + authz-gui/src/main/java/com/att/authz/cui/CUI.java | 65 + .../src/main/java/com/att/authz/gui/AuthGUI.java | 319 ++ .../main/java/com/att/authz/gui/BreadCrumbs.java | 37 + .../src/main/java/com/att/authz/gui/Controls.java | 27 + .../src/main/java/com/att/authz/gui/Display.java | 122 + .../src/main/java/com/att/authz/gui/Form.java | 51 + .../src/main/java/com/att/authz/gui/NamedCode.java | 31 + .../src/main/java/com/att/authz/gui/Page.java | 292 ++ .../src/main/java/com/att/authz/gui/Table.java | 149 + .../main/java/com/att/authz/gui/pages/ApiDocs.java | 304 ++ .../java/com/att/authz/gui/pages/ApiExample.java | 122 + .../com/att/authz/gui/pages/ApprovalAction.java | 108 + .../java/com/att/authz/gui/pages/ApprovalForm.java | 262 ++ .../main/java/com/att/authz/gui/pages/Home.java | 59 + .../java/com/att/authz/gui/pages/LoginLanding.java | 97 + .../att/authz/gui/pages/LoginLandingAction.java | 47 + .../java/com/att/authz/gui/pages/NsDetail.java | 223 ++ .../java/com/att/authz/gui/pages/NsHistory.java | 210 ++ .../java/com/att/authz/gui/pages/NsInfoAction.java | 140 + .../java/com/att/authz/gui/pages/NsInfoForm.java | 144 + .../main/java/com/att/authz/gui/pages/NssShow.java | 123 + .../com/att/authz/gui/pages/PassChangeAction.java | 138 + .../com/att/authz/gui/pages/PassChangeForm.java | 68 + .../att/authz/gui/pages/PendingRequestsShow.java | 174 + .../java/com/att/authz/gui/pages/PermDetail.java | 138 + .../com/att/authz/gui/pages/PermGrantAction.java | 117 + .../com/att/authz/gui/pages/PermGrantForm.java | 139 + .../java/com/att/authz/gui/pages/PermHistory.java | 223 ++ .../java/com/att/authz/gui/pages/PermsShow.java | 99 + .../com/att/authz/gui/pages/RequestDetail.java | 176 + .../java/com/att/authz/gui/pages/RoleDetail.java | 130 + .../java/com/att/authz/gui/pages/RoleHistory.java | 208 + .../java/com/att/authz/gui/pages/RolesShow.java | 119 + .../com/att/authz/gui/pages/UserRoleExtend.java | 81 + .../com/att/authz/gui/pages/UserRoleRemove.java | 79 + .../java/com/att/authz/gui/pages/WebCommand.java | 101 + .../main/java/com/att/authz/gui/table/AbsCell.java | 27 + .../java/com/att/authz/gui/table/ButtonCell.java | 27 + .../java/com/att/authz/gui/table/RadioCell.java | 29 + .../main/java/com/att/authz/gui/table/RefCell.java | 35 + .../com/att/authz/gui/table/TextAndRefCell.java | 25 + .../java/com/att/authz/gui/table/TextCell.java | 31 + authz-gui/theme/AAF_details.png | Bin 0 -> 650 bytes authz-gui/theme/AAF_font_size.png | Bin 0 -> 1280 bytes authz-gui/theme/AAF_maximize.png | Bin 0 -> 593 bytes authz-gui/theme/AAFdownload.png | Bin 0 -> 1834 bytes authz-gui/theme/AAFemail.png | Bin 0 -> 2277 bytes authz-gui/theme/aaf5.css | 524 +++ authz-gui/theme/aaf5Desktop.css | 92 + authz-gui/theme/aaf5iPhone.css | 38 + authz-gui/theme/aafOldIE.css | 162 + authz-gui/theme/aaf_1_0.xsd | 150 + authz-gui/theme/aaf_2_0.xsd | 394 ++ authz-gui/theme/comm.js | 24 + authz-gui/theme/common.js | 104 + authz-gui/theme/console.js | 275 ++ authz-gui/theme/favicon.ico | Bin 0 -> 3638 bytes authz-gui/theme/options_down.png | Bin 0 -> 833 bytes authz-gui/theme/options_up.png | Bin 0 -> 826 bytes authz-gui/theme/t_bubbles.jpg | Bin 0 -> 9157 bytes authz-gw/.gitignore | 5 + authz-gw/pom.xml | 176 + authz-gw/src/main/config/authGW.props | 33 + authz-gw/src/main/config/log4j.properties | 80 + authz-gw/src/main/config/lrm-authz-gw.xml | 83 + authz-gw/src/main/java/com/att/authz/gw/GwAPI.java | 248 ++ .../src/main/java/com/att/authz/gw/GwCode.java | 46 + .../java/com/att/authz/gw/api/API_AAFAccess.java | 363 ++ .../main/java/com/att/authz/gw/api/API_Api.java | 99 + .../main/java/com/att/authz/gw/api/API_Find.java | 87 + .../main/java/com/att/authz/gw/api/API_Proxy.java | 156 + .../main/java/com/att/authz/gw/api/API_TGuard.java | 75 + .../java/com/att/authz/gw/facade/GwFacade.java | 75 + .../com/att/authz/gw/facade/GwFacadeFactory.java | 48 + .../java/com/att/authz/gw/facade/GwFacadeImpl.java | 258 ++ .../java/com/att/authz/gw/facade/GwFacade_1_0.java | 40 + .../main/java/com/att/authz/gw/mapper/Mapper.java | 34 + .../java/com/att/authz/gw/mapper/Mapper_1_0.java | 70 + .../java/com/att/authz/gw/service/GwService.java | 30 + .../com/att/authz/gw/service/GwServiceImpl.java | 41 + authz-gw/src/main/xsd/gw_1_0.xsd | 103 + .../src/test/java/com/att/authz/gw/JU_GwAPI.java | 52 + authz-service/.gitignore | 7 + authz-service/pom.xml | 246 ++ authz-service/src/main/assemble/swm.xml | 36 + authz-service/src/main/config/authAPI.props | 24 + authz-service/src/main/config/log4j.properties | 91 + .../src/main/config/lrm-authz-service.xml | 83 + .../main/java/com/att/authz/cadi/DirectAAFLur.java | 170 + .../java/com/att/authz/cadi/DirectAAFUserPass.java | 74 + .../com/att/authz/cadi/DirectCertIdentity.java | 79 + .../java/com/att/authz/facade/AuthzFacade.java | 264 ++ .../com/att/authz/facade/AuthzFacadeFactory.java | 57 + .../java/com/att/authz/facade/AuthzFacadeImpl.java | 2565 +++++++++++++ .../java/com/att/authz/facade/AuthzFacade_2_0.java | 65 + .../main/java/com/att/authz/service/AuthAPI.java | 331 ++ .../att/authz/service/AuthzCassServiceImpl.java | 3973 ++++++++++++++++++++ .../java/com/att/authz/service/AuthzService.java | 749 ++++ .../src/main/java/com/att/authz/service/Code.java | 46 + .../main/java/com/att/authz/service/MayChange.java | 34 + .../java/com/att/authz/service/api/API_Api.java | 93 + .../com/att/authz/service/api/API_Approval.java | 108 + .../java/com/att/authz/service/api/API_Creds.java | 278 ++ .../com/att/authz/service/api/API_Delegate.java | 154 + .../com/att/authz/service/api/API_History.java | 239 ++ .../java/com/att/authz/service/api/API_Mgmt.java | 275 ++ .../java/com/att/authz/service/api/API_NS.java | 397 ++ .../java/com/att/authz/service/api/API_Perms.java | 292 ++ .../java/com/att/authz/service/api/API_Roles.java | 314 ++ .../java/com/att/authz/service/api/API_User.java | 134 + .../com/att/authz/service/api/API_UserRole.java | 182 + .../java/com/att/authz/service/mapper/Mapper.java | 123 + .../com/att/authz/service/mapper/Mapper_2_0.java | 791 ++++ .../att/authz/service/validation/Validator.java | 387 ++ authz-service/src/main/resources/authAPI.props | 24 + .../src/main/resources/docker-compose/aafcli.sh | 9 + .../main/resources/docker-compose/data/ecomp.cql | 169 + .../resources/docker-compose/data/identities.dat | 7 + .../resources/docker-compose/data/identities.idx | Bin 0 -> 56 bytes .../main/resources/docker-compose/data/init.cql | 242 ++ .../resources/docker-compose/data2/identities.dat | 9 + .../resources/docker-compose/docker-compose.yml | 59 + .../resources/docker-compose/old/dme2-3.1.200.jar | Bin 0 -> 21798449 bytes .../src/main/resources/docker-compose/runaafcli.sh | 9 + .../main/resources/docker-compose/startupaaf.sh | 32 + .../src/main/resources/docker-compose/sysctl.conf | 3 + .../resources/docker-compose/wait_for_host_port.sh | 17 + authz-service/src/main/sample/authAPI.props | 30 + authz-service/src/main/sample/log4j.properties | 86 + authz-service/src/main/swm/common/deinstall.sh | 40 + authz-service/src/main/swm/common/install.sh | 252 ++ .../src/main/swm/deinstall/postproc/post_proc | 7 + .../src/main/swm/deinstall/preproc/pre_proc | 3 + authz-service/src/main/swm/descriptor.xml | 52 + .../src/main/swm/fallback/postproc/post_proc | 6 + .../src/main/swm/fallback/preproc/pre_proc | 6 + .../src/main/swm/initinst/postproc/post_proc | 6 + .../src/main/swm/initinst/preproc/pre_proc | 7 + .../src/main/swm/install/postproc/post_proc | 7 + .../src/main/swm/install/preproc/pre_proc | 7 + authz-service/src/main/swm/packageNotes.txt | 33 + .../java/com/att/authz/cadi/JU_DirectAAFLur.java | 66 + .../com/att/authz/cadi/JU_DirectAAFUserPass.java | 73 + .../com/att/authz/cadi/JU_DirectCertIdentity.java | 73 + .../java/com/att/authz/service/JU_AuthAPI.java | 76 + .../java/com/att/authz/service/api/JU_API_Api.java | 60 + .../com/att/authz/service/api/JU_API_Approval.java | 62 + .../com/att/authz/service/api/JU_API_Creds.java | 73 + .../com/att/authz/service/api/JU_API_Delegate.java | 56 + .../com/att/authz/service/api/JU_API_History.java | 62 + .../com/att/authz/service/api/JU_API_Mgmt.java | 59 + .../java/com/att/authz/service/api/JU_API_NS.java | 51 + .../com/att/authz/service/api/JU_API_Perms.java | 68 + .../com/att/authz/service/api/JU_API_Roles.java | 57 + .../com/att/authz/service/api/JU_API_User.java | 57 + .../com/att/authz/service/api/JU_API_UserRole.java | 53 + .../att/authz/service/mapper/JU_Mapper_2_0.java | 164 + .../com/att/authz/service/test/JU_Validator.java | 161 + .../att/authz/service/validation/JU_Validator.java | 178 + authz-service/start.sh | 11 + authz-test/.gitignore | 5 + .../Instructions_for_MTCs/MTC_Appr_README.txt | 102 + authz-test/TestSuite/JU_Lur2_0/10_init | 34 + authz-test/TestSuite/JU_Lur2_0/Description | 2 + authz-test/TestSuite/MTC_Appr1/00_ids | 8 + authz-test/TestSuite/MTC_Appr1/10_init | 29 + authz-test/TestSuite/MTC_Appr1/15_create | 40 + authz-test/TestSuite/MTC_Appr1/Description | 16 + authz-test/TestSuite/MTC_Appr2/00_ids | 8 + authz-test/TestSuite/MTC_Appr2/99_cleanup | 35 + authz-test/TestSuite/MTC_Appr2/Description | 16 + authz-test/TestSuite/TC_Cred1/00_ids | 8 + authz-test/TestSuite/TC_Cred1/10_init | 36 + authz-test/TestSuite/TC_Cred1/15_create | 33 + authz-test/TestSuite/TC_Cred1/30_multiple_creds | 69 + authz-test/TestSuite/TC_Cred1/99_cleanup | 29 + authz-test/TestSuite/TC_Cred1/Description | 16 + authz-test/TestSuite/TC_DELG1/00_ids | 10 + authz-test/TestSuite/TC_DELG1/10_init | 55 + authz-test/TestSuite/TC_DELG1/20_create | 55 + authz-test/TestSuite/TC_DELG1/99_cleanup | 17 + authz-test/TestSuite/TC_DELG1/Description | 16 + authz-test/TestSuite/TC_Link/00_ids | 9 + authz-test/TestSuite/TC_Link/05_print | 6 + authz-test/TestSuite/TC_Link/10_init | 13 + authz-test/TestSuite/TC_Link/15_print | 6 + authz-test/TestSuite/TC_Link/20_del | 3 + authz-test/TestSuite/TC_Link/25_print | 6 + authz-test/TestSuite/TC_Link/30_readd | 5 + authz-test/TestSuite/TC_Link/35_print | 6 + authz-test/TestSuite/TC_Link/99_delete | 5 + authz-test/TestSuite/TC_Link/Description | 9 + authz-test/TestSuite/TC_NS1/00_ids | 9 + authz-test/TestSuite/TC_NS1/01_ERR_BadData | 14 + authz-test/TestSuite/TC_NS1/10_init | 30 + .../TestSuite/TC_NS1/11_ERR_Namespace_Exists | 4 + authz-test/TestSuite/TC_NS1/20_Commands | 7 + authz-test/TestSuite/TC_NS1/30_add_data | 14 + authz-test/TestSuite/TC_NS1/50_Admin | 49 + authz-test/TestSuite/TC_NS1/60_Responsible | 43 + authz-test/TestSuite/TC_NS1/80_CheckData | 15 + authz-test/TestSuite/TC_NS1/90_ERR_Delete | 7 + authz-test/TestSuite/TC_NS1/99_cleanup | 15 + authz-test/TestSuite/TC_NS1/Description | 15 + authz-test/TestSuite/TC_NS2/00_ids | 10 + authz-test/TestSuite/TC_NS2/10_init | 71 + authz-test/TestSuite/TC_NS2/20_add_data | 18 + authz-test/TestSuite/TC_NS2/40_viewByName | 31 + authz-test/TestSuite/TC_NS2/41_viewByAdmin | 20 + authz-test/TestSuite/TC_NS2/99_cleanup | 27 + authz-test/TestSuite/TC_NS2/Description | 7 + authz-test/TestSuite/TC_NS3/00_ids | 10 + authz-test/TestSuite/TC_NS3/10_init | 8 + authz-test/TestSuite/TC_NS3/20_add | 56 + authz-test/TestSuite/TC_NS3/50_delete | 27 + authz-test/TestSuite/TC_NS3/99_cleanup | 14 + authz-test/TestSuite/TC_NS3/Description | 10 + authz-test/TestSuite/TC_NSdelete1/00_ids | 10 + authz-test/TestSuite/TC_NSdelete1/10_init | 35 + authz-test/TestSuite/TC_NSdelete1/20_DeleteApp | 30 + authz-test/TestSuite/TC_NSdelete1/30_DeleteCompany | 42 + authz-test/TestSuite/TC_NSdelete1/40_ForceDelete | 26 + authz-test/TestSuite/TC_NSdelete1/99_cleanup | 36 + authz-test/TestSuite/TC_NSdelete1/Description | 15 + authz-test/TestSuite/TC_PW1/00_ids | 8 + authz-test/TestSuite/TC_PW1/10_init | 24 + authz-test/TestSuite/TC_PW1/20_length | 10 + authz-test/TestSuite/TC_PW1/21_groups | 40 + authz-test/TestSuite/TC_PW1/23_commands | 6 + authz-test/TestSuite/TC_PW1/30_reset | 15 + authz-test/TestSuite/TC_PW1/99_cleanup | 21 + authz-test/TestSuite/TC_PW1/Description | 16 + authz-test/TestSuite/TC_Perm1/00_ids | 9 + authz-test/TestSuite/TC_Perm1/10_init | 23 + authz-test/TestSuite/TC_Perm1/20_add_data | 38 + authz-test/TestSuite/TC_Perm1/22_rename | 52 + authz-test/TestSuite/TC_Perm1/25_grant_owned | 40 + authz-test/TestSuite/TC_Perm1/26_grant_unowned | 175 + authz-test/TestSuite/TC_Perm1/27_grant_force | 29 + authz-test/TestSuite/TC_Perm1/30_change_ns | 14 + authz-test/TestSuite/TC_Perm1/99_cleanup | 42 + authz-test/TestSuite/TC_Perm1/Description | 16 + authz-test/TestSuite/TC_Perm2/00_ids | 8 + authz-test/TestSuite/TC_Perm2/10_init | 8 + authz-test/TestSuite/TC_Perm2/20_add_data | 44 + authz-test/TestSuite/TC_Perm2/30_change_ns | 14 + authz-test/TestSuite/TC_Perm2/40_viewByType | 82 + authz-test/TestSuite/TC_Perm2/41_viewByUser | 34 + authz-test/TestSuite/TC_Perm2/42_viewByNS | 10 + authz-test/TestSuite/TC_Perm2/43_viewByRole | 15 + authz-test/TestSuite/TC_Perm2/99_cleanup | 24 + authz-test/TestSuite/TC_Perm2/Description | 9 + authz-test/TestSuite/TC_Perm3/00_ids | 10 + authz-test/TestSuite/TC_Perm3/10_init | 16 + authz-test/TestSuite/TC_Perm3/20_innerGrants | 29 + authz-test/TestSuite/TC_Perm3/30_outerGrants | 23 + authz-test/TestSuite/TC_Perm3/99_cleanup | 22 + authz-test/TestSuite/TC_Perm3/Description | 13 + authz-test/TestSuite/TC_Realm1/00_ids | 8 + authz-test/TestSuite/TC_Realm1/10_init | 20 + authz-test/TestSuite/TC_Realm1/20_ns | 26 + authz-test/TestSuite/TC_Realm1/30_role | 20 + authz-test/TestSuite/TC_Realm1/40_user | 42 + authz-test/TestSuite/TC_Realm1/99_cleanup | 28 + authz-test/TestSuite/TC_Realm1/Description | 2 + authz-test/TestSuite/TC_Role1/00_ids | 8 + authz-test/TestSuite/TC_Role1/10_init | 23 + authz-test/TestSuite/TC_Role1/20_add_data | 40 + authz-test/TestSuite/TC_Role1/30_change_ns | 14 + authz-test/TestSuite/TC_Role1/40_reports | 24 + authz-test/TestSuite/TC_Role1/50_force_delete | 28 + authz-test/TestSuite/TC_Role1/90_wait | 2 + authz-test/TestSuite/TC_Role1/99_cleanup | 34 + authz-test/TestSuite/TC_Role1/Description | 16 + authz-test/TestSuite/TC_Role2/00_ids | 8 + authz-test/TestSuite/TC_Role2/10_init | 8 + authz-test/TestSuite/TC_Role2/20_add_data | 39 + authz-test/TestSuite/TC_Role2/40_viewByName | 45 + authz-test/TestSuite/TC_Role2/41_viewByUser | 20 + authz-test/TestSuite/TC_Role2/42_viewByNS | 10 + authz-test/TestSuite/TC_Role2/43_viewByPerm | 15 + authz-test/TestSuite/TC_Role2/99_cleanup | 22 + authz-test/TestSuite/TC_Role2/Description | 9 + authz-test/TestSuite/TC_UR1/00_ids | 8 + authz-test/TestSuite/TC_UR1/10_init | 31 + authz-test/TestSuite/TC_UR1/23_commands | 10 + authz-test/TestSuite/TC_UR1/30_userrole | 53 + authz-test/TestSuite/TC_UR1/40_reset | 40 + authz-test/TestSuite/TC_UR1/90_wait | 2 + authz-test/TestSuite/TC_UR1/99_cleanup | 32 + authz-test/TestSuite/TC_UR1/Description | 16 + authz-test/TestSuite/TC_User1/00_ids | 12 + authz-test/TestSuite/TC_User1/10_init | 25 + authz-test/TestSuite/TC_User1/20_add_data | 26 + authz-test/TestSuite/TC_User1/40_viewByRole | 23 + authz-test/TestSuite/TC_User1/41_viewByPerm | 29 + authz-test/TestSuite/TC_User1/42_viewByDelegates | 12 + .../TestSuite/TC_User1/43_viewsExplicitiPerm | 27 + authz-test/TestSuite/TC_User1/99_cleanup | 37 + authz-test/TestSuite/TC_User1/Description | 6 + authz-test/TestSuite/TC_Wild/00_ids | 8 + authz-test/TestSuite/TC_Wild/10_init | 18 + authz-test/TestSuite/TC_Wild/20_perm | 33 + authz-test/TestSuite/TC_Wild/21_perm | 33 + authz-test/TestSuite/TC_Wild/30_role | 33 + authz-test/TestSuite/TC_Wild/31_role | 33 + authz-test/TestSuite/TC_Wild/32_role | 30 + authz-test/TestSuite/TC_Wild/50_global_perm | 33 + authz-test/TestSuite/TC_Wild/51_global_role | 33 + authz-test/TestSuite/TC_Wild/52_global_ns | 33 + authz-test/TestSuite/TC_Wild/99_cleanup | 25 + authz-test/TestSuite/TC_Wild/Description | 16 + authz-test/TestSuite/TEMPLATE_TC/00_ids | 10 + authz-test/TestSuite/TEMPLATE_TC/10_init | 24 + authz-test/TestSuite/TEMPLATE_TC/99_cleanup | 22 + authz-test/TestSuite/TEMPLATE_TC/Description | 10 + authz-test/TestSuite/cmds | 21 + authz-test/TestSuite/copy | 17 + authz-test/TestSuite/csv | 13 + authz-test/TestSuite/expected/MTC_Appr1.expected | 144 + authz-test/TestSuite/expected/MTC_Appr2.expected | 24 + authz-test/TestSuite/expected/TC_Cred1.expected | 269 ++ authz-test/TestSuite/expected/TC_DELG1.expected | 223 ++ authz-test/TestSuite/expected/TC_Link.expected | 253 ++ authz-test/TestSuite/expected/TC_NS1.expected | 327 ++ authz-test/TestSuite/expected/TC_NS2.expected | 389 ++ authz-test/TestSuite/expected/TC_NS3.expected | 192 + .../TestSuite/expected/TC_NSdelete1.expected | 362 ++ authz-test/TestSuite/expected/TC_PW1.expected | 170 + authz-test/TestSuite/expected/TC_Perm1.expected | 963 +++++ authz-test/TestSuite/expected/TC_Perm2.expected | 554 +++ authz-test/TestSuite/expected/TC_Perm3.expected | 136 + authz-test/TestSuite/expected/TC_Realm1.expected | 210 ++ authz-test/TestSuite/expected/TC_Role1.expected | 369 ++ authz-test/TestSuite/expected/TC_Role2.expected | 447 +++ authz-test/TestSuite/expected/TC_UR1.expected | 266 ++ authz-test/TestSuite/expected/TC_User1.expected | 485 +++ authz-test/TestSuite/expected/TC_Wild.expected | 520 +++ authz-test/TestSuite/list | 2 + authz-test/TestSuite/qc | 38 + authz-test/TestSuite/reset | 4 + authz-test/TestSuite/rpt1 | 22 + authz-test/TestSuite/rpt2 | 12 + authz-test/TestSuite/tc | 82 + authz-test/etc/tc.connection | 32 + authz-test/etc/tc.devl | 22 + authz-test/etc/tc.local | 22 + authz-test/pom.xml | 174 + authz-test/src/main/assemble/swm.xml | 35 + authz-test/src/main/config/lrm-authz-service.xml | 82 + authz-test/src/main/config/tc.devl | 16 + authz-test/src/main/scripts/cmds | 20 + authz-test/src/main/scripts/copy | 17 + authz-test/src/main/scripts/csv | 14 + authz-test/src/main/scripts/rpt1 | 23 + authz-test/src/main/scripts/rpt2 | 12 + authz-test/src/main/scripts/tc | 37 + authz-test/src/main/swm/common/deinstall.sh | 40 + authz-test/src/main/swm/common/install.sh | 144 + .../src/main/swm/deinstall/postproc/post_proc | 7 + authz-test/src/main/swm/deinstall/preproc/pre_proc | 3 + authz-test/src/main/swm/descriptor.xml | 50 + .../src/main/swm/fallback/postproc/post_proc | 6 + authz-test/src/main/swm/fallback/preproc/pre_proc | 6 + .../src/main/swm/initinst/postproc/post_proc | 6 + authz-test/src/main/swm/initinst/preproc/pre_proc | 7 + authz-test/src/main/swm/install/postproc/post_proc | 7 + authz-test/src/main/swm/install/preproc/pre_proc | 7 + authz-test/src/main/swm/packageNotes.txt | 33 + .../version=2.0/envContext=DEV/.gitignore | 2 + opt/app/aaf/common/.gitignore | 4 + opt/app/aaf/common/README.txt | 15 + opt/app/aaf/common/com.osaaf.common.props.sample | 78 + opt/app/aaf/common/com.osaaf.props.sample | 9 + opt/app/aaf/data/identities.dat | 7 + opt/app/aaf/data/identities.idx | Bin 0 -> 56 bytes pom.xml | 492 +++ 750 files changed, 81804 insertions(+) create mode 100644 authz-batch/.gitignore create mode 100644 authz-batch/pom.xml create mode 100644 authz-batch/src/main/config/authBatch.props create mode 100644 authz-batch/src/main/config/log4j.properties create mode 100644 authz-batch/src/main/java/com/att/authz/Batch.java create mode 100644 authz-batch/src/main/java/com/att/authz/BatchException.java create mode 100644 authz-batch/src/main/java/com/att/authz/CassBatch.java create mode 100644 authz-batch/src/main/java/com/att/authz/FileCassBatch.java create mode 100644 authz-batch/src/main/java/com/att/authz/JobChange.java create mode 100644 authz-batch/src/main/java/com/att/authz/UserRoleDataGeneration.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/Action.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/ActionDAO.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/ActionPuntDAO.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/CredDelete.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/CredPrint.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/CredPunt.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/Email.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/EmailPrint.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/FADelete.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/FAPrint.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/Key.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/Message.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/URAdd.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/URDelete.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/URFutureApprove.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/URFuturePrint.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/URPrint.java create mode 100644 authz-batch/src/main/java/com/att/authz/actions/URPunt.java create mode 100644 authz-batch/src/main/java/com/att/authz/entryConverters/AafEntryConverter.java create mode 100644 authz-batch/src/main/java/com/att/authz/entryConverters/CredEntryConverter.java create mode 100644 authz-batch/src/main/java/com/att/authz/entryConverters/NsEntryConverter.java create mode 100644 authz-batch/src/main/java/com/att/authz/entryConverters/PermEntryConverter.java create mode 100644 authz-batch/src/main/java/com/att/authz/entryConverters/RoleEntryConverter.java create mode 100644 authz-batch/src/main/java/com/att/authz/entryConverters/UserRoleEntryConverter.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/Approver.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/Creator.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/Cred.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/Future.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/InputIterator.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/MiscID.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/NS.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/Notification.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/NsAttrib.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/Perm.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/Role.java create mode 100644 authz-batch/src/main/java/com/att/authz/helpers/UserRole.java create mode 100644 authz-batch/src/main/java/com/att/authz/reports/ApprNotify.java create mode 100644 authz-batch/src/main/java/com/att/authz/reports/CheckCred.java create mode 100644 authz-batch/src/main/java/com/att/authz/reports/CheckNS.java create mode 100644 authz-batch/src/main/java/com/att/authz/reports/CheckRolePerm.java create mode 100644 authz-batch/src/main/java/com/att/authz/reports/CheckUR.java create mode 100644 authz-batch/src/main/java/com/att/authz/reports/Expiring.java create mode 100644 authz-batch/src/main/java/com/att/authz/reports/NSDump.java create mode 100644 authz-batch/src/main/scripts/SyncV1V2 create mode 100644 authz-batch/src/main/scripts/SyncV1V2daily create mode 100644 authz-batch/src/main/scripts/SyncV2V1 create mode 100644 authz-batch/src/main/scripts/SyncV2V1daily create mode 100644 authz-batch/src/main/scripts/V1daily create mode 100644 authz-batch/src/main/scripts/V2daily create mode 100644 authz-batch/src/main/scripts/aafbch create mode 100644 authz-batch/src/main/scripts/run_batch create mode 100644 authz-cass/.gitignore create mode 100644 authz-cass/pom.xml create mode 100644 authz-cass/src/main/cql/ecomp.cql create mode 100644 authz-cass/src/main/cql/init.cql create mode 100644 authz-cass/src/main/java/com/att/dao/AbsCassDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/Bytification.java create mode 100644 authz-cass/src/main/java/com/att/dao/CIDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/Cacheable.java create mode 100644 authz-cass/src/main/java/com/att/dao/Cached.java create mode 100644 authz-cass/src/main/java/com/att/dao/CachedDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/CassAccess.java create mode 100644 authz-cass/src/main/java/com/att/dao/CassDAOImpl.java create mode 100644 authz-cass/src/main/java/com/att/dao/DAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/DAOException.java create mode 100644 authz-cass/src/main/java/com/att/dao/DAO_RO.java create mode 100644 authz-cass/src/main/java/com/att/dao/Loader.java create mode 100644 authz-cass/src/main/java/com/att/dao/Streamer.java create mode 100644 authz-cass/src/main/java/com/att/dao/Touchable.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cached/CachedCertDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cached/CachedCredDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cached/CachedNSDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cached/CachedPermDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cached/CachedRoleDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cached/CachedUserRoleDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/ApprovalDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/ArtiDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/CacheInfoDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/CacheableData.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/CertDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/CredDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/DelegateDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/FutureDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/HistoryDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/Namespace.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/NsDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/NsSplit.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/NsType.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/PermDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/RoleDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/Status.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/cass/UserRoleDAO.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/hl/CassExecutor.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/hl/Function.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/hl/PermLookup.java create mode 100644 authz-cass/src/main/java/com/att/dao/aaf/hl/Question.java create mode 100644 authz-cass/src/main/java/com/att/dao/session/SessionFilter.java create mode 100644 authz-cass/src/test/java/com/att/authz/cass/hl/JU_Question.java create mode 100644 authz-cass/src/test/java/com/att/dao/JU_Cached.java create mode 100644 authz-cass/src/test/java/com/att/dao/JU_CachedDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/JU_CassAccess.java create mode 100644 authz-cass/src/test/java/com/att/dao/JU_CassDAOImpl.java create mode 100644 authz-cass/src/test/java/com/att/dao/JU_DAOException.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/AbsJUCass.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_ApprovalDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_ArtiDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_Bytification.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_CacheInfoDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_CertDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_CredDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_DelegateDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_FastCalling.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_HistoryDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_NsDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_NsType.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_PermDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/JU_RoleDAO.java create mode 100644 authz-cass/src/test/java/com/att/dao/aaf/test/NS_ChildUpdate.java create mode 100644 authz-cass/src/test/resources/cadi.properties create mode 100644 authz-certman/.gitignore create mode 100644 authz-certman/pom.xml create mode 100644 authz-certman/src/main/config/certman.props create mode 100644 authz-certman/src/main/config/log4j.properties create mode 100644 authz-certman/src/main/config/lrm-authz-certman.xml create mode 100644 authz-certman/src/main/java/com/att/authz/cm/api/API_Artifact.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/api/API_Cert.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/ca/AppCA.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/ca/CA.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/ca/DevlCA.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/cert/BCFactory.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/cert/CSRMeta.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/cert/StandardFields.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/data/CertDrop.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/data/CertRenew.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/data/CertReq.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/data/CertResp.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/facade/Facade.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/facade/Facade1_0.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/facade/FacadeFactory.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/facade/FacadeImpl.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/mapper/Mapper.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/mapper/Mapper1_0.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/service/CMService.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/service/CertManAPI.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/service/Code.java create mode 100644 authz-certman/src/main/java/com/att/authz/cm/validation/Validator.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Artifact.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Cert.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/ca/JU_AppCA.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/ca/JU_DevlCA.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/cert/JU_BCFactory.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/cert/JU_CSRMeta.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/data/JU_CertReq.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/facade/JU_FacadeImpl.java create mode 100644 authz-certman/src/test/java/com/att/authz/cm/validation/JU_Validator.java create mode 100644 authz-client/.gitignore create mode 100644 authz-client/pom.xml create mode 100644 authz-client/src/main/xsd/aaf_2_0.xsd create mode 100644 authz-client/src/main/xsd/certman_1_0.xsd create mode 100644 authz-cmd/.gitignore create mode 100644 authz-cmd/aafcli.sh create mode 100644 authz-cmd/etc/log4j.properties create mode 100644 authz-cmd/pom.xml create mode 100644 authz-cmd/src/main/assemble/authz-cmd.xml create mode 100644 authz-cmd/src/main/assemble/swm.xml create mode 100644 authz-cmd/src/main/config/log4j.properties create mode 100644 authz-cmd/src/main/config/logging.props create mode 100644 authz-cmd/src/main/java/com/att/cmd/AAFcli.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/BaseCmd.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/BasicAuth.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/Cmd.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/Help.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/MessageException.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/Param.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/Version.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/mgmt/Cache.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/mgmt/Clear.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/mgmt/Deny.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/mgmt/Log.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/mgmt/Mgmt.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/mgmt/SessClear.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/mgmt/Session.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/Admin.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/Attrib.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/Create.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/Delete.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/Describe.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/List.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/ListActivity.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/ListAdminResponsible.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/ListByName.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/ListChildren.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/ListNsKeysByAttrib.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/ListUsers.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/ListUsersInRole.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/ListUsersWithPerm.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/NS.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/ns/Responsible.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/Create.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/Delete.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/Describe.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/Grant.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/List.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/ListActivity.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/ListByNS.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/ListByName.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/ListByRole.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/ListByUser.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/Perm.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/perm/Rename.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/CreateDelete.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/Describe.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/List.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/ListActivity.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/ListByNS.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/ListByNameOnly.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/ListByPerm.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/ListByRole.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/ListByUser.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/Role.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/role/User.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/Cred.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/Delg.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/List.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/ListActivity.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/ListApprovals.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/ListDelegates.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/ListForCreds.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/ListForPermission.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/ListForRoles.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/Role.java create mode 100644 authz-cmd/src/main/java/com/att/cmd/user/User.java create mode 100644 authz-cmd/src/main/scripts/aaflogin create mode 100644 authz-cmd/src/test/java/com/att/cmd/JU_AAFCli.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/JU_BaseCmd.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/JU_BasicAuth.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/JU_Help.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/JU_Version.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/mgmt/JU_Clear.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/mgmt/JU_Log.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/mgmt/JU_SessClear.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_Admin.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_Attrib.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_Create.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_Delete.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_Describe.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_ListActivity.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_ListAdminResponsible.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_ListByName.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_ListChildren.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_ListNsKeysByAttrib.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_ListUsersInRole.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_ListUsersWithPerm.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/ns/JU_Responsible.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_Create.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_Delete.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_Describe.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_Grant.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_ListActivity.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByNS.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByName.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByRole.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByUser.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/perm/JU_Rename.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_CreateDelete.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_Describe.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_ListActivity.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_ListByNS.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_ListByNameOnly.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_ListByPerm.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_ListByRole.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_ListByUser.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/role/JU_User.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_Cred.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_Delg.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_ListActivity.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_ListApprovals.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_ListDelegates.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_ListForCreds.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_ListForPermission.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_ListForRoles.java create mode 100644 authz-cmd/src/test/java/com/att/cmd/user/JU_Role.java create mode 100644 authz-core/.gitignore create mode 100644 authz-core/pom.xml create mode 100644 authz-core/src/main/java/com/att/authz/common/Define.java create mode 100644 authz-core/src/main/java/com/att/authz/env/AuthzEnv.java create mode 100644 authz-core/src/main/java/com/att/authz/env/AuthzTrans.java create mode 100644 authz-core/src/main/java/com/att/authz/env/AuthzTransFilter.java create mode 100644 authz-core/src/main/java/com/att/authz/env/AuthzTransImpl.java create mode 100644 authz-core/src/main/java/com/att/authz/env/AuthzTransOnlyFilter.java create mode 100644 authz-core/src/main/java/com/att/authz/env/NullTrans.java create mode 100644 authz-core/src/main/java/com/att/authz/layer/FacadeImpl.java create mode 100644 authz-core/src/main/java/com/att/authz/layer/Result.java create mode 100644 authz-core/src/main/java/com/att/authz/local/AbsData.java create mode 100644 authz-core/src/main/java/com/att/authz/local/DataFile.java create mode 100644 authz-core/src/main/java/com/att/authz/local/TextIndex.java create mode 100644 authz-core/src/main/java/com/att/authz/org/EmailWarnings.java create mode 100644 authz-core/src/main/java/com/att/authz/org/Executor.java create mode 100644 authz-core/src/main/java/com/att/authz/org/Organization.java create mode 100644 authz-core/src/main/java/com/att/authz/org/OrganizationException.java create mode 100644 authz-core/src/main/java/com/att/authz/org/OrganizationFactory.java create mode 100644 authz-core/src/main/java/com/att/authz/server/AbsServer.java create mode 100644 authz-core/src/main/java/com/att/cache/Cache.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/Acceptor.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/CachingFileAccess.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/CodeSetter.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/Content.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/HttpCode.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/HttpMethods.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/Match.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/Pair.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/RServlet.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/Route.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/RouteReport.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/Routes.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/TransFilter.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/TransOnlyFilter.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/TypedCode.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/Version.java create mode 100644 authz-core/src/main/java/com/att/cssa/rserv/doc/ApiDoc.java create mode 100644 authz-core/src/test/java/com/att/authz/common/JU_Define.java create mode 100644 authz-core/src/test/java/com/att/authz/env/JU_AuthzEnv.java create mode 100644 authz-core/src/test/java/com/att/authz/env/JU_AuthzTransFilter.java create mode 100644 authz-core/src/test/java/com/att/authz/env/JU_AuthzTransImpl.java create mode 100644 authz-core/src/test/java/com/att/authz/env/JU_AuthzTransOnlyFilter.java create mode 100644 authz-core/src/test/java/com/att/authz/env/JU_NullTrans.java create mode 100644 authz-core/src/test/java/com/att/authz/layer/JU_Result.java create mode 100644 authz-core/src/test/java/com/att/authz/local/JU_DataFile.java create mode 100644 authz-core/src/test/java/com/att/authz/local/JU_TextIndex.java create mode 100644 authz-core/src/test/java/com/att/authz/org/JU_OrganizationException.java create mode 100644 authz-core/src/test/java/com/att/authz/org/JU_OrganizationFactory.java create mode 100644 authz-core/src/test/java/com/att/cssa/rserv/JU_CachingFileAccess.java create mode 100644 authz-core/src/test/java/com/att/cssa/rserv/JU_CodeSetter.java create mode 100644 authz-core/src/test/java/com/att/cssa/rserv/JU_Pair.java create mode 100644 authz-core/src/test/java/com/att/cssa/rserv/JU_Routes.java create mode 100644 authz-core/src/test/java/com/att/cssa/rserv/JU_TypedCode.java create mode 100644 authz-core/src/test/java/com/att/cssa/rserv/JU_Version.java create mode 100644 authz-core/src/test/java/com/att/cssa/rserv/test/JU_BetterMatch.java create mode 100644 authz-core/src/test/java/com/att/cssa/rserv/test/JU_Content.java create mode 100644 authz-defOrg/.gitignore create mode 100644 authz-defOrg/pom.xml create mode 100644 authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrg.java create mode 100644 authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrgIdentity.java create mode 100644 authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrgWarnings.java create mode 100644 authz-defOrg/src/main/java/com/osaaf/defOrg/Identities.java create mode 100644 authz-defOrg/src/test/java/com/osaaf/defOrd/test/JU_Identities.java create mode 100644 authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrg.java create mode 100644 authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrgIdentity.java create mode 100644 authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrgWarnings.java create mode 100644 authz-defOrg/src/test/java/com/osaaf/defOrg/JU_Identities.java create mode 100644 authz-fs/.gitignore create mode 100644 authz-fs/pom.xml create mode 100644 authz-fs/src/main/config/FileServer.props create mode 100644 authz-fs/src/main/config/log4j.properties create mode 100644 authz-fs/src/main/config/lrm-authz-fs.xml create mode 100644 authz-fs/src/main/data/test.html create mode 100644 authz-fs/src/main/java/com/att/authz/fs/FileServer.java create mode 100644 authz-fs/src/test/java/com/att/authz/fs/JU_FileServer.java create mode 100644 authz-gui/.gitignore create mode 100644 authz-gui/pom.xml create mode 100644 authz-gui/src/main/config/authGUI.props create mode 100644 authz-gui/src/main/config/log4j.properties create mode 100644 authz-gui/src/main/config/lrm-authz-gui.xml create mode 100644 authz-gui/src/main/java/com/att/authz/cui/CUI.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/AuthGUI.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/BreadCrumbs.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/Controls.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/Display.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/Form.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/NamedCode.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/Page.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/Table.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/ApiDocs.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/ApiExample.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/ApprovalAction.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/ApprovalForm.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/Home.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/LoginLanding.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/LoginLandingAction.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/NsDetail.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/NsHistory.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoAction.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoForm.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/NssShow.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/PassChangeAction.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/PassChangeForm.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/PendingRequestsShow.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/PermDetail.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/PermGrantAction.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/PermGrantForm.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/PermHistory.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/PermsShow.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/RequestDetail.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/RoleDetail.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/RoleHistory.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/RolesShow.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleExtend.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleRemove.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/pages/WebCommand.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/table/AbsCell.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/table/ButtonCell.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/table/RadioCell.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/table/RefCell.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/table/TextAndRefCell.java create mode 100644 authz-gui/src/main/java/com/att/authz/gui/table/TextCell.java create mode 100644 authz-gui/theme/AAF_details.png create mode 100644 authz-gui/theme/AAF_font_size.png create mode 100644 authz-gui/theme/AAF_maximize.png create mode 100644 authz-gui/theme/AAFdownload.png create mode 100644 authz-gui/theme/AAFemail.png create mode 100644 authz-gui/theme/aaf5.css create mode 100644 authz-gui/theme/aaf5Desktop.css create mode 100644 authz-gui/theme/aaf5iPhone.css create mode 100644 authz-gui/theme/aafOldIE.css create mode 100644 authz-gui/theme/aaf_1_0.xsd create mode 100644 authz-gui/theme/aaf_2_0.xsd create mode 100644 authz-gui/theme/comm.js create mode 100644 authz-gui/theme/common.js create mode 100644 authz-gui/theme/console.js create mode 100644 authz-gui/theme/favicon.ico create mode 100644 authz-gui/theme/options_down.png create mode 100644 authz-gui/theme/options_up.png create mode 100644 authz-gui/theme/t_bubbles.jpg create mode 100644 authz-gw/.gitignore create mode 100644 authz-gw/pom.xml create mode 100644 authz-gw/src/main/config/authGW.props create mode 100644 authz-gw/src/main/config/log4j.properties create mode 100644 authz-gw/src/main/config/lrm-authz-gw.xml create mode 100644 authz-gw/src/main/java/com/att/authz/gw/GwAPI.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/GwCode.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/api/API_AAFAccess.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/api/API_Api.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/api/API_Find.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/api/API_Proxy.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/api/API_TGuard.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/facade/GwFacade.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/facade/GwFacadeFactory.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/facade/GwFacadeImpl.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/facade/GwFacade_1_0.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/mapper/Mapper.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/mapper/Mapper_1_0.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/service/GwService.java create mode 100644 authz-gw/src/main/java/com/att/authz/gw/service/GwServiceImpl.java create mode 100644 authz-gw/src/main/xsd/gw_1_0.xsd create mode 100644 authz-gw/src/test/java/com/att/authz/gw/JU_GwAPI.java create mode 100644 authz-service/.gitignore create mode 100644 authz-service/pom.xml create mode 100644 authz-service/src/main/assemble/swm.xml create mode 100644 authz-service/src/main/config/authAPI.props create mode 100644 authz-service/src/main/config/log4j.properties create mode 100644 authz-service/src/main/config/lrm-authz-service.xml create mode 100644 authz-service/src/main/java/com/att/authz/cadi/DirectAAFLur.java create mode 100644 authz-service/src/main/java/com/att/authz/cadi/DirectAAFUserPass.java create mode 100644 authz-service/src/main/java/com/att/authz/cadi/DirectCertIdentity.java create mode 100644 authz-service/src/main/java/com/att/authz/facade/AuthzFacade.java create mode 100644 authz-service/src/main/java/com/att/authz/facade/AuthzFacadeFactory.java create mode 100644 authz-service/src/main/java/com/att/authz/facade/AuthzFacadeImpl.java create mode 100644 authz-service/src/main/java/com/att/authz/facade/AuthzFacade_2_0.java create mode 100644 authz-service/src/main/java/com/att/authz/service/AuthAPI.java create mode 100644 authz-service/src/main/java/com/att/authz/service/AuthzCassServiceImpl.java create mode 100644 authz-service/src/main/java/com/att/authz/service/AuthzService.java create mode 100644 authz-service/src/main/java/com/att/authz/service/Code.java create mode 100644 authz-service/src/main/java/com/att/authz/service/MayChange.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_Api.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_Approval.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_Creds.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_Delegate.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_History.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_Mgmt.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_NS.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_Perms.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_Roles.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_User.java create mode 100644 authz-service/src/main/java/com/att/authz/service/api/API_UserRole.java create mode 100644 authz-service/src/main/java/com/att/authz/service/mapper/Mapper.java create mode 100644 authz-service/src/main/java/com/att/authz/service/mapper/Mapper_2_0.java create mode 100644 authz-service/src/main/java/com/att/authz/service/validation/Validator.java create mode 100644 authz-service/src/main/resources/authAPI.props create mode 100644 authz-service/src/main/resources/docker-compose/aafcli.sh create mode 100644 authz-service/src/main/resources/docker-compose/data/ecomp.cql create mode 100644 authz-service/src/main/resources/docker-compose/data/identities.dat create mode 100644 authz-service/src/main/resources/docker-compose/data/identities.idx create mode 100644 authz-service/src/main/resources/docker-compose/data/init.cql create mode 100644 authz-service/src/main/resources/docker-compose/data2/identities.dat create mode 100644 authz-service/src/main/resources/docker-compose/docker-compose.yml create mode 100644 authz-service/src/main/resources/docker-compose/old/dme2-3.1.200.jar create mode 100644 authz-service/src/main/resources/docker-compose/runaafcli.sh create mode 100644 authz-service/src/main/resources/docker-compose/startupaaf.sh create mode 100644 authz-service/src/main/resources/docker-compose/sysctl.conf create mode 100644 authz-service/src/main/resources/docker-compose/wait_for_host_port.sh create mode 100644 authz-service/src/main/sample/authAPI.props create mode 100644 authz-service/src/main/sample/log4j.properties create mode 100644 authz-service/src/main/swm/common/deinstall.sh create mode 100644 authz-service/src/main/swm/common/install.sh create mode 100644 authz-service/src/main/swm/deinstall/postproc/post_proc create mode 100644 authz-service/src/main/swm/deinstall/preproc/pre_proc create mode 100644 authz-service/src/main/swm/descriptor.xml create mode 100644 authz-service/src/main/swm/fallback/postproc/post_proc create mode 100644 authz-service/src/main/swm/fallback/preproc/pre_proc create mode 100644 authz-service/src/main/swm/initinst/postproc/post_proc create mode 100644 authz-service/src/main/swm/initinst/preproc/pre_proc create mode 100644 authz-service/src/main/swm/install/postproc/post_proc create mode 100644 authz-service/src/main/swm/install/preproc/pre_proc create mode 100644 authz-service/src/main/swm/packageNotes.txt create mode 100644 authz-service/src/test/java/com/att/authz/cadi/JU_DirectAAFLur.java create mode 100644 authz-service/src/test/java/com/att/authz/cadi/JU_DirectAAFUserPass.java create mode 100644 authz-service/src/test/java/com/att/authz/cadi/JU_DirectCertIdentity.java create mode 100644 authz-service/src/test/java/com/att/authz/service/JU_AuthAPI.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_Api.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_Approval.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_Creds.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_Delegate.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_History.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_Mgmt.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_NS.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_Perms.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_Roles.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_User.java create mode 100644 authz-service/src/test/java/com/att/authz/service/api/JU_API_UserRole.java create mode 100644 authz-service/src/test/java/com/att/authz/service/mapper/JU_Mapper_2_0.java create mode 100644 authz-service/src/test/java/com/att/authz/service/test/JU_Validator.java create mode 100644 authz-service/src/test/java/com/att/authz/service/validation/JU_Validator.java create mode 100644 authz-service/start.sh create mode 100644 authz-test/.gitignore create mode 100644 authz-test/TestSuite/Instructions_for_MTCs/MTC_Appr_README.txt create mode 100644 authz-test/TestSuite/JU_Lur2_0/10_init create mode 100644 authz-test/TestSuite/JU_Lur2_0/Description create mode 100644 authz-test/TestSuite/MTC_Appr1/00_ids create mode 100644 authz-test/TestSuite/MTC_Appr1/10_init create mode 100644 authz-test/TestSuite/MTC_Appr1/15_create create mode 100644 authz-test/TestSuite/MTC_Appr1/Description create mode 100644 authz-test/TestSuite/MTC_Appr2/00_ids create mode 100644 authz-test/TestSuite/MTC_Appr2/99_cleanup create mode 100644 authz-test/TestSuite/MTC_Appr2/Description create mode 100644 authz-test/TestSuite/TC_Cred1/00_ids create mode 100644 authz-test/TestSuite/TC_Cred1/10_init create mode 100644 authz-test/TestSuite/TC_Cred1/15_create create mode 100644 authz-test/TestSuite/TC_Cred1/30_multiple_creds create mode 100644 authz-test/TestSuite/TC_Cred1/99_cleanup create mode 100644 authz-test/TestSuite/TC_Cred1/Description create mode 100644 authz-test/TestSuite/TC_DELG1/00_ids create mode 100644 authz-test/TestSuite/TC_DELG1/10_init create mode 100644 authz-test/TestSuite/TC_DELG1/20_create create mode 100644 authz-test/TestSuite/TC_DELG1/99_cleanup create mode 100644 authz-test/TestSuite/TC_DELG1/Description create mode 100644 authz-test/TestSuite/TC_Link/00_ids create mode 100644 authz-test/TestSuite/TC_Link/05_print create mode 100644 authz-test/TestSuite/TC_Link/10_init create mode 100644 authz-test/TestSuite/TC_Link/15_print create mode 100644 authz-test/TestSuite/TC_Link/20_del create mode 100644 authz-test/TestSuite/TC_Link/25_print create mode 100644 authz-test/TestSuite/TC_Link/30_readd create mode 100644 authz-test/TestSuite/TC_Link/35_print create mode 100644 authz-test/TestSuite/TC_Link/99_delete create mode 100644 authz-test/TestSuite/TC_Link/Description create mode 100644 authz-test/TestSuite/TC_NS1/00_ids create mode 100644 authz-test/TestSuite/TC_NS1/01_ERR_BadData create mode 100644 authz-test/TestSuite/TC_NS1/10_init create mode 100644 authz-test/TestSuite/TC_NS1/11_ERR_Namespace_Exists create mode 100644 authz-test/TestSuite/TC_NS1/20_Commands create mode 100644 authz-test/TestSuite/TC_NS1/30_add_data create mode 100644 authz-test/TestSuite/TC_NS1/50_Admin create mode 100644 authz-test/TestSuite/TC_NS1/60_Responsible create mode 100644 authz-test/TestSuite/TC_NS1/80_CheckData create mode 100644 authz-test/TestSuite/TC_NS1/90_ERR_Delete create mode 100644 authz-test/TestSuite/TC_NS1/99_cleanup create mode 100644 authz-test/TestSuite/TC_NS1/Description create mode 100644 authz-test/TestSuite/TC_NS2/00_ids create mode 100644 authz-test/TestSuite/TC_NS2/10_init create mode 100644 authz-test/TestSuite/TC_NS2/20_add_data create mode 100644 authz-test/TestSuite/TC_NS2/40_viewByName create mode 100644 authz-test/TestSuite/TC_NS2/41_viewByAdmin create mode 100644 authz-test/TestSuite/TC_NS2/99_cleanup create mode 100644 authz-test/TestSuite/TC_NS2/Description create mode 100644 authz-test/TestSuite/TC_NS3/00_ids create mode 100644 authz-test/TestSuite/TC_NS3/10_init create mode 100644 authz-test/TestSuite/TC_NS3/20_add create mode 100644 authz-test/TestSuite/TC_NS3/50_delete create mode 100644 authz-test/TestSuite/TC_NS3/99_cleanup create mode 100644 authz-test/TestSuite/TC_NS3/Description create mode 100644 authz-test/TestSuite/TC_NSdelete1/00_ids create mode 100644 authz-test/TestSuite/TC_NSdelete1/10_init create mode 100644 authz-test/TestSuite/TC_NSdelete1/20_DeleteApp create mode 100644 authz-test/TestSuite/TC_NSdelete1/30_DeleteCompany create mode 100644 authz-test/TestSuite/TC_NSdelete1/40_ForceDelete create mode 100644 authz-test/TestSuite/TC_NSdelete1/99_cleanup create mode 100644 authz-test/TestSuite/TC_NSdelete1/Description create mode 100644 authz-test/TestSuite/TC_PW1/00_ids create mode 100644 authz-test/TestSuite/TC_PW1/10_init create mode 100644 authz-test/TestSuite/TC_PW1/20_length create mode 100644 authz-test/TestSuite/TC_PW1/21_groups create mode 100644 authz-test/TestSuite/TC_PW1/23_commands create mode 100644 authz-test/TestSuite/TC_PW1/30_reset create mode 100644 authz-test/TestSuite/TC_PW1/99_cleanup create mode 100644 authz-test/TestSuite/TC_PW1/Description create mode 100644 authz-test/TestSuite/TC_Perm1/00_ids create mode 100644 authz-test/TestSuite/TC_Perm1/10_init create mode 100644 authz-test/TestSuite/TC_Perm1/20_add_data create mode 100644 authz-test/TestSuite/TC_Perm1/22_rename create mode 100644 authz-test/TestSuite/TC_Perm1/25_grant_owned create mode 100644 authz-test/TestSuite/TC_Perm1/26_grant_unowned create mode 100644 authz-test/TestSuite/TC_Perm1/27_grant_force create mode 100644 authz-test/TestSuite/TC_Perm1/30_change_ns create mode 100644 authz-test/TestSuite/TC_Perm1/99_cleanup create mode 100644 authz-test/TestSuite/TC_Perm1/Description create mode 100644 authz-test/TestSuite/TC_Perm2/00_ids create mode 100644 authz-test/TestSuite/TC_Perm2/10_init create mode 100644 authz-test/TestSuite/TC_Perm2/20_add_data create mode 100644 authz-test/TestSuite/TC_Perm2/30_change_ns create mode 100644 authz-test/TestSuite/TC_Perm2/40_viewByType create mode 100644 authz-test/TestSuite/TC_Perm2/41_viewByUser create mode 100644 authz-test/TestSuite/TC_Perm2/42_viewByNS create mode 100644 authz-test/TestSuite/TC_Perm2/43_viewByRole create mode 100644 authz-test/TestSuite/TC_Perm2/99_cleanup create mode 100644 authz-test/TestSuite/TC_Perm2/Description create mode 100644 authz-test/TestSuite/TC_Perm3/00_ids create mode 100644 authz-test/TestSuite/TC_Perm3/10_init create mode 100644 authz-test/TestSuite/TC_Perm3/20_innerGrants create mode 100644 authz-test/TestSuite/TC_Perm3/30_outerGrants create mode 100644 authz-test/TestSuite/TC_Perm3/99_cleanup create mode 100644 authz-test/TestSuite/TC_Perm3/Description create mode 100644 authz-test/TestSuite/TC_Realm1/00_ids create mode 100644 authz-test/TestSuite/TC_Realm1/10_init create mode 100644 authz-test/TestSuite/TC_Realm1/20_ns create mode 100644 authz-test/TestSuite/TC_Realm1/30_role create mode 100644 authz-test/TestSuite/TC_Realm1/40_user create mode 100644 authz-test/TestSuite/TC_Realm1/99_cleanup create mode 100644 authz-test/TestSuite/TC_Realm1/Description create mode 100644 authz-test/TestSuite/TC_Role1/00_ids create mode 100644 authz-test/TestSuite/TC_Role1/10_init create mode 100644 authz-test/TestSuite/TC_Role1/20_add_data create mode 100644 authz-test/TestSuite/TC_Role1/30_change_ns create mode 100644 authz-test/TestSuite/TC_Role1/40_reports create mode 100644 authz-test/TestSuite/TC_Role1/50_force_delete create mode 100644 authz-test/TestSuite/TC_Role1/90_wait create mode 100644 authz-test/TestSuite/TC_Role1/99_cleanup create mode 100644 authz-test/TestSuite/TC_Role1/Description create mode 100644 authz-test/TestSuite/TC_Role2/00_ids create mode 100644 authz-test/TestSuite/TC_Role2/10_init create mode 100644 authz-test/TestSuite/TC_Role2/20_add_data create mode 100644 authz-test/TestSuite/TC_Role2/40_viewByName create mode 100644 authz-test/TestSuite/TC_Role2/41_viewByUser create mode 100644 authz-test/TestSuite/TC_Role2/42_viewByNS create mode 100644 authz-test/TestSuite/TC_Role2/43_viewByPerm create mode 100644 authz-test/TestSuite/TC_Role2/99_cleanup create mode 100644 authz-test/TestSuite/TC_Role2/Description create mode 100644 authz-test/TestSuite/TC_UR1/00_ids create mode 100644 authz-test/TestSuite/TC_UR1/10_init create mode 100644 authz-test/TestSuite/TC_UR1/23_commands create mode 100644 authz-test/TestSuite/TC_UR1/30_userrole create mode 100644 authz-test/TestSuite/TC_UR1/40_reset create mode 100644 authz-test/TestSuite/TC_UR1/90_wait create mode 100644 authz-test/TestSuite/TC_UR1/99_cleanup create mode 100644 authz-test/TestSuite/TC_UR1/Description create mode 100644 authz-test/TestSuite/TC_User1/00_ids create mode 100644 authz-test/TestSuite/TC_User1/10_init create mode 100644 authz-test/TestSuite/TC_User1/20_add_data create mode 100644 authz-test/TestSuite/TC_User1/40_viewByRole create mode 100644 authz-test/TestSuite/TC_User1/41_viewByPerm create mode 100644 authz-test/TestSuite/TC_User1/42_viewByDelegates create mode 100644 authz-test/TestSuite/TC_User1/43_viewsExplicitiPerm create mode 100644 authz-test/TestSuite/TC_User1/99_cleanup create mode 100644 authz-test/TestSuite/TC_User1/Description create mode 100644 authz-test/TestSuite/TC_Wild/00_ids create mode 100644 authz-test/TestSuite/TC_Wild/10_init create mode 100644 authz-test/TestSuite/TC_Wild/20_perm create mode 100644 authz-test/TestSuite/TC_Wild/21_perm create mode 100644 authz-test/TestSuite/TC_Wild/30_role create mode 100644 authz-test/TestSuite/TC_Wild/31_role create mode 100644 authz-test/TestSuite/TC_Wild/32_role create mode 100644 authz-test/TestSuite/TC_Wild/50_global_perm create mode 100644 authz-test/TestSuite/TC_Wild/51_global_role create mode 100644 authz-test/TestSuite/TC_Wild/52_global_ns create mode 100644 authz-test/TestSuite/TC_Wild/99_cleanup create mode 100644 authz-test/TestSuite/TC_Wild/Description create mode 100644 authz-test/TestSuite/TEMPLATE_TC/00_ids create mode 100644 authz-test/TestSuite/TEMPLATE_TC/10_init create mode 100644 authz-test/TestSuite/TEMPLATE_TC/99_cleanup create mode 100644 authz-test/TestSuite/TEMPLATE_TC/Description create mode 100644 authz-test/TestSuite/cmds create mode 100644 authz-test/TestSuite/copy create mode 100644 authz-test/TestSuite/csv create mode 100644 authz-test/TestSuite/expected/MTC_Appr1.expected create mode 100644 authz-test/TestSuite/expected/MTC_Appr2.expected create mode 100644 authz-test/TestSuite/expected/TC_Cred1.expected create mode 100644 authz-test/TestSuite/expected/TC_DELG1.expected create mode 100644 authz-test/TestSuite/expected/TC_Link.expected create mode 100644 authz-test/TestSuite/expected/TC_NS1.expected create mode 100644 authz-test/TestSuite/expected/TC_NS2.expected create mode 100644 authz-test/TestSuite/expected/TC_NS3.expected create mode 100644 authz-test/TestSuite/expected/TC_NSdelete1.expected create mode 100644 authz-test/TestSuite/expected/TC_PW1.expected create mode 100644 authz-test/TestSuite/expected/TC_Perm1.expected create mode 100644 authz-test/TestSuite/expected/TC_Perm2.expected create mode 100644 authz-test/TestSuite/expected/TC_Perm3.expected create mode 100644 authz-test/TestSuite/expected/TC_Realm1.expected create mode 100644 authz-test/TestSuite/expected/TC_Role1.expected create mode 100644 authz-test/TestSuite/expected/TC_Role2.expected create mode 100644 authz-test/TestSuite/expected/TC_UR1.expected create mode 100644 authz-test/TestSuite/expected/TC_User1.expected create mode 100644 authz-test/TestSuite/expected/TC_Wild.expected create mode 100644 authz-test/TestSuite/list create mode 100644 authz-test/TestSuite/qc create mode 100644 authz-test/TestSuite/reset create mode 100644 authz-test/TestSuite/rpt1 create mode 100644 authz-test/TestSuite/rpt2 create mode 100644 authz-test/TestSuite/tc create mode 100644 authz-test/etc/tc.connection create mode 100644 authz-test/etc/tc.devl create mode 100644 authz-test/etc/tc.local create mode 100644 authz-test/pom.xml create mode 100644 authz-test/src/main/assemble/swm.xml create mode 100644 authz-test/src/main/config/lrm-authz-service.xml create mode 100644 authz-test/src/main/config/tc.devl create mode 100644 authz-test/src/main/scripts/cmds create mode 100644 authz-test/src/main/scripts/copy create mode 100644 authz-test/src/main/scripts/csv create mode 100644 authz-test/src/main/scripts/rpt1 create mode 100644 authz-test/src/main/scripts/rpt2 create mode 100644 authz-test/src/main/scripts/tc create mode 100644 authz-test/src/main/swm/common/deinstall.sh create mode 100644 authz-test/src/main/swm/common/install.sh create mode 100644 authz-test/src/main/swm/deinstall/postproc/post_proc create mode 100644 authz-test/src/main/swm/deinstall/preproc/pre_proc create mode 100644 authz-test/src/main/swm/descriptor.xml create mode 100644 authz-test/src/main/swm/fallback/postproc/post_proc create mode 100644 authz-test/src/main/swm/fallback/preproc/pre_proc create mode 100644 authz-test/src/main/swm/initinst/postproc/post_proc create mode 100644 authz-test/src/main/swm/initinst/preproc/pre_proc create mode 100644 authz-test/src/main/swm/install/postproc/post_proc create mode 100644 authz-test/src/main/swm/install/preproc/pre_proc create mode 100644 authz-test/src/main/swm/packageNotes.txt create mode 100644 dme2reg/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/.gitignore create mode 100644 opt/app/aaf/common/.gitignore create mode 100644 opt/app/aaf/common/README.txt create mode 100644 opt/app/aaf/common/com.osaaf.common.props.sample create mode 100644 opt/app/aaf/common/com.osaaf.props.sample create mode 100644 opt/app/aaf/data/identities.dat create mode 100644 opt/app/aaf/data/identities.idx create mode 100644 pom.xml diff --git a/authz-batch/.gitignore b/authz-batch/.gitignore new file mode 100644 index 00000000..cabe13d8 --- /dev/null +++ b/authz-batch/.gitignore @@ -0,0 +1,4 @@ +.metadata +.settings +.classpath +.project diff --git a/authz-batch/pom.xml b/authz-batch/pom.xml new file mode 100644 index 00000000..8c1347eb --- /dev/null +++ b/authz-batch/pom.xml @@ -0,0 +1,256 @@ + + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-batch + Authz Batch + Batch Processing for Authz + jar + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + false + 1 + + + + + + com.att.inno + env + + + + com.att.inno + rosetta + + + + com.att.cadi + cadi-core + + + + com.att.cadi + cadi-aaf + + + + + + + + com.att.authz + authz-cass + + + javax.servlet + servlet-api + + + com.att.cadi + cadi-aaf + + + com.att.cadi + cadi-core + + + com.att.cadi + cadi-client + + + + + + + org.joda + joda-time + 2.5 + + + + org.slf4j + slf4j-log4j12 + + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + maven-assembly-plugin + 2.4 + + + tests + + + true + + + + + + depends + package + + single + + + + jar-with-dependencies + + + + com.att.authz.Batch + + + + + + swm + package + + single + + + authz-batch-${project.version}.${project.swmVersion} + + ../authz-service/src/main/assemble/swm.xml + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + diff --git a/authz-batch/src/main/config/authBatch.props b/authz-batch/src/main/config/authBatch.props new file mode 100644 index 00000000..cfe75e32 --- /dev/null +++ b/authz-batch/src/main/config/authBatch.props @@ -0,0 +1,36 @@ +## +## AUTHZ Batch (authz-batch) Properties +## +## DISCOVERY (DME2) Parameters on the Command Line +AFT_LATITUDE=_AFT_LATITUDE_ +AFT_LONGITUDE=_AFT_LONGITUDE_ +AFT_ENVIRONMENT=_AFT_ENVIRONMENT_ +DEPLOYED_VERSION=_ARTIFACT_VERSION_ + + +DRY_RUN=false + +## Pull in common/security properties + +cadi_prop_files=_COMMON_DIR_/com.att.aaf.props;_COMMON_DIR_/com.att.aaf.common.props + + +## ------------------------------------- +## Batch specific Settings +## ------------------------------------- +SPECIAL_NAMES=testunused,testid,unknown + + +## ---------------------------------------------- +## Email Server settings +## ---------------------------------------------- +#Sender's email ID needs to be mentioned +mailFromUserId=DL-aaf-support@att.com +mailHost=smtp.it.att.com + +ALERT_TO_ADDRESS=DL-aaf-support@att.com + +PASSWORD_RESET_URL=_AUTHZ_GUI_URL_/gui/passwd +APPROVALS_URL=_AUTHZ_GUI_URL_/gui/approve + + diff --git a/authz-batch/src/main/config/log4j.properties b/authz-batch/src/main/config/log4j.properties new file mode 100644 index 00000000..169460c4 --- /dev/null +++ b/authz-batch/src/main/config/log4j.properties @@ -0,0 +1,84 @@ +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +log4j.rootLogger=INFO,FA +log4j.logger.aspr=INFO,aspr +log4j.additivity.aspr=false +log4j.logger.authz-batch=INFO,authz-batch +log4j.logger.sync=INFO,sync +log4j.additivity.sync=false +log4j.logger.jobchange=INFO,jobchange +log4j.additivity.jobchange=false +log4j.logger.validateuser=INFO,validateuser +log4j.additivity.validateuser=false + + +log4j.appender.FA=org.apache.log4j.RollingFileAppender +log4j.appender.FA.File=${LOG4J_FILENAME_authz-batch} +log4j.appender.FA.MaxFileSize=10000KB +log4j.appender.FA.MaxBackupIndex=7 +log4j.appender.FA.layout=org.apache.log4j.PatternLayout +log4j.appender.FA.layout.ConversionPattern=%d %p [%c] - %m %n + +log4j.appender.stderr=org.apache.log4j.ConsoleAppender +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.layout.ConversionPattern=%d %p [%c] - %m %n +log4j.appender.stderr.Target=System.err + +log4j.appender.authz-batch=org.apache.log4j.DailyRollingFileAppender +log4j.appender.authz-batch.encoding=UTF-8 +log4j.appender.authz-batch.layout=org.apache.log4j.PatternLayout +log4j.appender.authz-batch.layout.ConversionPattern=%d [%p] %m %n +log4j.appender.authz-batch.File=${LOG4J_FILENAME_authz-batch} +log4j.appender.authz-batch.DatePattern='.'yyyy-MM + +log4j.appender.aspr=org.apache.log4j.DailyRollingFileAppender +log4j.appender.aspr.encoding=UTF-8 +log4j.appender.aspr.layout=org.apache.log4j.PatternLayout +log4j.appender.aspr.layout.ConversionPattern=%d [%p] %m %n +log4j.appender.aspr.File=${LOG4J_FILENAME_aspr} +log4j.appender.aspr.DatePattern='.'yyyy-MM + + +log4j.appender.jobchange=org.apache.log4j.RollingFileAppender +log4j.appender.jobchange.File=${LOG4J_FILENAME_jobchange} +log4j.appender.jobchange.MaxFileSize=10000KB +log4j.appender.jobchange.MaxBackupIndex=7 +log4j.appender.jobchange.layout=org.apache.log4j.PatternLayout +log4j.appender.jobchange.layout.ConversionPattern=%d %p [%c] - %m %n + +log4j.appender.validateuser=org.apache.log4j.RollingFileAppender +log4j.appender.validateuser.File=${LOG4J_FILENAME_validateuser} +log4j.appender.validateuser.MaxFileSize=10000KB +log4j.appender.validateuser.MaxBackupIndex=7 +log4j.appender.validateuser.layout=org.apache.log4j.PatternLayout +log4j.appender.validateuser.layout.ConversionPattern=%d %p [%c] - %m %n + +log4j.appender.sync=org.apache.log4j.DailyRollingFileAppender +log4j.appender.sync.encoding=UTF-8 +log4j.appender.sync.layout=org.apache.log4j.PatternLayout +log4j.appender.sync.layout.ConversionPattern=%d [%p] %m %n +log4j.appender.sync.File=${LOG4J_FILENAME_sync} +log4j.appender.sync.DatePattern='.'yyyy-MM + +# General Apache libraries +log4j.logger.org.apache=WARN + diff --git a/authz-batch/src/main/java/com/att/authz/Batch.java b/authz-batch/src/main/java/com/att/authz/Batch.java new file mode 100644 index 00000000..f812d310 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/Batch.java @@ -0,0 +1,471 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.lang.reflect.Constructor; +import java.net.InetAddress; +import java.net.URL; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; +import java.util.TimeZone; + +import org.apache.log4j.Logger; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.org.Organization; +import com.att.authz.org.OrganizationException; +import com.att.authz.org.OrganizationFactory; +import com.att.dao.CassAccess; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.StaticSlot; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.impl.Log4JLogTarget; +import com.att.inno.env.log4j.LogFileNamer; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.Statement; + +public abstract class Batch { + private static StaticSlot ssargs; + + protected static final String STARS = "*****"; + + protected final Cluster cluster; + protected static AuthzEnv env; + protected static Session session; + protected static Logger aspr; + private static Set specialNames = null; + protected static boolean dryRun; + protected static String batchEnv; + + public static final String CASS_ENV = "CASS_ENV"; + protected final static String PUNT="punt"; + protected final static String VERSION="VERSION"; + public final static String GUI_URL="GUI_URL"; + + protected final static String ORA_URL="ora_url"; + protected final static String ORA_PASSWORD="ora_password"; + + + + protected Batch(AuthzEnv env) throws APIException, IOException { + // TODO - Property Driven Organization +// try { +// // att = new ATT(env); +// } catch (OrganizationException e) { +// throw new APIException(e); +// } + + // Be able to change Environments + // load extra properties, i.e. + // PERF.cassandra.clusters=.... + batchEnv = env.getProperty(CASS_ENV); + if(batchEnv != null) { + batchEnv = batchEnv.trim(); + env.info().log("Redirecting to ",batchEnv,"environment"); + String str; + for(String key : new String[]{ + CassAccess.CASSANDRA_CLUSTERS, + CassAccess.CASSANDRA_CLUSTERS_PORT, + CassAccess.CASSANDRA_CLUSTERS_USER_NAME, + CassAccess.CASSANDRA_CLUSTERS_PASSWORD, + VERSION,GUI_URL,PUNT, + // TEMP + ORA_URL, ORA_PASSWORD + }) { + if((str = env.getProperty(batchEnv+'.'+key))!=null) { + env.setProperty(key, str); + } + } + } + + // Setup for Dry Run + cluster = CassAccess.cluster(env,batchEnv); + env.info().log("cluster name - ",cluster.getClusterName()); + String dryRunStr = env.getProperty( "DRY_RUN" ); + if ( dryRunStr == null || dryRunStr.equals("false") ) { + dryRun = false; + } else { + dryRun = true; + env.info().log("dryRun set to TRUE"); + } + + // Special names to allow behaviors beyond normal rules + String names = env.getProperty( "SPECIAL_NAMES" ); + if ( names != null ) + { + env.info().log("Loading SPECIAL_NAMES"); + specialNames = new HashSet(); + for (String s :names.split(",") ) + { + env.info().log("\tspecial: " + s ); + specialNames.add( s.trim() ); + } + } + } + + protected abstract void run(AuthzTrans trans); + protected abstract void _close(AuthzTrans trans); + + public String[] args() { + return (String[])env.get(ssargs); + } + + public boolean isDryRun() + { + return( dryRun ); + } + + public boolean isSpecial(String user) { + if (specialNames != null && specialNames.contains(user)) { + env.info().log("specialName: " + user); + + return (true); + } else { + return (false); + } + } + + public boolean isMechID(String user) { + if (user.matches("m[0-9][0-9][0-9][0-9][0-9]")) { + return (true); + } else { + return (false); + } + } + + protected PrintStream fallout(PrintStream _fallout, String logType) + throws IOException { + PrintStream fallout = _fallout; + if (fallout == null) { + File dir = new File("logs"); + if (!dir.exists()) { + dir.mkdirs(); + } + + File f = null; + // String os = System.getProperty("os.name").toLowerCase(); + long uniq = System.currentTimeMillis(); + + f = new File(dir, getClass().getSimpleName() + "_" + logType + "_" + + uniq + ".log"); + + fallout = new PrintStream(new FileOutputStream(f, true)); + } + return fallout; + } + + public Organization getOrgFromID(AuthzTrans trans, String user) { + Organization org; + try { + org = OrganizationFactory.obtain(trans.env(),user.toLowerCase()); + } catch (OrganizationException e1) { + trans.error().log(e1); + org=null; + } + + if (org == null) { + PrintStream fallout = null; + + try { + fallout = fallout(fallout, "Fallout"); + fallout.print("INVALID_ID,"); + fallout.println(user); + } catch (Exception e) { + env.error().log("Could not write to Fallout File", e); + } + return (null); + } + + return (org); + } + + public static Row executeDeleteQuery(Statement stmt) { + Row row = null; + if (!dryRun) { + row = session.execute(stmt).one(); + } + + return (row); + + } + + public static int acquireRunLock(String className) { + Boolean testEnv = true; + String envStr = env.getProperty("AFT_ENVIRONMENT"); + + if (envStr != null) { + if (envStr.equals("AFTPRD")) { + testEnv = false; + } + } else { + env.fatal() + .log("AFT_ENVIRONMENT property is required and was not found. Exiting."); + System.exit(1); + } + + if (testEnv) { + env.info().log("TESTMODE: skipping RunLock"); + return (1); + } + + String hostname = null; + try { + hostname = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + e.printStackTrace(); + env.warn().log("Unable to get hostname"); + return (0); + } + + ResultSet existing = session.execute(String.format( + "select * from authz.run_lock where class = '%s'", className)); + + for (Row row : existing) { + long curr = System.currentTimeMillis(); + ByteBuffer lastRun = row.getBytesUnsafe(2); // Can I get this field + // by name? + + long interval = (1 * 60 * 1000); // @@ Create a value in props file + // for this + long prev = lastRun.getLong(); + + if ((curr - prev) <= interval) { + env.warn().log( + String.format("Too soon! Last run was %d minutes ago.", + ((curr - prev) / 1000) / 60)); + env.warn().log( + String.format("Min time between runs is %d minutes ", + (interval / 1000) / 60)); + env.warn().log( + String.format("Last ran on machine: %s at %s", + row.getString("host"), row.getDate("start"))); + return (0); + } else { + env.info().log("Delete old lock"); + deleteLock(className); + } + } + + GregorianCalendar current = new GregorianCalendar(); + + // We want our time in UTC, hence "+0000" + SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+0000"); + fmt.setTimeZone(TimeZone.getTimeZone("UTC")); + + String cql = String + .format("INSERT INTO authz.run_lock (class,host,start) VALUES ('%s','%s','%s') IF NOT EXISTS", + className, hostname, fmt.format(current.getTime())); + + env.info().log(cql); + + Row row = session.execute(cql).one(); + if (!row.getBool("[applied]")) { + env.warn().log("Lightweight Transaction failed to write lock."); + env.warn().log( + String.format("host with lock: %s, running at %s", + row.getString("host"), row.getDate("start"))); + return (0); + } + return (1); + } + + private static void deleteLock( String className) { + Row row = session.execute( String.format( "DELETE FROM authz.run_lock WHERE class = '%s' IF EXISTS", className ) ).one(); + if (! row.getBool("[applied]")) { + env.info().log( "delete failed" ); + } + } + + private static void transferVMProps(AuthzEnv env, String ... props) { + String value; + for(String key : props) { + if((value = System.getProperty(key))!=null) { + env.setProperty(key, value); + } + } + + } + + protected int count(String str, char c) { + int count=str==null||str.isEmpty()?0:1; + for(int i=str.indexOf(c);i>=0;i=str.indexOf(c,i+1)) { + ++count; + } + return count; + } + + public final void close(AuthzTrans trans) { + _close(trans); + cluster.close(); + } + + public static void main(String[] args) { + Properties props = new Properties(); + InputStream is=null; + String filename; + String propLoc; + try { + File f = new File("etc/authBatch.props"); + try { + if(f.exists()) { + filename = f.getCanonicalPath(); + is = new FileInputStream(f); + propLoc=f.getPath(); + } else { + URL rsrc = ClassLoader.getSystemResource("authBatch.props"); + filename = rsrc.toString(); + is = rsrc.openStream(); + propLoc=rsrc.getPath(); + } + props.load(is); + } finally { + if(is==null) { + System.err.println("authBatch.props must exist in etc dir, or in Classpath"); + System.exit(1); + } + is.close(); + } + + env = new AuthzEnv(props); + + transferVMProps(env,CASS_ENV,"DRY_RUN","NS","Organization"); + + // Flow all Env Logs to Log4j, with ENV + + LogFileNamer lfn; + if((batchEnv=env.getProperty(CASS_ENV))==null) { + lfn = new LogFileNamer("logs/").noPID(); + } else { + lfn = new LogFileNamer("logs/" + batchEnv+'/').noPID(); + } + + lfn.setAppender("authz-batch"); + lfn.setAppender("aspr|ASPR"); + lfn.setAppender("sync"); + lfn.setAppender("jobchange"); + lfn.setAppender("validateuser"); + aspr = Logger.getLogger("aspr"); + Log4JLogTarget.setLog4JEnv("authz-batch", env); + if(filename!=null) { + env.init().log("Instantiated properties from",filename); + } + + + // Log where Config found + env.info().log("Configuring from",propLoc); + propLoc=null; + + Batch batch = null; + // setup ATTUser and Organization Slots before starting this: + //TODO Property Driven Organization +// env.slot(ATT.ATT_USERSLOT); +// OrganizationFactory.setDefaultOrg(env, ATT.class.getName()); + AuthzTrans trans = env.newTrans(); + + TimeTaken tt = trans.start("Total Run", Env.SUB); + try { + int len = args.length; + if(len>0) { + String toolName = args[0]; + len-=1; + if(len<0)len=0; + String nargs[] = new String[len]; + if(len>0) { + System.arraycopy(args, 1, nargs, 0, len); + } + + env.put(ssargs=env.staticSlot("ARGS"), nargs); + + /* + * Add New Batch Programs (inherit from Batch) here + */ + + if( JobChange.class.getSimpleName().equals(toolName)) { + aspr.info( "Begin jobchange processing" ); + batch = new JobChange(trans); + } + //// else if( ValidateUsers.class.getSimpleName().equals(toolName)) { + //// aspr.info( "Begin ValidateUsers processing" ); + //// batch = new ValidateUsers(trans); + // } + else if( UserRoleDataGeneration.class.getSimpleName().equals(toolName)) { + // This job duplicates User Role add/delete History items + // so that we can search them by Role. Intended as a one-time + // script! but written as batch job because Java has better + // UUID support. Multiple runs will generate multiple copies of + // these history elements! + aspr.info( "Begin User Role Data Generation Processing "); + batch = new UserRoleDataGeneration(trans); + } else { // Might be a Report, Update or Temp Batch + Class cls; + String classifier = ""; + try { + cls = ClassLoader.getSystemClassLoader().loadClass("com.att.authz.update."+toolName); + classifier = "Update:"; + } catch(ClassNotFoundException e) { + try { + cls = ClassLoader.getSystemClassLoader().loadClass("com.att.authz.reports."+toolName); + classifier = "Report:"; + } catch (ClassNotFoundException e2) { + try { + cls = ClassLoader.getSystemClassLoader().loadClass("com.att.authz.temp."+toolName); + classifier = "Temp Utility:"; + } catch (ClassNotFoundException e3) { + cls = null; + } + } + } + if(cls!=null) { + Constructor cnst = cls.getConstructor(new Class[]{AuthzTrans.class}); + batch = (Batch)cnst.newInstance(trans); + env.info().log("Begin",classifier,toolName); + } + } + + if(batch==null) { + trans.error().log("No Batch named",toolName,"found"); + } + /* + * End New Batch Programs (inherit from Batch) here + */ + + } + if(batch!=null) { + batch.run(trans); + } + } finally { + tt.done(); + if(batch!=null) { + batch.close(trans); + } + StringBuilder sb = new StringBuilder("Task Times\n"); + trans.auditTrail(4, sb, AuthzTrans.REMOTE); + trans.info().log(sb); + } + } catch (Exception e) { + e.printStackTrace(System.err); + // Exceptions thrown by DB aren't stopping the whole process. + System.exit(1); + } + } + + +} + diff --git a/authz-batch/src/main/java/com/att/authz/BatchException.java b/authz-batch/src/main/java/com/att/authz/BatchException.java new file mode 100644 index 00000000..72475033 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/BatchException.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz; + +public class BatchException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -3877245367723491192L; + + public BatchException() { + } + + public BatchException(String message) { + super(message); + } + + public BatchException(Throwable cause) { + super(cause); + } + + public BatchException(String message, Throwable cause) { + super(message, cause); + } + + public BatchException(String message, Throwable cause, + boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/CassBatch.java b/authz-batch/src/main/java/com/att/authz/CassBatch.java new file mode 100644 index 00000000..5c247245 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/CassBatch.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.impl.Log4JLogTarget; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.exceptions.InvalidQueryException; + +public abstract class CassBatch extends Batch { + + protected CassBatch(AuthzTrans trans, String log4JName) throws APIException, IOException { + super(trans.env()); + // Flow all Env Logs to Log4j + Log4JLogTarget.setLog4JEnv(log4JName, env); + + TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = cluster.connect(); + } finally { + tt.done(); + } + } + + @Override + protected void _close(AuthzTrans trans) { + session.close(); + trans.info().log("Closed Session"); + } + + public ResultSet executeQuery(String cql) { + return executeQuery(cql,""); + } + + public ResultSet executeQuery(String cql, String extra) { + if(isDryRun() && !cql.startsWith("SELECT")) { + if(extra!=null)env.info().log("Would query" + extra + ": " + cql); + } else { + if(extra!=null)env.info().log("query" + extra + ": " + cql); + try { + return session.execute(cql); + } catch (InvalidQueryException e) { + if(extra==null) { + env.info().log("query: " + cql); + } + throw e; + } + } + return null; + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/FileCassBatch.java b/authz-batch/src/main/java/com/att/authz/FileCassBatch.java new file mode 100644 index 00000000..d037e75f --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/FileCassBatch.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz; + +import java.io.File; +import java.io.IOException; +import java.nio.file.DirectoryIteratorException; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.inno.env.APIException; + +public abstract class FileCassBatch extends CassBatch { + + public FileCassBatch(AuthzTrans trans, String log4jName) throws APIException, IOException { + super(trans, log4jName); + } + + protected List findAllFiles(String regex) { + List files = new ArrayList(); + FileSystem fileSystem = FileSystems.getDefault(); + PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + regex); + Path path = Paths.get(System.getProperty("user.dir"), "data"); + + try { + DirectoryStream directoryStream = Files.newDirectoryStream( + path, regex); + for (Path file : directoryStream) { + if (pathMatcher.matches(file.getFileName())) { + files.add(file.toFile()); + } + } + } catch (IOException ex) { + ex.printStackTrace(); + } catch (DirectoryIteratorException ex) { + ex.printStackTrace(); + } + + return files; + } + + + +} diff --git a/authz-batch/src/main/java/com/att/authz/JobChange.java b/authz-batch/src/main/java/com/att/authz/JobChange.java new file mode 100644 index 00000000..235ebacc --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/JobChange.java @@ -0,0 +1,743 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +// test for case where I'm an admin + +package com.att.authz; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.org.Organization; +import com.att.authz.org.OrganizationFactory; +import com.att.inno.env.APIException; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class JobChange extends Batch +{ + private class UserRole + { + String user; + String role; + } + private class UserCred + { + String user; + String ns; + } + + private class NamespaceOwner + { + String user; + String ns; + boolean responsible; + int ownerCount; + } + + + private AuthzTrans myTrans; + + private Map> rolesMap = new HashMap>(); + private Map> ownersMap = new HashMap>(); + private Map> credsMap = new HashMap>(); + + + public static void createDirectory( String dir ) + { + File f = new File( dir ); + + if ( ! f.exists()) + { + env.info().log( "creating directory: " + dir ); + boolean result = false; + + try + { + f.mkdir(); + result = true; + } catch(SecurityException e){ + e.printStackTrace(); + } + if(result) { + System.out.println("DIR created"); + } + } + } + + public static String getJobChangeDataFile() + { + File outFile = null; + BufferedWriter writer = null; + BufferedReader reader = null; + String line; + boolean errorFlag = false; + + try + { + createDirectory( "etc" ); + + outFile = new File("etc/jobchange." + getCurrentDate() ); + if (!outFile.exists()) + { + outFile.createNewFile(); + } + else + { + return( "etc/jobchange." + getCurrentDate() ); + } + + env.info().log("Creating the local file with the webphone data"); + + + + writer = new BufferedWriter(new FileWriter( + outFile.getAbsoluteFile())); + + URL u = new URL( "ftp://thprod37.sbc.com/jobchange_Delta.dat" ); + reader = new BufferedReader(new InputStreamReader( + new BufferedInputStream(u.openStream()))); + while ((line = reader.readLine()) != null) { + writer.write(line + "\n"); + } + + writer.close(); + reader.close(); + + env.info().log("Finished fetching the data from the webphone ftp site."); + return( "etc/jobchange." + getCurrentDate() ); + + } catch (MalformedURLException e) { + env.error().log("Could not open the remote job change data file.", e); + errorFlag = true; + + } catch (IOException e) { + env.error().log( + "Error while opening or writing to the local data file.", e); + errorFlag = true; + + } catch (Exception e) { + env.error().log("Error while fetching the data file.", e); + errorFlag = true; + + } finally { + if (errorFlag) + outFile.delete(); + } + return null; + } + + public static String getCurrentDate() + { + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd"); + Date now = new Date(); + String strDate = sdfDate.format(now); + return strDate; + } + + public void loadUsersFromCred() + { + String query = "select id,ns from authz.cred" ; + + env.info().log( "query: " + query ); + + Statement stmt = new SimpleStatement( query ); + ResultSet results = session.execute(stmt); + + Iterator iter = results.iterator(); + while( iter.hasNext() ) + { + Row row = iter.next(); + String user = row.getString( "id" ); + String ns = row.getString( "ns" ); + String simpleUser = user.substring( 0, user.indexOf( "@" ) ); + + if ( isMechID( simpleUser ) ) + { + continue; + } + else if ( credsMap.get( simpleUser ) == null ) + { + credsMap.put( simpleUser, new ArrayList() ); + + UserCred newEntry = new UserCred(); + newEntry.user = user; + newEntry.ns = ns; + + credsMap.get( simpleUser ).add( newEntry ); + } + else + { + UserCred newEntry = new UserCred(); + newEntry.user = user; + newEntry.ns = ns; + + credsMap.get( simpleUser ).add( newEntry ); + } + + env.debug().log( String.format( "\tUser: %s NS: %s", user, ns ) ); + } + } + + public void loadUsersFromRoles() + { + String query = "select user,role from authz.user_role" ; + + env.info().log( "query: " + query ); + + Statement stmt = new SimpleStatement( query ); + ResultSet results = session.execute(stmt); + int total=0, flagged=0; + + Iterator iter = results.iterator(); + while( iter.hasNext() ) + { + Row row = iter.next(); + String user = row.getString( "user" ); + String role = row.getString( "role" ); + String simpleUser = user.substring( 0, user.indexOf( "@" ) ); + + if ( isMechID( simpleUser ) ) + { + continue; + } + else if ( rolesMap.get( simpleUser ) == null ) + { + rolesMap.put( simpleUser, new ArrayList() ); + + UserRole newEntry = new UserRole(); + newEntry.user = user; + newEntry.role = role; + + rolesMap.get( simpleUser ).add( newEntry ); + } + else + { + UserRole newEntry = new UserRole(); + newEntry.user = user; + newEntry.role = role; + + rolesMap.get( simpleUser ).add( newEntry ); + } + + env.debug().log( String.format( "\tUser: %s Role: %s", user, role ) ); + + ++total; + } + env.info().log( String.format( "rows read: %d expiring: %d", total, flagged ) ); + } + + public void loadOwnersFromNS() + { + String query = "select name,admin,responsible from authz.ns" ; + + env.info().log( "query: " + query ); + + Statement stmt = new SimpleStatement( query ); + ResultSet results = session.execute(stmt); + + Iterator iter = results.iterator(); + while( iter.hasNext() ) + { + Row row = iter.next(); + Set responsibles = row.getSet( "responsible", String.class ); + + for ( String user : responsibles ) + { + env.info().log( String.format( "Found responsible %s", user ) ); + String simpleUser = user.substring( 0, user.indexOf( "@" ) ); + + if ( isMechID( simpleUser ) ) + { + continue; + } + else if ( ownersMap.get( simpleUser ) == null ) + { + ownersMap.put( simpleUser, new ArrayList() ); + + NamespaceOwner newEntry = new NamespaceOwner(); + newEntry.user = user; + newEntry.ns = row.getString( "name" ); + newEntry.ownerCount = responsibles.size(); + newEntry.responsible = true; + ownersMap.get( simpleUser ).add( newEntry ); + } + else + { + NamespaceOwner newEntry = new NamespaceOwner(); + newEntry.user = user; + newEntry.ns = row.getString( "name" ); + newEntry.ownerCount = responsibles.size(); + newEntry.responsible = true; + ownersMap.get( simpleUser ).add( newEntry ); + } + } + Set admins = row.getSet( "admin", String.class ); + + for ( String user : admins ) + { + env.info().log( String.format( "Found admin %s", user ) ); + String simpleUser = user.substring( 0, user.indexOf( "@" ) ); + + if ( isMechID( simpleUser ) ) + { + continue; + } + else if ( ownersMap.get( simpleUser ) == null ) + { + ownersMap.put( simpleUser, new ArrayList() ); + + NamespaceOwner newEntry = new NamespaceOwner(); + newEntry.user = user; + newEntry.ns = row.getString( "name" ); + newEntry.responsible = false; + newEntry.ownerCount = -1; // + ownersMap.get( simpleUser ).add( newEntry ); + } + else + { + NamespaceOwner newEntry = new NamespaceOwner(); + newEntry.user = user; + newEntry.ns = row.getString( "name" ); + newEntry.responsible = false; + newEntry.ownerCount = -1; // + ownersMap.get( simpleUser ).add( newEntry ); + } + } + + } + } + + /** + * Processes the specified JobChange data file obtained from Webphone. Each line is + * read and processed and any fallout is written to the specified fallout file. + * If fallout file already exists it is deleted and a new one is created. A + * comparison of the supervisor id in the job data file is done against the one returned + * by the authz service and if the supervisor Id has changed then the record is updated + * using the authz service. An email is sent to the new supervisor to approve the roles + * assigned to the user. + * + * @param fileName - name of the file to process including its path + * @param falloutFileName - the file where the fallout entries have to be written + * @param validDate - the valid effective date when the user had moved to the new supervisor + * @throws Exception + */ + public void processJobChangeDataFile(String fileName, + String falloutFileName, Date validDate) throws Exception + { + + BufferedWriter writer = null; + + try { + + env.info().log("Reading file: " + fileName ); + + FileInputStream fstream = new FileInputStream(fileName); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + String strLine; + + while ((strLine = br.readLine()) != null) { + processLine( strLine, writer ); + } + + br.close(); + + + } catch (IOException e) { + env.error().log( "Error while reading from the input data file: " + e ); + throw e; + } + } + + public void handleAdminChange( String user ) + { + ArrayList val = ownersMap.get( user ); + + for ( NamespaceOwner r : val ) + { + env.info().log( "handleAdminChange: " + user ); + AuthzTrans trans = env.newTransNoAvg(); + + + if ( r.responsible ) + { + env.info().log( String.format( "delete from NS owner: %s, NS: %s, count: %s", + r.user, r.ns, r.ownerCount ) ); + + aspr.info( String.format( "action=DELETE_NS_OWNER, user=%s, ns=%s", + r.user, r.ns ) ); + if ( r.ownerCount < 2 ) + { + // send warning email to aaf-support, after this deletion, no owner for NS + ArrayList toAddress = new ArrayList(); + toAddress.add( "XXX_EMAIL" ); + + env.warn().log( "removing last owner from namespace" ); + + Organization org = null; + org = getOrgFromID( myTrans, org, toAddress.get(0) ); + + env.info().log( "calling getOrgFromID with " + toAddress.get(0) ); + + if ( org != null ) + { + try + { + aspr.info( String.format( "action=EMAIL_NO_OWNER_NS to=%s, user=%s, ns=%s", + toAddress.get(0), r.user, r.ns ) ); + org.sendEmail( trans, toAddress, + new ArrayList(), + String.format( "WARNING: no owners for AAF namespace '%s'", r.ns ), // subject: + String.format( "AAF recieved a jobchange notification for user %s who was the owner of the '%s' namespace. Please identify a new owner for this namespace and update AAF.", r.user, r.ns ), // body of msg + true ); + } catch (Exception e) { + env.error().log("calling sendEmail()"); + + e.printStackTrace(); + } + } + else + { + env.error().log( "Failed getOrgFromID" ); + } + } + } + else + { + env.info().log( String.format( "delete from NS admin: %s, NS: %s", + r.user, r.ns ) ); + + aspr.info( String.format( "action=DELETE_NS_ADMIN, user=%s, ns=%s", + r.user, r.ns ) ); + } + + String field = (r.responsible == true) ? "responsible" : "admin"; + + String query = String.format( "update authz.ns set %s = %s - {'%s'} where name = '%s'", + field, field, r.user, r.ns ) ; + env.info().log( "query: " + query ); + Statement stmt = new SimpleStatement( query ); + /*Row row = */session.execute(stmt).one(); + + String attribQuery = String.format( "delete from authz.ns_attrib where ns = '%s' AND type='%s' AND name='%s'", + r.ns, field, r.user); + env.info().log( "ns_attrib query: " + attribQuery); + Statement attribStmt = new SimpleStatement( attribQuery ); + /*Row attribRow = */session.execute(attribStmt).one(); + + } + } + + public void handleRoleChange( String user ) + { + ArrayList val = rolesMap.get( user ); + + for ( UserRole r : val ) + { + env.info().log( "handleRoleChange: " + user ); + + env.info().log( String.format( "delete from %s from user_role: %s", + r.user, r.role ) ); + + aspr.info( String.format( "action=DELETE_FROM_ROLE, user=%s, role=%s", + r.user, r.role ) ); + + + String query = String.format( "delete from authz.user_role where user = '%s' and role = '%s'", + r.user, r.role ); + + env.info().log( "query: " + query ); + + Statement stmt = new SimpleStatement( query ); + /* Row row = */ session.execute(stmt).one(); + + } + } + + public void handleCredChange( String user ) + { + ArrayList val = credsMap.get( user ); + + for ( UserCred r : val ) + { + env.info().log( "handleCredChange: " + user ); + + env.info().log( String.format( "delete user %s cred from ns: %s", + r.user, r.ns ) ); + + aspr.info( String.format( "action=DELETE_FROM_CRED, user=%s, ns=%s", + r.user, r.ns ) ); + + String query = String.format( "delete from authz.cred where id = '%s'", + r.user ); + + env.info().log( "query: " + query ); + + Statement stmt = new SimpleStatement( query ); + /*Row row = */session.execute(stmt).one(); + + } + + } + + public boolean processLine(String line, BufferedWriter writer) throws IOException + { + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyyMMdd"); + boolean errorFlag = false; + String errorMsg = ""; + + try + { + String[] phoneInfo = line.split( "\\|" ); + + if ((phoneInfo != null) && (phoneInfo.length >= 8) + && (!phoneInfo[0].startsWith("#"))) + { + String user = phoneInfo[0]; + String newSupervisor = phoneInfo[7]; + Date effectiveDate = sdfDate.parse(phoneInfo[8].trim()); + + env.debug().log( String.format( "checking user: %s, newSupervisor: %s, date: %s", + user, newSupervisor, effectiveDate ) ); + + // Most important case, user is owner of a namespace + // + if ( ownersMap.get( user ) != null ) + { + env.info().log( String.format( "Found %s as a namespace admin/owner", user ) ); + handleAdminChange( user ); + } + + if ( credsMap.get( user ) != null ) + { + env.info().log( String.format( "Found %s in cred table", user ) ); + handleCredChange( user ); + } + + if ( rolesMap.get( user ) != null ) + { + env.info().log( String.format( "Found %s in a role ", user ) ); + handleRoleChange( user ); + } + } + + else if (phoneInfo[0].startsWith("#")) + { + return true; + } + else + { + env.warn().log("Can't parse. Skipping the line." + line); + errorFlag = true; + } + } catch (Exception e) { + errorFlag = true; + errorMsg = e.getMessage(); + env.error().log( "Error while processing line:" + line + e ); + e.printStackTrace(); + } finally { + if (errorFlag) { + env.info().log( "Fallout enrty being written for line:" + line ); + writer.write(line + "|Failed to update supervisor for user:" + errorMsg + "\n"); + } + } + return true; + } + + + public JobChange(AuthzTrans trans) throws APIException, IOException { + super( trans.env() ); + myTrans = trans; + session = cluster.connect(); + } + + public Organization getOrgFromID( AuthzTrans trans, Organization _org, String user ) { + Organization org = _org; + if ( org == null || ! user.endsWith( org.getRealm() ) ) { + int idx = user.lastIndexOf('.'); + if ( idx > 0 ) + idx = user.lastIndexOf( '.', idx-1 ); + + org = null; + if ( idx > 0 ) { + try { + org = OrganizationFactory.obtain( trans.env(), user.substring( idx+1 ) ); + } catch (Exception e) { + trans.error().log(e,"Failure Obtaining Organization"); + } + } + + if ( org == null ) { + PrintStream fallout = null; + + try { + fallout= fallout(fallout, "Fallout"); + fallout.print("INVALID_ID,"); + fallout.println(user); + } catch (Exception e) { + env.error().log("Could not write to Fallout File",e); + } + return( null ); + } + } + return( org ); + } + + public void dumpOwnersMap() + { + for ( Map.Entry> e : ownersMap.entrySet() ) + { + String key = e.getKey(); + ArrayList values = e.getValue(); + + env.info().log( "ns user: " + key ); + + for ( NamespaceOwner r : values ) + { + env.info().log( String.format( "\tNS-user: %s, NS-name: %s, ownerCount: %d", + r.user, r.ns, r.ownerCount ) ); + + } + } + } + + public void dumpRolesMap() + { + for ( Map.Entry> e : rolesMap.entrySet() ) + { + String key = e.getKey(); + ArrayList values = e.getValue(); + + env.info().log( "user: " + key ); + + for ( UserRole r : values ) + { + env.info().log( String.format( "\trole-user: %s, role-name: %s", + r.user, r.role ) ); + } + } + } + public void dumpCredMap() + { + for ( Map.Entry> e : credsMap.entrySet() ) + { + String key = e.getKey(); + ArrayList values = e.getValue(); + + env.info().log( "user: " + key ); + + for ( UserCred r : values ) + { + env.info().log( String.format( "\tcred-user: %s, ns: %s", + r.user, r.ns ) ); + } + + } + } + + @Override + protected void run (AuthzTrans trans) + { + if ( acquireRunLock( this.getClass().getName() ) != 1 ) { + env.warn().log( "Cannot acquire run lock, exiting" ); + System.exit( 1 ); + } + + try { +// Map email = new HashMap(); + + try + { + String workingDir = System.getProperty("user.dir"); + env.info().log( "Process jobchange file. PWD is " + workingDir ); + + loadUsersFromRoles(); + loadOwnersFromNS(); + loadUsersFromCred(); + + dumpRolesMap(); + dumpOwnersMap(); + dumpCredMap(); + + String fname = getJobChangeDataFile(); + + if ( fname == null ) + { + env.warn().log("getJobChangedatafile returned null"); + } + else + { + env.info().log("done with FTP"); + } + processJobChangeDataFile( fname, "fallout", null ); + } + catch (Exception e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +/* + private class EmailMsg { + private boolean urgent = false; + public String url; + public Organization org; + public String summary; + + public EmailMsg() { + org = null; + summary = ""; + } + + public boolean getUrgent() { + return( this.urgent ); + } + + public void setUrgent( boolean val ) { + this.urgent = val; + } + public void setOrg( Organization newOrg ) { + this.org = newOrg; + } + public Organization getOrg() { + return( this.org ); + } + } +*/ + @Override + protected void _close(AuthzTrans trans) { + session.close(); + } +} + + diff --git a/authz-batch/src/main/java/com/att/authz/UserRoleDataGeneration.java b/authz-batch/src/main/java/com/att/authz/UserRoleDataGeneration.java new file mode 100644 index 00000000..f638a001 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/UserRoleDataGeneration.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Random; +import java.util.UUID; + +import com.att.authz.env.AuthzTrans; +import com.att.inno.env.APIException; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class UserRoleDataGeneration extends Batch { + + protected UserRoleDataGeneration(AuthzTrans trans) throws APIException, IOException { + super(trans.env()); + session = cluster.connect(); + + } + + @Override + protected void run(AuthzTrans trans) { + + String query = "select * from authz.history" ; + + env.info().log( "query: " + query ); + + Statement stmt = new SimpleStatement( query ); + ResultSet results = session.execute(stmt); + int total=0; + + Iterator iter = results.iterator(); + + Random rand = new Random(); + + int min = 1; + int max = 32; + + while( iter.hasNext() ) { + Row row = iter.next(); + if (row.getString("target").equals("user_role")) { + int randomNum = rand.nextInt((max - min) + 1) + min; + + String newId = modifiedTimeuid(row.getUUID("id").toString(), randomNum); + String subject = row.getString("subject"); + String newSubject = subject.split("\\|")[1]; + + String newInsert = insertStmt(row, newId, "role", newSubject); + Statement statement = new SimpleStatement(newInsert); + session.executeAsync(statement); + + total++; + } + } + + env.info().log(total+ " history elements inserted for user roles"); + + } + + private String insertStmt(Row row, String newId, String newTarget, String newSubject) { + StringBuilder sb = new StringBuilder(); + sb.append("INSERT INTO authz.history (id,action,memo,reconstruct,subject,target,user,yr_mon) VALUES ("); + sb.append(newId+","); + sb.append("'"+row.getString("action")+"',"); + sb.append("'"+row.getString("memo")+"',"); + sb.append("null,"); + sb.append("'"+newSubject+"',"); + sb.append("'"+newTarget+"',"); + sb.append("'"+row.getString("user")+"',"); + sb.append(row.getInt("yr_mon")); + sb.append(")"); + + return sb.toString(); + } + + private String modifiedTimeuid(String origTimeuuid, int rand) { + UUID uuid = UUID.fromString(origTimeuuid); + + long bottomBits = uuid.getLeastSignificantBits(); + long newBottomBits = bottomBits + (1 << rand); + if (newBottomBits - bottomBits == 0) + env.info().log("Duplicate!\t"+uuid + " not duplicated for role history function."); + + UUID newUuid = new UUID(uuid.getMostSignificantBits(),newBottomBits); + return newUuid.toString(); + } + + @Override + protected void _close(AuthzTrans trans) { + session.close(); + aspr.info( "End UserRoleDataGeneration processing" ); + + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/actions/Action.java b/authz-batch/src/main/java/com/att/authz/actions/Action.java new file mode 100644 index 00000000..f69bb22a --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/Action.java @@ -0,0 +1,11 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; + +public interface Action { + public Result exec(AuthzTrans trans, T ur); +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/ActionDAO.java b/authz-batch/src/main/java/com/att/authz/actions/ActionDAO.java new file mode 100644 index 00000000..4e951f81 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/ActionDAO.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.dao.CassAccess; +import com.att.dao.aaf.hl.Function; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; + +public abstract class ActionDAO implements Action { + protected final Question q; + protected final Function f; + private boolean clean; + + public ActionDAO(AuthzTrans trans, Cluster cluster) throws APIException, IOException { + q = new Question(trans, cluster, CassAccess.KEYSPACE, false); + f = new Function(trans,q); + clean = true; + } + + public ActionDAO(AuthzTrans trans, ActionDAO predecessor) { + q = predecessor.q; + f = new Function(trans,q); + clean = false; + } + + public Session getSession(AuthzTrans trans) throws APIException, IOException { + return q.historyDAO.getSession(trans); + } + + public void close(AuthzTrans trans) { + if(clean) { + q.close(trans); + } + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/actions/ActionPuntDAO.java b/authz-batch/src/main/java/com/att/authz/actions/ActionPuntDAO.java new file mode 100644 index 00000000..fb94ab30 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/ActionPuntDAO.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; +import java.security.SecureRandom; +import java.util.Date; +import java.util.GregorianCalendar; + +import com.att.authz.env.AuthzTrans; +import com.att.inno.env.APIException; +import com.datastax.driver.core.Cluster; + +public abstract class ActionPuntDAO extends ActionDAO { + private static final SecureRandom random = new SecureRandom(); + private int months, range; + protected static final Date now = new Date(); + + public ActionPuntDAO(AuthzTrans trans, Cluster cluster, int months, int range) throws APIException, IOException { + super(trans, cluster); + this.months = months; + this.range = range; + } + + public ActionPuntDAO(AuthzTrans trans, ActionDAO predecessor, int months, int range) { + super(trans, predecessor); + this.months = months; + this.range = range; + } + + + protected Date puntDate() { + GregorianCalendar temp = new GregorianCalendar(); + temp.setTime(now); + if(range>0) { + int forward = months+Math.abs(random.nextInt()%range); + temp.add(GregorianCalendar.MONTH, forward); + temp.add(GregorianCalendar.DAY_OF_MONTH, (random.nextInt()%30)-15); + } + return temp.getTime(); + + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/actions/CredDelete.java b/authz-batch/src/main/java/com/att/authz/actions/CredDelete.java new file mode 100644 index 00000000..7d5fd1ef --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/CredDelete.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.CredDAO; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + +public class CredDelete extends ActionDAO { + + public CredDelete(AuthzTrans trans, Cluster cluster) throws APIException, IOException { + super(trans, cluster); + } + + public CredDelete(AuthzTrans trans, ActionDAO adao) { + super(trans, adao); + } + + @Override + public Result exec(AuthzTrans trans, CredDAO.Data cred) { + Result rv = q.credDAO.delete(trans, cred, true); // need to read for undelete + trans.info().log("Deleted:",cred.id,CredPrint.type(cred.type),Chrono.dateOnlyStamp(cred.expires)); + return rv; + } +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/CredPrint.java b/authz-batch/src/main/java/com/att/authz/actions/CredPrint.java new file mode 100644 index 00000000..ff3f7ff2 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/CredPrint.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.CredDAO; +import com.att.inno.env.util.Chrono; + +public class CredPrint implements Action { + private String text; + + public CredPrint(String text) { + this.text = text; + } + + @Override + public Result exec(AuthzTrans trans, CredDAO.Data cred) { + trans.info().log(text,cred.id,type(cred.type),Chrono.dateOnlyStamp(cred.expires)); + return Result.ok(); + } + + + public static String type(int type) { + switch(type) { + case CredDAO.BASIC_AUTH: // 1 + return "OLD"; + case CredDAO.BASIC_AUTH_SHA256: // 2 + return "U/P"; + case CredDAO.CERT_SHA256_RSA: // 200 + return "Cert"; + default: + return "Unknown"; + } + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/CredPunt.java b/authz-batch/src/main/java/com/att/authz/actions/CredPunt.java new file mode 100644 index 00000000..195dc67e --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/CredPunt.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; +import java.util.Date; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.CredDAO; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + +public class CredPunt extends ActionPuntDAO { + + public CredPunt(AuthzTrans trans, Cluster cluster, int months, int range) throws IOException, APIException { + super(trans,cluster,months,range); + } + + public CredPunt(AuthzTrans trans, ActionDAO adao, int months, int range) throws IOException { + super(trans, adao, months,range); + } + + public Result exec(AuthzTrans trans, CredDAO.Data cdd) { + Result rv = null; + Result> read = q.credDAO.read(trans, cdd); + if(read.isOKhasData()) { + for(CredDAO.Data data : read.value) { + Date from = data.expires; + data.expires = puntDate(); + if(data.expires.before(from)) { + trans.error().printf("Error: %s is before %s", Chrono.dateOnlyStamp(data.expires), Chrono.dateOnlyStamp(from)); + } else { + rv = q.credDAO.update(trans, data); + trans.info().log("Updated Cred",cdd.id, CredPrint.type(cdd.type), "from",Chrono.dateOnlyStamp(from),"to",Chrono.dateOnlyStamp(data.expires)); + } + } + } + if(rv==null) { + rv=Result.err(read); + } + return rv; + } +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/Email.java b/authz-batch/src/main/java/com/att/authz/actions/Email.java new file mode 100644 index 00000000..df491df3 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/Email.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.authz.org.Organization; + +public class Email implements Action{ + protected final List toList; + protected final List ccList; + private final String[] defaultCC; + protected String subject; + private String preamble; + private Message msg; + private String sig; + protected String lineIndent=" "; + + + public Email(String ... defaultCC) { + toList = new ArrayList(); + this.defaultCC = defaultCC; + ccList = new ArrayList(); + clear(); + } + + public Email clear() { + toList.clear(); + ccList.clear(); + for(String s: defaultCC) { + ccList.add(s); + } + return this; + } + + + public void indent(String indent) { + lineIndent = indent; + } + + public void preamble(String format, Object ... args) { + preamble = String.format(format, args); + } + + public Email addTo(Collection users) { + toList.addAll(users); + return this; + } + + public Email addTo(String email) { + toList.add(email); + return this; + } + + + public Email subject(String format, Object ... args) { + subject = String.format(format, args); + return this; + } + + + public Email signature(String format, Object ... args) { + sig = String.format(format, args); + return this; + } + + public void msg(Message msg) { + this.msg = msg; + } + + @Override + public Result exec(AuthzTrans trans, Organization org) { + StringBuilder sb = new StringBuilder(); + if(preamble!=null) { + sb.append(lineIndent); + sb.append(preamble); + sb.append("\n\n"); + } + + if(msg!=null) { + msg.msg(sb,lineIndent); + sb.append("\n"); + } + + if(sig!=null) { + sb.append(sig); + sb.append("\n"); + } + + return exec(trans,org,sb); + } + + protected Result exec(AuthzTrans trans, Organization org, StringBuilder sb) { + try { + /* int status = */ + org.sendEmail(trans, + toList, + ccList, + subject, + sb.toString(), + false); + } catch (Exception e) { + return Result.err(Result.ERR_ActionNotCompleted,e.getMessage()); + } + return Result.ok(); + + } +} diff --git a/authz-batch/src/main/java/com/att/authz/actions/EmailPrint.java b/authz-batch/src/main/java/com/att/authz/actions/EmailPrint.java new file mode 100644 index 00000000..5b356ce1 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/EmailPrint.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.PrintStream; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.authz.org.Organization; + +public class EmailPrint extends Email { + + public EmailPrint(String... defaultCC) { + super(defaultCC); + } + + /* (non-Javadoc) + * @see com.att.authz.actions.Email#exec(com.att.authz.org.Organization, java.lang.StringBuilder) + */ + @Override + protected Result exec(AuthzTrans trans, Organization org, StringBuilder msg) { + PrintStream out = System.out; + boolean first = true; + out.print("To: "); + for(String s: toList) { + if(first) {first = false;} + else {out.print(',');} + out.print(s); + } + out.println(); + + first = true; + out.print("CC: "); + for(String s: ccList) { + if(first) {first = false;} + else {out.print(',');} + out.print(s); + } + out.println(); + + out.print("Subject: "); + out.println(subject); + out.println(); + + out.println(msg); + return Result.ok(); + + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/actions/FADelete.java b/authz-batch/src/main/java/com/att/authz/actions/FADelete.java new file mode 100644 index 00000000..4ce11e54 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/FADelete.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.Future; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.ApprovalDAO; +import com.att.dao.aaf.cass.FutureDAO; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + +public class FADelete extends ActionDAO { + public FADelete(AuthzTrans trans, Cluster cluster) throws APIException, IOException { + super(trans, cluster); + } + + public FADelete(AuthzTrans trans, ActionDAO adao) { + super(trans, adao); + } + + @Override + public Result exec(AuthzTrans trans, Future f) { + FutureDAO.Data fdd = new FutureDAO.Data(); + fdd.id=f.id; + Result rv = q.futureDAO.delete(trans, fdd, true); // need to read for undelete + if(rv.isOK()) { + trans.info().log("Deleted:",f.id,f.memo,"expiring on",Chrono.dateOnlyStamp(f.expires)); + } else { + trans.info().log("Failed to Delete Approval"); + } + + Result> ral = q.approvalDAO.readByTicket(trans, f.id); + if(ral.isOKhasData()) { + for(ApprovalDAO.Data add : ral.value) { + rv = q.approvalDAO.delete(trans, add, false); + if(rv.isOK()) { + trans.info().log("Deleted: Approval",add.id,"on ticket",add.ticket,"for",add.approver); + } else { + trans.info().log("Failed to Delete Approval"); + } + } + } + return rv; + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/FAPrint.java b/authz-batch/src/main/java/com/att/authz/actions/FAPrint.java new file mode 100644 index 00000000..a687dc1b --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/FAPrint.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.Future; +import com.att.authz.layer.Result; +import com.att.inno.env.util.Chrono; + +public class FAPrint implements Action { + private String text; + + public FAPrint(String text) { + this.text = text; + } + + @Override + public Result exec(AuthzTrans trans, Future f) { + trans.info().log(text,f.id,f.memo,"expiring on",Chrono.dateOnlyStamp(f.expires)); + return Result.ok(); + } +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/Key.java b/authz-batch/src/main/java/com/att/authz/actions/Key.java new file mode 100644 index 00000000..89b7c6f8 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/Key.java @@ -0,0 +1,8 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +public interface Key { + public String key(HELPER H); +} diff --git a/authz-batch/src/main/java/com/att/authz/actions/Message.java b/authz-batch/src/main/java/com/att/authz/actions/Message.java new file mode 100644 index 00000000..2aca4eac --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/Message.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.util.ArrayList; +import java.util.List; + +public class Message { + public final List lines; + + public Message() { + lines = new ArrayList(); + } + + public void clear() { + lines.clear(); + } + + public void line(String format, Object ... args) { + lines.add(String.format(format, args)); + } + + public void msg(StringBuilder sb, String lineIndent) { + if(lines.size()>0) { + for(String line : lines) { + sb.append(lineIndent); + sb.append(line); + sb.append('\n'); + } + } + } +} diff --git a/authz-batch/src/main/java/com/att/authz/actions/URAdd.java b/authz-batch/src/main/java/com/att/authz/actions/URAdd.java new file mode 100644 index 00000000..3e254e9f --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/URAdd.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.UserRole; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.dao.aaf.cass.UserRoleDAO.Data; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + +public class URAdd extends ActionDAO { + public URAdd(AuthzTrans trans, Cluster cluster) throws APIException, IOException { + super(trans, cluster); + } + + public URAdd(AuthzTrans trans, ActionDAO adao) { + super(trans, adao); + } + + @Override + public Result exec(AuthzTrans trans, UserRole ur) { + UserRoleDAO.Data urd = new UserRoleDAO.Data(); + urd.user = ur.user; + urd.role = ur.role; + urd.ns=ur.ns; + urd.rname = ur.rname; + urd.expires = ur.expires; + Result rv = q.userRoleDAO.create(trans, urd); + trans.info().log("Added:",ur.role,ur.user,"on",Chrono.dateOnlyStamp(ur.expires)); + return rv; + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/URDelete.java b/authz-batch/src/main/java/com/att/authz/actions/URDelete.java new file mode 100644 index 00000000..064b6dce --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/URDelete.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.UserRole; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + +public class URDelete extends ActionDAO { + public URDelete(AuthzTrans trans, Cluster cluster) throws APIException, IOException { + super(trans, cluster); + } + + public URDelete(AuthzTrans trans, ActionDAO adao) { + super(trans, adao); + } + + @Override + public Result exec(AuthzTrans trans, UserRole ur) { + UserRoleDAO.Data urd = new UserRoleDAO.Data(); + urd.user = ur.user; + urd.role = ur.role; + Result rv = q.userRoleDAO.delete(trans, urd, true); // need to read for undelete + trans.info().log("Deleted:",ur.role,ur.user,"on",Chrono.dateOnlyStamp(ur.expires)); + return rv; + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/URFutureApprove.java b/authz-batch/src/main/java/com/att/authz/actions/URFutureApprove.java new file mode 100644 index 00000000..3401080c --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/URFutureApprove.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.UserRole; +import com.att.authz.layer.Result; +import com.att.authz.org.Organization.Expiration; +import com.att.authz.org.Organization.Identity; +import com.att.dao.aaf.cass.FutureDAO; +import com.att.dao.aaf.cass.NsDAO; +import com.att.dao.aaf.hl.Function; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + +public class URFutureApprove extends ActionDAO> implements Action>, Key { + private final Date start, expires; + + public URFutureApprove(AuthzTrans trans, Cluster cluster) throws APIException, IOException { + super(trans,cluster); + GregorianCalendar gc = new GregorianCalendar(); + start = gc.getTime(); + expires = trans.org().expiration(gc, Expiration.Future).getTime(); + } + + public URFutureApprove(AuthzTrans trans, ActionDAO adao) { + super(trans, adao); + GregorianCalendar gc = new GregorianCalendar(); + start = gc.getTime(); + expires = trans.org().expiration(gc, Expiration.Future).getTime(); + } + + @Override + public Result> exec(AuthzTrans trans, UserRole ur) { + Result rns = q.deriveNs(trans, ur.ns); + if(rns.isOK()) { + + FutureDAO.Data data = new FutureDAO.Data(); + data.id=null; // let Create function assign UUID + data.target=Function.FOP_USER_ROLE; + + data.memo = key(ur); + data.start = start; + data.expires = expires; + try { + data.construct = ur.to().bytify(); + } catch (IOException e) { + return Result.err(e); + } + Result> rapprovers = f.createFuture(trans, data, Function.FOP_USER_ROLE, ur.user, rns.value, "U"); + return rapprovers; + } else { + return Result.err(rns); + } + } + + @Override + public String key(UserRole ur) { + String expire; + if(expires.before(start)) { + expire = "' - EXPIRED "; + } else { + expire = "' - expiring "; + } + + if(Question.OWNER.equals(ur.rname)) { + return "Re-Validate Ownership for AAF Namespace '" + ur.ns + expire + Chrono.dateOnlyStamp(ur.expires); + } else if(Question.ADMIN.equals(ur.rname)) { + return "Re-Validate as Administrator for AAF Namespace '" + ur.ns + expire + Chrono.dateOnlyStamp(ur.expires); + } else { + return "Re-Approval in Role '" + ur.role + expire + Chrono.dateOnlyStamp(ur.expires); + } + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/URFuturePrint.java b/authz-batch/src/main/java/com/att/authz/actions/URFuturePrint.java new file mode 100644 index 00000000..812aa81e --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/URFuturePrint.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.util.ArrayList; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.UserRole; +import com.att.authz.layer.Result; +import com.att.authz.org.Organization.Identity; +import com.att.inno.env.util.Chrono; + + +public class URFuturePrint implements Action> { + private String text; + private final static List rv = new ArrayList(); + + public URFuturePrint(String text) { + this.text = text; + } + + @Override + public Result> exec(AuthzTrans trans, UserRole ur) { + trans.info().log(text,ur.user,"to",ur.role,"on",Chrono.dateOnlyStamp(ur.expires)); + return Result.ok(rv); + }} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/URPrint.java b/authz-batch/src/main/java/com/att/authz/actions/URPrint.java new file mode 100644 index 00000000..a643851e --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/URPrint.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.UserRole; +import com.att.authz.layer.Result; +import com.att.inno.env.util.Chrono; + +public class URPrint implements Action { + private String text; + + public URPrint(String text) { + this.text = text; + } + + @Override + public Result exec(AuthzTrans trans, UserRole ur) { + trans.info().log(text,ur.user,"to",ur.role,"expiring on",Chrono.dateOnlyStamp(ur.expires)); + return Result.ok(); + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/actions/URPunt.java b/authz-batch/src/main/java/com/att/authz/actions/URPunt.java new file mode 100644 index 00000000..803fdb94 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/actions/URPunt.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.actions; + +import java.io.IOException; +import java.util.Date; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.UserRole; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.dao.aaf.cass.UserRoleDAO.Data; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + +public class URPunt extends ActionPuntDAO { + public URPunt(AuthzTrans trans, Cluster cluster, int months, int range) throws APIException, IOException { + super(trans,cluster, months, range); + } + + public URPunt(AuthzTrans trans, ActionDAO adao, int months, int range) { + super(trans, adao, months, range); + } + + public Result exec(AuthzTrans trans, UserRole ur) { + Result> read = q.userRoleDAO.read(trans, ur.user, ur.role); + if(read.isOK()) { + for(UserRoleDAO.Data data : read.value) { + Date from = data.expires; + data.expires = puntDate(); + if(data.expires.before(from)) { + trans.error().printf("Error: %s is before %s", Chrono.dateOnlyStamp(data.expires), Chrono.dateOnlyStamp(from)); + } else { + q.userRoleDAO.update(trans, data); + trans.info().log("Updated User",ur.user,"and Role", ur.role, "from",Chrono.dateOnlyStamp(from),"to",Chrono.dateOnlyStamp(data.expires)); + } + } + return Result.ok(); + } else { + return Result.err(read); + } + } +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/entryConverters/AafEntryConverter.java b/authz-batch/src/main/java/com/att/authz/entryConverters/AafEntryConverter.java new file mode 100644 index 00000000..4f05f203 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/entryConverters/AafEntryConverter.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.entryConverters; + +import java.util.Set; + +public abstract class AafEntryConverter { + + protected String formatSet(Set set) { + if (set==null || set.isEmpty()) return ""; + StringBuilder sb = new StringBuilder(); + int curr = 0; + sb.append("{"); + for (String s : set) { + sb.append("'"); + sb.append(s); + sb.append("'"); + if (set.size() != curr + 1) { + sb.append(","); + } + curr++; + } + sb.append("}"); + return sb.toString(); + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/entryConverters/CredEntryConverter.java b/authz-batch/src/main/java/com/att/authz/entryConverters/CredEntryConverter.java new file mode 100644 index 00000000..96c88122 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/entryConverters/CredEntryConverter.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.entryConverters; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; + +import com.att.dao.aaf.cass.CredDAO; +import com.datastax.driver.core.utils.Bytes; +import com.googlecode.jcsv.writer.CSVEntryConverter; + +public class CredEntryConverter extends AafEntryConverter implements CSVEntryConverter { + private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ssZ"; + + @Override + public String[] convertEntry(CredDAO.Data cd) { + String[] columns = new String[5]; + + columns[0] = cd.id; + columns[1] = String.valueOf(cd.type); + DateFormat df = new SimpleDateFormat(DATE_FORMAT); + columns[2] = df.format(cd.expires); + columns[3] = Bytes.toHexString(cd.cred); + columns[4] = (cd.ns==null)?"":cd.ns; + + return columns; + } +} diff --git a/authz-batch/src/main/java/com/att/authz/entryConverters/NsEntryConverter.java b/authz-batch/src/main/java/com/att/authz/entryConverters/NsEntryConverter.java new file mode 100644 index 00000000..e9cd91c4 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/entryConverters/NsEntryConverter.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.entryConverters; + +import com.att.dao.aaf.cass.NsDAO; +import com.googlecode.jcsv.writer.CSVEntryConverter; + +public class NsEntryConverter extends AafEntryConverter implements CSVEntryConverter { + + @Override + public String[] convertEntry(NsDAO.Data nsd) { + String[] columns = new String[5]; + + columns[0] = nsd.name; + // JG changed from "scope" to "type" + columns[1] = String.valueOf(nsd.type); + //TODO Chris: need to look at this +// columns[2] = formatSet(nsd.admin); +// columns[3] = formatSet(nsd.responsible); +// columns[4] = nsd.description==null?"":nsd.description; + columns[5] = nsd.description==null?"":nsd.description; + + return columns; + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/entryConverters/PermEntryConverter.java b/authz-batch/src/main/java/com/att/authz/entryConverters/PermEntryConverter.java new file mode 100644 index 00000000..afabdfdf --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/entryConverters/PermEntryConverter.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.entryConverters; + +import com.att.dao.aaf.cass.PermDAO; +import com.googlecode.jcsv.writer.CSVEntryConverter; + +public class PermEntryConverter extends AafEntryConverter implements CSVEntryConverter { + + @Override + public String[] convertEntry(PermDAO.Data pd) { + String[] columns = new String[6]; + + columns[0] = pd.ns; + columns[1] = pd.type; + columns[2] = pd.instance; + columns[3] = pd.action; + columns[4] = formatSet(pd.roles); + columns[5] = pd.description==null?"":pd.description; + + return columns; + } +} diff --git a/authz-batch/src/main/java/com/att/authz/entryConverters/RoleEntryConverter.java b/authz-batch/src/main/java/com/att/authz/entryConverters/RoleEntryConverter.java new file mode 100644 index 00000000..51389bd3 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/entryConverters/RoleEntryConverter.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.entryConverters; + +import com.att.dao.aaf.cass.RoleDAO; +import com.googlecode.jcsv.writer.CSVEntryConverter; + +public class RoleEntryConverter extends AafEntryConverter implements CSVEntryConverter { + + @Override + public String[] convertEntry(RoleDAO.Data rd) { + String[] columns = new String[4]; + + columns[0] = rd.ns; + columns[1] = rd.name; + columns[2] = formatSet(rd.perms); + columns[3] = rd.description==null?"":rd.description; + + return columns; + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/entryConverters/UserRoleEntryConverter.java b/authz-batch/src/main/java/com/att/authz/entryConverters/UserRoleEntryConverter.java new file mode 100644 index 00000000..0b2a956e --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/entryConverters/UserRoleEntryConverter.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.entryConverters; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; + +import com.att.dao.aaf.cass.UserRoleDAO; +import com.googlecode.jcsv.writer.CSVEntryConverter; + +public class UserRoleEntryConverter extends AafEntryConverter implements CSVEntryConverter { + private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ssZ"; + + @Override + public String[] convertEntry(UserRoleDAO.Data urd) { + String[] columns = new String[3]; + + columns[0] = urd.user; + columns[1] = urd.role; + DateFormat df = new SimpleDateFormat(DATE_FORMAT); + columns[2] = df.format(urd.expires); + + return columns; + } +} diff --git a/authz-batch/src/main/java/com/att/authz/helpers/Approver.java b/authz-batch/src/main/java/com/att/authz/helpers/Approver.java new file mode 100644 index 00000000..0cac97bc --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/Approver.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.HashMap; +import java.util.Map; + +import com.att.authz.actions.Message; +import com.att.authz.org.Organization; + +public class Approver { + public String name; + public Organization org; + public Map userRequests; + + public Approver(String approver, Organization org) { + this.name = approver; + this.org = org; + userRequests = new HashMap(); + } + + public void addRequest(String user) { + if (userRequests.get(user) == null) { + userRequests.put(user, 1); + } else { + Integer curCount = userRequests.remove(user); + userRequests.put(user, curCount+1); + } + } + + /** + * @param sb + * @return + */ + public void build(Message msg) { + msg.clear(); + msg.line("You have %d total pending approvals from the following users:", userRequests.size()); + for (Map.Entry entry : userRequests.entrySet()) { + msg.line(" %s (%d)",entry.getKey(),entry.getValue()); + } + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/helpers/Creator.java b/authz-batch/src/main/java/com/att/authz/helpers/Creator.java new file mode 100644 index 00000000..1fe513e8 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/Creator.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import com.datastax.driver.core.Row; + +public abstract class Creator { + public abstract T create(Row row); + public abstract String select(); + + public String query(String where) { + StringBuilder sb = new StringBuilder(select()); + if(where!=null) { + sb.append(" WHERE "); + sb.append(where); + } + sb.append(';'); + return sb.toString(); + } + + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/helpers/Cred.java b/authz-batch/src/main/java/com/att/authz/helpers/Cred.java new file mode 100644 index 00000000..39691df9 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/Cred.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeMap; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class Cred { + public static final TreeMap data = new TreeMap(); + + public final String id; + public final List instances; + + public Cred(String id) { + this.id = id; + instances = new ArrayList(); + } + + public static class Instance { + public final int type; + public final Date expires; + public final Integer other; + + public Instance(int type, Date expires, Integer other) { + this.type = type; + this.expires = expires; + this.other = other; + } + } + + public Date last(final int type) { + Date last = null; + for(Instance i : instances) { + if(i.type==type && (last==null || i.expires.after(last))) { + last = i.expires; + } + } + return last; + } + + + public Set types() { + Set types = new HashSet(); + for(Instance i : instances) { + types.add(i.type); + } + return types; + } + + public static void load(Trans trans, Session session ) { + load(trans, session,"select id, type, expires, other from authz.cred;"); + + } + + public static void loadOneNS(Trans trans, Session session, String ns ) { + load(trans, session,"select id, type, expires, other from authz.cred WHERE ns='" + ns + "';"); + } + + private static void load(Trans trans, Session session, String query) { + + trans.info().log( "query: " + query ); + TimeTaken tt = trans.start("Read Creds", Env.REMOTE); + + ResultSet results; + try { + Statement stmt = new SimpleStatement( query ); + results = session.execute(stmt); + } finally { + tt.done(); + } + int count = 0; + try { + Iterator iter = results.iterator(); + Row row; + tt = trans.start("Load Roles", Env.SUB); + try { + while(iter.hasNext()) { + ++count; + row = iter.next(); + String id = row.getString(0); + Cred cred = data.get(id); + if(cred==null) { + cred = new Cred(id); + data.put(id, cred); + } + cred.instances.add(new Instance(row.getInt(1), row.getDate(2), row.getInt(3))); + } + } finally { + tt.done(); + } + } finally { + trans.info().log("Found",count,"creds"); + } + + + } + public String toString() { + StringBuilder sb = new StringBuilder(id); + sb.append('['); + for(Instance i : instances) { + sb.append('{'); + sb.append(i.type); + sb.append(",\""); + sb.append(i.expires); + sb.append("\"}"); + } + sb.append(']'); + return sb.toString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return id.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return id.equals(obj); + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/helpers/Future.java b/authz-batch/src/main/java/com/att/authz/helpers/Future.java new file mode 100644 index 00000000..13ee8222 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/Future.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.TreeMap; +import java.util.UUID; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class Future { + public static final List data = new ArrayList(); + public static final TreeMap> byMemo = new TreeMap>(); + + public final UUID id; + public final String memo, target; + public final Date start, expires; + public Future(UUID id, String memo, String target, Date start, Date expires) { + this.id = id; + this.memo = memo; + this.target = target; + this.start = start; + this.expires = expires; + } + + public static void load(Trans trans, Session session, Creator creator) { + trans.info().log( "query: " + creator.select() ); + ResultSet results; + TimeTaken tt = trans.start("Load Futures", Env.REMOTE); + try { + Statement stmt = new SimpleStatement(creator.select()); + results = session.execute(stmt); + } finally { + tt.done(); + } + + int count = 0; + tt = trans.start("Process Futures", Env.SUB); + try { + for(Row row : results.all()) { + ++count; + Future f = creator.create(row); + data.add(f); + + List lf = byMemo.get(f.memo); + if(lf == null) { + lf = new ArrayList(); + byMemo.put(f.memo, lf); + } + lf.add(f); + + } + } finally { + trans.info().log("Found",count,"Futures"); + } + } + + public static Creator v2_0_15 = new Creator() { + @Override + public Future create(Row row) { + return new Future(row.getUUID(0),row.getString(1),row.getString(2), + row.getDate(3),row.getDate(4)); + } + + @Override + public String select() { + return "select id,memo,target,start,expires from authz.future"; + } + }; + + public static void delete(List fl) { + if(fl==null || fl.isEmpty()) { + return; + } + for(Future f : fl) { + data.remove(f); + } + // Faster to start over, then look for entries. + byMemo.clear(); + for(Future f : data) { + List lf = byMemo.get(f.memo); + if(lf == null) { + lf = new ArrayList(); + byMemo.put(f.memo, lf); + } + lf.add(f); + } + } +} diff --git a/authz-batch/src/main/java/com/att/authz/helpers/InputIterator.java b/authz-batch/src/main/java/com/att/authz/helpers/InputIterator.java new file mode 100644 index 00000000..02fdc166 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/InputIterator.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Iterator; + +public class InputIterator implements Iterable { + private BufferedReader in; + private final PrintStream out; + private final String prompt, instructions; + + public InputIterator(BufferedReader in, PrintStream out, String prompt, String instructions) { + this.in = in; + this.out = out; + this.prompt = prompt; + this.instructions = instructions; + } + + @Override + public Iterator iterator() { + out.println(instructions); + return new Iterator() { + String input; + @Override + public boolean hasNext() { + out.append(prompt); + try { + input = in.readLine(); + } catch (IOException e) { + input = null; + return false; + } + return input.length()>0; + } + + @Override + public String next() { + return input; + } + + @Override + public void remove() { + } + }; + } +} + diff --git a/authz-batch/src/main/java/com/att/authz/helpers/MiscID.java b/authz-batch/src/main/java/com/att/authz/helpers/MiscID.java new file mode 100644 index 00000000..c60a97a1 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/MiscID.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.Map; +import java.util.TreeMap; + +import com.att.authz.BatchException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class MiscID { + public static final TreeMap data = new TreeMap(); + /* + Sample Record + aad890|mj9030|20040902|20120207 + + **** Field Definitions **** + MISCID - AT&T Miscellaneous ID - Non-User ID (Types: Internal Mechanized ID, External Mechanized ID, Datagate ID, Customer ID, Vendor ID, Exchange Mail ID, CLEC ID, Specialized ID, Training ID) + SPONSOR_ATTUID - ATTUID of MiscID Sponsor (Owner) + CREATE_DATE - Date when MiscID was created + LAST_RENEWAL_DATE - Date when MiscID Sponsorship was last renewed + */ + public String id,sponsor,created,renewal; + + private static final String fieldString = "id,created,sponsor,renewal"; + + /** + * Load a Row of Strings (from CSV file). + * + * Be CAREFUL that the Row lists match the Fields above!!! If this changes, change + * 1) This Object + * 2) DB "suits.cql" + * 3) Alter existing Tables + * @param row + * @throws BatchException + * @throws IllegalAccessException + * @throws IllegalArgumentException + */ + public void set(String row []) throws BatchException { + if(row.length<4) {throw new BatchException("Row of MiscID_XRef is too short");} + id = row[0]; + sponsor = row[1]; + created = row[2]; + renewal = row[3]; + } + + public void set(Row row) { + id = row.getString(0); + sponsor = row.getString(1); + created = row.getString(2); + renewal = row.getString(3); + } + + + public static void load(Trans trans, Session session ) { + load(trans, session,"SELECT " + fieldString + " FROM authz.miscid;",data); + } + + public static void load(Trans trans, Session session, Map map ) { + load(trans, session,"SELECT " + fieldString + " FROM authz.miscid;",map); + } + + public static void loadOne(Trans trans, Session session, String id ) { + load(trans, session,"SELECT " + fieldString + " FROM authz.miscid WHERE id ='" + id + "';", data); + } + + public static void load(Trans trans, Session session, String query, Map map) { + trans.info().log( "query: " + query ); + TimeTaken tt = trans.start("Read MiscID", Env.REMOTE); + + ResultSet results; + try { + Statement stmt = new SimpleStatement( query ); + results = session.execute(stmt); + } finally { + tt.done(); + } + int count = 0; + try { + tt = trans.start("Load Map", Env.SUB); + try { + for( Row row : results.all()) { + MiscID miscID = new MiscID(); + miscID.set(row); + data.put(miscID.id,miscID); + ++count; + } + } finally { + tt.done(); + } + } finally { + trans.info().log("Found",count,"miscID records"); + } + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return id.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if(obj!=null && obj instanceof MiscID) { + return id.equals(((MiscID)obj).id); + } + return false; + } + + public StringBuilder insertStmt() throws IllegalArgumentException, IllegalAccessException { + StringBuilder sb = new StringBuilder("INSERT INTO authz.miscid ("); + sb.append(fieldString); + sb.append(") VALUES ('"); + sb.append(id); + sb.append("','"); + sb.append(sponsor); + sb.append("','"); + sb.append(created); + sb.append("','"); + sb.append(renewal); + sb.append("')"); + return sb; + } + + public StringBuilder updateStmt(MiscID source) { + StringBuilder sb = null; + if(id.equals(source.id)) { + sb = addField(sb,"sponser",sponsor,source.sponsor); + sb = addField(sb,"created",created,source.created); + sb = addField(sb,"renewal",renewal,source.renewal); + } + if(sb!=null) { + sb.append(" WHERE id='"); + sb.append(id); + sb.append('\''); + } + return sb; + } + + private StringBuilder addField(StringBuilder sb, String name, String a, String b) { + if(!a.equals(b)) { + if(sb==null) { + sb = new StringBuilder("UPDATE authz.miscid SET "); + } else { + sb.append(','); + } + sb.append(name); + sb.append("='"); + sb.append(b); + sb.append('\''); + } + return sb; + } + + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/helpers/NS.java b/authz-batch/src/main/java/com/att/authz/helpers/NS.java new file mode 100644 index 00000000..a97b2d2b --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/NS.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.Iterator; +import java.util.Map; +import java.util.TreeMap; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class NS implements Comparable { + public final static Map data = new TreeMap(); + + public final String name, description, parent; + public final int scope,type; + + public NS(String name, String description, String parent, int type, int scope) { + this.name = name; + this.description = description; + this.parent = parent; + this.scope = scope; + this.type = type; + } + + public static void load(Trans trans, Session session, Creator creator) { + load(trans,session, + "select name, description, parent, type, scope from authz.ns;" + ,creator); + } + + public static void loadOne(Trans trans, Session session, Creator creator, String ns) { + load(trans,session, + ("select name, description, parent, type, scope from authz.ns WHERE name='"+ns+"';") + ,creator + ); + } + + private static void load(Trans trans, Session session, String query, Creator creator) { + trans.info().log( "query: " + query ); + ResultSet results; + TimeTaken tt; + + tt = trans.start("Read Namespaces", Env.REMOTE); + try { + Statement stmt = new SimpleStatement( query ); + results = session.execute(stmt); + } finally { + tt.done(); + } + + + try { + Iterator iter = results.iterator(); + Row row; + tt = trans.start("Load Namespaces", Env.SUB); + try { + while(iter.hasNext()) { + row = iter.next(); + NS ns = creator.create(row); + data.put(ns.name,ns); + } + } finally { + tt.done(); + } + } finally { + trans.info().log("Found",data.size(),"Namespaces"); + } + + } + + public String toString() { + return name; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return name.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return name.equals(obj); + } + + @Override + public int compareTo(NS o) { + return name.compareTo(o.name); + } + + public static class NSSplit { + public String ns; + public String other; + public NSSplit(String s, int dot) { + ns = s.substring(0,dot); + other = s.substring(dot+1); + } + } + public static NSSplit deriveParent(String dotted) { + if(dotted==null)return null; + for(int idx = dotted.lastIndexOf('.');idx>=0; idx=dotted.lastIndexOf('.',idx-1)) { + if(data.get(dotted.substring(0, idx))!=null) { + return new NSSplit(dotted,idx); + } + } + return null; + } + + public static Creator v2_0_11 = new Creator () { + @Override + public NS create(Row row) { + return new NS(row.getString(0),row.getString(1), row.getString(2),row.getInt(3),row.getInt(4)); + } + + @Override + public String select() { + return "SELECT name, description, parent, type, scope FROM authz.ns "; + } + }; + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/helpers/Notification.java b/authz-batch/src/main/java/com/att/authz/helpers/Notification.java new file mode 100644 index 00000000..279e5881 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/Notification.java @@ -0,0 +1,273 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.TreeMap; + +import com.att.authz.actions.Message; +import com.att.authz.env.AuthzTrans; +import com.att.authz.org.EmailWarnings; +import com.att.authz.org.Organization; +import com.att.authz.org.Organization.Notify; +import com.att.authz.org.Organization.Identity; +import com.att.authz.org.OrganizationException; +import com.att.authz.org.OrganizationFactory; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class Notification { + + public static final TreeMap> data = new TreeMap>(); + public static final long now = System.currentTimeMillis(); + + public final String user; + public final Notify type; + public final Date last; + public final int checksum; + public Message msg; + private int current; + public Organization org; + public int count; + private long graceEnds,lastdays; + + private Notification(String user, int type, Date last, int checksum) { + this.user = user; + this.type = Notify.from(type); + this.last = last; + this.checksum = checksum; + current = 0; + count = 0; + } + + private Notification(String user, Notify type, Date last, int checksum) { + this.user = user; + this.type = type; + this.last = last; + this.checksum = checksum; + current = 0; + count = 0; + } + + public static void load(Trans trans, Session session, Creator creator ) { + trans.info().log( "query: " + creator.select() ); + TimeTaken tt = trans.start("Load Notify", Env.REMOTE); + + ResultSet results; + try { + Statement stmt = new SimpleStatement(creator.select()); + results = session.execute(stmt); + } finally { + tt.done(); + } + int count = 0; + tt = trans.start("Process Notify", Env.SUB); + + try { + for(Row row : results.all()) { + ++count; + try { + Notification not = creator.create(row); + List ln = data.get(not.user); + if(ln==null) { + ln = new ArrayList(); + data.put(not.user, ln); + } + ln.add(not); + } finally { + tt.done(); + } + } + } finally { + tt.done(); + trans.info().log("Found",count,"Notify Records"); + } + } + + public static Notification get(String user, Notify type) { + List ln = data.get(user); + if(ln!=null) { + for(Notification n : ln) { + if(type.equals(n.type)) { + return n; + } + } + } + return null; + } + + private static Notification getOrCreate(String user, Notify type) { + List ln = data.get(user); + Notification n = null; + if(ln==null) { + ln = new ArrayList(); + data.put(user, ln); + } else { + for(Notification n2 : ln) { + if(type.equals(n2.type)) { + n=n2; + break; + } + } + } + if(n==null) { + n = new Notification(user, type, new Date(), 0); + ln.add(n); + } + return n; + } + + public static Notification add(AuthzTrans trans, UserRole ur) { + Notification n = getOrCreate(ur.user,Notify.RoleExpiration); + if(n.org==null) { + try { + n.org = OrganizationFactory.obtain(trans.env(), ur.ns); + } catch (OrganizationException e) { + trans.error().log(ur.ns, " does not have a Namespace"); + } + } + + if(n.count==0) { + EmailWarnings ew = n.org.emailWarningPolicy(); + n.graceEnds = ew.roleEmailInterval(); + n.lastdays = ew.emailUrgentWarning(); + } + ++n.count; + + /* + StringBuilder sb = new StringBuilder(); + sb.append("ID: "); + sb.append(ur.user); + User ouser; + try { + ouser = n.org.getUser(trans, ur.user); + if(ouser!=null) { + sb.append(" ("); + sb.append(ouser.fullName()); + sb.append(')'); + } + } catch (Exception e) { + } + sb.append(" Role: "); + sb.append(ur.role); + sb.append(" Expire"); + if(now v2_0_14 = new Creator() { + @Override + public Notification create(Row row) { + return new Notification(row.getString(0), row.getInt(1), row.getDate(2),row.getInt(3)); + } + + @Override + public String select() { + return "select user,type,last,checksum from authz.notify"; + } + }; + + public void set(Message msg) { + this.msg = msg; + } + + public int checksum() { + if(current==0) { + for(String l : msg.lines) { + for(byte b : l.getBytes()) { + current+=b; + } + } + } + return current; + } + + public boolean update(AuthzTrans trans, Session session, boolean dryRun) { + String update = update(); + if(update!=null) { + if(dryRun) { + trans.info().log(update); + } else { + session.execute(update); + } + return true; // Updated info, expect to notify + } + return false; + } + + /** + * Returns an Update String for CQL if there is data. + * + * Returns null if nothing to update + * @return + */ + private String update() { + // If this has been done before, there is no change in checkSum and the last time notified is within GracePeriod + if(checksum!=0 && checksum()==checksum && now < last.getTime()+graceEnds && now > last.getTime()+lastdays) { + return null; + } else { + return "UPDATE authz.notify SET last = '" + + Chrono.dateOnlyStamp(last) + + "', checksum=" + + current + + " WHERE user='" + + user + + "' AND type=" + + type.getValue() + + ";"; + } + } + +// public void text(Email email) { +// for(String s : msg) { +// email.line(s); +// } +// } +// + public String toString() { + return "\"" + user + "\",\"" + type.name() + "\",\"" + Chrono.dateOnlyStamp(last); + } +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/helpers/NsAttrib.java b/authz-batch/src/main/java/com/att/authz/helpers/NsAttrib.java new file mode 100644 index 00000000..33de9d85 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/NsAttrib.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.ArrayList; +import java.util.List; +import java.util.TreeMap; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class NsAttrib { + public static final List data = new ArrayList(); + public static final TreeMap> byKey = new TreeMap>(); + public static final TreeMap> byNS = new TreeMap>(); + + public final String ns,key,value; + + public NsAttrib(String ns, String key, String value) { + this.ns = ns; + this.key = key; + this.value = value; + } + + public static void load(Trans trans, Session session, Creator creator ) { + trans.info().log( "query: " + creator.select() ); + ResultSet results; + TimeTaken tt = trans.start("Load NsAttributes", Env.REMOTE); + try { + Statement stmt = new SimpleStatement(creator.select()); + results = session.execute(stmt); + } finally { + tt.done(); + } + int count = 0; + tt = trans.start("Process NsAttributes", Env.SUB); + + try { + for(Row row : results.all()) { + ++count; + NsAttrib ur = creator.create(row); + data.add(ur); + + List lna = byKey.get(ur.key); + if(lna==null) { + lna = new ArrayList(); + byKey.put(ur.key, lna); + } + lna.add(ur); + + lna = byNS.get(ur.ns); + if(lna==null) { + lna = new ArrayList(); + byNS.put(ur.ns, lna); + } + lna.add(ur); + } + } finally { + tt.done(); + trans.info().log("Found",count,"NS Attributes"); + } + } + + public static Creator v2_0_11 = new Creator() { + @Override + public NsAttrib create(Row row) { + return new NsAttrib(row.getString(0), row.getString(1), row.getString(2)); + } + + @Override + public String select() { + return "select ns,key,value from authz.ns_attrib"; + } + }; + + + public String toString() { + return "\"" + ns + "\",\"" + key + "\",\"" + value; + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/helpers/Perm.java b/authz-batch/src/main/java/com/att/authz/helpers/Perm.java new file mode 100644 index 00000000..39092791 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/Perm.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.Iterator; +import java.util.Set; +import java.util.TreeMap; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class Perm implements Comparable { + public static final TreeMap> data = new TreeMap>(); + public static final TreeMap keys = new TreeMap(); + + public final String ns, type, instance, action,description; + private String fullType = null, fullPerm = null, encode = null; + public final Set roles; + + public String encode() { + if(encode == null) { + encode = ns + '|' + type + '|' + instance + '|' + action; + } + return encode; + } + + public String fullType() { + if(fullType==null) { + fullType = ns + '.' + type; + } + return fullType; + } + + public String fullPerm() { + if(fullPerm==null) { + fullPerm = ns + '.' + type + '|' + instance + '|' + action; + } + return fullPerm; + } + + public Perm(String ns, String type, String instance, String action, String description, Set roles) { + this.ns = ns; + this.type = type; + this.instance = instance; + this.action = action; + this.description = description; + // 2.0.11 +// this.full = encode();//ns+'.'+type+'|'+instance+'|'+action; + this.roles = roles; + } + + public static void load(Trans trans, Session session) { + load(trans, session, "select ns, type, instance, action, description, roles from authz.perm;"); + } + + public static void loadOneNS(Trans trans, Session session, String ns) { + load(trans, session, "select ns, type, instance, action, description, roles from authz.perm WHERE ns='" + ns + "';"); + + } + + private static void load(Trans trans, Session session, String query) { + // + trans.info().log( "query: " + query ); + TimeTaken tt = trans.start("Read Perms", Env.REMOTE); + ResultSet results; + try { + Statement stmt = new SimpleStatement( query ); + results = session.execute(stmt); + } finally { + tt.done(); + } + + try { + Iterator iter = results.iterator(); + Row row; + tt = trans.start("Load Perms", Env.SUB); + try { + while(iter.hasNext()) { + row = iter.next(); + Perm pk = new Perm(row.getString(0),row.getString(1),row.getString(2),row.getString(3), row.getString(4), row.getSet(5,String.class)); + keys.put(pk.encode(), pk); + data.put(pk,pk.roles); + } + } finally { + tt.done(); + } + } finally { + trans.info().log("Found",data.size(),"perms"); + } + } + + public String toString() { + return encode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return encode().hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return encode().equals(obj); + } + + @Override + public int compareTo(Perm o) { + return encode().compareTo(o.encode()); + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/helpers/Role.java b/authz-batch/src/main/java/com/att/authz/helpers/Role.java new file mode 100644 index 00000000..f599d561 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/Role.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.TreeMap; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class Role implements Comparable { + public static final TreeMap> data = new TreeMap>(); + public static final TreeMap keys = new TreeMap(); + + public final String ns, name, description; + private String full, encode; + public final Set perms; + + public Role(String full) { + ns = name = description = ""; + this.full = full; + perms = new HashSet(); + } + + public Role(String ns, String name, String description,Set perms) { + this.ns = ns; + this.name = name; + this.description = description; + this.full = null; + this.encode = null; + this.perms = perms; + } + + public String encode() { + if(encode==null) { + encode = ns + '|' + name; + } + return encode; + } + + public String fullName() { + if(full==null) { + full = ns + '.' + name; + } + return full; + } + + public static void load(Trans trans, Session session ) { + load(trans,session,"select ns, name, description, perms from authz.role;"); + } + + public static void loadOneNS(Trans trans, Session session, String ns ) { + load(trans,session,"select ns, name, description, perms from authz.role WHERE ns='" + ns + "';"); + } + + private static void load(Trans trans, Session session, String query) { + trans.info().log( "query: " + query ); + TimeTaken tt = trans.start("Read Roles", Env.REMOTE); + + ResultSet results; + try { + Statement stmt = new SimpleStatement( query ); + results = session.execute(stmt); + } finally { + tt.done(); + } + + try { + Iterator iter = results.iterator(); + Row row; + tt = trans.start("Load Roles", Env.SUB); + try { + while(iter.hasNext()) { + row = iter.next(); + Role rk =new Role(row.getString(0),row.getString(1), row.getString(2),row.getSet(3,String.class)); + keys.put(rk.encode(), rk); + data.put(rk,rk.perms); + } + } finally { + tt.done(); + } + } finally { + trans.info().log("Found",data.size(),"roles"); + } + + + } + public String toString() { + return encode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return encode().hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return encode().equals(obj); + } + + @Override + public int compareTo(Role o) { + return encode().compareTo(o.encode()); + } + + public static String fullName(String role) { + return role.replace('|', '.'); + } +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/helpers/UserRole.java b/authz-batch/src/main/java/com/att/authz/helpers/UserRole.java new file mode 100644 index 00000000..65abc0f6 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/helpers/UserRole.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.helpers; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.TreeMap; + +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class UserRole implements Cloneable { + public static final List data = new ArrayList(); + public static final TreeMap> byUser = new TreeMap>(); + public static final TreeMap> byRole = new TreeMap>(); + + public final String user, role, ns, rname; + public final Date expires; + + public UserRole(String user, String ns, String rname, Date expires) { + this.user = user; + this.role = ns + '.' + rname; + this.ns = ns; + this.rname = rname; + this.expires = expires; + } + + public UserRole(String user, String role, String ns, String rname, Date expires) { + this.user = user; + this.role = role; + this.ns = ns; + this.rname = rname; + this.expires = expires; + } + + public static void load(Trans trans, Session session, Creator creator ) { + load(trans,session,creator,null); + } + + public static void loadOneRole(Trans trans, Session session, Creator creator, String role) { + load(trans,session,creator,"role='" + role +"' ALLOW FILTERING;"); + } + + public static void loadOneUser(Trans trans, Session session, Creator creator, String user ) { + load(trans,session,creator,"role='"+ user +"';"); + } + + private static void load(Trans trans, Session session, Creator creator, String where) { + String query = creator.query(where); + trans.info().log( "query: " + query ); + TimeTaken tt = trans.start("Read UserRoles", Env.REMOTE); + + ResultSet results; + try { + Statement stmt = new SimpleStatement( query ); + results = session.execute(stmt); + } finally { + tt.done(); + } + int count = 0; + try { + Iterator iter = results.iterator(); + Row row; + tt = trans.start("Load UserRole", Env.SUB); + try { + while(iter.hasNext()) { + ++count; + row = iter.next(); + UserRole ur = creator.create(row); + data.add(ur); + + List lur = byUser.get(ur.user); + if(lur==null) { + lur = new ArrayList(); + byUser.put(ur.user, lur); + } + lur.add(ur); + + lur = byRole.get(ur.role); + if(lur==null) { + lur = new ArrayList(); + byRole.put(ur.role, lur); + } + lur.add(ur); + } + } finally { + tt.done(); + } + } finally { + trans.info().log("Found",count,"UserRoles"); + } + + + } + + public static Creator v2_0_11 = new Creator() { + @Override + public UserRole create(Row row) { + return new UserRole(row.getString(0), row.getString(1), row.getString(2),row.getString(3),row.getDate(4)); + } + + @Override + public String select() { + return "select user,role,ns,rname,expires from authz.user_role"; + } + }; + + public UserRoleDAO.Data to() { + UserRoleDAO.Data urd = new UserRoleDAO.Data(); + urd.user = user; + urd.role = role; + urd.ns = ns; + urd.rname = rname; + urd.expires = expires; + return urd; + } + + public String toString() { + return "\"" + user + "\",\"" + role + "\",\"" + ns + "\",\"" + rname + "\",\""+ Chrono.dateOnlyStamp(expires); + } + +} \ No newline at end of file diff --git a/authz-batch/src/main/java/com/att/authz/reports/ApprNotify.java b/authz-batch/src/main/java/com/att/authz/reports/ApprNotify.java new file mode 100644 index 00000000..38567747 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/reports/ApprNotify.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.reports; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import com.att.authz.Batch; +import com.att.authz.actions.Email; +import com.att.authz.actions.Message; +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.Approver; +import com.att.authz.helpers.Notification; +import com.att.authz.layer.Result; +import com.att.authz.org.Organization; +import com.att.authz.org.Organization.Identity; +import com.att.authz.org.OrganizationException; +import com.att.authz.org.OrganizationFactory; +import com.att.dao.CassAccess; +import com.att.dao.aaf.cass.ApprovalDAO; +import com.att.dao.aaf.cass.ApprovalDAO.Data; +import com.att.inno.env.APIException; + +public class ApprNotify extends Batch { + private final ApprovalDAO apprDAO; + private Result> rladd; + private Email email; + + public ApprNotify(AuthzTrans trans) throws APIException, IOException { + super(trans.env()); + apprDAO = new ApprovalDAO(trans, cluster, CassAccess.KEYSPACE); + session = apprDAO.getSession(trans); + rladd = apprDAO.readByStatus(trans,"pending"); + if(isDryRun()) { + email = new Email();//EmailPrint(); + } else { + email = new Email(); + } + email.subject("AAF Approval Notification (ENV: %s)",batchEnv); + email.preamble("AAF is the AT&T System for Fine-Grained Authorizations. " + + "You are being asked to Approve in the %s environment before AAF Actions can be taken. \n\n" + + " Please follow this link:\n\n\t%s/approve" + ,batchEnv,env.getProperty(GUI_URL)); + + Notification.load(trans, session, Notification.v2_0_14); + } + + @Override + protected void run(AuthzTrans trans) { + if(rladd.isOK()) { + if(rladd.isEmpty()) { + trans.warn().log("No Pending Approvals to Process"); + } else { + Organization org=null; + //Map users = new HashMap(); + Map users = new TreeMap(); + + for(Data data : rladd.value) { + // We've already seen this approver. Simply add the new request to him. + try { + Approver approver = users.get(data.approver); + if(approver==null) { + org = OrganizationFactory.obtain(trans.env(), data.approver); + approver = new Approver(data.approver, org); + users.put(data.approver, approver); + } + approver.addRequest(data.user); + } catch (OrganizationException e) { + trans.error().log(e); + } + } + + // Notify + Message msg = new Message(); + for(Approver approver : users.values()) { + try { + Notification n = Notification.addApproval(trans, org.getIdentity(trans, approver.name)); + approver.build(msg); + n.set(msg); + if(n.update(trans, session, isDryRun())) { + Identity user = n.org.getIdentity(trans, approver.name); + email.clear(); + email.addTo(user.email()); + email.msg(msg); + email.exec(trans, n.org); + } + } catch (OrganizationException e) { + trans.error().log(e); + } + } + } + } else { + trans.error().log('[',rladd.status,']',rladd.details); + } + } + + @Override + protected void _close(AuthzTrans trans) { + apprDAO.close(trans); + } + + + +} diff --git a/authz-batch/src/main/java/com/att/authz/reports/CheckCred.java b/authz-batch/src/main/java/com/att/authz/reports/CheckCred.java new file mode 100644 index 00000000..f9d2cfaf --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/reports/CheckCred.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.reports; + +import java.io.IOException; + +import com.att.authz.Batch; +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.Cred; +import com.att.authz.helpers.Cred.Instance; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Chrono; + +public class CheckCred extends Batch{ + + public CheckCred(AuthzTrans trans) throws APIException, IOException { + super(trans.env()); + TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = cluster.connect(); + } finally { + tt.done(); + } + + Cred.load(trans, session); + } + + @Override + protected void run(AuthzTrans trans) { + String query; + for(Cred cred : Cred.data.values()) { + for(Instance inst : cred.instances) { + if(inst.other==0) { + if(dryRun) { + trans.warn().log("Ensuring 'other' is numeric"); + } else { + query = "UPDATE authz.cred SET other=0 WHERE " + + "id='" + cred.id + + "' AND type=" + inst.type + + " AND expires='" + Chrono.dateStamp(inst.expires) + + "';"; + session.execute(query); + trans.warn().log("resetting 'other'",query); + } + } + } + } + + } + /* + /// Evaluate + for(UserRole urKey : UserRole.data) { + NSSplit nss = NS.deriveParent(urKey.role); + if(nss==null && NS.data.size()>0 ) { // there is no Namespace for this UserRole + if(dryRun) { + trans.warn().printf("Would delete %s %s, which has no corresponding Namespace",urKey.user,urKey.role); + } else { + query = "DELETE FROM authz.user_role WHERE " + + "user='" + urKey.user + + "' AND role='" + urKey.role + + "';"; + session.execute(query); + trans.warn().printf("Deleting %s %s, which has no corresponding Namespace",urKey.user,urKey.role); + } + } else if(urKey.ns == null || urKey.rname == null || !urKey.role.equals(urKey.ns+'.'+urKey.rname)) { + if(dryRun) { + trans.warn().log(urKey,"needs to be split and added to Record (", urKey.ns, urKey.rname,")"); + } else { + query = "UPDATE authz.user_role SET ns='" + nss.ns + + "', rname='" + nss.other + + "' WHERE " + + "user='" + urKey.user + + "' AND role='" + urKey.role + + "';"; + session.execute(query); + trans.warn().log("Setting ns and rname",query); + } + } + } + } + */ + @Override + protected void _close(AuthzTrans trans) { + session.close(); + aspr.info("End " + this.getClass().getSimpleName() + " processing" ); + } +} diff --git a/authz-batch/src/main/java/com/att/authz/reports/CheckNS.java b/authz-batch/src/main/java/com/att/authz/reports/CheckNS.java new file mode 100644 index 00000000..36bcd348 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/reports/CheckNS.java @@ -0,0 +1,425 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.reports; + +import java.io.IOException; +import java.util.List; + +import com.att.authz.Batch; +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.NS; +import com.att.authz.helpers.NsAttrib; +import com.att.authz.helpers.Perm; +import com.att.authz.helpers.Role; +import com.att.dao.aaf.cass.NsType; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +public class CheckNS extends Batch{ + + public CheckNS(AuthzTrans trans) throws APIException, IOException { + super(trans.env()); + TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = cluster.connect(); + } finally { + tt.done(); + } + NS.load(trans, session,NS.v2_0_11); + Role.load(trans, session); + Perm.load(trans, session); + NsAttrib.load(trans, session, NsAttrib.v2_0_11); + } + + @Override + protected void run(AuthzTrans trans) { + + String msg; + String query; + trans.info().log(STARS, msg = "Checking for NS type mis-match", STARS); + TimeTaken tt = trans.start(msg, Env.SUB); + try { + for(NS ns : NS.data.values()) { + if(ns.description==null) { + trans.warn().log("Namepace description is null. Changing to empty string."); + if(dryRun) { + trans.warn().log("Namepace description is null. Changing to empty string"); + } else { + query = "UPDATE authz.ns SET description='' WHERE name='" + ns.name +"';"; + session.execute(query); + } + } + int scope = count(ns.name,'.'); + NsType nt; + switch(scope) { + case 0: + nt = NsType.DOT; + break; + case 1: + nt = NsType.ROOT; + break; + case 2: + nt = NsType.COMPANY; + break; + default: + nt = NsType.APP; + break; + } + if(ns.type!=nt.type || ns.scope !=scope) { + if(dryRun) { + trans.warn().log("Namepace",ns.name,"has no type. Should change to ",nt.name()); + } else { + query = "UPDATE authz.ns SET type=" + nt.type + ", scope=" + scope + " WHERE name='" + ns.name +"';"; + trans.warn().log("Namepace",ns.name,"changing to",nt.name()+":",query); + session.execute(query); + } + } + } + } finally { + tt.done(); + } + + + trans.info().log(STARS, msg = "Checking for NS admin/owner mis-match", STARS); + tt = trans.start(msg, Env.SUB); + try { + /// Evaluate + for(NS nk : NS.data.values()) { + //String name; + String roleAdmin = nk.name+"|admin"; + String roleAdminPrev = nk.name+".admin"; + String roleOwner = nk.name+"|owner"; + String roleOwnerPrev = nk.name+".owner"; + String permAll = nk.name+"|access|*|*"; + String permAllPrev = nk.name+".access|*|*"; + String permRead = nk.name+"|access|*|read"; + String permReadPrev = nk.name+".access|*|read"; + // Admins + + Role rk = Role.keys.get(roleAdmin); // accomodate new role key + // Role Admin should exist + if(rk==null) { + if(dryRun) { + trans.warn().log(nk.name + " is missing role: " + roleAdmin); + } else { + query = "INSERT INTO authz.role(ns, name, description, perms) VALUES ('" + + nk.name + + "','admin','Automatic Administration'," + + "{'" + nk.name + "|access|*|*'});"; + session.execute(query); + env.info().log(query); + + + if(Role.keys.get(roleAdminPrev)!=null) { + query = "UPDATE authz.role set perms = perms + " + + "{'" + roleAdminPrev + "'} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='admin'" + + ";"; + session.execute(query); + env.info().log(query); + } + } + } else { + // Role Admin should be linked to Perm All + if(!rk.perms.contains(permAll)) { + if(dryRun) { + trans.warn().log(roleAdmin,"is not linked to",permAll); + } else { + query = "UPDATE authz.role set perms = perms + " + + "{'" + nk.name + "|access|*|*'} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='admin'" + + ";"; + session.execute(query); + env.info().log(query); + + if(rk.perms.contains(permAllPrev)) { + query = "UPDATE authz.role set perms = perms - " + + "{'" + nk.name + ".access|*|*'} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='admin'" + + ";"; + session.execute(query); + env.info().log(query); + } + } + } + // Role Admin should not be linked to Perm Read + if(rk.perms.contains(permRead)) { + if(dryRun) { + trans.warn().log(roleAdmin,"should not be linked to",permRead); + } else { + query = "UPDATE authz.role set perms = perms - " + + "{'" + nk.name + "|access|*|read'} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='admin'" + + ";"; + session.execute(query); + env.info().log(query); + } + } + } + + Perm pk = Perm.keys.get(permAll); + if(pk==null) { + trans.warn().log(nk.name + " is missing perm: " + permAll); + if(!dryRun) { + query = "INSERT INTO authz.perm(ns, type,instance,action,description, roles) VALUES ('" + + nk.name + + "','access','*','*','Namespace Write'," + + "{'" + nk.name + "|admin'});"; + session.execute(query); + env.info().log(query); + + } + } else { + // PermALL should be linked to Role Admin + if(!pk.roles.contains(roleAdmin)) { + trans.warn().log(permAll,"is not linked to",roleAdmin); + if(!dryRun) { + query = "UPDATE authz.perm set roles = roles + " + + "{'" + nk.name + "|admin'} WHERE " + + "ns='"+ pk.ns + "' AND " + + "type='access' AND instance='*' and action='*'" + + ";"; + session.execute(query); + env.info().log(query); + + if(pk.roles.contains(roleAdminPrev)) { + query = "UPDATE authz.perm set roles = roles - " + + "{'" + nk.name + ".admin'} WHERE " + + "ns='"+ pk.ns + "' AND " + + "type='access' AND instance='*' and action='*'" + + ";"; + session.execute(query); + env.info().log(query); + + } + } + } + + // PermALL should be not linked to Role Owner + if(pk.roles.contains(roleOwner)) { + trans.warn().log(permAll,"should not be linked to",roleOwner); + if(!dryRun) { + query = "UPDATE authz.perm set roles = roles - " + + "{'" + nk.name + "|owner'} WHERE " + + "ns='"+ pk.ns + "' AND " + + "type='access' AND instance='*' and action='*'" + + ";"; + session.execute(query); + env.info().log(query); + } + } + + } + + + + // Owner + rk = Role.keys.get(roleOwner); + if(rk==null) { + trans.warn().log(nk.name + " is missing role: " + roleOwner); + if(!dryRun) { + query = "INSERT INTO authz.role(ns, name, description, perms) VALUES('" + + nk.name + + "','owner','Automatic Owners'," + + "{'" + nk.name + "|access|*|read'});"; + session.execute(query); + env.info().log(query); + + } + } else { + // Role Owner should be linked to permRead + if(!rk.perms.contains(permRead)) { + trans.warn().log(roleOwner,"is not linked to",permRead); + if(!dryRun) { + query = "UPDATE authz.role set perms = perms + " + + "{'" + nk.name + "|access|*|read'} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='owner'" + + ";"; + session.execute(query); + env.info().log(query); + + if(rk.perms.contains(permReadPrev)) { + query = "UPDATE authz.role set perms = perms - " + + "{'" + nk.name + ".access|*|read'} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='owner'" + + ";"; + session.execute(query); + env.info().log(query); + + } + } + } + // Role Owner should not be linked to PermAll + if(rk.perms.contains(permAll)) { + trans.warn().log(roleAdmin,"should not be linked to",permAll); + if(!dryRun) { + query = "UPDATE authz.role set perms = perms - " + + "{'" + nk.name + "|access|*|*'} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='admin'" + + ";"; + session.execute(query); + env.info().log(query); + } + } + + } + + pk = Perm.keys.get(permRead); + if(pk==null) { + trans.warn().log(nk.name + " is missing perm: " + permRead); + if(!dryRun) { + query = "INSERT INTO authz.perm(ns, type,instance,action,description, roles) VALUES ('" + + nk.name + + "','access','*','read','Namespace Read'," + + "{'" + nk.name + "|owner'});"; + session.execute(query); + env.info().log(query); + } + } else { + // PermRead should be linked to roleOwner + if(!pk.roles.contains(roleOwner)) { + trans.warn().log(permRead, "is not linked to", roleOwner); + if(!dryRun) { + query = "UPDATE authz.perm set roles = roles + " + + "{'" + nk.name + "|owner'} WHERE " + + "ns='"+ pk.ns + "' AND " + + "type='access' AND instance='*' and action='read'" + + ";"; + session.execute(query); + env.info().log(query); + + if(pk.roles.contains(roleOwnerPrev)) { + query = "UPDATE authz.perm set roles = roles - " + + "{'" + nk.name + ".owner'} WHERE " + + "ns='"+ pk.ns + "' AND " + + "type='access' AND instance='*' and action='read'" + + ";"; + session.execute(query); + env.info().log(query); + + } + } + } + // PermRead should be not linked to RoleAdmin + if(pk.roles.contains(roleAdmin)) { + if(dryRun) { + trans.warn().log(permRead,"should not be linked to",roleAdmin); + } else { + query = "UPDATE authz.perm set roles = roles - " + + "{'" + nk.name + "|admin'} WHERE " + + "ns='"+ pk.ns + "' AND " + + "type='access' AND instance='*' and action='read'" + + ";"; + session.execute(query); + env.info().log(query); + } + } + } + + + int dot = nk.name.lastIndexOf('.'); + String parent; + if(dot<0) { + parent = "."; + } else { + parent = nk.name.substring(0, dot); + } + + if(!parent.equals(nk.parent)) { + if(dryRun) { + trans.warn().log(nk.name + " is missing namespace data"); + } else { + query = "UPDATE authz.ns SET parent='"+parent+"'" + + " WHERE name='" + nk.name + "';"; + session.execute(query); + env.info().log(query); + } + } + + // During Migration: + List swm = NsAttrib.byNS.get(nk.name); + boolean hasSwmV1 = false; + if(swm!=null) {for(NsAttrib na : swm) { + if("swm".equals(na.key) && "v1".equals(na.value)) { + hasSwmV1=true; + break; + } + }} + String roleMem = nk.name+"|member"; + Role rm = Role.keys.get(roleMem); // Accommodate new role key + if(rm==null && hasSwmV1) { + query = "INSERT INTO authz.role(ns, name, description, perms) VALUES ('" + + nk.name + + "','member','Member'," + + "{'" + nk.name + "|access|*|read'});"; + session.execute(query); + query = "UPDATE authz.role set perms = perms + " + + "{'" + nk.name + "|access|*|read'} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='member'" + + ";"; + session.execute(query); + env.info().log(query); + } + if(rm!=null) { + if(!rm.perms.contains(permRead)) { + if(isDryRun()) { + env.info().log(nk.name+"|member needs " + nk.name + "|access|*|read"); + } else { + query = "UPDATE authz.perm set roles = roles + " + + "{'" + nk.name + "|member'} WHERE " + + "ns='"+ pk.ns + "' AND " + + "type='access' AND instance='*' and action='read'" + + ";"; + session.execute(query); + env.info().log(query); + query = "UPDATE authz.role set perms = perms + " + + "{'" + nk.name + "|access|*|read'" + + (hasSwmV1?",'"+nk.name+"|swm.star|*|*'":"") + + "} " + + "WHERE ns='"+ nk.name + "' AND " + + "name='member'" + + ";"; + session.execute(query); + env.info().log(query); + if(hasSwmV1) { + query = "UPDATE authz.perm set roles = roles + " + + "{'" + nk.name + "|member'} WHERE " + + "ns='"+ pk.ns + "' AND " + + "type='swm.star' AND instance='*' and action='*'" + + ";"; + session.execute(query); + env.info().log(query); + } + } + } + } + + + + // Best Guess Owner + +// owner = Role.keys.get(ns.) + } + } finally { + tt.done(); + } + + } + + + @Override + protected void _close(AuthzTrans trans) { + session.close(); + aspr.info("End " + this.getClass().getSimpleName() + " processing" ); + } +} diff --git a/authz-batch/src/main/java/com/att/authz/reports/CheckRolePerm.java b/authz-batch/src/main/java/com/att/authz/reports/CheckRolePerm.java new file mode 100644 index 00000000..ef3d933c --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/reports/CheckRolePerm.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.reports; + +import java.io.IOException; +import java.util.Set; + +import com.att.authz.Batch; +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.NS; +import com.att.authz.helpers.Perm; +import com.att.authz.helpers.Role; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Split; + +public class CheckRolePerm extends Batch{ + + public CheckRolePerm(AuthzTrans trans) throws APIException, IOException { + super(trans.env()); + TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = cluster.connect(); + } finally { + tt.done(); + } + NS.load(trans,session,NS.v2_0_11); + Role.load(trans, session); + Perm.load(trans, session); + } + + @Override + protected void run(AuthzTrans trans) { + // Run for Roles + trans.info().log("Checking for Role/Perm mis-match"); + + String query; + /// Evaluate from Role side + for(Role roleKey : Role.data.keySet()) { + for(String perm : Role.data.get(roleKey)) { + Perm pk = Perm.keys.get(perm); + if(pk==null) { + NS ns=null; + String msg = perm + " in role " + roleKey.fullName() + " does not exist"; + String newPerm; + String[] s = Split.split('|', perm); + if(s.length==3) { + int i; + String find = s[0]; + for(i=find.lastIndexOf('.');ns==null && i>=0;i=find.lastIndexOf('.', i-1)) { + ns = NS.data.get(find.substring(0,i)); + } + if(ns==null) { + newPerm = perm; + } else { + newPerm = ns.name + '|' + s[0].substring(i+1) + '|' + s[1] + '|' + s[2]; + } + } else { + newPerm = perm; + } + if(dryRun) { + if(ns==null) { + trans.warn().log(msg, "- would remove role from perm;"); + } else { + trans.warn().log(msg, "- would update role in perm;"); + } + } else { + if(ns!=null) { + query = "UPDATE authz.role SET perms = perms + {'" + + newPerm + "'}" + + (roleKey.description==null?", description='clean'":"") + + " WHERE " + + "ns='" + roleKey.ns + + "' AND name='" + roleKey.name + "';"; + trans.warn().log("Fixing role in perm",query); + session.execute(query); + } + + query = "UPDATE authz.role SET perms = perms - {'" + + perm.replace("'", "''") + "'}" + + (roleKey.description==null?", description='clean'":"") + + " WHERE " + + "ns='" + roleKey.ns + + "' AND name='" + roleKey.name + "';"; + session.execute(query); + trans.warn().log(msg, "- removing role from perm"); +// env.info().log( "query: " + query ); + } + } else { + Set p_roles = Perm.data.get(pk); + if(p_roles!=null && !p_roles.contains(roleKey.encode())) { + String msg = perm + " does not have role: " + roleKey; + if(dryRun) { + trans.warn().log(msg,"- should add this role to this perm;"); + } else { + query = "update authz.perm set roles = roles + {'" + + roleKey.encode() + "'}" + + (pk.description==null?", description=''":"") + + " WHERE " + + "ns='" + pk.ns + + "' AND type='" + pk.type + + "' AND instance='" + pk.instance + + "' AND action='" + pk.action + + "';"; + session.execute(query); + trans.warn().log(msg,"- adding perm to role"); + } + + } + } + } + } + + for(Perm permKey : Perm.data.keySet()) { + for(String role : Perm.data.get(permKey)) { + Role rk = Role.keys.get(role); + if(rk==null) { + String s = role + " in perm " + permKey.encode() + " does not exist"; + if(dryRun) { + trans.warn().log(s,"- would remove perm from role;"); + } else { + query = "update authz.perm set roles = roles - {'" + + role.replace("'","''") + "'}" + + (permKey.description==null?", description='clean'":"") + + " WHERE " + + "ns='" + permKey.ns + + "' AND type='" + permKey.type + + "' AND instance='" + permKey.instance + + "' AND action='" + permKey.action + "';"; + session.execute(query); + trans.warn().log(s,"- removing role from perm"); + } + } else { + Set r_perms = Role.data.get(rk); + if(r_perms!=null && !r_perms.contains(permKey.encode())) { + String s ="Role '" + role + "' does not have perm: '" + permKey + '\''; + if(dryRun) { + trans.warn().log(s,"- should add this perm to this role;"); + } else { + query = "update authz.role set perms = perms + {'" + + permKey.encode() + "'}" + + (rk.description==null?", description=''":"") + + " WHERE " + + "ns='" + rk.ns + + "' AND name='" + rk.name + "';"; + session.execute(query); + trans.warn().log(s,"- adding role to perm"); + } + } + } + } + } + + } + + + @Override + protected void _close(AuthzTrans trans) { + session.close(); + aspr.info("End " + this.getClass().getSimpleName() + " processing" ); + } +} diff --git a/authz-batch/src/main/java/com/att/authz/reports/CheckUR.java b/authz-batch/src/main/java/com/att/authz/reports/CheckUR.java new file mode 100644 index 00000000..99a2ae5d --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/reports/CheckUR.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.reports; + +import java.io.IOException; + +import com.att.authz.Batch; +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.NS; +import com.att.authz.helpers.NS.NSSplit; +import com.att.authz.helpers.UserRole; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +public class CheckUR extends Batch{ + + public CheckUR(AuthzTrans trans) throws APIException, IOException { + super(trans.env()); + TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = cluster.connect(); + } finally { + tt.done(); + } + NS.load(trans, session,NS.v2_0_11); + UserRole.load(trans, session,UserRole.v2_0_11); + } + + @Override + protected void run(AuthzTrans trans) { + trans.info().log("Get All Namespaces"); + + + String query; + + /// Evaluate + for(UserRole urKey : UserRole.data) { + NSSplit nss = NS.deriveParent(urKey.role); + if(nss==null && NS.data.size()>0 ) { // there is no Namespace for this UserRole + if(dryRun) { + trans.warn().printf("Would delete %s %s, which has no corresponding Namespace",urKey.user,urKey.role); + } else { + query = "DELETE FROM authz.user_role WHERE " + + "user='" + urKey.user + + "' AND role='" + urKey.role + + "';"; + session.execute(query); + trans.warn().printf("Deleting %s %s, which has no corresponding Namespace",urKey.user,urKey.role); + } + } else if(urKey.ns == null || urKey.rname == null || !urKey.role.equals(urKey.ns+'.'+urKey.rname)) { + if(dryRun) { + trans.warn().log(urKey,"needs to be split and added to Record (", urKey.ns, urKey.rname,")"); + } else { + query = "UPDATE authz.user_role SET ns='" + nss.ns + + "', rname='" + nss.other + + "' WHERE " + + "user='" + urKey.user + + "' AND role='" + urKey.role + + "';"; + session.execute(query); + trans.warn().log("Setting ns and rname",query); + } + } + } + } + + @Override + protected void _close(AuthzTrans trans) { + session.close(); + aspr.info("End " + this.getClass().getSimpleName() + " processing" ); + } +} diff --git a/authz-batch/src/main/java/com/att/authz/reports/Expiring.java b/authz-batch/src/main/java/com/att/authz/reports/Expiring.java new file mode 100644 index 00000000..eb420433 --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/reports/Expiring.java @@ -0,0 +1,235 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.reports; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; + +import com.att.authz.Batch; +import com.att.authz.actions.Action; +import com.att.authz.actions.ActionDAO; +import com.att.authz.actions.CredDelete; +import com.att.authz.actions.CredPrint; +import com.att.authz.actions.FADelete; +import com.att.authz.actions.FAPrint; +import com.att.authz.actions.Key; +import com.att.authz.actions.URDelete; +import com.att.authz.actions.URFutureApprove; +import com.att.authz.actions.URFuturePrint; +import com.att.authz.actions.URPrint; +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.Cred; +import com.att.authz.helpers.Cred.Instance; +import com.att.authz.helpers.Future; +import com.att.authz.helpers.Notification; +import com.att.authz.helpers.UserRole; +import com.att.authz.layer.Result; +import com.att.authz.org.Organization.Identity; +import com.att.dao.aaf.cass.CredDAO; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +public class Expiring extends Batch { + + private final Action urDelete,urPrint; + private final Action> urFutureApprove; + private final Action crDelete,crPrint; + private final Action faDelete; +// private final Email email; + private final Key memoKey; + + public Expiring(AuthzTrans trans) throws APIException, IOException { + super(trans.env()); + trans.info().log("Starting Connection Process"); + TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB); + try { + urPrint = new URPrint("Expired:"); + crPrint = new CredPrint("Expired:"); + + URFutureApprove ufr = new URFutureApprove(trans,cluster); + memoKey = ufr; + + if(isDryRun()) { + urDelete = new URPrint("Would Delete:"); + // While Testing +// urFutureApprove = ufr; + urFutureApprove = new URFuturePrint("Would setup Future/Approvals"); + crDelete = new CredPrint("Would Delete:"); + faDelete = new FAPrint("Would Delete:"); +// email = new EmailPrint(); + + TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = cluster.connect(); + } finally { + tt.done(); + } + + } else { + TimeTaken tt = trans.start("Connect to Cluster with DAOs", Env.REMOTE); + try { + ActionDAO adao; + urDelete = adao = new URDelete(trans, cluster); + urFutureApprove = new URFutureApprove(trans,adao); + faDelete = new FADelete(trans, adao); + + crDelete = new CredDelete(trans, adao); +// email = new Email(); + TimeTaken tt2 = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = adao.getSession(trans); + } finally { + tt2.done(); + } + } finally { + tt.done(); + } + } + + UserRole.load(trans, session, UserRole.v2_0_11); + Cred.load(trans, session); + Notification.load(trans, session, Notification.v2_0_14); + Future.load(trans,session,Future.v2_0_15); + } finally { + tt0.done(); + } + } + + @Override + protected void run(AuthzTrans trans) { + // Setup Date boundaries + Date now = new Date(); + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(now); + gc.add(GregorianCalendar.MONTH, 1); + Date future = gc.getTime(); + gc.setTime(now); + gc.add(GregorianCalendar.MONTH, -1); + Date tooLate = gc.getTime(); + int count = 0, deleted=0; + +// List ln = new ArrayList(); + TimeTaken tt; + + // Run for Expired Futures + trans.info().log("Checking for Expired Futures"); + tt = trans.start("Delete old Futures", Env.REMOTE); + try { + List delf = new ArrayList(); + for(Future f : Future.data) { + AuthzTrans localTrans = env.newTransNoAvg(); + if(f.expires.before(now)) { + faDelete.exec(localTrans, f); + delf.add(f); + } + } + Future.delete(delf); + } finally { + tt.done(); + } + + // Run for Roles + trans.info().log("Checking for Expired Roles"); + try { + for(UserRole ur : UserRole.data) { + AuthzTrans localTrans = env.newTransNoAvg(); + if(ur.expires.before(tooLate)) { + if("owner".equals(ur.rname)) { // don't delete Owners, even if Expired + urPrint.exec(localTrans,ur); + } else { + urDelete.exec(localTrans,ur); + ++deleted; + trans.logAuditTrail(trans.info()); + } + ++count; + } else if(ur.expires.before(future)) { + List fbm = Future.byMemo.get(memoKey.key(ur)); + if(fbm==null || fbm.isEmpty()) { + Result> rapprovers = urFutureApprove.exec(localTrans, ur); + if(rapprovers.isOK()) { + for(Identity ou : rapprovers.value) { +// Notification n = Notification.addApproval(localTrans,ou); +// if(n.org==null) { +// n.org = getOrgFromID(localTrans, ur.user); +// } +// ln.add(n); + urPrint.exec(localTrans,ur); + if(isDryRun()) { + trans.logAuditTrail(trans.info()); + } + } + } + } + ++count; + } + } + } finally { + env.info().log("Found",count,"roles expiring before",future); + env.info().log("deleting",deleted,"roles expiring before",tooLate); + } + +// // Email Approval Notification +// email.subject("AAF Role Expiration Warning (ENV: %s)", batchEnv); +// email.indent(""); +// for(Notification n: ln) { +// if(n.org==null) { +// trans.error().log("No Organization for Notification"); +// } else if(n.update(trans, session, isDryRun())) { +// email.clear(); +// email.addTo(n.user); +// email.line(n.text(new StringBuilder()).toString()); +// email.exec(trans,n.org); +// } +// } + // Run for Creds + trans.info().log("Checking for Expired Credentials"); + System.out.flush(); + count = 0; + try { + CredDAO.Data crd = new CredDAO.Data(); + Date last = null; + for( Cred creds : Cred.data.values()) { + AuthzTrans localTrans = env.newTransNoAvg(); + crd.id = creds.id; + for(int type : creds.types()) { + crd.type = type; + for( Instance inst : creds.instances) { + if(inst.expires.before(tooLate)) { + crd.expires = inst.expires; + crDelete.exec(localTrans, crd); + } else if(last==null || inst.expires.after(last)) { + last = inst.expires; + } + } + if(last!=null) { + if(last.before(future)) { + crd.expires = last; + crPrint.exec(localTrans, crd); + ++count; + } + } + } + } + } finally { + env.info().log("Found",count,"current creds expiring before",future); + } + + } + + @Override + protected void _close(AuthzTrans trans) { + aspr.info("End " + this.getClass().getSimpleName() + " processing" ); + for(Action action : new Action[] {urDelete,crDelete}) { + if(action instanceof ActionDAO) { + ((ActionDAO)action).close(trans); + } + } + session.close(); + } + +} diff --git a/authz-batch/src/main/java/com/att/authz/reports/NSDump.java b/authz-batch/src/main/java/com/att/authz/reports/NSDump.java new file mode 100644 index 00000000..bfed2a3f --- /dev/null +++ b/authz-batch/src/main/java/com/att/authz/reports/NSDump.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.reports; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.Date; +import java.util.List; + +import com.att.authz.Batch; +import com.att.authz.env.AuthzTrans; +import com.att.authz.helpers.Cred; +import com.att.authz.helpers.NS; +import com.att.authz.helpers.Perm; +import com.att.authz.helpers.Role; +import com.att.authz.helpers.UserRole; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +public class NSDump extends Batch{ + private PrintStream out = System.out; + private final String ns, admin, owner; + + public NSDump(AuthzTrans trans) throws APIException, IOException { + super(trans.env()); + if(args().length>0) { + ns = args()[0]; + } else { + throw new APIException("NSDump requires \"NS\" parameter"); + } + admin = ns + "|admin"; + owner = ns + "|owner"; + + TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = cluster.connect(); + } finally { + tt.done(); + } + + NS.loadOne(trans, session,NS.v2_0_11,ns); + Role.loadOneNS(trans, session, ns); + if(Role.data.keySet().size()>5) { + UserRole.load(trans, session,UserRole.v2_0_11); + } else { + for(Role r : Role.data.keySet()) { + UserRole.loadOneRole(trans, session, UserRole.v2_0_11, r.fullName()); + } + } + Perm.loadOneNS(trans,session,ns); + Cred.loadOneNS(trans, session, ns); + } + + @Override + protected void run(AuthzTrans trans) { + Date now = new Date(); + for(NS ns : NS.data.values()) { + out.format("# Data for Namespace [%s] - %s\n",ns.name,ns.description); + out.format("ns create %s",ns); + boolean first = true; + List owners = UserRole.byRole.get(owner); + if(owners!=null)for(UserRole ur : owners) { + if(first) { + out.append(' '); + first = false; + } else { + out.append(','); + } + out.append(ur.user); + } + first = true; + List admins = UserRole.byRole.get(admin); + if(admins!=null)for(UserRole ur : admins) { + if(first) { + out.append(' '); + first = false; + } else { + out.append(','); + } + out.append(ur.user); + } + out.println(); + + // Load Creds + Date last; + for(Cred c : Cred.data.values()) { + for(int i : c.types()) { + last = c.last(i); + if(last!=null && now.before(last)) { + switch(i) { + case 1: + out.format(" user cred add %s %s\n", c.id,"new2you!"); + break; + case 200: + out.format(" # CERT needs registering for %s\n", c.id); + break; + default: + out.format(" # Unknown Type for %s\n", c.id); + } + } + } + } + + // Load Roles + for(Role r : Role.data.keySet()) { + if(!"admin".equals(r.name) && !"owner".equals(r.name)) { + out.format(" role create %s\n",r.fullName()); + List lur = UserRole.byRole.get(r.fullName()); + if(lur!=null)for(UserRole ur : lur) { + if(ur.expires.after(now)) { + out.format(" request role user add %s %s\n", ur.role,ur.user); + } + } + } + } + + // Load Perms + for(Perm r : Perm.data.keySet()) { + out.format(" perm create %s.%s %s %s\n",r.ns,r.type,r.instance,r.action); + for(String role : r.roles) { + out.format(" request perm grant %s.%s %s %s %s\n", r.ns,r.type,r.instance,r.action,Role.fullName(role)); + } + } + + } + } + + @Override + protected void _close(AuthzTrans trans) { + session.close(); + aspr.info("End " + this.getClass().getSimpleName() + " processing" ); + } + +} diff --git a/authz-batch/src/main/scripts/SyncV1V2 b/authz-batch/src/main/scripts/SyncV1V2 new file mode 100644 index 00000000..c3a9115a --- /dev/null +++ b/authz-batch/src/main/scripts/SyncV1V2 @@ -0,0 +1,17 @@ +#!/bin/bash +JAVA_HOME=_JAVA_HOME_ +PATH=${PATH}:${JAVA_HOME}/bin +ROOT_DIR=_ROOT_DIR_ + +cd $ROOT_DIR + +CP=${ROOT_DIR}/etc +for FILE in `ls $ROOT_DIR/lib/*.jar`; do + CP=$CP:$FILE +done + +CMD="SyncV1V2" +echo $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog +$JAVA_HOME/bin/java -Xmx2048m -classpath $CP com.att.authz.Batch $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog diff --git a/authz-batch/src/main/scripts/SyncV1V2daily b/authz-batch/src/main/scripts/SyncV1V2daily new file mode 100644 index 00000000..5c89d04d --- /dev/null +++ b/authz-batch/src/main/scripts/SyncV1V2daily @@ -0,0 +1,17 @@ +#!/bin/bash +JAVA_HOME=_JAVA_HOME_ +PATH=${PATH}:${JAVA_HOME}/bin +ROOT_DIR=_ROOT_DIR_ + +cd $ROOT_DIR + +CP=${ROOT_DIR}/etc +for FILE in `ls $ROOT_DIR/lib/*.jar`; do + CP=$CP:$FILE +done + +CMD="SyncV1V2 v1 v2" +echo $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog +$JAVA_HOME/bin/java -Xmx2048m -classpath $CP com.att.authz.Batch $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog diff --git a/authz-batch/src/main/scripts/SyncV2V1 b/authz-batch/src/main/scripts/SyncV2V1 new file mode 100644 index 00000000..e766218f --- /dev/null +++ b/authz-batch/src/main/scripts/SyncV2V1 @@ -0,0 +1,17 @@ +#!/bin/bash +JAVA_HOME=_JAVA_HOME_ +PATH=${PATH}:${JAVA_HOME}/bin +ROOT_DIR=_ROOT_DIR_ + +cd $ROOT_DIR + +CP=${ROOT_DIR}/etc +for FILE in `ls $ROOT_DIR/lib/*.jar`; do + CP=$CP:$FILE +done + +CMD="SyncV2V1" +echo $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog +$JAVA_HOME/bin/java -Xmx2048m -classpath $CP com.att.authz.Batch $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog \ No newline at end of file diff --git a/authz-batch/src/main/scripts/SyncV2V1daily b/authz-batch/src/main/scripts/SyncV2V1daily new file mode 100644 index 00000000..8a676928 --- /dev/null +++ b/authz-batch/src/main/scripts/SyncV2V1daily @@ -0,0 +1,17 @@ +#!/bin/bash +JAVA_HOME=_JAVA_HOME_ +PATH=${PATH}:${JAVA_HOME}/bin +ROOT_DIR=_ROOT_DIR_ + +cd $ROOT_DIR + +CP=${ROOT_DIR}/etc +for FILE in `ls $ROOT_DIR/lib/*.jar`; do + CP=$CP:$FILE +done + +CMD="SyncV2V1 v2 v1" +echo $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog +$JAVA_HOME/bin/java -Xmx2048m -classpath $CP com.att.authz.Batch $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog \ No newline at end of file diff --git a/authz-batch/src/main/scripts/V1daily b/authz-batch/src/main/scripts/V1daily new file mode 100644 index 00000000..9f6c4ca9 --- /dev/null +++ b/authz-batch/src/main/scripts/V1daily @@ -0,0 +1,46 @@ +#!/bin/bash +JAVA_HOME=_JAVA_HOME_ +PATH=${PATH}:${JAVA_HOME}/bin +ROOT_DIR=_ROOT_DIR_ +ENV_CONTEXT=_ENV_CONTEXT_ + +cd $ROOT_DIR + +if [ ! -e "$ROOT_DIR/data/stage" ]; then + mkdir -p $ROOT_DIR/data/stage +fi + +if [ ! -e "$ROOT_DIR/data/$ENV_CONTEXT/stage" ]; then + mkdir -p $ROOT_DIR/data/$ENV_CONTEXT + ln -s $ROOT_DIR/data/stage $ROOT_DIR/data/$ENV_CONTEXT/stage +fi + +CP=${ROOT_DIR}/etc +for FILE in `ls $ROOT_DIR/lib/*.jar`; do + CP=$CP:$FILE +done + +CMD="V1DataFile all" +echo $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog +$JAVA_HOME/bin/java -Xmx2048m -classpath $CP com.att.authz.Batch $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog + +cd $ROOT_DIR/data/stage +LATEST=`ls -tr v1*.dat | tail -1` +if [ "$LATEST" != "" ]; then + > ../v1.lock + cp -p $LATEST ../v1.dat + rm ../v1.lock +fi + +LATEST=`ls -tr v1*.skip | tail -1` +if [ "$LATEST" != "" ]; then + cp -p $LATEST ../v1.skip +fi + +for FILE in `ls v1* | grep -v .gz`; do + gzip $FILE +done + + diff --git a/authz-batch/src/main/scripts/V2daily b/authz-batch/src/main/scripts/V2daily new file mode 100644 index 00000000..c547a949 --- /dev/null +++ b/authz-batch/src/main/scripts/V2daily @@ -0,0 +1,46 @@ +#!/bin/bash +JAVA_HOME=_JAVA_HOME_ +PATH=${PATH}:${JAVA_HOME}/bin +ROOT_DIR=_ROOT_DIR_ +ENV_CONTEXT=_ENV_CONTEXT_ + +cd $ROOT_DIR + +if [ ! -e "$ROOT_DIR/data/stage" ]; then + mkdir -p $ROOT_DIR/data/stage +fi + +if [ ! -e "$ROOT_DIR/data/$ENV_CONTEXT/stage" ]; then + mkdir -p $ROOT_DIR/data/$ENV_CONTEXT + ln -s $ROOT_DIR/data/stage $ROOT_DIR/data/$ENV_CONTEXT/stage +fi + +CP=${ROOT_DIR}/etc +for FILE in `ls $ROOT_DIR/lib/*.jar`; do + CP=$CP:$FILE +done + +CMD="V2DataFile all" +echo $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog +$JAVA_HOME/bin/java -Xmx2048m -classpath $CP com.att.authz.Batch $CMD >> $ROOT_DIR/cronlog +date >> $ROOT_DIR/cronlog + +cd $ROOT_DIR/data/stage +LATEST=`ls -tr v2*.dat | tail -1` +if [ "$LATEST" != "" ]; then + > ../v2.lock + cp -p $LATEST ../v2.dat + rm ../v2.lock +fi + +LATEST=`ls -tr v2*.skip | tail -1` +if [ "$LATEST" != "" ]; then + cp -p $LATEST ../v2.skip +fi + +for FILE in `ls v2* | grep -v .gz`; do + gzip $FILE +done + + diff --git a/authz-batch/src/main/scripts/aafbch b/authz-batch/src/main/scripts/aafbch new file mode 100644 index 00000000..fdeb22ea --- /dev/null +++ b/authz-batch/src/main/scripts/aafbch @@ -0,0 +1,21 @@ +#!/bin/bash +JAVA_HOME=_JAVA_HOME_ +PATH=${PATH}:${JAVA_HOME}/bin +ROOT_DIR=_ROOT_DIR_ +cd $ROOT_DIR + +if [ "$1" = "InnerConsistency" ]; then + CLS=com.att.authz.temp.InnerConsistency + shift +else + CLS=com.att.authz.Batch +fi + +CP=${ROOT_DIR}/etc +for FILE in `ls $ROOT_DIR/lib/*.jar`; do + CP=$CP:$FILE +done + +date +$JAVA_HOME/bin/java -Xmx2048m -classpath $CP $CLS $* +date diff --git a/authz-batch/src/main/scripts/run_batch b/authz-batch/src/main/scripts/run_batch new file mode 100644 index 00000000..c09ea0a3 --- /dev/null +++ b/authz-batch/src/main/scripts/run_batch @@ -0,0 +1,16 @@ +#!/bin/env bash + +if [[ $# < 1 ]]; then + echo "USAGE: run_batch ExpiryNotification|ApprNotify|JobChange|RoleExpiration|ValidateUsers" + exit 1; +fi + +JAVA_HOME=_JAVA_HOME_ +AAF_CP="_ROOT_DIR_/etc" +for JAR in `find _ROOT_DIR_/lib -name *.jar` ; do + AAF_CP="$AAF_CP:$JAR" +done + +$JAVA_HOME/bin/java -cp $AAF_CP com.att.authz.Batch $* + + diff --git a/authz-cass/.gitignore b/authz-cass/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-cass/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-cass/pom.xml b/authz-cass/pom.xml new file mode 100644 index 00000000..266485a5 --- /dev/null +++ b/authz-cass/pom.xml @@ -0,0 +1,155 @@ + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-cass + Authz Cass + Cassandra DAOs for Authz + jar + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + + com.att.authz + authz-core + + + + com.att.cadi + cadi-aaf + + + + com.datastax.cassandra + cassandra-driver-core + + + + + org.xerial.snappy + snappy-java + 1.1.1-M1 + + + + net.jpountz.lz4 + lz4 + 1.2.0 + + + + com.googlecode.jcsv + jcsv + 1.4.0 + + + + org.slf4j + slf4j-log4j12 + test + + + + + + + + org.apache.maven.plugins + maven-jarsigner-plugin + + + org.apache.maven.plugins + maven-deploy-plugin + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + diff --git a/authz-cass/src/main/cql/ecomp.cql b/authz-cass/src/main/cql/ecomp.cql new file mode 100644 index 00000000..967d6daf --- /dev/null +++ b/authz-cass/src/main/cql/ecomp.cql @@ -0,0 +1,118 @@ +// +// Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +// +USE authz; + +// Create Root pass +INSERT INTO cred (id,ns,type,cred,expires) + VALUES ('dgl@openecomp.org','org.openecomp',1,0xab3831f27b39d7a039f9a92aa2bbfe51,'2020-12-31'); + +// Create 'com' root NS +INSERT INTO ns (name,scope,description,parent,type) + VALUES('com',1,'Root Namespace',null,1); + +INSERT INTO role(ns, name, perms, description) + VALUES('com','admin',{'com.access|*|*'},'Com Admins'); + +INSERT INTO role(ns, name, perms, description) + VALUES('com','owner',{'com.access|*|read'},'Com Owners'); + +INSERT INTO perm(ns, type, instance, action, roles, description) + VALUES ('com','access','*','read',{'com.owner'},'Com Read Access'); + +INSERT INTO perm(ns, type, instance, action, roles, description) + VALUES ('com','access','*','*',{'com.admin'},'Com Write Access'); + +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','com.owner','2020-12-31','com','owner'); + +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','com.admin','2020-12-31','com','admin'); + +// Create org root NS +INSERT INTO ns (name,scope,description,parent,type) + VALUES('org',1,'Root Namespace Org',null,1); + +INSERT INTO role(ns, name, perms, description) + VALUES('org','admin',{'org.access|*|*'},'Com Admins'); + +INSERT INTO role(ns, name, perms, description) + VALUES('org','owner',{'org.access|*|read'},'Com Owners'); + +INSERT INTO perm(ns, type, instance, action, roles, description) + VALUES ('org','access','*','read',{'org.owner'},'Com Read Access'); + +INSERT INTO perm(ns, type, instance, action, roles, description) + VALUES ('org','access','*','*',{'org.admin'},'Com Write Access'); + +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','org.owner','2020-12-31','org','owner'); + +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','org.admin','2020-12-31','org','admin'); + + +// Create com.att + +INSERT INTO ns (name,scope,description,parent,type) + VALUES('com.att',2,'AT&T Namespace','com',2); + +INSERT INTO role(ns, name, perms,description) + VALUES('com.att','admin',{'com.att.access|*|*'},'AT&T Admins'); + +INSERT INTO role(ns, name, perms,description) + VALUES('com.att','owner',{'com.att.access|*|read'},'AT&T Owners'); + +INSERT INTO perm(ns, type, instance, action, roles,description) + VALUES ('com.att','access','*','read',{'com.att.owner'},'AT&T Read Access'); + +INSERT INTO perm(ns, type, instance, action, roles,description) + VALUES ('com.att','access','*','*',{'com.att.admin'},'AT&T Write Access'); + +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','com.att.owner','2020-12-31','com.att','owner'); + +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','com.att.admin','2020-12-31','com.att','admin'); + +// Create com.att.aaf + +INSERT INTO ns (name,scope,description,parent,type) + VALUES('com.att.aaf',3,'Application Authorization Framework','com.att',3); + +INSERT INTO role(ns, name, perms, description) + VALUES('com.att.aaf','admin',{'com.att.aaf.access|*|*'},'AAF Admins'); + +INSERT INTO role(ns, name, perms, description) + VALUES('com.att.aaf','owner',{'com.att.aaf.access|*|read'},'AAF Owners'); + +INSERT INTO perm(ns, type, instance, action, roles, description) + VALUES ('com.att.aaf','access','*','read',{'com.att.aaf.owner'},'AAF Read Access'); + +INSERT INTO perm(ns, type, instance, action, roles, description) + VALUES ('com.att.aaf','access','*','*',{'com.att.aaf.admin'},'AAF Write Access'); + +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','com.att.aaf.admin','2020-12-31','com.att.aaf','admin'); +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','com.att.aaf.owner','2020-12-31','com.att.aaf','owner'); + + +// Create org.openecomp +INSERT INTO ns (name,scope,description,parent,type) + VALUES('org.openecomp',2,'Open EComp NS','com.att',2); + +INSERT INTO role(ns, name, perms, description) + VALUES('org.openecomp','admin',{'org.openecomp.access|*|*'},'OpenEcomp Admins'); + +INSERT INTO role(ns, name, perms, description) + VALUES('org.openecomp','owner',{'org.openecomp.access|*|read'},'OpenEcomp Owners'); + +INSERT INTO perm(ns, type, instance, action, roles, description) + VALUES ('org.openecomp','access','*','read',{'org.openecomp.owner'},'OpenEcomp Read Access'); + +INSERT INTO perm(ns, type, instance, action, roles, description) + VALUES ('org.openecomp','access','*','*',{'org.openecomp.admin'},'OpenEcomp Write Access'); + +INSERT INTO user_role(user,role,expires,ns,rname) + VALUES ('dgl@openecomp.org','org.openecomp.admin','2020-12-31','org.openecomp','admin'); diff --git a/authz-cass/src/main/cql/init.cql b/authz-cass/src/main/cql/init.cql new file mode 100644 index 00000000..3b2688a6 --- /dev/null +++ b/authz-cass/src/main/cql/init.cql @@ -0,0 +1,212 @@ +// +// Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +// +// For Developer Machine single instance +// + CREATE KEYSPACE authz + WITH REPLICATION = {'class' : 'SimpleStrategy','replication_factor':1}; + +USE authz; + +// +// CORE Table function +// + +// Namespace - establish hierarchical authority to modify +// Permissions and Roles +// "scope" is flag to determine Policy. Typical important scope +// is "company" (1) +CREATE TABLE ns ( + name varchar, + scope int, // deprecated 2.0.11 + description varchar, + parent varchar, + type int, + PRIMARY KEY (name) +); +CREATE INDEX ns_parent on ns(parent); + + +CREATE TABLE ns_attrib ( + ns varchar, + key varchar, + value varchar, + PRIMARY KEY (ns,key) +); +create index ns_attrib_key on ns_attrib(key); + +// Will be cached +CREATE TABLE role ( + ns varchar, + name varchar, + perms set, // Use "Key" of "name|type|action" + description varchar, + PRIMARY KEY (ns,name) +); +CREATE INDEX role_name ON role(name); + +// Will be cached +CREATE TABLE perm ( + ns varchar, + type varchar, + instance varchar, + action varchar, + roles set, // Need to find Roles given Permissions + description varchar, + PRIMARY KEY (ns,type,instance,action) +); + +// This table is user for Authorization +CREATE TABLE user_role ( + user varchar, + role varchar, // deprecated: change to ns/rname after 2.0.11 + ns varchar, + rname varchar, + expires timestamp, + PRIMARY KEY(user,role) + ); +CREATE INDEX user_role_ns ON user_role(ns); +CREATE INDEX user_role_role ON user_role(role); + +// This table is only for the case where return User Credential (MechID) Authentication +CREATE TABLE cred ( + id varchar, + type int, + expires timestamp, + ns varchar, + other int, + notes varchar, + cred blob, + prev blob, + PRIMARY KEY (id,type,expires) + ); +CREATE INDEX cred_ns ON cred(ns); + +// Certificate Cross Table +// coordinated with CRED type 2 +CREATE TABLE cert ( + fingerprint blob, + id varchar, + x500 varchar, + expires timestamp, + PRIMARY KEY (fingerprint) + ); +CREATE INDEX cert_id ON cert(id); +CREATE INDEX cert_x500 ON cert(x500); + +CREATE TABLE notify ( + user text, + type int, + last timestamp, + checksum int, + PRIMARY KEY (user,type) +); + +CREATE TABLE x509 ( + ca text, + serial blob, + id text, + x500 text, + x509 text, + PRIMARY KEY (ca,serial) +); + + +CREATE INDEX x509_id ON x509 (id); +CREATE INDEX x509_x500 ON x509 (x500); + +// +// Deployment Artifact (for Certman) +// +CREATE TABLE artifact ( + mechid text, + machine text, + type Set, + sponsor text, + ca text, + dir text, + appName text, + os_user text, + notify text, + expires timestamp, + renewDays int, + PRIMARY KEY (mechid,machine) +); +CREATE INDEX artifact_machine ON artifact(machine); + +// +// Non-Critical Table functions +// +// Table Info - for Caching +CREATE TABLE cache ( + name varchar, + seg int, // cache Segment + touched timestamp, + PRIMARY KEY(name,seg) +); + +CREATE TABLE history ( + id timeuuid, + yr_mon int, + user varchar, + action varchar, + target varchar, // user, user_role, + subject varchar, // field for searching main portion of target key + memo varchar, //description of the action + reconstruct blob, //serialized form of the target + // detail Map, // additional information + PRIMARY KEY (id) +); +CREATE INDEX history_yr_mon ON history(yr_mon); +CREATE INDEX history_user ON history(user); +CREATE INDEX history_subject ON history(subject); + +// +// A place to hold objects to be created at a future time. +// +CREATE TABLE future ( + id uuid, // uniquify + target varchar, // Target Table + memo varchar, // Description + start timestamp, // When it should take effect + expires timestamp, // When not longer valid + construct blob, // How to construct this object (like History) + PRIMARY KEY(id) +); +CREATE INDEX future_idx ON future(target); +CREATE INDEX future_start_idx ON future(start); + + +CREATE TABLE approval ( + id timeuuid, // unique Key + ticket uuid, // Link to Future Record + user varchar, // the user who needs to be approved + approver varchar, // user approving + type varchar, // approver types i.e. Supervisor, Owner + status varchar, // approval status. pending, approved, denied + memo varchar, // Text for Approval to know what's going on + operation varchar, // List operation to perform + PRIMARY KEY(id) + ); +CREATE INDEX appr_approver_idx ON approval(approver); +CREATE INDEX appr_user_idx ON approval(user); +CREATE INDEX appr_ticket_idx ON approval(ticket); +CREATE INDEX appr_status_idx ON approval(status); + +CREATE TABLE delegate ( + user varchar, + delegate varchar, + expires timestamp, + PRIMARY KEY (user) +); +CREATE INDEX delg_delg_idx ON delegate(delegate); + +// +// Used by authz-batch processes to ensure only 1 runs at a time +// +CREATE TABLE run_lock ( + class text, + host text, + start timestamp, + PRIMARY KEY ((class)) +); diff --git a/authz-cass/src/main/java/com/att/dao/AbsCassDAO.java b/authz-cass/src/main/java/com/att/dao/AbsCassDAO.java new file mode 100644 index 00000000..2ea4e6ec --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/AbsCassDAO.java @@ -0,0 +1,497 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Deque; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedDeque; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.Status; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.TransStore; +import com.datastax.driver.core.BoundStatement; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ConsistencyLevel; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.ResultSetFuture; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.exceptions.DriverException; + +public abstract class AbsCassDAO { + protected static final char DOT = '.'; + protected static final char DOT_PLUS_ONE = '.'+1; + protected static final String FIRST_CHAR = Character.toString((char)0); + protected static final String LAST_CHAR = Character.toString((char)Character.MAX_VALUE); + protected static final int FIELD_COMMAS = 0; + protected static final int QUESTION_COMMAS = 1; + protected static final int ASSIGNMENT_COMMAS = 2; + protected static final int WHERE_ANDS = 3; + + private Cluster cluster; + private Session session; + private final String keyspace; + // If this is null, then we own session + private final AbsCassDAO owningDAO; + protected Class dataClass; + private final String name; + private static Slot sessionSlot; + //private static final ArrayList.PSInfo> psinfos = new ArrayList.PSInfo>(); + private static final ArrayList.PSInfo> psinfos = new ArrayList.PSInfo>(); + private static final List EMPTY = new ArrayList(0); + private static final Deque resetDeque = new ConcurrentLinkedDeque(); + private static boolean resetTrigger = false; + private static long nextAvailableReset = 0; + + + public AbsCassDAO(TRANS trans, String name, Cluster cluster, String keyspace, Class dataClass) { + this.name = name; + this.cluster = cluster; + this.keyspace = keyspace; + owningDAO = null; // we own session + session = null; + this.dataClass = dataClass; + + } + + public AbsCassDAO(TRANS trans, String name, AbsCassDAO aDao, Class dataClass) { + this.name = name; + cluster = aDao.cluster; + keyspace = aDao.keyspace; + session = null; + owningDAO = aDao; // We do not own session + this.dataClass = dataClass; + } + + public static void setSessionSlot(Slot slot) { + sessionSlot = slot; + } + + //Note: Lower case ON PURPOSE. These names used to create History Messages + public enum CRUD { + create,read,update,delete + ; + +} + + public class PSInfo { + private BoundStatement ps; + private final int size; + private final Loader loader; + private final CRUD crud; // Store CRUD, because it makes a difference in Object Order, see Loader + private final String cql; + private final ConsistencyLevel consistency; + + + /** + * Create a PSInfo and create Prepared Statement + * + * @param trans + * @param theCQL + * @param loader + */ + public PSInfo(TRANS trans, String theCQL, Loader loader, ConsistencyLevel consistency) { + this.loader = loader; + this.consistency=consistency; + psinfos.add(this); + + cql = theCQL.trim().toUpperCase(); + if(cql.startsWith("INSERT")) { + crud = CRUD.create; + } else if(cql.startsWith("UPDATE")) { + crud = CRUD.update; + } else if(cql.startsWith("DELETE")) { + crud = CRUD.delete; + } else { + crud = CRUD.read; + } + + int idx = 0, count=0; + while((idx=cql.indexOf('?',idx))>=0) { + ++idx; + ++count; + } + size=count; + } + + public synchronized void reset() { + ps = null; + } + + private BoundStatement ps(TransStore trans) throws APIException, IOException { + if(ps==null) { + synchronized(this) { + if(ps==null) { + TimeTaken tt = trans.start("Preparing PSInfo " + crud.toString().toUpperCase() + " on " + name,Env.SUB); + try { + ps = new BoundStatement(getSession(trans).prepare(cql)); + ps.setConsistencyLevel(consistency); + } catch (DriverException e) { + reportPerhapsReset(trans,e); + throw e; + } finally { + tt.done(); + } + } + } + } + return ps; + } + + /** + * Execute a Prepared Statement by extracting from DATA object + * + * @param trans + * @param text + * @param data + * @return + */ + public Result execAsync(TRANS trans, String text, DATA data) { + TimeTaken tt = trans.start(text, Env.REMOTE); + try { + return Result.ok(getSession(trans).executeAsync( + ps(trans).bind(loader.extract(data, size, crud)))); + } catch (DriverException | APIException | IOException e) { + AbsCassDAO.this.reportPerhapsReset(trans,e); + return Result.err(Status.ERR_Backend,"%s-%s executing %s",e.getClass().getName(),e.getMessage(), cql); + } finally { + tt.done(); + } + } + + /** + * Execute a Prepared Statement on Object[] key + * + * @param trans + * @param text + * @param objs + * @return + */ + public Result execAsync(TRANS trans, String text, Object ... objs) { + TimeTaken tt = trans.start(text, Env.REMOTE); + try { + return Result.ok(getSession(trans).executeAsync(ps(trans).bind(objs))); + } catch (DriverException | APIException | IOException e) { + AbsCassDAO.this.reportPerhapsReset(trans,e); + return Result.err(Status.ERR_Backend,"%s-%s executing %s",e.getClass().getName(),e.getMessage(), cql); + } finally { + tt.done(); + } + } + + /* + * Note: + * + */ + + /** + * Execute a Prepared Statement by extracting from DATA object + * + * @param trans + * @param text + * @param data + * @return + */ + public Result exec(TRANS trans, String text, DATA data) { + TimeTaken tt = trans.start(text, Env.REMOTE); + try { + /* + * "execute" (and executeAsync) + * Executes the provided query. + This method blocks until at least some result has been received from the database. However, + for SELECT queries, it does not guarantee that the result has been received in full. But it + does guarantee that some response has been received from the database, and in particular + guarantee that if the request is invalid, an exception will be thrown by this method. + + Parameters: + statement - the CQL query to execute (that can be any Statement). + Returns: + the result of the query. That result will never be null but can be empty (and will + be for any non SELECT query). + */ + return Result.ok(getSession(trans).execute( + ps(trans).bind(loader.extract(data, size, crud)))); + } catch (DriverException | APIException | IOException e) { + AbsCassDAO.this.reportPerhapsReset(trans,e); + return Result.err(Status.ERR_Backend,"%s-%s executing %s",e.getClass().getName(),e.getMessage(), cql); + } finally { + tt.done(); + } + } + + /** + * Execute a Prepared Statement on Object[] key + * + * @param trans + * @param text + * @param objs + * @return + */ + public Result exec(TRANS trans, String text, Object ... objs) { + TimeTaken tt = trans.start(text, Env.REMOTE); + try { + return Result.ok(getSession(trans).execute(ps(trans).bind(objs))); + } catch (DriverException | APIException | IOException e) { + AbsCassDAO.this.reportPerhapsReset(trans,e); + return Result.err(Status.ERR_Backend,"%s-%s executing %s",e.getClass().getName(),e.getMessage(), cql); + } finally { + tt.done(); + } + } + + /** + * Read the Data from Cassandra given a Prepared Statement (defined by the + * DAO Instance) + * + * This is common behavior among all DAOs. + * @throws DAOException + */ + public Result> read(TRANS trans, String text, Object[] key) { + TimeTaken tt = trans.start(text,Env.REMOTE); + + ResultSet rs; + try { + rs = getSession(trans).execute(key==null?ps(trans):ps(trans).bind(key)); +/// TEST CODE for Exception +// boolean force = true; +// if(force) { +// Map misa = new HashMap(); +// //misa.put(new InetSocketAddress(444),new Exception("no host was tried")); +// misa.put(new InetSocketAddress(444),new Exception("Connection has been closed")); +// throw new com.datastax.driver.core.exceptions.NoHostAvailableException(misa); +//// throw new com.datastax.driver.core.exceptions.AuthenticationException(new InetSocketAddress(9999),"no host was tried"); +// } +//// END TEST CODE + } catch (DriverException | APIException | IOException e) { + AbsCassDAO.this.reportPerhapsReset(trans,e); + return Result.err(Status.ERR_Backend,"%s-%s executing %s",e.getClass().getName(),e.getMessage(), cql); + } finally { + tt.done(); + } + + return extract(loader,rs,null /*let Array be created if necessary*/,dflt); + } + + public Result> read(TRANS trans, String text, DATA data) { + return read(trans,text, loader.extract(data, size, crud)); + } + + public Object[] keyFrom(DATA data) { + return loader.extract(data, size, CRUD.delete); // Delete is key only + } + + /* + * Note: in case PSInfos are deleted, we want to remove them from list. This is not expected, + * but we don't want a data leak if it does. Finalize doesn't have to happen quickly + */ + @Override + protected void finalize() throws Throwable { + psinfos.remove(this); + } + } + + protected final Accept dflt = new Accept() { + @Override + public boolean ok(DATA data) { + return true; + } + }; + + + @SuppressWarnings("unchecked") + protected final Result> extract(Loader loader, ResultSet rs, List indata, Accept accept) { + List rows = rs.all(); + if(rows.isEmpty()) { + return Result.ok((List)EMPTY); // Result sets now .emptyList(true); + } else { + DATA d; + List data = indata==null?new ArrayList(rows.size()):indata; + + for(Row row : rows) { + try { + d = loader.load(dataClass.newInstance(),row); + if(accept.ok(d)) { + data.add(d); + } + } catch(Exception e) { + return Result.err(e); + } + } + return Result.ok(data); + } + } + + private static final String NEW_CASSANDRA_SESSION_CREATED = "New Cassandra Session Created"; + private static final String NEW_CASSANDRA_CLUSTER_OBJECT_CREATED = "New Cassandra Cluster Object Created"; + private static final String NEW_CASSANDRA_SESSION = "New Cassandra Session"; + + private static class ResetRequest { + //package on purpose + Session session; + long timestamp; + + public ResetRequest(Session session) { + this.session = session; + timestamp = System.currentTimeMillis(); + } + } + + + public static final void primePSIs(TransStore trans) throws APIException, IOException { + for(AbsCassDAO.PSInfo psi : psinfos) { + if(psi.ps==null) { + psi.ps(trans); + } + } + } + + public final Session getSession(TransStore trans) throws APIException, IOException { + // Try to use Trans' session, if exists + if(sessionSlot!=null) { // try to get from Trans + Session sess = trans.get(sessionSlot, null); + if(sess!=null) { + return sess; + } + } + + // If there's an owning DAO, use it's session + if(owningDAO!=null) { + return owningDAO.getSession(trans); + } + + // OK, nothing else works... get our own. + if(session==null || resetTrigger) { + Cluster tempCluster = null; + Session tempSession = null; + try { + synchronized(NEW_CASSANDRA_SESSION_CREATED) { + boolean reset = false; + for(ResetRequest r : resetDeque) { + if(r.session == session) { + if(r.timestamp>nextAvailableReset) { + reset=true; + nextAvailableReset = System.currentTimeMillis() + 60000; + tempCluster = cluster; + tempSession = session; + break; + } else { + trans.warn().log("Cassandra Connection Reset Ignored: Recent Reset"); + } + } + } + + if(reset || session == null) { + TimeTaken tt = trans.start(NEW_CASSANDRA_SESSION, Env.SUB); + try { + // Note: Maitrayee recommended not closing the cluster, just + // overwrite it. 9/30/2016 assuming same for Session + // This was a bad idea. Ran out of File Handles as I suspected.. + if(reset) { + for(AbsCassDAO.PSInfo psi : psinfos) { + psi.reset(); + } + } + if(reset || cluster==null) { + cluster = CassAccess.cluster(trans, keyspace); + trans.warn().log(NEW_CASSANDRA_CLUSTER_OBJECT_CREATED); + } + if(reset || session==null) { + session = cluster.connect(keyspace); + trans.warn().log(NEW_CASSANDRA_SESSION_CREATED); + } + } finally { + resetTrigger=false; + tt.done(); + } + } + } + } finally { + TimeTaken tt = trans.start("Clear Reset Deque", Env.SUB); + try { + resetDeque.clear(); + // Not clearing Session/Cluster appears to kill off FileHandles + if(tempSession!=null && !tempSession.isClosed()) { + tempSession.close(); + } + if(tempCluster!=null && !tempCluster.isClosed()) { + tempCluster.close(); + } + } finally { + tt.done(); + } + } + } + return session; + } + + public final boolean reportPerhapsReset(TransStore trans, Exception e) { + if(owningDAO!=null) { + return owningDAO.reportPerhapsReset(trans, e); + } else { + boolean rv = false; + if(CassAccess.isResetException(e)) { + trans.warn().printf("Session Reset called for %s by %s ",session==null?"":session,e==null?"Mgmt Command":e.getClass().getName()); + resetDeque.addFirst(new ResetRequest(session)); + rv = resetTrigger = true; + } + trans.error().log(e); + return rv; + } + } + + public void close(TransStore trans) { + if(owningDAO==null) { + if(session!=null) { + TimeTaken tt = trans.start("Cassandra Session Close", Env.SUB); + try { + session.close(); + } finally { + tt.done(); + } + session = null; + } else { + trans.debug().log("close called(), Session already closed"); + } + } else { + owningDAO.close(trans); + } + } + + protected void wasModified(TRANS trans, CRUD modified, DATA data, String ... override) { + } + + protected interface Accept { + public boolean ok(DATA data); + } + +} + + + diff --git a/authz-cass/src/main/java/com/att/dao/Bytification.java b/authz-cass/src/main/java/com/att/dao/Bytification.java new file mode 100644 index 00000000..b563be98 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/Bytification.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public interface Bytification { + public ByteBuffer bytify() throws IOException; + public void reconstitute(ByteBuffer bb) throws IOException; +} diff --git a/authz-cass/src/main/java/com/att/dao/CIDAO.java b/authz-cass/src/main/java/com/att/dao/CIDAO.java new file mode 100644 index 00000000..ee5e611a --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/CIDAO.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.util.Date; + +import com.att.authz.layer.Result; +import com.att.inno.env.Trans; + +public interface CIDAO { + + /** + * Touch the date field for given Table + * + * @param trans + * @param name + * @return + */ + public abstract Result touch(TRANS trans, String name, int ... seg); + + /** + * Read all Info entries, and set local Date objects + * + * This is to support regular data checks on the Database to speed up Caching behavior + * + */ + public abstract Result check(TRANS trans); + + public abstract Date get(TRANS trans, String table, int seg); + +} diff --git a/authz-cass/src/main/java/com/att/dao/Cacheable.java b/authz-cass/src/main/java/com/att/dao/Cacheable.java new file mode 100644 index 00000000..71b48962 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/Cacheable.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; +/** + * Interface to obtain Segment Integer from DAO Data + * for use in Caching mechanism + * + * This should typically be obtained by getting the Hash of the key, then using modulus on the size of segment. + * + * + */ +public interface Cacheable { + public int[] invalidate(Cached cache); +} diff --git a/authz-cass/src/main/java/com/att/dao/Cached.java b/authz-cass/src/main/java/com/att/dao/Cached.java new file mode 100644 index 00000000..2cdd2b21 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/Cached.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cache.Cache; +import com.att.dao.aaf.cass.Status; +import com.att.inno.env.Env; +import com.att.inno.env.Trans; + +public class Cached extends Cache { + // Java does not allow creation of Arrays with Generics in them... + // private Map cache[]; + protected final CIDAO info; + + private static Timer infoTimer; + private Object cache[]; + public final int segSize; + + protected final String name; + + + + // Taken from String Hash, but coded, to ensure consistent across Java versions. Also covers negative case; + public int cacheIdx(String key) { + int h = 0; + for (int i = 0; i < key.length(); i++) { + h = 31*h + key.charAt(i); + } + if(h<0)h*=-1; + return h%segSize; + } + + public Cached(CIDAO info, String name, int segSize) { + this.name =name; + this.segSize = segSize; + this.info = info; + cache = new Object[segSize]; + // Create a new Map for each Segment, and store locally + for(int i=0;i data) { + @SuppressWarnings("unchecked") + Map map = ((Map)cache[cacheIdx(key)]); + map.put(key, new Dated(data)); + } + + + public int invalidate(String key) { + int cacheIdx = cacheIdx(key); + @SuppressWarnings("unchecked") + Map map = ((Map)cache[cacheIdx]); +// if(map.remove(key)!=null) // Not seeming to remove all the time + if(map!=null)map.clear(); +// System.err.println("Remove " + name + " " + key); + return cacheIdx; + } + + public Result invalidate(int segment) { + if(segment<0 || segment>=cache.length) return Result.err(Status.ERR_BadData,"Cache Segment %s is out of range",Integer.toString(segment)); + @SuppressWarnings("unchecked") + Map map = ((Map)cache[segment]); + if(map!=null) { + map.clear(); + } + return Result.ok(); + } + + protected interface Getter { + public abstract Result> get(); + }; + + // TODO utilize Segmented Caches, and fold "get" into "reads" + @SuppressWarnings("unchecked") + public Result> get(TRANS trans, String key, Getter getter) { + List ld = null; + Result> rld = null; + + int cacheIdx = cacheIdx(key); + Map map = ((Map)cache[cacheIdx]); + + // Check for saved element in cache + Dated cached = map.get(key); + // Note: These Segment Timestamps are kept up to date with DB + Date dbStamp = info.get(trans, name,cacheIdx); + + // Check for cache Entry and whether it is still good (a good Cache Entry is same or after DBEntry, so we use "before" syntax) + if(cached!=null && dbStamp.before(cached.timestamp)) { + ld = (List)cached.data; + rld = Result.ok(ld); + } else { + rld = getter.get(); + if(rld.isOK()) { // only store valid lists + map.put(key, new Dated(rld.value)); // successful item found gets put in cache +// } else if(rld.status == Result.ERR_Backend){ +// map.remove(key); + } + } + return rld; + } + + /** + * Each Cached object has multiple Segments that need cleaning. Derive each, and add to Cleansing Thread + * @param env + * @param dao + */ + public static void startCleansing(AuthzEnv env, CachedDAO ... dao) { + for(CachedDAO d : dao) { + for(int i=0;i void startRefresh(AuthzEnv env, CIDAO cidao) { + if(infoTimer==null) { + infoTimer = new Timer("CachedDAO Info Refresh Timer"); + int minRefresh = 10*1000*60; // 10 mins Integer.parseInt(env.getProperty(CACHE_MIN_REFRESH_INTERVAL,"2000")); // 2 second minimum refresh + infoTimer.schedule(new Refresh(env,cidao, minRefresh), 1000, minRefresh); // note: Refresh from DB immediately + } + } + + public static void stopTimer() { + Cache.stopTimer(); + if(infoTimer!=null) { + infoTimer.cancel(); + infoTimer = null; + } + } + + private final static class Refresh extends TimerTask { + private static final int maxRefresh = 2*60*10000; // 20 mins + private AuthzEnv env; + private CIDAO cidao; + private int minRefresh; + private long lastRun; + + public Refresh(AuthzEnv env, CIDAO cidao, int minRefresh) { + this.env = env; + this.cidao = cidao; + this.minRefresh = minRefresh; + lastRun = System.currentTimeMillis()-maxRefresh-1000; + } + + @Override + public void run() { + // Evaluate whether to refresh based on transaction rate + long now = System.currentTimeMillis(); + long interval = now-lastRun; + + if(interval < minRefresh || interval < Math.min(env.transRate(),maxRefresh)) return; + lastRun = now; + AuthzTrans trans = env.newTransNoAvg(); + Result rv = cidao.check(trans); + if(rv.status!=Result.OK) { + env.error().log("Error in CacheInfo Refresh",rv.details); + } + if(env.debug().isLoggable()) { + StringBuilder sb = new StringBuilder("Cache Info Refresh: "); + trans.auditTrail(0, sb, Env.REMOTE); + env.debug().log(sb); + } + } + } +} diff --git a/authz-cass/src/main/java/com/att/dao/CachedDAO.java b/authz-cass/src/main/java/com/att/dao/CachedDAO.java new file mode 100644 index 00000000..bcfccbd1 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/CachedDAO.java @@ -0,0 +1,229 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.util.ArrayList; +import java.util.List; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.Status; +import com.att.inno.env.Trans; + +/** + * CachedDAO + * + * Cache the response of "get" of any DAO. + * + * For simplicity's sake, at this time, we only do this for single Object keys + * + * + * @param + */ +public class CachedDAO,DATA extends Cacheable> + extends Cached implements DAO_RO{ +// private final String dirty_str; + + private final D dao; + + public CachedDAO(D dao, CIDAO info, int segsize) { + super(info, dao.table(), segsize); + + // Instantiate a new Cache per DAO name (so separate instances use the same cache) + this.dao = dao; + //read_str = "Cached READ for " + dao.table(); +// dirty_str = "Cache DIRTY on " + dao.table(); + if(dao instanceof CassDAOImpl) { + ((CassDAOImpl)dao).cache = this; + } + } + + public static, DT extends Cacheable> + CachedDAO create(DA dao, CIDAO info, int segsize) { + return new CachedDAO(dao,info, segsize); + } + + public void add(DATA data) { + String key = keyFromObjs(dao.keyFrom(data)); + List list = new ArrayList(); + list.add(data); + super.add(key,list); + } + +// public void invalidate(TRANS trans, Object ... objs) { +// TimeTaken tt = trans.start(dirty_str, Env.SUB); +// try { +// super.invalidate(keyFromObjs(objs)); +// } finally { +// tt.done(); +// } +// } + + public static String keyFromObjs(Object ... objs) { + String key; + if(objs.length==1 && objs[0] instanceof String) { + key = (String)objs[0]; + } else { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for(Object o : objs) { + if(o!=null) { + if(first) { + first =false; + } else { + sb.append('|'); + } + sb.append(o.toString()); + } + } + key = sb.toString(); + } + return key; + } + + public Result create(TRANS trans, DATA data) { + Result d = dao.create(trans,data); + if(d.status==Status.OK) { + add(d.value); + } else { + trans.error().log(d.errorString()); + } + invalidate(trans,data); + return d; + } + + protected class DAOGetter implements Getter { + protected TRANS trans; + protected Object objs[]; + protected D dao; + public Result> result; + + public DAOGetter(TRANS trans, D dao, Object ... objs) { + this.trans = trans; + this.dao = dao; + this.objs = objs; + } + + /** + * Separated into single call for easy overloading + * @return + */ + public Result> call() { + return dao.read(trans, objs); + } + + @Override + public final Result> get() { + return call(); +// if(result.isOKhasData()) { // Note, given above logic, could exist, but stale +// return result.value; +// } else { +// return null; +// } + } + } + + @Override + public Result> read(final TRANS trans, final Object ... objs) { + DAOGetter getter = new DAOGetter(trans,dao,objs); + return get(trans, keyFromObjs(objs),getter); +// if(ld!=null) { +// return Result.ok(ld);//.emptyList(ld.isEmpty()); +// } +// // Result Result if exists +// if(getter.result==null) { +// return Result.err(Status.ERR_NotFound, "No Cache or Lookup found on [%s]",dao.table()); +// } +// return getter.result; + } + + // Slight Improved performance available when String and Obj versions are known. + public Result> read(final String key, final TRANS trans, final Object ... objs) { + DAOGetter getter = new DAOGetter(trans,dao,objs); + return get(trans, key, getter); +// if(ld!=null) { +// return Result.ok(ld);//.emptyList(ld.isEmpty()); +// } +// // Result Result if exists +// if(getter.result==null) { +// return Result.err(Status.ERR_NotFound, "No Cache or Lookup found on [%s]",dao.table()); +// } +// return getter.result; + } + + @Override + public Result> read(TRANS trans, DATA data) { + return read(trans,dao.keyFrom(data)); + } + public Result update(TRANS trans, DATA data) { + Result d = dao.update(trans, data); + if(d.status==Status.OK) { + add(data); + } else { + trans.error().log(d.errorString()); + } + return d; + } + + public Result delete(TRANS trans, DATA data, boolean reread) { + if(reread) { // If reread, get from Cache, if possible, not DB exclusively + Result> rd = read(trans,data); + if(rd.notOK()) { + return Result.err(rd); + } else { + trans.error().log(rd.errorString()); + } + if(rd.isEmpty()) { + data.invalidate(this); + return Result.err(Status.ERR_NotFound,"Not Found"); + } + data = rd.value.get(0); + } + Result rv=dao.delete(trans, data, false); + data.invalidate(this); + return rv; + } + + @Override + public void close(TRANS trans) { + if(dao!=null) { + dao.close(trans); + } + } + + + @Override + public String table() { + return dao.table(); + } + + public D dao() { + return dao; + } + + public void invalidate(TRANS trans, DATA data) { + if(info.touch(trans, dao.table(),data.invalidate(this)).notOK()) { + trans.error().log("Cannot touch CacheInfo for Role"); + } + } +} diff --git a/authz-cass/src/main/java/com/att/dao/CassAccess.java b/authz-cass/src/main/java/com/att/dao/CassAccess.java new file mode 100644 index 00000000..a935aff2 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/CassAccess.java @@ -0,0 +1,220 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.att.authz.env.AuthzEnv; +import com.att.cadi.routing.GreatCircle; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.util.Split; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Cluster.Builder; +import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; + +public class CassAccess { + public static final String KEYSPACE = "authz"; + public static final String CASSANDRA_CLUSTERS = "cassandra.clusters"; + public static final String CASSANDRA_CLUSTERS_PORT = "cassandra.clusters.port"; + public static final String CASSANDRA_CLUSTERS_USER_NAME = "cassandra.clusters.user"; + public static final String CASSANDRA_CLUSTERS_PASSWORD = "cassandra.clusters.password"; + public static final String CASSANDRA_RESET_EXCEPTIONS = "cassandra.reset.exceptions"; + public static final String LATITUDE = "LATITUDE"; + public static final String LONGITUDE = "LONGITUDE"; + private static final List resetExceptions = new ArrayList(); + public static final String ERR_ACCESS_MSG = "Accessing Backend"; + private static Builder cb = null; + + /** + * To create DCAwareRoundRobing Policy: + * Need Properties + * LATITUDE (or AFT_LATITUDE) + * LONGITUDE (or AFT_LONGITUDE) + * CASSANDRA CLUSTERS with additional information: + * machine:DC:lat:long,machine:DC:lat:long + * @param env + * @param prefix + * @return + * @throws APIException + * @throws IOException + */ + + @SuppressWarnings("deprecation") + public static synchronized Cluster cluster(Env env, String prefix) throws APIException, IOException { + if(cb == null) { + String pre; + if(prefix==null) { + pre=""; + } else { + env.info().log("Cassandra Connection for ",prefix); + pre = prefix+'.'; + } + cb = Cluster.builder(); + String str = env.getProperty(pre+CASSANDRA_CLUSTERS_PORT,"9042"); + if(str!=null) { + env.init().log("Cass Port = ",str ); + cb.withPort(Integer.parseInt(str)); + } + str = env.getProperty(pre+CASSANDRA_CLUSTERS_USER_NAME,null); + if(str!=null) { + env.init().log("Cass User = ",str ); + String epass = env.getProperty(pre + CASSANDRA_CLUSTERS_PASSWORD,null); + if(epass==null) { + throw new APIException("No Password configured for " + str); + } + //TODO Figure out way to ensure Decryptor setting in AuthzEnv + if(env instanceof AuthzEnv) { + cb.withCredentials(str,((AuthzEnv)env).decrypt(epass,true)); + } else { + cb.withCredentials(str, env.decryptor().decrypt(epass)); + } + } + + str = env.getProperty(pre+CASSANDRA_RESET_EXCEPTIONS,null); + if(str!=null) { + env.init().log("Cass ResetExceptions = ",str ); + for(String ex : Split.split(',', str)) { + resetExceptions.add(new Resettable(env,ex)); + } + } + + str = env.getProperty(LATITUDE,env.getProperty("AFT_LATITUDE",null)); + Double lat = str!=null?Double.parseDouble(str):null; + str = env.getProperty(LONGITUDE,env.getProperty("AFT_LONGITUDE",null)); + Double lon = str!=null?Double.parseDouble(str):null; + if(lat == null || lon == null) { + throw new APIException("LATITUDE(or AFT_LATITUDE) and/or LONGITUDE(or AFT_LATITUDE) are not set"); + } + + env.init().printf("Service Latitude,Longitude = %f,%f",lat,lon); + + str = env.getProperty(pre+CASSANDRA_CLUSTERS,"localhost"); + env.init().log("Cass Clusters = ",str ); + String[] machs = Split.split(',', str); + String[] cpoints = new String[machs.length]; + String bestDC = null; + int numInBestDC = 1; + double mlat, mlon,temp,distance = -1.0; + for(int i=0;i0) { + cpoints[i]=minfo[0]; + } + + // Calc closest DC with Great Circle + if(minfo.length>3) { + mlat = Double.parseDouble(minfo[2]); + mlon = Double.parseDouble(minfo[3]); + if((temp=GreatCircle.calc(lat, lon, mlat, mlon)) > distance) { + distance = temp; + if(bestDC!=null && bestDC.equals(minfo[1])) { + ++numInBestDC; + } else { + bestDC = minfo[1]; + numInBestDC = 1; + } + } else { + if(bestDC!=null && bestDC.equals(minfo[1])) { + ++numInBestDC; + } + } + } + } + + cb.addContactPoints(cpoints); + + if(bestDC!=null) { + // 8/26/2016 Management has determined that Accuracy is preferred over speed in bad situations + // Local DC Aware Load Balancing appears to have the highest normal performance, with the best + // Degraded Accuracy + cb.withLoadBalancingPolicy(new DCAwareRoundRobinPolicy( + bestDC, numInBestDC, true /*allow LocalDC to look at other DCs for LOCAL_QUORUM */)); + env.init().printf("Cassandra configured for DCAwareRoundRobinPolicy at %s with emergency remote of up to %d node(s)" + ,bestDC, numInBestDC); + } else { + env.init().printf("Cassandra is using Default Policy, which is not DC aware"); + } + } + return cb.build(); + } + + private static class Resettable { + private Class cls; + private List messages; + + @SuppressWarnings("unchecked") + public Resettable(Env env, String propData) throws APIException { + if(propData!=null && propData.length()>1) { + String[] split = Split.split(':', propData); + if(split.length>0) { + try { + cls = (Class)Class.forName(split[0]); + } catch (ClassNotFoundException e) { + throw new APIException("Declared Cassandra Reset Exception, " + propData + ", cannot be ClassLoaded"); + } + } + if(split.length>1) { + messages=new ArrayList(); + for(int i=1;i + */ +public class CassDAOImpl extends AbsCassDAO implements DAO { + public static final String USER_NAME = "__USER_NAME__"; + protected static final String CREATE_SP = "CREATE "; + protected static final String UPDATE_SP = "UPDATE "; + protected static final String DELETE_SP = "DELETE "; + protected static final String SELECT_SP = "SELECT "; + + protected final String C_TEXT = getClass().getSimpleName() + " CREATE"; + protected final String R_TEXT = getClass().getSimpleName() + " READ"; + protected final String U_TEXT = getClass().getSimpleName() + " UPDATE"; + protected final String D_TEXT = getClass().getSimpleName() + " DELETE"; + private String table; + + protected final ConsistencyLevel readConsistency,writeConsistency; + + // Setteable only by CachedDAO + protected Cached cache; + + /** + * A Constructor from the originating Cluster. This DAO will open the Session at need, + * and shutdown the session when "close()" is called. + * + * @param cluster + * @param keyspace + * @param dataClass + */ + public CassDAOImpl(TRANS trans, String name, Cluster cluster, String keyspace, Class dataClass, String table, ConsistencyLevel read, ConsistencyLevel write) { + super(trans, name, cluster,keyspace,dataClass); + this.table = table; + readConsistency = read; + writeConsistency = write; + } + + /** + * A Constructor to share Session with other DAOs. + * + * This method get the Session and Cluster information from the calling DAO, and won't + * touch the Session on closure. + * + * @param aDao + * @param dataClass + */ + public CassDAOImpl(TRANS trans, String name, AbsCassDAO aDao, Class dataClass, String table, ConsistencyLevel read, ConsistencyLevel write) { + super(trans, name, aDao,dataClass); + this.table = table; + readConsistency = read; + writeConsistency = write; + } + + protected PSInfo createPS; + protected PSInfo readPS; + protected PSInfo updatePS; + protected PSInfo deletePS; + private boolean async=false; + + public void async(boolean bool) { + async = bool; + } + + public final String[] setCRUD(TRANS trans, String table, Class dc,Loader loader) { + return setCRUD(trans, table, dc, loader, -1); + } + + public final String[] setCRUD(TRANS trans, String table, Class dc,Loader loader, int max) { + Field[] fields = dc.getDeclaredFields(); + int end = max>=0 & max0) { + for(int i=0;i0) { + sbfc.append(','); + sbq.append(','); + if(i=keylimit) { + if(i>keylimit) { + sbup.append(','); + } + sbup.append(fields[i].getName()); + sbup.append("=?"); + } + if(i create(TRANS trans, DATA data) { + if(createPS==null) { + Result.err(Result.ERR_NotImplemented,"Create is disabled for %s",getClass().getSimpleName()); + } + if(async) /*ResultSetFuture */ { + Result rs = createPS.execAsync(trans, C_TEXT, data); + if(rs.notOK()) { + return Result.err(rs); + } + } else { + Result rs = createPS.exec(trans, C_TEXT, data); + if(rs.notOK()) { + return Result.err(rs); + } + } + wasModified(trans, CRUD.create, data); + return Result.ok(data); + } + + /** + * Read the Unique Row associated with Full Keys + */ + public Result> read(TRANS trans, DATA data) { + if(readPS==null) { + Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName()); + } + return readPS.read(trans, R_TEXT, data); + } + + public Result> read(TRANS trans, Object ... key) { + if(readPS==null) { + Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName()); + } + return readPS.read(trans, R_TEXT, key); + } + + public Result update(TRANS trans, DATA data) { + if(updatePS==null) { + Result.err(Result.ERR_NotImplemented,"Update is disabled for %s",getClass().getSimpleName()); + } + if(async)/* ResultSet rs =*/ { + Result rs = updatePS.execAsync(trans, U_TEXT, data); + if(rs.notOK()) { + return Result.err(rs); + } + } else { + Result rs = updatePS.exec(trans, U_TEXT, data); + if(rs.notOK()) { + return Result.err(rs); + } + } + + wasModified(trans, CRUD.update, data); + return Result.ok(); + } + + // This method Sig for Cached... + public Result delete(TRANS trans, DATA data, boolean reread) { + if(deletePS==null) { + Result.err(Result.ERR_NotImplemented,"Delete is disabled for %s",getClass().getSimpleName()); + } + // Since Deleting will be stored off, for possible re-constitution, need the whole thing + if(reread) { + Result> rd = read(trans,data); + if(rd.notOK()) { + return Result.err(rd); + } + if(rd.isEmpty()) { + return Result.err(Status.ERR_NotFound,"Not Found"); + } + for(DATA d : rd.value) { + if(async) { + Result rs = deletePS.execAsync(trans, D_TEXT, d); + if(rs.notOK()) { + return Result.err(rs); + } + } else { + Result rs = deletePS.exec(trans, D_TEXT, d); + if(rs.notOK()) { + return Result.err(rs); + } + } + wasModified(trans, CRUD.delete, d); + } + } else { + if(async)/* ResultSet rs =*/ { + Result rs = deletePS.execAsync(trans, D_TEXT, data); + if(rs.notOK()) { + return Result.err(rs); + } + } else { + Result rs = deletePS.exec(trans, D_TEXT, data); + if(rs.notOK()) { + return Result.err(rs); + } + } + wasModified(trans, CRUD.delete, data); + } + return Result.ok(); + } + + public final Object[] keyFrom(DATA data) { + return createPS.keyFrom(data); + } + + @Override + public String table() { + return table; + } + + public static final String CASS_READ_CONSISTENCY="cassandra.readConsistency"; + public static final String CASS_WRITE_CONSISTENCY="cassandra.writeConsistency"; + protected static ConsistencyLevel readConsistency(AuthzTrans trans, String table) { + String prop = trans.getProperty(CASS_READ_CONSISTENCY+'.'+table); + if(prop==null) { + prop = trans.getProperty(CASS_READ_CONSISTENCY); + if(prop==null) { + return ConsistencyLevel.ONE; // this is Cassandra Default + } + } + return ConsistencyLevel.valueOf(prop); + } + + protected static ConsistencyLevel writeConsistency(AuthzTrans trans, String table) { + String prop = trans.getProperty(CASS_WRITE_CONSISTENCY+'.'+table); + if(prop==null) { + prop = trans.getProperty(CASS_WRITE_CONSISTENCY); + if(prop==null) { + return ConsistencyLevel.ONE; // this is Cassandra Default\ + } + } + return ConsistencyLevel.valueOf(prop); + } + + public static DataInputStream toDIS(ByteBuffer bb) { + byte[] b = bb.array(); + return new DataInputStream( + new ByteArrayInputStream(b,bb.position(),bb.limit()) + ); + } + + +} diff --git a/authz-cass/src/main/java/com/att/dao/DAO.java b/authz-cass/src/main/java/com/att/dao/DAO.java new file mode 100644 index 00000000..e2144162 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/DAO.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import com.att.authz.layer.Result; +import com.att.inno.env.Trans; + + +/** + * DataAccessObject Interface + * + * Extend the ReadOnly form (for Get), and add manipulation methods + * + * @param + */ +public interface DAO extends DAO_RO { + public Result create(TRANS trans, DATA data); + public Result update(TRANS trans, DATA data); + // In many cases, the data has been correctly read first, so we shouldn't read again + // Use reread=true if you are using DATA with only a Key + public Result delete(TRANS trans, DATA data, boolean reread); + public Object[] keyFrom(DATA data); +} diff --git a/authz-cass/src/main/java/com/att/dao/DAOException.java b/authz-cass/src/main/java/com/att/dao/DAOException.java new file mode 100644 index 00000000..8c9a701e --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/DAOException.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +public class DAOException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1527904125585539823L; + +// // TODO - enum in result class == is our intended design, currently the DAO layer does not use Result so we still use these for now +// public final static DAOException RoleNotFoundDAOException = new DAOException("RoleNotFound"); +// public final static DAOException PermissionNotFoundDAOException = new DAOException("PermissionNotFound"); +// public final static DAOException UserNotFoundDAOException = new DAOException("UserNotFound"); + + public DAOException() { + } + + public DAOException(String message) { + super(message); + } + + public DAOException(Throwable cause) { + super(cause); + } + + public DAOException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/DAO_RO.java b/authz-cass/src/main/java/com/att/dao/DAO_RO.java new file mode 100644 index 00000000..2b6173c5 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/DAO_RO.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.util.List; + +import com.att.authz.layer.Result; +import com.att.inno.env.Trans; + +/** + * DataAccessObject - ReadOnly + * + * It is useful to have a ReadOnly part of the interface for CachedDAO + * + * Normal DAOs will implement full DAO + * + * + * @param + */ +public interface DAO_RO { + /** + * Get a List of Data given Key of Object Array + * @param objs + * @return + * @throws DAOException + */ + public Result> read(TRANS trans, Object ... key); + + /** + * Get a List of Data given Key of DATA Object + * @param trans + * @param key + * @return + * @throws DAOException + */ + public Result> read(TRANS trans, DATA key); + + /** + * close DAO + */ + public void close(TRANS trans); + + /** + * Return name of referenced Data + * @return + */ + public String table(); + + +} diff --git a/authz-cass/src/main/java/com/att/dao/Loader.java b/authz-cass/src/main/java/com/att/dao/Loader.java new file mode 100644 index 00000000..6b09df96 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/Loader.java @@ -0,0 +1,215 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import com.datastax.driver.core.Row; + +public abstract class Loader { + private int keylimit; + public Loader(int keylimit) { + this.keylimit = keylimit; + } + + public int keylimit() { + return keylimit; + } + + protected abstract DATA load(DATA data, Row row); + protected abstract void key(DATA data, int idx, Object[] obj); + protected abstract void body(DATA data, int idx, Object[] obj); + + public final Object[] extract(DATA data, int size, CassDAOImpl.CRUD type) { + Object[] rv=null; + switch(type) { + case delete: + rv = new Object[keylimit()]; + key(data,0,rv); + break; + case update: + rv = new Object[size]; + body(data,0,rv); + int body = size-keylimit(); + if(body>0) { + key(data,body,rv); + } + break; + default: + rv = new Object[size]; + key(data,0,rv); + if(size>keylimit()) { + body(data,keylimit(),rv); + } + break; + } + return rv; + } + + public static void writeString(DataOutputStream os, String s) throws IOException { + if(s==null) { + os.writeInt(-1); + } else { + switch(s.length()) { + case 0: + os.writeInt(0); + break; + default: + byte[] bytes = s.getBytes(); + os.writeInt(bytes.length); + os.write(bytes); + } + } + } + + /** + * We use bytes here to set a Maximum + * + * @param is + * @param MAX + * @return + * @throws IOException + */ + public static String readString(DataInputStream is, byte[] _buff) throws IOException { + int l = is.readInt(); + byte[] buff = _buff; + switch(l) { + case -1: return null; + case 0: return ""; + default: + // Cover case where there is a large string, without always allocating a large buffer. + if(l>buff.length) { + buff = new byte[l]; + } + is.read(buff,0,l); + return new String(buff,0,l); + } + } + + /** + * Write a set with proper sizing + * + * Note: at the moment, this is just String. Probably can develop system where types + * are supported too... but not now. + * + * @param os + * @param set + * @throws IOException + */ + public static void writeStringSet(DataOutputStream os, Collection set) throws IOException { + if(set==null) { + os.writeInt(-1); + } else { + os.writeInt(set.size()); + for(String s : set) { + writeString(os, s); + } + } + + } + + public static Set readStringSet(DataInputStream is, byte[] buff) throws IOException { + int l = is.readInt(); + if(l<0) { + return null; + } + Set set = new HashSet(l); + for(int i=0;i readStringList(DataInputStream is, byte[] buff) throws IOException { + int l = is.readInt(); + if(l<0) { + return null; + } + List list = new ArrayList(l); + for(int i=0;i map) throws IOException { + if(map==null) { + os.writeInt(-1); + } else { + Set> es = map.entrySet(); + os.writeInt(es.size()); + for(Entry e : es) { + writeString(os, e.getKey()); + writeString(os, e.getValue()); + } + } + + } + + public static Map readStringMap(DataInputStream is, byte[] buff) throws IOException { + int l = is.readInt(); + if(l<0) { + return null; + } + Map map = new HashMap(l); + for(int i=0;iversion) { + throw new IOException("Unsupported Data Version: " + v); + } + return v; + } + +} + diff --git a/authz-cass/src/main/java/com/att/dao/Streamer.java b/authz-cass/src/main/java/com/att/dao/Streamer.java new file mode 100644 index 00000000..385877ea --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/Streamer.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public interface Streamer { + public abstract void marshal(DATA data, DataOutputStream os) throws IOException; + public abstract void unmarshal(DATA data, DataInputStream is) throws IOException; +} diff --git a/authz-cass/src/main/java/com/att/dao/Touchable.java b/authz-cass/src/main/java/com/att/dao/Touchable.java new file mode 100644 index 00000000..4f8b7f6e --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/Touchable.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +public interface Touchable { + // Or make all DAOs accept list of CIDAOs... +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedCertDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedCertDAO.java new file mode 100644 index 00000000..611aa4eb --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedCertDAO.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cached; + +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.CIDAO; +import com.att.dao.CachedDAO; +import com.att.dao.aaf.cass.CertDAO; + +public class CachedCertDAO extends CachedDAO { + public CachedCertDAO(CertDAO dao, CIDAO info) { + super(dao, info, CertDAO.CACHE_SEG); + } + + /** + * Pass through Cert ID Lookup + * + * @param trans + * @param ns + * @return + */ + + public Result> readID(AuthzTrans trans, final String id) { + return dao().readID(trans, id); + } + + public Result> readX500(AuthzTrans trans, final String x500) { + return dao().readX500(trans, x500); + } + + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedCredDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedCredDAO.java new file mode 100644 index 00000000..b9f20c24 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedCredDAO.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cached; + +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.CIDAO; +import com.att.dao.CachedDAO; +import com.att.dao.aaf.cass.CredDAO; +import com.att.dao.aaf.cass.Status; + +public class CachedCredDAO extends CachedDAO { + public CachedCredDAO(CredDAO dao, CIDAO info) { + super(dao, info, CredDAO.CACHE_SEG); + } + + /** + * Pass through Cred Lookup + * + * Unlike Role and Perm, we don't need or want to cache these elements... Only used for NS Delete. + * + * @param trans + * @param ns + * @return + */ + public Result> readNS(AuthzTrans trans, final String ns) { + + return dao().readNS(trans, ns); + } + + public Result> readID(AuthzTrans trans, final String id) { + DAOGetter getter = new DAOGetter(trans,dao()) { + public Result> call() { + return dao().readID(trans, id); + } + }; + + Result> lurd = get(trans, id, getter); + if(lurd.isOK() && lurd.isEmpty()) { + return Result.err(Status.ERR_UserNotFound,"No User Cred found"); + } + return lurd; + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedNSDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedNSDAO.java new file mode 100644 index 00000000..0008dff1 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedNSDAO.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cached; + +import com.att.authz.env.AuthzTrans; +import com.att.dao.CIDAO; +import com.att.dao.CachedDAO; +import com.att.dao.aaf.cass.NsDAO; + +public class CachedNSDAO extends CachedDAO { + public CachedNSDAO(NsDAO dao, CIDAO info) { + super(dao, info, NsDAO.CACHE_SEG); + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedPermDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedPermDAO.java new file mode 100644 index 00000000..e900f691 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedPermDAO.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cached; + +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.CIDAO; +import com.att.dao.CachedDAO; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.PermDAO.Data; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.Status; + +public class CachedPermDAO extends CachedDAO { + + public CachedPermDAO(PermDAO dao, CIDAO info) { + super(dao, info, PermDAO.CACHE_SEG); + } + + public Result> readNS(AuthzTrans trans, final String ns) { + DAOGetter getter = new DAOGetter(trans,dao()) { + public Result> call() { + return dao.readNS(trans, ns); + } + }; + + Result> lurd = get(trans, ns, getter); + if(lurd.isOKhasData()) { + return lurd; + } else { + + } +// if(getter.result==null) { +// if(lurd==null) { + return Result.err(Status.ERR_PermissionNotFound,"No Permission found - " + lurd.details); +// } else { +// return Result.ok(lurd); +// } +// } +// return getter.result; + } + + public Result> readChildren(AuthzTrans trans, final String ns, final String type) { + return dao().readChildren(trans,ns,type); + } + + /** + * + * @param trans + * @param ns + * @param type + * @return + */ + public Result> readByType(AuthzTrans trans, final String ns, final String type) { + DAOGetter getter = new DAOGetter(trans,dao()) { + public Result> call() { + return dao.readByType(trans, ns, type); + } + }; + + // Note: Can reuse index1 here, because there is no name collision versus response + Result> lurd = get(trans, ns+'|'+type, getter); + if(lurd.isOK() && lurd.isEmpty()) { + return Result.err(Status.ERR_PermissionNotFound,"No Permission found"); + } + return lurd; + } + + /** + * Add desciption to this permission + * + * @param trans + * @param ns + * @param type + * @param instance + * @param action + * @param description + * @return + */ + public Result addDescription(AuthzTrans trans, String ns, String type, + String instance, String action, String description) { + //TODO Invalidate? + return dao().addDescription(trans, ns, type, instance, action, description); + } + + public Result addRole(AuthzTrans trans, PermDAO.Data perm, RoleDAO.Data role) { + Result rv = dao().addRole(trans,perm,role.encode()); + if(trans.debug().isLoggable()) + trans.debug().log("Adding",role.encode(),"to", perm, "with CachedPermDAO.addRole"); + invalidate(trans,perm); + return rv; + } + + public Result delRole(AuthzTrans trans, Data perm, RoleDAO.Data role) { + Result rv = dao().delRole(trans,perm,role.encode()); + if(trans.debug().isLoggable()) + trans.debug().log("Removing",role.encode(),"from", perm, "with CachedPermDAO.delRole"); + invalidate(trans,perm); + return rv; + } + + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedRoleDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedRoleDAO.java new file mode 100644 index 00000000..b7836449 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedRoleDAO.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cached; + +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.CIDAO; +import com.att.dao.CachedDAO; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.RoleDAO.Data; +import com.att.dao.aaf.cass.Status; + +public class CachedRoleDAO extends CachedDAO { + public CachedRoleDAO(RoleDAO dao, CIDAO info) { + super(dao, info, RoleDAO.CACHE_SEG); + } + + public Result> readNS(AuthzTrans trans, final String ns) { + DAOGetter getter = new DAOGetter(trans,dao()) { + public Result> call() { + return dao.readNS(trans, ns); + } + }; + + Result> lurd = get(trans, ns, getter); + if(lurd.isOK() && lurd.isEmpty()) { + return Result.err(Status.ERR_RoleNotFound,"No Role found"); + } + return lurd; + } + + public Result> readName(AuthzTrans trans, final String name) { + DAOGetter getter = new DAOGetter(trans,dao()) { + public Result> call() { + return dao().readName(trans, name); + } + }; + + Result> lurd = get(trans, name, getter); + if(lurd.isOK() && lurd.isEmpty()) { + return Result.err(Status.ERR_RoleNotFound,"No Role found"); + } + return lurd; + } + + public Result> readChildren(AuthzTrans trans, final String ns, final String name) { + // At this point, I'm thinking it's better not to try to cache "*" results + // Data probably won't be accurate, and adding it makes every update invalidate most of the cache + // 2/4/2014 + return dao().readChildren(trans,ns,name); + } + + public Result addPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) { + Result rv = dao().addPerm(trans,rd,perm); + if(trans.debug().isLoggable()) + trans.debug().log("Adding",perm,"to", rd, "with CachedRoleDAO.addPerm"); + invalidate(trans, rd); + return rv; + } + + public Result delPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) { + Result rv = dao().delPerm(trans,rd,perm); + if(trans.debug().isLoggable()) + trans.debug().log("Removing",perm,"from", rd, "with CachedRoleDAO.addPerm"); + invalidate(trans, rd); + return rv; + } + + /** + * Add description to this role + * + * @param trans + * @param ns + * @param name + * @param description + * @return + */ + public Result addDescription(AuthzTrans trans, String ns, String name, String description) { + //TODO Invalidate? + return dao().addDescription(trans, ns, name, description); + + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedUserRoleDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedUserRoleDAO.java new file mode 100644 index 00000000..45e61bd9 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cached/CachedUserRoleDAO.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cached; + +import java.util.ArrayList; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.CIDAO; +import com.att.dao.CachedDAO; +import com.att.dao.aaf.cass.Status; +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.dao.aaf.cass.UserRoleDAO.Data; +import com.att.inno.env.Slot; + +public class CachedUserRoleDAO extends CachedDAO { + private Slot transURSlot; + + public CachedUserRoleDAO(UserRoleDAO dao, CIDAO info) { + super(dao, info, UserRoleDAO.CACHE_SEG); + transURSlot = dao.transURSlot; + } + + /** + * Special Case. + * User Roles by User are very likely to be called many times in a Transaction, to validate "May User do..." + * Pull result, and make accessible by the Trans, which is always keyed by User. + * @param trans + * @param user + * @return + */ + public Result> readByUser(AuthzTrans trans, final String user) { + DAOGetter getter = new DAOGetter(trans,dao()) { + public Result> call() { + // If the call is for THIS user, and it exists, get from TRANS, add to TRANS if not. + if(user!=null && user.equals(trans.user())) { + Result> transLD = trans.get(transURSlot,null); + if(transLD==null ) { + transLD = dao.readByUser(trans, user); + } + return transLD; + } else { + return dao.readByUser(trans, user); + } + } + }; + Result> lurd = get(trans, user, getter); + if(lurd.isOK() && lurd.isEmpty()) { + return Result.err(Status.ERR_UserRoleNotFound,"UserRole not found for [%s]",user); + } + return lurd; + } + + + public Result> readByRole(AuthzTrans trans, final String role) { + DAOGetter getter = new DAOGetter(trans,dao()) { + public Result> call() { + return dao.readByRole(trans, role); + } + }; + Result> lurd = get(trans, role, getter); + if(lurd.isOK() && lurd.isEmpty()) { + return Result.err(Status.ERR_UserRoleNotFound,"UserRole not found for [%s]",role); + } + return lurd; + } + + public Result> readUserInRole(final AuthzTrans trans, final String user, final String role) { + DAOGetter getter = new DAOGetter(trans,dao()) { + public Result> call() { + if(user.equals(trans.user())) { + Result> rrbu = readByUser(trans, user); + if(rrbu.isOK()) { + List ld = new ArrayList(1); + for(Data d : rrbu.value) { + if(d.role.equals(role)) { + ld.add(d); + break; + } + } + return Result.ok(ld).emptyList(ld.isEmpty()); + } else { + return rrbu; + } + } + return dao.readByUserRole(trans, user, role); + } + }; + Result> lurd = get(trans, keyFromObjs(user,role), getter); + if(lurd.isOK() && lurd.isEmpty()) { + return Result.err(Status.ERR_UserRoleNotFound,"UserRole not found for role [%s] and user [%s]",role,user); + } + return lurd; + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/ApprovalDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/ApprovalDAO.java new file mode 100644 index 00000000..f2f25e7d --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/ApprovalDAO.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Row; + + +public class ApprovalDAO extends CassDAOImpl { + public static final String PENDING = "pending"; + public static final String DENIED = "denied"; + public static final String APPROVED = "approved"; + + private static final String TABLE = "approval"; + private HistoryDAO historyDAO; + private PSInfo psByUser, psByApprover, psByTicket, psByStatus; + + + public ApprovalDAO(AuthzTrans trans, Cluster cluster, String keyspace) { + super(trans, ApprovalDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO = new HistoryDAO(trans, this); + init(trans); + } + + + public ApprovalDAO(AuthzTrans trans, HistoryDAO hDAO) { + super(trans, ApprovalDAO.class.getSimpleName(),hDAO,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO=hDAO; + init(trans); + } + + private static final int KEYLIMIT = 1; + public static class Data { + public UUID id; + public UUID ticket; + public String user; + public String approver; + public String type; + public String status; + public String memo; + public String operation; + public Date updated; + } + + private static class ApprovalLoader extends Loader { + public static final ApprovalLoader deflt = new ApprovalLoader(KEYLIMIT); + + public ApprovalLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + data.id = row.getUUID(0); + data.ticket = row.getUUID(1); + data.user = row.getString(2); + data.approver = row.getString(3); + data.type = row.getString(4); + data.status = row.getString(5); + data.memo = row.getString(6); + data.operation = row.getString(7); + if(row.getColumnDefinitions().size()>8) { + // Rows reported in MicroSeconds + data.updated = new Date(row.getLong(8)/1000); + } + return data; + } + + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.id; + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx]=data.ticket; + obj[++idx]=data.user; + obj[++idx]=data.approver; + obj[++idx]=data.type; + obj[++idx]=data.status; + obj[++idx]=data.memo; + obj[++idx]=data.operation; + } + } + + private void init(AuthzTrans trans) { + String[] helpers = setCRUD(trans, TABLE, Data.class, ApprovalLoader.deflt,8); + // Need a specialty Creator to handle the "now()" + replace(CRUD.create, new PSInfo(trans, "INSERT INTO " + TABLE + " (" + helpers[FIELD_COMMAS] + + ") VALUES(now(),?,?,?,?,?,?,?)",new ApprovalLoader(0) { + @Override + protected void key(Data data, int idx, Object[] obj) { + // Overridden because key is the "now()" + } + },writeConsistency) + ); + + psByUser = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + + " WHERE user = ?", new ApprovalLoader(1) { + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.user; + } + }, readConsistency); + + psByApprover = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + + " WHERE approver = ?", new ApprovalLoader(1) { + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.approver; + } + }, readConsistency); + + psByTicket = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + + " WHERE ticket = ?", new ApprovalLoader(1) { + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.ticket; + } + }, readConsistency); + + psByStatus = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + + " WHERE status = ?", new ApprovalLoader(1) { + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.status; + } + }, readConsistency); + + + } + + public Result> readByUser(AuthzTrans trans, String user) { + return psByUser.read(trans, R_TEXT, new Object[]{user}); + } + + public Result> readByApprover(AuthzTrans trans, String approver) { + return psByApprover.read(trans, R_TEXT, new Object[]{approver}); + } + + public Result> readByTicket(AuthzTrans trans, UUID ticket) { + return psByTicket.read(trans, R_TEXT, new Object[]{ticket}); + } + + public Result> readByStatus(AuthzTrans trans, String status) { + return psByStatus.read(trans, R_TEXT, new Object[]{status}); + } + + /** + * Log Modification statements to History + * + * @param modified which CRUD action was done + * @param data entity data that needs a log entry + * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + hd.user = trans.user(); + hd.action = modified.name(); + hd.target = TABLE; + hd.subject = subject?override[1]:data.user + "|" + data.approver; + hd.memo = memo + ? String.format("%s by %s", override[0], hd.user) + : (modified.name() + "d approval for " + data.user); + // Detail? + // Reconstruct? + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/ArtiDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/ArtiDAO.java new file mode 100644 index 00000000..397a8834 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/ArtiDAO.java @@ -0,0 +1,267 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.Bytification; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.att.dao.Streamer; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Row; + +/** + * CredDAO manages credentials. + * Date: 7/19/13 + */ +public class ArtiDAO extends CassDAOImpl { + public static final String TABLE = "artifact"; + + private HistoryDAO historyDAO; + private PSInfo psByMechID,psByMachine; + + public ArtiDAO(AuthzTrans trans, Cluster cluster, String keyspace) { + super(trans, ArtiDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + init(trans); + } + + public ArtiDAO(AuthzTrans trans, HistoryDAO hDao, CacheInfoDAO ciDao) { + super(trans, ArtiDAO.class.getSimpleName(),hDao, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO = hDao; + init(trans); + } + + public static final int KEYLIMIT = 2; + public static class Data implements Bytification { + public String mechid; + public String machine; + private Set type; + public String sponsor; + public String ca; + public String dir; + public String appName; + public String os_user; + public String notify; + public Date expires; + public int renewDays; + +// // Getters + public Set type(boolean mutable) { + if (type == null) { + type = new HashSet(); + } else if (mutable && !(type instanceof HashSet)) { + type = new HashSet(type); + } + return type; + } + + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ArtifactLoader.deflt.marshal(this,new DataOutputStream(baos)); + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + ArtifactLoader.deflt.unmarshal(this, toDIS(bb)); + } + + public String toString() { + return mechid + ' ' + machine + ' ' + Chrono.dateTime(expires); + } + } + + private static class ArtifactLoader extends Loader implements Streamer{ + public static final int MAGIC=95829343; + public static final int VERSION=1; + public static final int BUFF_SIZE=48; // Note: + + public static final ArtifactLoader deflt = new ArtifactLoader(KEYLIMIT); + public ArtifactLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + data.mechid = row.getString(0); + data.machine = row.getString(1); + data.type = row.getSet(2, String.class); + data.sponsor = row.getString(3); + data.ca = row.getString(4); + data.dir = row.getString(5); + data.appName = row.getString(6); + data.os_user = row.getString(7); + data.notify = row.getString(8); + data.expires = row.getDate(9); + data.renewDays = row.getInt(10); + return data; + } + + @Override + protected void key(final Data data, final int idx, Object[] obj) { + int i; + obj[i=idx] = data.mechid; + obj[++i] = data.machine; + } + + @Override + protected void body(final Data data, final int idx, Object[] obj) { + int i; + obj[i=idx] = data.type; + obj[++i] = data.sponsor; + obj[++i] = data.ca; + obj[++i] = data.dir; + obj[++i] = data.appName; + obj[++i] = data.os_user; + obj[++i] = data.notify; + obj[++i] = data.expires; + obj[++i] = data.renewDays; + } + + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + writeString(os, data.mechid); + writeString(os, data.machine); + os.writeInt(data.type.size()); + for(String s : data.type) { + writeString(os, s); + } + writeString(os, data.sponsor); + writeString(os, data.ca); + writeString(os, data.dir); + writeString(os, data.appName); + writeString(os, data.os_user); + writeString(os, data.notify); + os.writeLong(data.expires==null?-1:data.expires.getTime()); + os.writeInt(data.renewDays); + } + + @Override + public void unmarshal(Data data, DataInputStream is) throws IOException { + /*int version = */readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + byte[] buff = new byte[BUFF_SIZE]; + data.mechid = readString(is,buff); + data.machine = readString(is,buff); + int size = is.readInt(); + data.type = new HashSet(size); + for(int i=0;i> readByMechID(AuthzTrans trans, String mechid) { + return psByMechID.read(trans, R_TEXT, new Object[]{mechid}); + } + + public Result> readByMachine(AuthzTrans trans, String machine) { + return psByMachine.read(trans, R_TEXT, new Object[]{machine}); + } + + /** + * Log Modification statements to History + * + * @param modified which CRUD action was done + * @param data entity data that needs a log entry + * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + hd.user = trans.user(); + hd.action = modified.name(); + hd.target = TABLE; + hd.subject = subject?override[1]: data.mechid; + hd.memo = memo + ? String.format("%s by %s", override[0], hd.user) + : String.format("%sd %s for %s",modified.name(),data.mechid,data.machine); + // Detail? + if(modified==CRUD.delete) { + try { + hd.reconstruct = data.bytify(); + } catch (IOException e) { + trans.error().log(e,"Could not serialize CredDAO.Data"); + } + } + + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/CacheInfoDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/CacheInfoDAO.java new file mode 100644 index 00000000..ef8201ab --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/CacheInfoDAO.java @@ -0,0 +1,464 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URI; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cadi.CadiException; +import com.att.cadi.SecuritySetter; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cadi.http.HMangr; +import com.att.dao.AbsCassDAO; +import com.att.dao.CIDAO; +import com.att.dao.CassAccess; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.datastax.driver.core.BoundStatement; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.exceptions.DriverException; + +public class CacheInfoDAO extends CassDAOImpl implements CIDAO { + + private static final String TABLE = "cache"; + public static final Map info = new ConcurrentHashMap(); + + private static CacheUpdate cacheUpdate; + + + private BoundStatement check; + // Hold current time stamps from Tables + private final Date startTime; + + public CacheInfoDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { + super(trans, CacheInfoDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE,readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + startTime = new Date(); + init(trans); + } + + public CacheInfoDAO(AuthzTrans trans, AbsCassDAO aDao) throws APIException, IOException { + super(trans, CacheInfoDAO.class.getSimpleName(),aDao,Data.class,TABLE,readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + startTime = new Date(); + init(trans); + } + + + ////////////////////////////////////////// + // Data Definition, matches Cassandra DM + ////////////////////////////////////////// + private static final int KEYLIMIT = 2; + /** + */ + public static class Data { + public Data() { + name = null; + touched = null; + } + public Data(String name, int seg) { + this.name = name; + this.seg = seg; + touched = null; + } + + public String name; + public int seg; + public Date touched; + } + + private static class InfoLoader extends Loader { + public static final InfoLoader dflt = new InfoLoader(KEYLIMIT); + + public InfoLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + // Int more efficient + data.name = row.getString(0); + data.seg = row.getInt(1); + data.touched = row.getDate(2); + return data; + } + + @Override + protected void key(Data data, int _idx, Object[] obj) { + int idx = _idx; + + obj[idx]=data.name; + obj[++idx]=data.seg; + } + + @Override + protected void body(Data data, int idx, Object[] obj) { + obj[idx]=data.touched; + } + } + + public static void startUpdate(AuthzEnv env, HMangr hman, SecuritySetter ss, String ip, int port) { + if(cacheUpdate==null) { + Thread t= new Thread(cacheUpdate = new CacheUpdate(env,hman,ss, ip,port),"CacheInfo Update Thread"); + t.setDaemon(true); + t.start(); + } + } + + public static void stopUpdate() { + if(cacheUpdate!=null) { + cacheUpdate.go=false; + } + } + + private final static class CacheUpdate extends Thread { + public static BlockingQueue notifyDQ = new LinkedBlockingQueue(2000); + + private static final String VOID_CT="application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0"; + private AuthzEnv env; + private HMangr hman; + private SecuritySetter ss; + private final String authority; + public boolean go = true; + + public CacheUpdate(AuthzEnv env, HMangr hman, SecuritySetter ss, String ip, int port) { + this.env = env; + this.hman = hman; + this.ss = ss; + + this.authority = ip+':'+port; + } + + private static class Transfer { + public String table; + public int segs[]; + public Transfer(String table, int[] segs) { + this.table = table; + this.segs = segs; + } + } + private class CacheClear extends Retryable { + public int total=0; + private AuthzTrans trans; + private String type; + private String segs; + + public CacheClear(AuthzTrans trans) { + this.trans = trans; + } + + public void set(Entry es) { + type = es.getKey(); + segs = es.getValue().toString(); + } + + @Override + public Integer code(Rcli client) throws APIException, CadiException { + URI to = client.getURI(); + if(!to.getAuthority().equals(authority)) { + Future f = client.delete("/mgmt/cache/"+type+'/'+segs,VOID_CT); + if(f.get(hman.readTimeout())) { + ++total; + } else { + trans.error().log("Error During AAF Peer Notify",f.code(),f.body()); + } + } + return total; + } + } + + private class IntHolder { + private int[] raw; + HashSet set; + + public IntHolder(int ints[]) { + raw = ints; + set = null; + } + public void add(int[] ints) { + if(set==null) { + set = new HashSet(); + + for(int i=0;i gather = null; + AuthzTrans trans = null; + long start=0; + // Do a block poll first + do { + if(gather==null) { + start = System.nanoTime(); + trans = env.newTransNoAvg(); + cc = new CacheClear(trans); + gather = new HashMap(); + } + IntHolder prev = gather.get(data.table); + if(prev==null) { + gather.put(data.table,new IntHolder(data.segs)); + } else { + prev.add(data.segs); + } + // continue while there is data + } while((data = notifyDQ.poll())!=null); + if(gather!=null) { + for(Entry es : gather.entrySet()) { + cc.set(es); + try { + if(hman.all(ss, cc, false)!=null) { + ++count; + } + } catch (Exception e) { + trans.error().log(e, "Error on Cache Update"); + } + } + if(env.debug().isLoggable()) { + float millis = (System.nanoTime()-start)/1000000f; + StringBuilder sb = new StringBuilder("Direct Cache Refresh: "); + sb.append("Updated "); + sb.append(count); + if(count==1) { + sb.append(" entry for "); + } else { + sb.append(" entries for "); + } + int peers = count<=0?0:cc.total/count; + sb.append(peers); + sb.append(" client"); + if(peers!=1) { + sb.append('s'); + } + sb.append(" in "); + sb.append(millis); + sb.append("ms"); + trans.auditTrail(0, sb, Env.REMOTE); + env.debug().log(sb); + } + } + } catch (InterruptedException e1) { + go = false; + } + } while(go); + } + } + + private void init(AuthzTrans trans) throws APIException, IOException { + + String[] helpers = setCRUD(trans, TABLE, Data.class, InfoLoader.dflt); + check = getSession(trans).prepare(SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE).bind(); + + disable(CRUD.create); + disable(CRUD.delete); + } + + /* (non-Javadoc) + * @see com.att.dao.aaf.cass.CIDAO#touch(com.att.authz.env.AuthzTrans, java.lang.String, int) + */ + + @Override + public Result touch(AuthzTrans trans, String name, int ... seg) { + ///////////// + // Direct Service Cache Invalidation + ///////////// + // ConcurrentQueues are open-ended. We don't want any Memory leaks + // Note: we keep a separate counter, because "size()" on a Linked Queue is expensive + if(cacheUpdate!=null) { + try { + if(!CacheUpdate.notifyDQ.offer(new CacheUpdate.Transfer(name, seg),2,TimeUnit.SECONDS)) { + trans.error().log("Cache Notify Queue is not accepting messages, bouncing may be appropriate" ); + } + } catch (InterruptedException e) { + trans.error().log("Cache Notify Queue posting was interrupted" ); + } + } + + ///////////// + // Table Based Cache Invalidation (original) + ///////////// + // Note: Save time with multiple Sequence Touches, but PreparedStmt doesn't support IN + StringBuilder start = new StringBuilder("CacheInfoDAO Touch segments "); + start.append(name); + start.append(": "); + StringBuilder sb = new StringBuilder("BEGIN BATCH\n"); + boolean first = true; + for(int s : seg) { + sb.append(UPDATE_SP); + sb.append(TABLE); + sb.append(" SET touched=dateof(now()) WHERE name = '"); + sb.append(name); + sb.append("' AND seg = "); + sb.append(s); + sb.append(";\n"); + if(first) { + first =false; + } else { + start.append(','); + } + start.append(s); + } + sb.append("APPLY BATCH;"); + TimeTaken tt = trans.start(start.toString(),Env.REMOTE); + try { + getSession(trans).executeAsync(sb.toString()); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } finally { + tt.done(); + } + return Result.ok(); + } + + /* (non-Javadoc) + * @see com.att.dao.aaf.cass.CIDAO#check(com.att.authz.env.AuthzTrans) + */ + @Override + public Result check(AuthzTrans trans) { + ResultSet rs; + TimeTaken tt = trans.start("Check Table Timestamps",Env.REMOTE); + try { + rs = getSession(trans).execute(check); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } finally { + tt.done(); + } + + String lastName = null; + Date[] dates = null; + for(Row row : rs.all()) { + String name = row.getString(0); + int seg = row.getInt(1); + if(!name.equals(lastName)) { + dates = info.get(name); + lastName=name; + } + if(dates==null) { + dates=new Date[seg+1]; + info.put(name,dates); + } else if(dates.length<=seg) { + Date[] temp = new Date[seg+1]; + System.arraycopy(dates, 0, temp, 0, dates.length); + dates = temp; + info.put(name, dates); + } + Date temp = row.getDate(2); + if(dates[seg]==null || dates[seg].before(temp)) { + dates[seg]=temp; + } + } + return Result.ok(); + } + + /* (non-Javadoc) + * @see com.att.dao.aaf.cass.CIDAO#get(java.lang.String, int) + */ + @Override + public Date get(AuthzTrans trans, String table, int seg) { + Date[] dates = info.get(table); + if(dates==null) { + dates = new Date[seg+1]; + touch(trans,table, seg); + } else if(dates.length<=seg) { + Date[] temp = new Date[seg+1]; + System.arraycopy(dates, 0, temp, 0, dates.length); + dates = temp; + } + Date rv = dates[seg]; + if(rv==null) { + rv=dates[seg]=startTime; + } + return rv; + } + + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + // Do nothing + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/CacheableData.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/CacheableData.java new file mode 100644 index 00000000..2afefb1b --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/CacheableData.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import com.att.dao.Cacheable; +import com.att.dao.Cached; +import com.att.dao.CachedDAO; + +public abstract class CacheableData implements Cacheable { + // WARNING: DON'T attempt to add any members here, as it will + // be treated by system as fields expected in Tables + protected int seg(Cached cache, Object ... fields) { + return cache==null?0:cache.invalidate(CachedDAO.keyFromObjs(fields)); + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/CertDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/CertDAO.java new file mode 100644 index 00000000..6952841b --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/CertDAO.java @@ -0,0 +1,244 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.Bytification; +import com.att.dao.CIDAO; +import com.att.dao.Cached; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.att.dao.Streamer; +import com.att.inno.env.APIException; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Row; + +/** + * CredDAO manages credentials. + * Date: 7/19/13 + */ +public class CertDAO extends CassDAOImpl { + public static final String TABLE = "x509"; + public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F + + private HistoryDAO historyDAO; + private CIDAO infoDAO; + private PSInfo psX500,psID; + + public CertDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { + super(trans, CertDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + init(trans); + } + + public CertDAO(AuthzTrans trans, HistoryDAO hDao, CacheInfoDAO ciDao) throws APIException, IOException { + super(trans, CertDAO.class.getSimpleName(),hDao, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO = hDao; + infoDAO = ciDao; + init(trans); + } + + public static final int KEYLIMIT = 2; + public static class Data extends CacheableData implements Bytification { + + public String ca; + public BigInteger serial; + public String id; + public String x500; + public String x509; + + @Override + public int[] invalidate(Cached cache) { + return new int[] { + seg(cache,ca,serial) + }; + } + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + CertLoader.deflt.marshal(this,new DataOutputStream(baos)); + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + CertLoader.deflt.unmarshal(this, toDIS(bb)); + } + } + + private static class CertLoader extends Loader implements Streamer{ + public static final int MAGIC=85102934; + public static final int VERSION=1; + public static final int BUFF_SIZE=48; // Note: + + public static final CertLoader deflt = new CertLoader(KEYLIMIT); + public CertLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + data.ca = row.getString(0); + ByteBuffer bb = row.getBytesUnsafe(1); + byte[] bytes = new byte[bb.remaining()]; + bb.get(bytes); + data.serial = new BigInteger(bytes); + data.id = row.getString(2); + data.x500 = row.getString(3); + data.x509 = row.getString(4); + return data; + } + + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx] = data.ca; + obj[++idx] = ByteBuffer.wrap(data.serial.toByteArray()); + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + + obj[idx] = data.id; + obj[++idx] = data.x500; + obj[++idx] = data.x509; + + + } + + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + writeString(os, data.id); + writeString(os, data.x500); + writeString(os, data.x509); + writeString(os, data.ca); + if(data.serial==null) { + os.writeInt(-1); + } else { + byte[] dsba = data.serial.toByteArray(); + int l = dsba.length; + os.writeInt(l); + os.write(dsba,0,l); + } + } + + @Override + public void unmarshal(Data data, DataInputStream is) throws IOException { + /*int version = */readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + byte[] buff = new byte[BUFF_SIZE]; + data.id = readString(is,buff); + data.x500 = readString(is,buff); + data.x509 = readString(is,buff); + data.ca = readString(is,buff); + int i = is.readInt(); + if(i<0) { + data.serial=null; + } else { + byte[] bytes = new byte[i]; // a bit dangerous, but lessened because of all the previous sized data reads + is.read(bytes); + data.serial = new BigInteger(bytes); + } + } + } + + public Result> read(AuthzTrans trans, Object ... key) { + // Translate BigInteger to Byte array for lookup + return super.read(trans, key[0],ByteBuffer.wrap(((BigInteger)key[1]).toByteArray())); + } + + private void init(AuthzTrans trans) throws APIException, IOException { + // Set up sub-DAOs + if(historyDAO==null) { + historyDAO = new HistoryDAO(trans,this); + } + if(infoDAO==null) { + infoDAO = new CacheInfoDAO(trans,this); + } + + String[] helpers = setCRUD(trans, TABLE, Data.class, CertLoader.deflt); + + psID = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE id = ?", CertLoader.deflt,readConsistency); + + psX500 = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE x500 = ?", CertLoader.deflt,readConsistency); + + } + + public Result> readX500(AuthzTrans trans, String x500) { + return psX500.read(trans, R_TEXT, new Object[]{x500}); + } + + public Result> readID(AuthzTrans trans, String id) { + return psID.read(trans, R_TEXT, new Object[]{id}); + } + + /** + * Log Modification statements to History + * + * @param modified which CRUD action was done + * @param data entity data that needs a log entry + * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + hd.user = trans.user(); + hd.action = modified.name(); + hd.target = TABLE; + hd.subject = subject?override[1]: data.id; + hd.memo = memo + ? String.format("%s by %s", override[0], hd.user) + : (modified.name() + "d certificate info for " + data.id); + // Detail? + if(modified==CRUD.delete) { + try { + hd.reconstruct = data.bytify(); + } catch (IOException e) { + trans.error().log(e,"Could not serialize CertDAO.Data"); + } + } + + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + if(infoDAO.touch(trans, TABLE,data.invalidate(cache)).status!=Status.OK) { + trans.error().log("Cannot touch Cert"); + } + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/CredDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/CredDAO.java new file mode 100644 index 00000000..9d403fe4 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/CredDAO.java @@ -0,0 +1,258 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Date; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.Bytification; +import com.att.dao.CIDAO; +import com.att.dao.Cached; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.att.dao.Streamer; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Row; + +/** + * CredDAO manages credentials. + * Date: 7/19/13 + */ +public class CredDAO extends CassDAOImpl { + public static final String TABLE = "cred"; + public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F + public static final int RAW = -1; + public static final int BASIC_AUTH = 1; + public static final int BASIC_AUTH_SHA256 = 2; + public static final int CERT_SHA256_RSA =200; + + private HistoryDAO historyDAO; + private CIDAO infoDAO; + private PSInfo psNS; + private PSInfo psID; + + public CredDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { + super(trans, CredDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + init(trans); + } + + public CredDAO(AuthzTrans trans, HistoryDAO hDao, CacheInfoDAO ciDao) throws APIException, IOException { + super(trans, CredDAO.class.getSimpleName(),hDao, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO = hDao; + infoDAO = ciDao; + init(trans); + } + + public static final int KEYLIMIT = 3; + public static class Data extends CacheableData implements Bytification { + + public String id; + public Integer type; + public Date expires; + public Integer other; + public String ns; + public String notes; + public ByteBuffer cred; // this is a blob in cassandra + + + @Override + public int[] invalidate(Cached cache) { + return new int[] { + seg(cache,id) // cache is for all entities + }; + } + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + CredLoader.deflt.marshal(this,new DataOutputStream(baos)); + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + CredLoader.deflt.unmarshal(this, toDIS(bb)); + } + + public String toString() { + return id + ' ' + type + ' ' + Chrono.dateTime(expires); + } + } + + private static class CredLoader extends Loader implements Streamer{ + public static final int MAGIC=153323443; + public static final int VERSION=1; + public static final int BUFF_SIZE=48; // Note: + + public static final CredLoader deflt = new CredLoader(KEYLIMIT); + public CredLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + data.id = row.getString(0); + data.type = row.getInt(1); // NOTE: in datastax driver, If the int value is NULL, 0 is returned! + data.expires = row.getDate(2); + data.other = row.getInt(3); + data.ns = row.getString(4); + data.notes = row.getString(5); + data.cred = row.getBytesUnsafe(6); + return data; + } + + @Override + protected void key(Data data, int _idx, Object[] obj) { + int idx = _idx; + + obj[idx] = data.id; + obj[++idx] = data.type; + obj[++idx] = data.expires; + } + + @Override + protected void body(Data data, int idx, Object[] obj) { + int i; + obj[i=idx] = data.other; + obj[++i] = data.ns; + obj[++i] = data.notes; + obj[++i] = data.cred; + } + + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + writeString(os, data.id); + os.writeInt(data.type); + os.writeLong(data.expires==null?-1:data.expires.getTime()); + os.writeInt(data.other==null?0:data.other); + writeString(os, data.ns); + writeString(os, data.notes); + if(data.cred==null) { + os.writeInt(-1); + } else { + int l = data.cred.limit()-data.cred.position(); + os.writeInt(l); + os.write(data.cred.array(),data.cred.position(),l); + } + } + + @Override + public void unmarshal(Data data, DataInputStream is) throws IOException { + /*int version = */readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + byte[] buff = new byte[BUFF_SIZE]; + data.id = readString(is,buff); + data.type = is.readInt(); + + long l = is.readLong(); + data.expires = l<0?null:new Date(l); + data.other = is.readInt(); + data.ns = readString(is,buff); + data.notes = readString(is,buff); + + int i = is.readInt(); + if(i<0) { + data.cred=null; + } else { + byte[] bytes = new byte[i]; // a bit dangerous, but lessened because of all the previous sized data reads + is.read(bytes); + data.cred = ByteBuffer.wrap(bytes); + } + } + } + + private void init(AuthzTrans trans) throws APIException, IOException { + // Set up sub-DAOs + if(historyDAO==null) { + historyDAO = new HistoryDAO(trans,this); + } + if(infoDAO==null) { + infoDAO = new CacheInfoDAO(trans,this); + } + + + String[] helpers = setCRUD(trans, TABLE, Data.class, CredLoader.deflt); + + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns = ?", CredLoader.deflt,readConsistency); + + psID = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE id = ?", CredLoader.deflt,readConsistency); + } + + public Result> readNS(AuthzTrans trans, String ns) { + return psNS.read(trans, R_TEXT, new Object[]{ns}); + } + + public Result> readID(AuthzTrans trans, String id) { + return psID.read(trans, R_TEXT, new Object[]{id}); + } + + /** + * Log Modification statements to History + * + * @param modified which CRUD action was done + * @param data entity data that needs a log entry + * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + hd.user = trans.user(); + hd.action = modified.name(); + hd.target = TABLE; + hd.subject = subject?override[1]: data.id; + hd.memo = memo + ? String.format("%s by %s", override[0], hd.user) + : (modified.name() + "d credential for " + data.id); + // Detail? + if(modified==CRUD.delete) { + try { + hd.reconstruct = data.bytify(); + } catch (IOException e) { + trans.error().log(e,"Could not serialize CredDAO.Data"); + } + } + + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + if(infoDAO.touch(trans, TABLE,data.invalidate(cache)).status!=Status.OK) { + trans.error().log("Cannot touch Cred"); + } + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/DelegateDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/DelegateDAO.java new file mode 100644 index 00000000..7cebc88d --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/DelegateDAO.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Date; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.AbsCassDAO; +import com.att.dao.Bytification; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.att.dao.Streamer; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Row; + +public class DelegateDAO extends CassDAOImpl { + + public static final String TABLE = "delegate"; + private PSInfo psByDelegate; + + public DelegateDAO(AuthzTrans trans, Cluster cluster, String keyspace) { + super(trans, DelegateDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + init(trans); + } + + public DelegateDAO(AuthzTrans trans, AbsCassDAO aDao) { + super(trans, DelegateDAO.class.getSimpleName(),aDao,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + init(trans); + } + + private static final int KEYLIMIT = 1; + public static class Data implements Bytification { + public String user; + public String delegate; + public Date expires; + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DelegateLoader.dflt.marshal(this,new DataOutputStream(baos)); + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + DelegateLoader.dflt.unmarshal(this, toDIS(bb)); + } + } + + private static class DelegateLoader extends Loader implements Streamer{ + public static final int MAGIC=0xD823ACF2; + public static final int VERSION=1; + public static final int BUFF_SIZE=48; + + public static final DelegateLoader dflt = new DelegateLoader(KEYLIMIT); + + public DelegateLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + data.user = row.getString(0); + data.delegate = row.getString(1); + data.expires = row.getDate(2); + return data; + } + + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.user; + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + + obj[idx]=data.delegate; + obj[++idx]=data.expires; + } + + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + writeString(os, data.user); + writeString(os, data.delegate); + os.writeLong(data.expires.getTime()); + } + + @Override + public void unmarshal(Data data, DataInputStream is) throws IOException { + /*int version = */readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + byte[] buff = new byte[BUFF_SIZE]; + data.user = readString(is, buff); + data.delegate = readString(is,buff); + data.expires = new Date(is.readLong()); + } + } + + private void init(AuthzTrans trans) { + String[] helpers = setCRUD(trans, TABLE, Data.class, DelegateLoader.dflt); + psByDelegate = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE delegate = ?", new DelegateLoader(1),readConsistency); + + } + + public Result> readByDelegate(AuthzTrans trans, String delegate) { + return psByDelegate.read(trans, R_TEXT, new Object[]{delegate}); + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/FutureDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/FutureDAO.java new file mode 100644 index 00000000..5db689d7 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/FutureDAO.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.nio.ByteBuffer; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.CassDAOImpl; +import com.att.dao.DAOException; +import com.att.dao.Loader; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; + +/** + * FutureDAO stores Construction information to create + * elements at another time. + * + * 8/20/2013 + */ +public class FutureDAO extends CassDAOImpl { + private static final String TABLE = "future"; + private final HistoryDAO historyDAO; +// private static String createString; + private PSInfo psByStartAndTarget; + + public FutureDAO(AuthzTrans trans, Cluster cluster, String keyspace) { + super(trans, FutureDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO = new HistoryDAO(trans, this); + init(trans); + } + + public FutureDAO(AuthzTrans trans, HistoryDAO hDAO) { + super(trans, FutureDAO.class.getSimpleName(),hDAO, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO=hDAO; + init(trans); + } + + public static final int KEYLIMIT = 1; + public static class Data { + public UUID id; + public String target; + public String memo; + public Date start; + public Date expires; + public ByteBuffer construct; // this is a blob in cassandra + } + + private static class FLoader extends Loader { + public FLoader() { + super(KEYLIMIT); + } + + public FLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + data.id = row.getUUID(0); + data.target = row.getString(1); + data.memo = row.getString(2); + data.start = row.getDate(3); + data.expires = row.getDate(4); + data.construct = row.getBytes(5); + return data; + } + + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx] = data.id; + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + + obj[idx] = data.target; + obj[++idx] = data.memo; + obj[++idx] = data.start; + obj[++idx] = data.expires; + obj[++idx] = data.construct; + } + } + + private void init(AuthzTrans trans) { + // Set up sub-DAOs + String[] helpers = setCRUD(trans, TABLE, Data.class, new FLoader(KEYLIMIT)); + + // Uh, oh. Can't use "now()" in Prepared Statements (at least at this level) +// createString = "INSERT INTO " + TABLE + " ("+helpers[FIELD_COMMAS] +") VALUES (now(),"; +// +// // Need a specialty Creator to handle the "now()" +// replace(CRUD.Create, new PSInfo(trans, "INSERT INTO future (" + helpers[FIELD_COMMAS] + +// ") VALUES(now(),?,?,?,?,?)",new FLoader(0))); + + // Other SELECT style statements... match with a local Method + psByStartAndTarget = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + + " FROM future WHERE start <= ? and target = ? ALLOW FILTERING", new FLoader(2) { + @Override + protected void key(Data data, int _idx, Object[] obj) { + int idx = _idx; + + obj[idx]=data.start; + obj[++idx]=data.target; + } + },readConsistency); + + + } + + public Result> readByStartAndTarget(AuthzTrans trans, Date start, String target) throws DAOException { + return psByStartAndTarget.read(trans, R_TEXT, new Object[]{start, target}); + } + + /** + * Override create to add secondary ID to Subject in History, and create Data.ID, if it is null + */ + public Result create(AuthzTrans trans, FutureDAO.Data data, String id) { + // If ID is not set (typical), create one. + if(data.id==null) { + StringBuilder sb = new StringBuilder(trans.user()); + sb.append(data.target); + sb.append(System.currentTimeMillis()); + data.id = UUID.nameUUIDFromBytes(sb.toString().getBytes()); + } + Result rs = createPS.exec(trans, C_TEXT, data); + if(rs.notOK()) { + return Result.err(rs); + } + wasModified(trans, CRUD.create, data, null, id); + return Result.ok(data); + } + + /** + * Log Modification statements to History + * + * @param modified which CRUD action was done + * @param data entity data that needs a log entry + * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + hd.user = trans.user(); + hd.action = modified.name(); + hd.target = TABLE; + hd.subject = subject?override[1]:""; + hd.memo = memo?String.format("%s by %s", override[0], hd.user):data.memo; + + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/HistoryDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/HistoryDAO.java new file mode 100644 index 00000000..4a9d105d --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/HistoryDAO.java @@ -0,0 +1,237 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.AbsCassDAO; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ConsistencyLevel; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; + +/** + * History + * + * + * History is a special case, because we don't want Updates or Deletes... Too likely to mess up history. + * + * 9-9-2013 - Found a problem with using "Prepare". You cannot prepare anything with a "now()" in it, as + * it is evaluated once during the prepare, and kept. That renders any use of "now()" pointless. Therefore + * the Create function needs to be run fresh everytime. + * + * Fixed in Cassandra 1.2.6 https://issues.apache.org/jira/browse/CASSANDRA-5616 + * + */ +public class HistoryDAO extends CassDAOImpl { + private static final String TABLE = "history"; + + public static final SimpleDateFormat monthFormat = new SimpleDateFormat("yyyyMM"); +// private static final SimpleDateFormat dayTimeFormat = new SimpleDateFormat("ddHHmmss"); + + private String[] helpers; + + private HistLoader defLoader; + + private AbsCassDAO.PSInfo readByUser, readBySubject, readByYRMN; + + public HistoryDAO(AuthzTrans trans, Cluster cluster, String keyspace) { + super(trans, HistoryDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE,ConsistencyLevel.LOCAL_ONE,ConsistencyLevel.ANY); + init(trans); + } + + public HistoryDAO(AuthzTrans trans, AbsCassDAO aDao) { + super(trans, HistoryDAO.class.getSimpleName(),aDao,Data.class,TABLE,ConsistencyLevel.LOCAL_ONE,ConsistencyLevel.ANY); + init(trans); + } + + + private static final int KEYLIMIT = 1; + public static class Data { + public UUID id; + public int yr_mon; + public String user; + public String action; + public String target; + public String subject; + public String memo; +// Map detail = null; +// public Map detail() { +// if(detail == null) { +// detail = new HashMap(); +// } +// return detail; +// } + public ByteBuffer reconstruct; + } + + private static class HistLoader extends Loader { + public HistLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + data.id = row.getUUID(0); + data.yr_mon = row.getInt(1); + data.user = row.getString(2); + data.action = row.getString(3); + data.target = row.getString(4); + data.subject = row.getString(5); + data.memo = row.getString(6); +// data.detail = row.getMap(6, String.class, String.class); + data.reconstruct = row.getBytes(7); + return data; + } + + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.id; + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx]=data.yr_mon; + obj[++idx]=data.user; + obj[++idx]=data.action; + obj[++idx]=data.target; + obj[++idx]=data.subject; + obj[++idx]=data.memo; +// obj[++idx]=data.detail; + obj[++idx]=data.reconstruct; + } + }; + + private void init(AuthzTrans trans) { + // Loader must match fields order + defLoader = new HistLoader(KEYLIMIT); + helpers = setCRUD(trans, TABLE, Data.class, defLoader); + + // Need a specialty Creator to handle the "now()" + // 9/9/2013 - jg - Just great... now() is evaluated once on Client side, invalidating usage (what point is a now() from a long time in the past? + // Unless this is fixed, we're putting in non-prepared statement + // Solved in Cassandra. Make sure you are running 1.2.6 Cassandra or later. https://issues.apache.org/jira/browse/CASSANDRA-5616 + replace(CRUD.create, new PSInfo(trans, "INSERT INTO history (" + helpers[FIELD_COMMAS] + + ") VALUES(now(),?,?,?,?,?,?,?)", + new HistLoader(0) { + @Override + protected void key(Data data, int idx, Object[] obj) { + } + },writeConsistency) + ); +// disable(CRUD.Create); + + replace(CRUD.read, new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + + " FROM history WHERE id = ?", defLoader,readConsistency) +// new HistLoader(2) { +// @Override +// protected void key(Data data, int idx, Object[] obj) { +// obj[idx]=data.yr_mon; +// obj[++idx]=data.id; +// } +// }) + ); + disable(CRUD.update); + disable(CRUD.delete); + + readByUser = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + + " FROM history WHERE user = ?", defLoader,readConsistency); + readBySubject = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + + " FROM history WHERE subject = ? and target = ? ALLOW FILTERING", defLoader,readConsistency); + readByYRMN = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + + " FROM history WHERE yr_mon = ?", defLoader,readConsistency); + async(true); //TODO dropping messages with Async + } + + public static Data newInitedData() { + Data data = new Data(); + Date now = new Date(); + data.yr_mon = Integer.parseInt(monthFormat.format(now)); + // data.day_time = Integer.parseInt(dayTimeFormat.format(now)); + return data; + } + + public Result> readByYYYYMM(AuthzTrans trans, int yyyymm) { + Result rs = readByYRMN.exec(trans, "yr_mon", yyyymm); + if(rs.notOK()) { + return Result.err(rs); + } + return extract(defLoader,rs.value,null,dflt); + } + + /** + * Gets the history for a user in the specified year and month + * year - the year in yyyy format + * month - the month in a year ...values 1 - 12 + **/ + public Result> readByUser(AuthzTrans trans, String user, int ... yyyymm) { + if(yyyymm.length==0) { + return Result.err(Status.ERR_BadData, "No or invalid yyyymm specified"); + } + Result rs = readByUser.exec(trans, "user", user); + if(rs.notOK()) { + return Result.err(rs); + } + return extract(defLoader,rs.value,null,yyyymm.length>0?new YYYYMM(yyyymm):dflt); + } + + public Result> readBySubject(AuthzTrans trans, String subject, String target, int ... yyyymm) { + if(yyyymm.length==0) { + return Result.err(Status.ERR_BadData, "No or invalid yyyymm specified"); + } + Result rs = readBySubject.exec(trans, "subject", subject, target); + if(rs.notOK()) { + return Result.err(rs); + } + return extract(defLoader,rs.value,null,yyyymm.length>0?new YYYYMM(yyyymm):dflt); + } + + private class YYYYMM implements Accept { + private int[] yyyymm; + public YYYYMM(int yyyymm[]) { + this.yyyymm = yyyymm; + } + @Override + public boolean ok(Data data) { + int dym = data.yr_mon; + for(int ym:yyyymm) { + if(dym==ym) { + return true; + } + } + return false; + } + + }; + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/Namespace.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/Namespace.java new file mode 100644 index 00000000..fa61372e --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/Namespace.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import com.att.cssa.rserv.Pair; +import com.att.dao.Bytification; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; + + +public class Namespace implements Bytification { + public static final int MAGIC=250935515; + public static final int VERSION=1; + public static final int BUFF_SIZE=48; + + public String name; + public List owner; + public List admin; + public List> attrib; + public String description; + public Integer type; + public String parent; + public Namespace() {} + + public Namespace(NsDAO.Data ndd) { + name = ndd.name; + description = ndd.description; + type = ndd.type; + parent = ndd.parent; + if(ndd.attrib!=null && !ndd.attrib.isEmpty()) { + attrib = new ArrayList>(); + for( Entry entry : ndd.attrib.entrySet()) { + attrib.add(new Pair(entry.getKey(),entry.getValue())); + } + } + } + + public Namespace(NsDAO.Data ndd,List owner, List admin) { + name = ndd.name; + this.owner = owner; + this.admin = admin; + description = ndd.description; + type = ndd.type; + parent = ndd.parent; + if(ndd.attrib!=null && !ndd.attrib.isEmpty()) { + attrib = new ArrayList>(); + for( Entry entry : ndd.attrib.entrySet()) { + attrib.add(new Pair(entry.getKey(),entry.getValue())); + } + } + } + + public NsDAO.Data data() { + NsDAO.Data ndd = new NsDAO.Data(); + ndd.name = name; + ndd.description = description; + ndd.parent = parent; + ndd.type = type; + return ndd; + } + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream os = new DataOutputStream(baos); + + Loader.writeHeader(os,MAGIC,VERSION); + Loader.writeString(os, name); + os.writeInt(type); + Loader.writeStringSet(os,admin); + Loader.writeStringSet(os,owner); + Loader.writeString(os,description); + Loader.writeString(os,parent); + + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + DataInputStream is = CassDAOImpl.toDIS(bb); + /*int version = */Loader.readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + + byte[] buff = new byte[BUFF_SIZE]; + name = Loader.readString(is, buff); + type = is.readInt(); + admin = Loader.readStringList(is,buff); + owner = Loader.readStringList(is,buff); + description = Loader.readString(is,buff); + parent = Loader.readString(is,buff); + + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return name.hashCode(); + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return name.toString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object arg0) { + if(arg0==null || !(arg0 instanceof Namespace)) { + return false; + } + return name.equals(((Namespace)arg0).name); + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/NsDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/NsDAO.java new file mode 100644 index 00000000..39a52af9 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/NsDAO.java @@ -0,0 +1,541 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.Bytification; +import com.att.dao.Cached; +import com.att.dao.CassAccess; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.att.dao.Streamer; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.exceptions.DriverException; + +/** + * NsDAO + * + * Data Access Object for Namespace Data + * + */ +public class NsDAO extends CassDAOImpl { + public static final String TABLE = "ns"; + public static final String TABLE_ATTRIB = "ns_attrib"; + public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F + public static final int ROOT = 1; + public static final int COMPANY=2; + public static final int APP = 3; + + private static final String BEGIN_BATCH = "BEGIN BATCH\n"; + private static final String APPLY_BATCH = "APPLY BATCH;\n"; + private static final String SQSCCR = "';\n"; + private static final String SQCSQ = "','"; + + private HistoryDAO historyDAO; + private CacheInfoDAO infoDAO; + private PSInfo psNS; + + public NsDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { + super(trans, NsDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + init(trans); + } + + public NsDAO(AuthzTrans trans, HistoryDAO hDAO, CacheInfoDAO iDAO) throws APIException, IOException { + super(trans, NsDAO.class.getSimpleName(),hDAO,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO=hDAO; + infoDAO = iDAO; + init(trans); + } + + + ////////////////////////////////////////// + // Data Definition, matches Cassandra DM + ////////////////////////////////////////// + private static final int KEYLIMIT = 1; + /** + * Data class that matches the Cassandra Table "role" + * + */ + public static class Data extends CacheableData implements Bytification { + public String name; + public int type; + public String description; + public String parent; + public Map attrib; + +// //////////////////////////////////////// +// // Getters + public Map attrib(boolean mutable) { + if (attrib == null) { + attrib = new HashMap(); + } else if (mutable && !(attrib instanceof HashMap)) { + attrib = new HashMap(attrib); + } + return attrib; + } + + @Override + public int[] invalidate(Cached cache) { + return new int[] { + seg(cache,name) + }; + } + + public NsSplit split(String name) { + return new NsSplit(this,name); + } + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + NSLoader.deflt.marshal(this,new DataOutputStream(baos)); + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + NSLoader.deflt.unmarshal(this,toDIS(bb)); + } + + @Override + public String toString() { + return name; + } + + } + + private void init(AuthzTrans trans) throws APIException, IOException { + // Set up sub-DAOs + if(historyDAO==null) { + historyDAO = new HistoryDAO(trans, this); + } + if(infoDAO==null) { + infoDAO = new CacheInfoDAO(trans,this); + } + + String[] helpers = setCRUD(trans, TABLE, Data.class, NSLoader.deflt,4/*need to skip attrib */); + + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE parent = ?", new NSLoader(1),readConsistency); + + } + + private static final class NSLoader extends Loader implements Streamer { + public static final int MAGIC=250935515; + public static final int VERSION=1; + public static final int BUFF_SIZE=48; + + public static final NSLoader deflt = new NSLoader(KEYLIMIT); + + public NSLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + // Int more efficient + data.name = row.getString(0); + data.type = row.getInt(1); + data.description = row.getString(2); + data.parent = row.getString(3); + return data; + } + + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.name; + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + + obj[idx]=data.type; + obj[++idx]=data.description; + obj[++idx]=data.parent; + } + + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + writeString(os, data.name); + os.writeInt(data.type); + writeString(os,data.description); + writeString(os,data.parent); + if(data.attrib==null) { + os.writeInt(-1); + } else { + os.writeInt(data.attrib.size()); + for(Entry es : data.attrib(false).entrySet()) { + writeString(os,es.getKey()); + writeString(os,es.getValue()); + } + } + } + + @Override + public void unmarshal(Data data, DataInputStream is) throws IOException { + /*int version = */readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + + byte[] buff = new byte[BUFF_SIZE]; + data.name = readString(is, buff); + data.type = is.readInt(); + data.description = readString(is,buff); + data.parent = readString(is,buff); + int count = is.readInt(); + if(count>0) { + Map da = data.attrib(true); + for(int i=0;i create(AuthzTrans trans, Data data) { + String ns = data.name; + // Ensure Parent is set + int ldot = ns.lastIndexOf('.'); + data.parent=ldot<0?".":ns.substring(0,ldot); + + // insert Attributes + StringBuilder stmt = new StringBuilder(); + stmt.append(BEGIN_BATCH); + attribInsertStmts(stmt, data); + stmt.append(APPLY_BATCH); + try { + getSession(trans).execute(stmt.toString()); +//// TEST CODE for Exception +// boolean force = true; +// if(force) { +// throw new com.datastax.driver.core.exceptions.NoHostAvailableException(new HashMap()); +//// throw new com.datastax.driver.core.exceptions.AuthenticationException(new InetSocketAddress(9999),"Sample Message"); +// } +////END TEST CODE + + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + trans.info().log(stmt); + return Result.err(Result.ERR_Backend, "Backend Access"); + } + return super.create(trans, data); + } + + @Override + public Result update(AuthzTrans trans, Data data) { + String ns = data.name; + // Ensure Parent is set + int ldot = ns.lastIndexOf('.'); + data.parent=ldot<0?".":ns.substring(0,ldot); + + StringBuilder stmt = new StringBuilder(); + stmt.append(BEGIN_BATCH); + try { + Map localAttr = data.attrib; + Result> rremoteAttr = readAttribByNS(trans,ns); + if(rremoteAttr.notOK()) { + return Result.err(rremoteAttr); + } + // update Attributes + String str; + for(Entry es : localAttr.entrySet()) { + str = rremoteAttr.value.get(es.getKey()); + if(str==null || !str.equals(es.getValue())) { + attribInsertStmt(stmt, ns, es.getKey(),es.getValue()); + } + } + + // No point in deleting... insert overwrites... +// for(Entry es : remoteAttr.entrySet()) { +// str = localAttr.get(es.getKey()); +// if(str==null || !str.equals(es.getValue())) { +// attribDeleteStmt(stmt, ns, es.getKey()); +// } +// } + if(stmt.length()>BEGIN_BATCH.length()) { + stmt.append(APPLY_BATCH); + getSession(trans).execute(stmt.toString()); + } + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + trans.info().log(stmt); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + + return super.update(trans,data); + } + + /* (non-Javadoc) + * @see com.att.dao.CassDAOImpl#read(com.att.inno.env.TransStore, java.lang.Object) + */ + @Override + public Result> read(AuthzTrans trans, Data data) { + Result> rld = super.read(trans, data); + + if(rld.isOKhasData()) { + for(Data d : rld.value) { + // Note: Map is null at this point, save time/mem by assignment + Result> rabn = readAttribByNS(trans,d.name); + if(rabn.isOK()) { + d.attrib = rabn.value; + } else { + return Result.err(rabn); + } + } + } + return rld; + } + + /* (non-Javadoc) + * @see com.att.dao.CassDAOImpl#read(com.att.inno.env.TransStore, java.lang.Object[]) + */ + @Override + public Result> read(AuthzTrans trans, Object... key) { + Result> rld = super.read(trans, key); + + if(rld.isOKhasData()) { + for(Data d : rld.value) { + // Note: Map is null at this point, save time/mem by assignment + Result> rabn = readAttribByNS(trans,d.name); + if(rabn.isOK()) { + d.attrib = rabn.value; + } else { + return Result.err(rabn); + } + } + } + return rld; + } + + @Override + public Result delete(AuthzTrans trans, Data data, boolean reread) { + TimeTaken tt = trans.start("Delete NS Attributes " + data.name, Env.REMOTE); + try { + StringBuilder stmt = new StringBuilder(); + attribDeleteAllStmt(stmt, data); + try { + getSession(trans).execute(stmt.toString()); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + trans.info().log(stmt); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + } finally { + tt.done(); + } + return super.delete(trans, data, reread); + + } + + public Result> readAttribByNS(AuthzTrans trans, String ns) { + Map map = new HashMap(); + TimeTaken tt = trans.start("readAttribByNS " + ns, Env.REMOTE); + try { + ResultSet rs = getSession(trans).execute("SELECT key,value FROM " + + TABLE_ATTRIB + + " WHERE ns='" + + ns + + "';"); + + for(Iterator iter = rs.iterator();iter.hasNext(); ) { + Row r = iter.next(); + map.put(r.getString(0), r.getString(1)); + } + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } finally { + tt.done(); + } + return Result.ok(map); + } + + public Result> readNsByAttrib(AuthzTrans trans, String key) { + Set set = new HashSet(); + TimeTaken tt = trans.start("readNsBykey " + key, Env.REMOTE); + try { + ResultSet rs = getSession(trans).execute("SELECT ns FROM " + + TABLE_ATTRIB + + " WHERE key='" + + key + + "';"); + + for(Iterator iter = rs.iterator();iter.hasNext(); ) { + Row r = iter.next(); + set.add(r.getString(0)); + } + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } finally { + tt.done(); + } + return Result.ok(set); + } + + public Result attribAdd(AuthzTrans trans, String ns, String key, String value) { + try { + getSession(trans).execute(attribInsertStmt(new StringBuilder(),ns,key,value).toString()); + return Result.ok(); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + } + + private StringBuilder attribInsertStmt(StringBuilder sb, String ns, String key, String value) { + sb.append("INSERT INTO "); + sb.append(TABLE_ATTRIB); + sb.append(" (ns,key,value) VALUES ('"); + sb.append(ns); + sb.append(SQCSQ); + sb.append(key); + sb.append(SQCSQ); + sb.append(value); + sb.append("');"); + return sb; + } + + public Result attribRemove(AuthzTrans trans, String ns, String key) { + try { + getSession(trans).execute(attribDeleteStmt(new StringBuilder(),ns,key).toString()); + return Result.ok(); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + } + + private StringBuilder attribDeleteStmt(StringBuilder stmt, String ns, String key) { + stmt.append("DELETE FROM "); + stmt.append(TABLE_ATTRIB); + stmt.append(" WHERE ns='"); + stmt.append(ns); + stmt.append("' AND key='"); + stmt.append(key); + stmt.append("';"); + return stmt; + } + + private void attribDeleteAllStmt(StringBuilder stmt, Data data) { + stmt.append(" DELETE FROM "); + stmt.append(TABLE_ATTRIB); + stmt.append(" WHERE ns='"); + stmt.append(data.name); + stmt.append(SQSCCR); + } + + private void attribInsertStmts(StringBuilder stmt, Data data) { + // INSERT new Attrib + for(Entry es : data.attrib(false).entrySet() ) { + stmt.append(" "); + attribInsertStmt(stmt,data.name,es.getKey(),es.getValue()); + } + } + + /** + * Add description to Namespace + * @param trans + * @param ns + * @param description + * @return + */ + public Result addDescription(AuthzTrans trans, String ns, String description) { + try { + getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + + description + "' WHERE name = '" + ns + "';"); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + + Data data = new Data(); + data.name=ns; + wasModified(trans, CRUD.update, data, "Added description " + description + " to namespace " + ns, null ); + return Result.ok(); + } + + public Result> getChildren(AuthzTrans trans, String parent) { + return psNS.read(trans, R_TEXT, new Object[]{parent}); + } + + + /** + * Log Modification statements to History + * + * @param modified which CRUD action was done + * @param data entity data that needs a log entry + * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + + //TODO Must log history + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + hd.user = trans.user(); + hd.action = modified.name(); + hd.target = TABLE; + hd.subject = subject ? override[1] : data.name; + hd.memo = memo ? override[0] : (data.name + " was " + modified.name() + 'd' ); + if(modified==CRUD.delete) { + try { + hd.reconstruct = data.bytify(); + } catch (IOException e) { + trans.error().log(e,"Could not serialize NsDAO.Data"); + } + } + + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + if(infoDAO.touch(trans, TABLE,data.invalidate(cache)).notOK()) { + trans.error().log("Cannot touch CacheInfo"); + } + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/NsSplit.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/NsSplit.java new file mode 100644 index 00000000..ad896fc5 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/NsSplit.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +public class NsSplit { + public final String ns; + public final String name; + public final NsDAO.Data nsd; + + public NsSplit(NsDAO.Data nsd, String child) { + this.nsd = nsd; + if(child.startsWith(nsd.name)) { + ns = nsd.name; + int dot = ns.length(); + if(dot=0) { + nsd.parent = ns.substring(0, dot); + } else { + nsd.parent = "."; + } + } + + public boolean isOK() { + return ns!=null && name !=null; + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/NsType.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/NsType.java new file mode 100644 index 00000000..442e26e3 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/NsType.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +/** + * Defines the Type Codes in the NS Table. + * + */ +public enum NsType { + UNKNOWN (-1), + DOT (0), + ROOT (1), + COMPANY (2), + APP (3), + STACKED_APP (10), + STACK (11); + + public final int type; + private NsType(int t) { + type = t; + } + /** + * This is not the Ordinal, but the Type that is stored in NS Tables + * + * @param t + * @return + */ + public static NsType fromType(int t) { + for(NsType nst : values()) { + if(t==nst.type) { + return nst; + } + } + return UNKNOWN; + } + + /** + * Use this one rather than "valueOf" to avoid Exception + * @param s + * @return + */ + public static NsType fromString(String s) { + if(s!=null) { + for(NsType nst : values()) { + if(nst.name().equals(s)) { + return nst; + } + } + } + return UNKNOWN; + } + + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/PermDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/PermDAO.java new file mode 100644 index 00000000..b54b6fc7 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/PermDAO.java @@ -0,0 +1,502 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.Bytification; +import com.att.dao.Cached; +import com.att.dao.CassAccess; +import com.att.dao.CassDAOImpl; +import com.att.dao.DAOException; +import com.att.dao.Loader; +import com.att.dao.Streamer; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Split; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.exceptions.DriverException; + +public class PermDAO extends CassDAOImpl { + + public static final String TABLE = "perm"; + + public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F + private static final String STAR = "*"; + + private final HistoryDAO historyDAO; + private final CacheInfoDAO infoDAO; + + private PSInfo psNS, psChildren, psByType; + + public PermDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { + super(trans, PermDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + init(trans); + historyDAO = new HistoryDAO(trans, this); + infoDAO = new CacheInfoDAO(trans,this); + } + + public PermDAO(AuthzTrans trans, HistoryDAO hDAO, CacheInfoDAO ciDAO) { + super(trans, PermDAO.class.getSimpleName(),hDAO,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO = hDAO; + infoDAO=ciDAO; + init(trans); + } + + + private static final int KEYLIMIT = 4; + public static class Data extends CacheableData implements Bytification { + public String ns; + public String type; + public String instance; + public String action; + public Set roles; + public String description; + + public Data() {} + + public Data(NsSplit nss, String instance, String action) { + ns = nss.ns; + type = nss.name; + this.instance = instance; + this.action = action; + } + + public String fullType() { + return ns + '.' + type; + } + + public String fullPerm() { + return ns + '.' + type + '|' + instance + '|' + action; + } + + public String encode() { + return ns + '|' + type + '|' + instance + '|' + action; + } + + /** + * Decode Perm String, including breaking into appropriate Namespace + * + * @param trans + * @param q + * @param p + * @return + */ + public static Result decode(AuthzTrans trans, Question q, String p) { + String[] ss = Split.splitTrim('|', p,4); + if(ss[2]==null) { + return Result.err(Status.ERR_BadData,"Perm Encodings must be separated by '|'"); + } + Data data = new Data(); + if(ss[3]==null) { // older 3 part encoding must be evaluated for NS + Result nss = q.deriveNsSplit(trans, ss[0]); + if(nss.notOK()) { + return Result.err(nss); + } + data.ns=nss.value.ns; + data.type=nss.value.name; + data.instance=ss[1]; + data.action=ss[2]; + } else { // new 4 part encoding + data.ns=ss[0]; + data.type=ss[1]; + data.instance=ss[2]; + data.action=ss[3]; + } + return Result.ok(data); + } + + /** + * Decode Perm String, including breaking into appropriate Namespace + * + * @param trans + * @param q + * @param p + * @return + */ + public static Result decodeToArray(AuthzTrans trans, Question q, String p) { + String[] ss = Split.splitTrim('|', p,4); + if(ss[2]==null) { + return Result.err(Status.ERR_BadData,"Perm Encodings must be separated by '|'"); + } + + if(ss[3]==null) { // older 3 part encoding must be evaluated for NS + ss[3] = ss[2]; + ss[2] = ss[1]; + Result nss = q.deriveNsSplit(trans, ss[0]); + if(nss.notOK()) { + return Result.err(nss); + } + ss[1] = nss.value.name; + ss[0] = nss.value.ns; + } + return Result.ok(ss); + } + + public static Data create(NsDAO.Data ns, String name) { + NsSplit nss = new NsSplit(ns,name); + Data rv = new Data(); + rv.ns = nss.ns; + String[] s = nss.name.split("\\|"); + switch(s.length) { + case 3: + rv.type=s[0]; + rv.instance=s[1]; + rv.action=s[2]; + break; + case 2: + rv.type=s[0]; + rv.instance=s[1]; + rv.action=STAR; + break; + default: + rv.type=s[0]; + rv.instance = STAR; + rv.action = STAR; + } + return rv; + } + + public static Data create(AuthzTrans trans, Question q, String name) { + String[] s = name.split("\\|"); + Result rdns = q.deriveNsSplit(trans, s[0]); + Data rv = new PermDAO.Data(); + if(rdns.isOKhasData()) { + switch(s.length) { + case 3: + rv.type=s[1]; + rv.instance=s[2]; + rv.action=s[3]; + break; + case 2: + rv.type=s[1]; + rv.instance=s[2]; + rv.action=STAR; + break; + default: + rv.type=s[1]; + rv.instance = STAR; + rv.action = STAR; + } + } + return rv; + } + + //////////////////////////////////////// + // Getters + public Set roles(boolean mutable) { + if (roles == null) { + roles = new HashSet(); + } else if (mutable && !(roles instanceof HashSet)) { + roles = new HashSet(roles); + } + return roles; + } + + @Override + public int[] invalidate(Cached cache) { + return new int[] { + seg(cache,ns), + seg(cache,ns,type), + seg(cache,ns,type,STAR), + seg(cache,ns,type,instance,action) + }; + } + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PermLoader.deflt.marshal(this, new DataOutputStream(baos)); + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + PermLoader.deflt.unmarshal(this, toDIS(bb)); + } + + @Override + public String toString() { + return encode(); + } + } + + private static class PermLoader extends Loader implements Streamer { + public static final int MAGIC=283939453; + public static final int VERSION=1; + public static final int BUFF_SIZE=96; + + public static final PermLoader deflt = new PermLoader(KEYLIMIT); + + public PermLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + // Int more efficient Match "fields" string + data.ns = row.getString(0); + data.type = row.getString(1); + data.instance = row.getString(2); + data.action = row.getString(3); + data.roles = row.getSet(4,String.class); + data.description = row.getString(5); + return data; + } + + @Override + protected void key(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx]=data.ns; + obj[++idx]=data.type; + obj[++idx]=data.instance; + obj[++idx]=data.action; + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx]=data.roles; + obj[++idx]=data.description; + } + + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + writeString(os, data.ns); + writeString(os, data.type); + writeString(os, data.instance); + writeString(os, data.action); + writeStringSet(os, data.roles); + writeString(os, data.description); + } + + @Override + public void unmarshal(Data data, DataInputStream is) throws IOException { + /*int version = */readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + byte[] buff = new byte[BUFF_SIZE]; + data.ns = readString(is, buff); + data.type = readString(is,buff); + data.instance = readString(is,buff); + data.action = readString(is,buff); + data.roles = readStringSet(is,buff); + data.description = readString(is,buff); + } + } + + private void init(AuthzTrans trans) { + // the 3 is the number of key fields + String[] helpers = setCRUD(trans, TABLE, Data.class, PermLoader.deflt); + + // Other SELECT style statements... match with a local Method + psByType = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns = ? AND type = ?", new PermLoader(2) { + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.type; + } + },readConsistency); + + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns = ?", new PermLoader(1),readConsistency); + + psChildren = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns=? AND type > ? AND type < ?", + new PermLoader(3) { + @Override + protected void key(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx] = data.ns; + obj[++idx]=data.type + DOT; + obj[++idx]=data.type + DOT_PLUS_ONE; + } + },readConsistency); + + } + + + /** + * Add a single Permission to the Role's Permission Collection + * + * @param trans + * @param roleFullName + * @param perm + * @param type + * @param action + * @return + */ + public Result addRole(AuthzTrans trans, PermDAO.Data perm, String roleFullName) { + // Note: Prepared Statements for Collection updates aren't supported + //ResultSet rv = + try { + getSession(trans).execute(UPDATE_SP + TABLE + " SET roles = roles + {'" + roleFullName + "'} " + + "WHERE " + + "ns = '" + perm.ns + "' AND " + + "type = '" + perm.type + "' AND " + + "instance = '" + perm.instance + "' AND " + + "action = '" + perm.action + "';" + ); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + + wasModified(trans, CRUD.update, perm, "Added role " + roleFullName + " to perm " + + perm.ns + '.' + perm.type + '|' + perm.instance + '|' + perm.action); + return Result.ok(); + } + + /** + * Remove a single Permission from the Role's Permission Collection + * @param trans + * @param roleFullName + * @param perm + * @param type + * @param action + * @return + */ + public Result delRole(AuthzTrans trans, PermDAO.Data perm, String roleFullName) { + // Note: Prepared Statements for Collection updates aren't supported + //ResultSet rv = + try { + getSession(trans).execute(UPDATE_SP + TABLE + " SET roles = roles - {'" + roleFullName + "'} " + + "WHERE " + + "ns = '" + perm.ns + "' AND " + + "type = '" + perm.type + "' AND " + + "instance = '" + perm.instance + "' AND " + + "action = '" + perm.action + "';" + ); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + + //TODO how can we tell when it doesn't? + wasModified(trans, CRUD.update, perm, "Removed role " + roleFullName + " from perm " + + perm.ns + '.' + perm.type + '|' + perm.instance + '|' + perm.action); + return Result.ok(); + } + + + + /** + * Additional method: + * Select all Permissions by Name + * + * @param name + * @return + * @throws DAOException + */ + public Result> readByType(AuthzTrans trans, String ns, String type) { + return psByType.read(trans, R_TEXT, new Object[]{ns, type}); + } + + public Result> readChildren(AuthzTrans trans, String ns, String type) { + return psChildren.read(trans, R_TEXT, new Object[]{ns, type+DOT, type + DOT_PLUS_ONE}); + } + + public Result> readNS(AuthzTrans trans, String ns) { + return psNS.read(trans, R_TEXT, new Object[]{ns}); + } + + /** + * Add description to this permission + * + * @param trans + * @param ns + * @param type + * @param instance + * @param action + * @param description + * @return + */ + public Result addDescription(AuthzTrans trans, String ns, String type, + String instance, String action, String description) { + try { + getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + + description + "' WHERE ns = '" + ns + "' AND type = '" + type + "'" + + "AND instance = '" + instance + "' AND action = '" + action + "';"); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + + Data data = new Data(); + data.ns=ns; + data.type=type; + data.instance=instance; + data.action=action; + wasModified(trans, CRUD.update, data, "Added description " + description + " to permission " + + data.encode(), null ); + return Result.ok(); + } + + /** + * Log Modification statements to History + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + + // Need to update history + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + hd.user = trans.user(); + hd.action = modified.name(); + hd.target = TABLE; + hd.subject = subject ? override[1] : data.fullType(); + if (memo) { + hd.memo = String.format("%s", override[0]); + } else { + hd.memo = String.format("%sd %s|%s|%s", modified.name(),data.fullType(),data.instance,data.action); + } + + if(modified==CRUD.delete) { + try { + hd.reconstruct = data.bytify(); + } catch (IOException e) { + trans.error().log(e,"Could not serialize PermDAO.Data"); + } + } + + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + if(infoDAO.touch(trans, TABLE,data.invalidate(cache)).notOK()) { + trans.error().log("Cannot touch CacheInfo"); + } + } +} + diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/RoleDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/RoleDAO.java new file mode 100644 index 00000000..84290ef7 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/RoleDAO.java @@ -0,0 +1,412 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.Bytification; +import com.att.dao.Cached; +import com.att.dao.CassAccess; +import com.att.dao.CassDAOImpl; +import com.att.dao.Loader; +import com.att.dao.Streamer; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Split; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.exceptions.DriverException; + +public class RoleDAO extends CassDAOImpl { + + public static final String TABLE = "role"; + public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F + + private final HistoryDAO historyDAO; + private final CacheInfoDAO infoDAO; + + private PSInfo psChildren, psNS, psName; + + public RoleDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { + super(trans, RoleDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + // Set up sub-DAOs + historyDAO = new HistoryDAO(trans, this); + infoDAO = new CacheInfoDAO(trans,this); + init(trans); + } + + public RoleDAO(AuthzTrans trans, HistoryDAO hDAO, CacheInfoDAO ciDAO) { + super(trans, RoleDAO.class.getSimpleName(),hDAO,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + historyDAO = hDAO; + infoDAO = ciDAO; + init(trans); + } + + + ////////////////////////////////////////// + // Data Definition, matches Cassandra DM + ////////////////////////////////////////// + private static final int KEYLIMIT = 2; + /** + * Data class that matches the Cassandra Table "role" + */ + public static class Data extends CacheableData implements Bytification { + public String ns; + public String name; + public Set perms; + public String description; + + //////////////////////////////////////// + // Getters + public Set perms(boolean mutable) { + if (perms == null) { + perms = new HashSet(); + } else if (mutable && !(perms instanceof HashSet)) { + perms = new HashSet(perms); + } + return perms; + } + + public static Data create(NsDAO.Data ns, String name) { + NsSplit nss = new NsSplit(ns,name); + RoleDAO.Data rv = new Data(); + rv.ns = nss.ns; + rv.name=nss.name; + return rv; + } + + public String fullName() { + return ns + '.' + name; + } + + public String encode() { + return ns + '|' + name; + } + + /** + * Decode Perm String, including breaking into appropriate Namespace + * + * @param trans + * @param q + * @param r + * @return + */ + public static Result decode(AuthzTrans trans, Question q, String r) { + String[] ss = Split.splitTrim('|', r,2); + Data data = new Data(); + if(ss[1]==null) { // older 1 part encoding must be evaluated for NS + Result nss = q.deriveNsSplit(trans, ss[0]); + if(nss.notOK()) { + return Result.err(nss); + } + data.ns=nss.value.ns; + data.name=nss.value.name; + } else { // new 4 part encoding + data.ns=ss[0]; + data.name=ss[1]; + } + return Result.ok(data); + } + + /** + * Decode from UserRole Data + * @param urdd + * @return + */ + public static RoleDAO.Data decode(UserRoleDAO.Data urdd) { + RoleDAO.Data rd = new RoleDAO.Data(); + rd.ns = urdd.ns; + rd.name = urdd.rname; + return rd; + } + + + /** + * Decode Perm String, including breaking into appropriate Namespace + * + * @param trans + * @param q + * @param p + * @return + */ + public static Result decodeToArray(AuthzTrans trans, Question q, String p) { + String[] ss = Split.splitTrim('|', p,2); + if(ss[1]==null) { // older 1 part encoding must be evaluated for NS + Result nss = q.deriveNsSplit(trans, ss[0]); + if(nss.notOK()) { + return Result.err(nss); + } + ss[0] = nss.value.ns; + ss[1] = nss.value.name; + } + return Result.ok(ss); + } + + @Override + public int[] invalidate(Cached cache) { + return new int[] { + seg(cache,ns,name), + seg(cache,ns), + seg(cache,name), + }; + } + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + RoleLoader.deflt.marshal(this,new DataOutputStream(baos)); + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + RoleLoader.deflt.unmarshal(this, toDIS(bb)); + } + + @Override + public String toString() { + return ns + '.' + name; + } + } + + private static class RoleLoader extends Loader implements Streamer { + public static final int MAGIC=923577343; + public static final int VERSION=1; + public static final int BUFF_SIZE=96; + + public static final RoleLoader deflt = new RoleLoader(KEYLIMIT); + + public RoleLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + // Int more efficient + data.ns = row.getString(0); + data.name = row.getString(1); + data.perms = row.getSet(2,String.class); + data.description = row.getString(3); + return data; + } + + @Override + protected void key(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx]=data.ns; + obj[++idx]=data.name; + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx]=data.perms; + obj[++idx]=data.description; + } + + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + writeString(os, data.ns); + writeString(os, data.name); + writeStringSet(os,data.perms); + writeString(os, data.description); + } + + @Override + public void unmarshal(Data data, DataInputStream is) throws IOException { + /*int version = */readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + byte[] buff = new byte[BUFF_SIZE]; + data.ns = readString(is, buff); + data.name = readString(is,buff); + data.perms = readStringSet(is,buff); + data.description = readString(is,buff); + } + }; + + private void init(AuthzTrans trans) { + String[] helpers = setCRUD(trans, TABLE, Data.class, RoleLoader.deflt); + + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns = ?", new RoleLoader(1),readConsistency); + + psName = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE name = ?", new RoleLoader(1),readConsistency); + + psChildren = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns=? AND name > ? AND name < ?", + new RoleLoader(3) { + @Override + protected void key(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx] = data.ns; + obj[++idx]=data.name + DOT; + obj[++idx]=data.name + DOT_PLUS_ONE; + } + },readConsistency); + + } + + public Result> readNS(AuthzTrans trans, String ns) { + return psNS.read(trans, R_TEXT + " NS " + ns, new Object[]{ns}); + } + + public Result> readName(AuthzTrans trans, String name) { + return psName.read(trans, R_TEXT + name, new Object[]{name}); + } + + public Result> readChildren(AuthzTrans trans, String ns, String role) { + if(role.length()==0 || "*".equals(role)) { + return psChildren.read(trans, R_TEXT, new Object[]{ns, FIRST_CHAR, LAST_CHAR}); + } else { + return psChildren.read(trans, R_TEXT, new Object[]{ns, role+DOT, role+DOT_PLUS_ONE}); + } + } + + /** + * Add a single Permission to the Role's Permission Collection + * + * @param trans + * @param role + * @param perm + * @param type + * @param action + * @return + */ + public Result addPerm(AuthzTrans trans, RoleDAO.Data role, PermDAO.Data perm) { + // Note: Prepared Statements for Collection updates aren't supported + String pencode = perm.encode(); + try { + getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms + {'" + + pencode + "'} WHERE " + + "ns = '" + role.ns + "' AND name = '" + role.name + "';"); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + + wasModified(trans, CRUD.update, role, "Added permission " + pencode + " to role " + role.fullName()); + return Result.ok(); + } + + /** + * Remove a single Permission from the Role's Permission Collection + * @param trans + * @param role + * @param perm + * @param type + * @param action + * @return + */ + public Result delPerm(AuthzTrans trans, RoleDAO.Data role, PermDAO.Data perm) { + // Note: Prepared Statements for Collection updates aren't supported + + String pencode = perm.encode(); + + //ResultSet rv = + try { + getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms - {'" + + pencode + "'} WHERE " + + "ns = '" + role.ns + "' AND name = '" + role.name + "';"); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + + //TODO how can we tell when it doesn't? + wasModified(trans, CRUD.update, role, "Removed permission " + pencode + " from role " + role.fullName() ); + return Result.ok(); + } + + /** + * Add description to role + * + * @param trans + * @param ns + * @param name + * @param description + * @return + */ + public Result addDescription(AuthzTrans trans, String ns, String name, String description) { + try { + getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + + description + "' WHERE ns = '" + ns + "' AND name = '" + name + "';"); + } catch (DriverException | APIException | IOException e) { + reportPerhapsReset(trans,e); + return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); + } + + Data data = new Data(); + data.ns=ns; + data.name=name; + wasModified(trans, CRUD.update, data, "Added description " + description + " to role " + data.fullName(), null ); + return Result.ok(); + } + + + /** + * Log Modification statements to History + * @param modified which CRUD action was done + * @param data entity data that needs a log entry + * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + hd.user = trans.user(); + hd.action = modified.name(); + hd.target = TABLE; + hd.subject = subject ? override[1] : data.fullName(); + hd.memo = memo ? override[0] : (data.fullName() + " was " + modified.name() + 'd' ); + if(modified==CRUD.delete) { + try { + hd.reconstruct = data.bytify(); + } catch (IOException e) { + trans.error().log(e,"Could not serialize RoleDAO.Data"); + } + } + + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + if(infoDAO.touch(trans, TABLE,data.invalidate(cache)).notOK()) { + trans.error().log("Cannot touch CacheInfo for Role"); + } + } + + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/Status.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/Status.java new file mode 100644 index 00000000..d275f3d7 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/Status.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import com.att.authz.layer.Result; + + + + +/** + * Add additional Behavior for Specific Applications for Results + * + * In this case, we add additional BitField information accessible by + * method ( + * + * @param + */ +public class Status extends Result { + + // 10/1/2013: Initially, I used enum, but it's not extensible. + public final static int ERR_NsNotFound = Result.ERR_General+1, + ERR_RoleNotFound = Result.ERR_General+2, + ERR_PermissionNotFound = Result.ERR_General+3, + ERR_UserNotFound = Result.ERR_General+4, + ERR_UserRoleNotFound = Result.ERR_General+5, + ERR_DelegateNotFound = Result.ERR_General+6, + ERR_InvalidDelegate = Result.ERR_General+7, + ERR_DependencyExists = Result.ERR_General+8, + ERR_NoApprovals = Result.ERR_General+9, + ACC_Now = Result.ERR_General+10, + ACC_Future = Result.ERR_General+11, + ERR_ChoiceNeeded = Result.ERR_General+12, + ERR_FutureNotRequested = Result.ERR_General+13; + + /** + * Constructor for Result set. + * @param data + * @param status + */ + private Status(RV value, int status, String details, String[] variables ) { + super(value,status,details,variables); + } + + public static String name(int status) { + switch(status) { + case OK: return "OK"; + case ERR_NsNotFound: return "ERR_NsNotFound"; + case ERR_RoleNotFound: return "ERR_RoleNotFound"; + case ERR_PermissionNotFound: return "ERR_PermissionNotFound"; + case ERR_UserNotFound: return "ERR_UserNotFound"; + case ERR_UserRoleNotFound: return "ERR_UserRoleNotFound"; + case ERR_DelegateNotFound: return "ERR_DelegateNotFound"; + case ERR_InvalidDelegate: return "ERR_InvalidDelegate"; + case ERR_ConflictAlreadyExists: return "ERR_ConflictAlreadyExists"; + case ERR_DependencyExists: return "ERR_DependencyExists"; + case ERR_ActionNotCompleted: return "ERR_ActionNotCompleted"; + case ERR_Denied: return "ERR_Denied"; + case ERR_Policy: return "ERR_Policy"; + case ERR_BadData: return "ERR_BadData"; + case ERR_NotImplemented: return "ERR_NotImplemented"; + case ERR_NotFound: return "ERR_NotFound"; + case ERR_ChoiceNeeded: return "ERR_ChoiceNeeded"; + } + //case ERR_General: or unknown... + return "ERR_General"; + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/cass/UserRoleDAO.java b/authz-cass/src/main/java/com/att/dao/aaf/cass/UserRoleDAO.java new file mode 100644 index 00000000..d3fffe8c --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/cass/UserRoleDAO.java @@ -0,0 +1,320 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.cass; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Date; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.Bytification; +import com.att.dao.Cached; +import com.att.dao.CassDAOImpl; +import com.att.dao.DAOException; +import com.att.dao.Loader; +import com.att.dao.Streamer; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.att.inno.env.Slot; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Row; + +public class UserRoleDAO extends CassDAOImpl { + public static final String TABLE = "user_role"; + + public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F + + private static final String TRANS_UR_SLOT = "_TRANS_UR_SLOT_"; + public Slot transURSlot; + + private final HistoryDAO historyDAO; + private final CacheInfoDAO infoDAO; + + private PSInfo psByUser, psByRole, psUserInRole; + + + + public UserRoleDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { + super(trans, UserRoleDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + transURSlot = trans.slot(TRANS_UR_SLOT); + init(trans); + + // Set up sub-DAOs + historyDAO = new HistoryDAO(trans, this); + infoDAO = new CacheInfoDAO(trans,this); + } + + public UserRoleDAO(AuthzTrans trans, HistoryDAO hDAO, CacheInfoDAO ciDAO) { + super(trans, UserRoleDAO.class.getSimpleName(),hDAO,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + transURSlot = trans.slot(TRANS_UR_SLOT); + historyDAO = hDAO; + infoDAO = ciDAO; + init(trans); + } + + private static final int KEYLIMIT = 2; + public static class Data extends CacheableData implements Bytification { + public String user; + public String role; + public String ns; + public String rname; + public Date expires; + + @Override + public int[] invalidate(Cached cache) { + // Note: I'm not worried about Name collisions, because the formats are different: + // myName ... etc versus + // com. ... + // The "dot" makes the difference. + return new int[] { + seg(cache,user,role), + seg(cache,user), + seg(cache,role) + }; + } + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + URLoader.deflt.marshal(this,new DataOutputStream(baos)); + return ByteBuffer.wrap(baos.toByteArray()); + } + + @Override + public void reconstitute(ByteBuffer bb) throws IOException { + URLoader.deflt.unmarshal(this, toDIS(bb)); + } + + public void role(String ns, String rname) { + this.ns = ns; + this.rname = rname; + this.role = ns + '.' + rname; + } + + public void role(RoleDAO.Data rdd) { + ns = rdd.ns; + rname = rdd.name; + role = rdd.fullName(); + } + + + public boolean role(AuthzTrans trans, Question ques, String role) { + this.role = role; + Result rnss = ques.deriveNsSplit(trans, role); + if(rnss.isOKhasData()) { + ns = rnss.value.ns; + rname = rnss.value.name; + return true; + } else { + return false; + } + } + + @Override + public String toString() { + return user + '|' + ns + '|' + rname + '|' + Chrono.dateStamp(expires); + } + + + } + + private static class URLoader extends Loader implements Streamer { + public static final int MAGIC=738469903; + public static final int VERSION=1; + public static final int BUFF_SIZE=48; + + public static final URLoader deflt = new URLoader(KEYLIMIT); + + public URLoader(int keylimit) { + super(keylimit); + } + + @Override + public Data load(Data data, Row row) { + data.user = row.getString(0); + data.role = row.getString(1); + data.ns = row.getString(2); + data.rname = row.getString(3); + data.expires = row.getDate(4); + return data; + } + + @Override + protected void key(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx]=data.user; + obj[++idx]=data.role; + } + + @Override + protected void body(Data data, int _idx, Object[] obj) { + int idx = _idx; + obj[idx]=data.ns; + obj[++idx]=data.rname; + obj[++idx]=data.expires; + } + + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + + writeString(os, data.user); + writeString(os, data.role); + writeString(os, data.ns); + writeString(os, data.rname); + os.writeLong(data.expires==null?-1:data.expires.getTime()); + } + + @Override + public void unmarshal(Data data, DataInputStream is) throws IOException { + /*int version = */readHeader(is,MAGIC,VERSION); + // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields + + byte[] buff = new byte[BUFF_SIZE]; + data.user = readString(is,buff); + data.role = readString(is,buff); + data.ns = readString(is,buff); + data.rname = readString(is,buff); + long l = is.readLong(); + data.expires = l<0?null:new Date(l); + } + + }; + + private void init(AuthzTrans trans) { + String[] helper = setCRUD(trans, TABLE, Data.class, URLoader.deflt); + + psByUser = new PSInfo(trans, SELECT_SP + helper[FIELD_COMMAS] + " FROM user_role WHERE user = ?", + new URLoader(1) { + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.user; + } + },readConsistency); + + // Note: We understand this call may have poor performance, so only should be used in Management (Delete) func + psByRole = new PSInfo(trans, SELECT_SP + helper[FIELD_COMMAS] + " FROM user_role WHERE role = ? ALLOW FILTERING", + new URLoader(1) { + @Override + protected void key(Data data, int idx, Object[] obj) { + obj[idx]=data.role; + } + },readConsistency); + + psUserInRole = new PSInfo(trans,SELECT_SP + helper[FIELD_COMMAS] + " FROM user_role WHERE user = ? AND role = ?", + URLoader.deflt,readConsistency); + } + + public Result> readByUser(AuthzTrans trans, String user) { + return psByUser.read(trans, R_TEXT + " by User " + user, new Object[]{user}); + } + + /** + * Note: Use Sparingly. Cassandra's forced key structure means this will perform fairly poorly + * @param trans + * @param role + * @return + * @throws DAOException + */ + public Result> readByRole(AuthzTrans trans, String role) { + return psByRole.read(trans, R_TEXT + " by Role " + role, new Object[]{role}); + } + + /** + * Direct Lookup of User Role + * Don't forget to check for Expiration + */ + public Result> readByUserRole(AuthzTrans trans, String user, String role) { + return psUserInRole.read(trans, R_TEXT + " by User " + user + " and Role " + role, new Object[]{user,role}); + } + + + /** + * Log Modification statements to History + * @param modified which CRUD action was done + * @param data entity data that needs a log entry + * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data + */ + @Override + protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { + boolean memo = override.length>0 && override[0]!=null; + boolean subject = override.length>1 && override[1]!=null; + + HistoryDAO.Data hd = HistoryDAO.newInitedData(); + HistoryDAO.Data hdRole = HistoryDAO.newInitedData(); + + hd.user = hdRole.user = trans.user(); + hd.action = modified.name(); + // Modifying User/Role is an Update to Role, not a Create. JG, 07-14-2015 + hdRole.action = CRUD.update.name(); + hd.target = TABLE; + hdRole.target = RoleDAO.TABLE; + hd.subject = subject?override[1] : (data.user + '|'+data.role); + hdRole.subject = data.role; + switch(modified) { + case create: + hd.memo = hdRole.memo = memo + ? String.format("%s by %s", override[0], hd.user) + : String.format("%s added to %s",data.user,data.role); + break; + case update: + hd.memo = hdRole.memo = memo + ? String.format("%s by %s", override[0], hd.user) + : String.format("%s - %s was updated",data.user,data.role); + break; + case delete: + hd.memo = hdRole.memo = memo + ? String.format("%s by %s", override[0], hd.user) + : String.format("%s removed from %s",data.user,data.role); + try { + hd.reconstruct = hdRole.reconstruct = data.bytify(); + } catch (IOException e) { + trans.warn().log(e,"Deleted UserRole could not be serialized"); + } + break; + default: + hd.memo = hdRole.memo = memo + ? String.format("%s by %s", override[0], hd.user) + : "n/a"; + } + + if(historyDAO.create(trans, hd).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + + if(historyDAO.create(trans, hdRole).status!=Status.OK) { + trans.error().log("Cannot log to History"); + } + // uses User as Segment + if(infoDAO.touch(trans, TABLE,data.invalidate(cache)).notOK()) { + trans.error().log("Cannot touch CacheInfo"); + } + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/hl/CassExecutor.java b/authz-cass/src/main/java/com/att/dao/aaf/hl/CassExecutor.java new file mode 100644 index 00000000..6f62acec --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/hl/CassExecutor.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.hl; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.authz.org.Executor; +import com.att.dao.aaf.cass.NsDAO.Data; +import com.att.dao.aaf.cass.NsSplit; + +public class CassExecutor implements Executor { + + private Question q; + private Function f; + private AuthzTrans trans; + + public CassExecutor(AuthzTrans trans, Function f) { + this.trans = trans; + this.f = f; + this.q = this.f.q; + } + + @Override + public boolean hasPermission(String user, String ns, String type, String instance, String action) { + return isGranted(user, ns, type, instance, action); + } + + @Override + public boolean inRole(String name) { + Result nss = q.deriveNsSplit(trans, name); + if(nss.notOK())return false; + return q.roleDAO.read(trans, nss.value.ns,nss.value.name).isOKhasData(); + } + + public boolean isGranted(String user, String ns, String type, String instance, String action) { + return q.isGranted(trans, user, ns, type, instance,action); + } + + @Override + public String namespace() throws Exception { + Result res = q.validNSOfDomain(trans,trans.user()); + if(res.isOK()) { + String user[] = trans.user().split("\\."); + return user[user.length-1] + '.' + user[user.length-2]; + } + throw new Exception(res.status + ' ' + res.details); + } + + @Override + public String id() { + return trans.user(); + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/hl/Function.java b/authz-cass/src/main/java/com/att/dao/aaf/hl/Function.java new file mode 100644 index 00000000..d1db39da --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/hl/Function.java @@ -0,0 +1,1575 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.hl; + +import static com.att.authz.layer.Result.OK; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import com.att.authz.common.Define; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.authz.org.Executor; +import com.att.authz.org.Organization; +import com.att.authz.org.Organization.Expiration; +import com.att.authz.org.Organization.Policy; +import com.att.authz.org.Organization.Identity; +import com.att.dao.DAOException; +import com.att.dao.aaf.cass.ApprovalDAO; +import com.att.dao.aaf.cass.CredDAO; +import com.att.dao.aaf.cass.DelegateDAO; +import com.att.dao.aaf.cass.FutureDAO; +import com.att.dao.aaf.cass.Namespace; +import com.att.dao.aaf.cass.NsDAO; +import com.att.dao.aaf.cass.NsDAO.Data; +import com.att.dao.aaf.cass.NsSplit; +import com.att.dao.aaf.cass.NsType; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.Status; +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.dao.aaf.hl.Question.Access; + +public class Function { + + public static final String FOP_CRED = "cred"; + public static final String FOP_DELEGATE = "delegate"; + public static final String FOP_NS = "ns"; + public static final String FOP_PERM = "perm"; + public static final String FOP_ROLE = "role"; + public static final String FOP_USER_ROLE = "user_role"; + // First Action should ALWAYS be "write", see "CreateRole" + public final Question q; + + public Function(AuthzTrans trans, Question question) { + q = question; + } + + private class ErrBuilder { + private StringBuilder sb; + private List ao; + + public void log(Result result) { + if (result.notOK()) { + if (sb == null) { + sb = new StringBuilder(); + ao = new ArrayList(); + } + sb.append(result.details); + sb.append('\n'); + for (String s : result.variables) { + ao.add(s); + } + } + } + + public String[] vars() { + String[] rv = new String[ao.size()]; + ao.toArray(rv); + return rv; + } + + public boolean hasErr() { + return sb != null; + } + + @Override + public String toString() { + return sb == null ? "" : String.format(sb.toString(), ao); + } + } + + /** + * createNS + * + * Create Namespace + * + * @param trans + * @param org + * @param ns + * @param user + * @return + * @throws DAOException + * + * To create an NS, you need to: 1) validate permission to + * modify parent NS 2) Does NS exist already? 3) Create NS with + * a) "user" as owner. NOTE: Per 10-15 request for AAF 1.0 4) + * Loop through Roles with Parent NS, and map any that start + * with this NS into this one 5) Loop through Perms with Parent + * NS, and map any that start with this NS into this one + */ + public Result createNS(AuthzTrans trans, Namespace namespace, boolean fromApproval) { + Result rq; + + if (namespace.name.endsWith(Question.DOT_ADMIN) + || namespace.name.endsWith(Question.DOT_OWNER)) { + return Result.err(Status.ERR_BadData, + "'admin' and 'owner' are reserved names in AAF"); + } + + try { + for (String u : namespace.owner) { + Organization org = trans.org(); + Identity orgUser = org.getIdentity(trans, u); + if (orgUser == null || !orgUser.isResponsible()) { + // check if user has explicit permission + String reason; + if (org.isTestEnv() && (reason=org.validate(trans, Policy.AS_EMPLOYEE, + new CassExecutor(trans, this), u))!=null) { + return Result.err(Status.ERR_Policy,reason); + } + } + } + } catch (Exception e) { + trans.error().log(e, + "Could not contact Organization for User Validation"); + } + + String user = trans.user(); + // 1) May Change Parent? + int idx = namespace.name.lastIndexOf('.'); + String parent; + if (idx < 0) { + if (!q.isGranted(trans, user, Define.ROOT_NS,Question.NS, ".", "create")) { + return Result.err(Result.ERR_Security, + "%s may not create Root Namespaces", user); + } + parent = null; + fromApproval = true; + } else { + parent = namespace.name.substring(0, idx); + } + + if (!fromApproval) { + Result rparent = q.deriveNs(trans, parent); + if (rparent.notOK()) { + return Result.err(rparent); + } + rparent = q.mayUser(trans, user, rparent.value, Access.write); + if (rparent.notOK()) { + return Result.err(rparent); + } + } + + // 2) Does requested NS exist + if (q.nsDAO.read(trans, namespace.name).isOKhasData()) { + return Result.err(Status.ERR_ConflictAlreadyExists, + "Target Namespace already exists"); + } + + // Someone must be responsible. + if (namespace.owner == null || namespace.owner.isEmpty()) { + return Result + .err(Status.ERR_Policy, + "Namespaces must be assigned at least one responsible party"); + } + + // 3) Create NS + Date now = new Date(); + + Result r; + // 3a) Admin + + try { + // Originally, added the enterer as Admin, but that's not necessary, + // or helpful for Operations folks.. + // Admins can be empty, because they can be changed by lower level + // NSs + // if(ns.admin(false).isEmpty()) { + // ns.admin(true).add(user); + // } + if (namespace.admin != null) { + for (String u : namespace.admin) { + if ((r = checkValidID(trans, now, u)).notOK()) { + return r; + } + } + } + + // 3b) Responsible + Organization org = trans.org(); + for (String u : namespace.owner) { + Identity orgUser = org.getIdentity(trans, u); + if (orgUser == null) { + return Result + .err(Status.ERR_BadData, + "NS must be created with an %s approved Responsible Party", + org.getName()); + } + } + } catch (Exception e) { + return Result.err(Status.ERR_UserNotFound, e.getMessage()); + } + + // VALIDATIONS done... Add NS + if ((rq = q.nsDAO.create(trans, namespace.data())).notOK()) { + return Result.err(rq); + } + + // Since Namespace is now created, we need to grab all subsequent errors + ErrBuilder eb = new ErrBuilder(); + + // Add UserRole(s) + UserRoleDAO.Data urdd = new UserRoleDAO.Data(); + urdd.expires = trans.org().expiration(null, Expiration.UserInRole).getTime(); + urdd.role(namespace.name, Question.ADMIN); + for (String admin : namespace.admin) { + urdd.user = admin; + eb.log(q.userRoleDAO.create(trans, urdd)); + } + urdd.role(namespace.name,Question.OWNER); + for (String owner : namespace.owner) { + urdd.user = owner; + eb.log(q.userRoleDAO.create(trans, urdd)); + } + + addNSAdminRolesPerms(trans, eb, namespace.name); + + addNSOwnerRolesPerms(trans, eb, namespace.name); + + if (parent != null) { + // Build up with any errors + + Result parentNS = q.deriveNs(trans, parent); + String targetNs = parentNS.value.name; // Get the Parent Namespace, + // not target + String targetName = namespace.name.substring(parentNS.value.name.length() + 1); // Remove the Parent Namespace from the + // Target + a dot, and you'll get the name + int targetNameDot = targetName.length() + 1; + + // 4) Change any roles with children matching this NS, and + Result> rrdc = q.roleDAO.readChildren(trans, targetNs, targetName); + if (rrdc.isOKhasData()) { + for (RoleDAO.Data rdd : rrdc.value) { + // Remove old Role from Perms, save them off + List lpdd = new ArrayList(); + for(String p : rdd.perms(false)) { + Result rpdd = PermDAO.Data.decode(trans,q,p); + if(rpdd.isOKhasData()) { + PermDAO.Data pdd = rpdd.value; + lpdd.add(pdd); + q.permDAO.delRole(trans, pdd, rdd); + } else{ + trans.error().log(rpdd.errorString()); + } + } + + // Save off Old keys + String delP1 = rdd.ns; + String delP2 = rdd.name; + + // Write in new key + rdd.ns = namespace.name; + rdd.name = (delP2.length() > targetNameDot) ? delP2 + .substring(targetNameDot) : ""; + + // Need to use non-cached, because switching namespaces, not + // "create" per se + if ((rq = q.roleDAO.create(trans, rdd)).isOK()) { + // Put Role back into Perm, with correct info + for(PermDAO.Data pdd : lpdd) { + q.permDAO.addRole(trans, pdd, rdd); + } + // Change data for User Roles + Result> rurd = q.userRoleDAO.readByRole(trans, rdd.fullName()); + if(rurd.isOKhasData()) { + for(UserRoleDAO.Data urd : rurd.value) { + urd.ns = rdd.ns; + urd.rname = rdd.name; + q.userRoleDAO.update(trans, urd); + } + } + // Now delete old one + rdd.ns = delP1; + rdd.name = delP2; + if ((rq = q.roleDAO.delete(trans, rdd, false)).notOK()) { + eb.log(rq); + } + } else { + eb.log(rq); + } + } + } + + // 4) Change any Permissions with children matching this NS, and + Result> rpdc = q.permDAO.readChildren(trans,targetNs, targetName); + if (rpdc.isOKhasData()) { + for (PermDAO.Data pdd : rpdc.value) { + // Remove old Perm from Roles, save them off + List lrdd = new ArrayList(); + + for(String rl : pdd.roles(false)) { + Result rrdd = RoleDAO.Data.decode(trans,q,rl); + if(rrdd.isOKhasData()) { + RoleDAO.Data rdd = rrdd.value; + lrdd.add(rdd); + q.roleDAO.delPerm(trans, rdd, pdd); + } else{ + trans.error().log(rrdd.errorString()); + } + } + + // Save off Old keys + String delP1 = pdd.ns; + String delP2 = pdd.type; + pdd.ns = namespace.name; + pdd.type = (delP2.length() > targetNameDot) ? delP2 + .substring(targetNameDot) : ""; + if ((rq = q.permDAO.create(trans, pdd)).isOK()) { + // Put Role back into Perm, with correct info + for(RoleDAO.Data rdd : lrdd) { + q.roleDAO.addPerm(trans, rdd, pdd); + } + + pdd.ns = delP1; + pdd.type = delP2; + if ((rq = q.permDAO.delete(trans, pdd, false)).notOK()) { + eb.log(rq); + // } else { + // Need to invalidate directly, because we're + // switching places in NS, not normal cache behavior + // q.permDAO.invalidate(trans,pdd); + } + } else { + eb.log(rq); + } + } + } + if (eb.hasErr()) { + return Result.err(Status.ERR_ActionNotCompleted,eb.sb.toString(), eb.vars()); + } + } + return Result.ok(); + } + + private void addNSAdminRolesPerms(AuthzTrans trans, ErrBuilder eb, String ns) { + // Admin Role/Perm + RoleDAO.Data rd = new RoleDAO.Data(); + rd.ns = ns; + rd.name = "admin"; + rd.description = "AAF Namespace Administrators"; + + PermDAO.Data pd = new PermDAO.Data(); + pd.ns = ns; + pd.type = "access"; + pd.instance = Question.ASTERIX; + pd.action = Question.ASTERIX; + pd.description = "AAF Namespace Write Access"; + + rd.perms = new HashSet(); + rd.perms.add(pd.encode()); + eb.log(q.roleDAO.create(trans, rd)); + + pd.roles = new HashSet(); + pd.roles.add(rd.encode()); + eb.log(q.permDAO.create(trans, pd)); + } + + private void addNSOwnerRolesPerms(AuthzTrans trans, ErrBuilder eb, String ns) { + RoleDAO.Data rd = new RoleDAO.Data(); + rd.ns = ns; + rd.name = "owner"; + rd.description = "AAF Namespace Owners"; + + PermDAO.Data pd = new PermDAO.Data(); + pd.ns = ns; + pd.type = "access"; + pd.instance = Question.ASTERIX; + pd.action = Question.READ; + pd.description = "AAF Namespace Read Access"; + + rd.perms = new HashSet(); + rd.perms.add(pd.encode()); + eb.log(q.roleDAO.create(trans, rd)); + + pd.roles = new HashSet(); + pd.roles.add(rd.encode()); + eb.log(q.permDAO.create(trans, pd)); + } + + /** + * deleteNS + * + * Delete Namespace + * + * @param trans + * @param org + * @param ns + * @param force + * @param user + * @return + * @throws DAOException + * + * + * To delete an NS, you need to: 1) validate permission to + * modify this NS 2) Find all Roles with this NS, and 2a) if + * Force, delete them, else modify to Parent NS 3) Find all + * Perms with this NS, and modify to Parent NS 3a) if Force, + * delete them, else modify to Parent NS 4) Find all IDs + * associated to this NS, and deny if exists. 5) Remove NS + */ + public Result deleteNS(AuthzTrans trans, String ns) { + boolean force = trans.forceRequested(); + boolean move = trans.moveRequested(); + // 1) Validate + Result> nsl; + if ((nsl = q.nsDAO.read(trans, ns)).notOKorIsEmpty()) { + return Result.err(Status.ERR_NsNotFound, "%s does not exist", ns); + } + NsDAO.Data nsd = nsl.value.get(0); + NsType nt; + if (move && !q.canMove(nt = NsType.fromType(nsd.type))) { + return Result.err(Status.ERR_Denied, "Namespace Force=move not permitted for Type %s",nt.name()); + } + + Result dnr = q.mayUser(trans, trans.user(), nsd, Access.write); + if (dnr.status != Status.OK) { + return Result.err(dnr); + } + + // 2) Find Parent + String user = trans.user(); + int idx = ns.lastIndexOf('.'); + NsDAO.Data parent; + if (idx < 0) { + if (!q.isGranted(trans, user, Define.ROOT_NS,Question.NS, ".", "delete")) { + return Result.err(Result.ERR_Security, + "%s may not delete Root Namespaces", user); + } + parent = null; + } else { + Result rlparent = q.deriveNs(trans, ns.substring(0, idx)); + if (rlparent.notOKorIsEmpty()) { + return Result.err(rlparent); + } + parent = rlparent.value; + } + + // Build up with any errors + // If sb != null below is an indication of error + StringBuilder sb = null; + ErrBuilder er = new ErrBuilder(); + + // 2a) Deny if any IDs on Namespace + Result> creds = q.credDAO.readNS(trans, ns); + if (creds.isOKhasData()) { + if (force || move) { + for (CredDAO.Data cd : creds.value) { + er.log(q.credDAO.delete(trans, cd, false)); + // Since we're deleting all the creds, we should delete all + // the user Roles for that Cred + Result> rlurd = q.userRoleDAO + .readByUser(trans, cd.id); + if (rlurd.isOK()) { + for (UserRoleDAO.Data data : rlurd.value) { + q.userRoleDAO.delete(trans, data, false); + } + } + + } + } else { + // first possible StringBuilder Create. + sb = new StringBuilder(); + sb.append('['); + sb.append(ns); + sb.append("] contains users"); + } + } + + // 2b) Find (or delete if forced flag is set) dependencies + // First, find if NS Perms are the only ones + Result> rpdc = q.permDAO.readNS(trans, ns); + if (rpdc.isOKhasData()) { + // Since there are now NS perms, we have to count NON-NS perms. + // FYI, if we delete them now, and the NS is not deleted, it is in + // an inconsistent state. + boolean nonaccess = false; + for (PermDAO.Data pdd : rpdc.value) { + if (!"access".equals(pdd.type)) { + nonaccess = true; + break; + } + } + if (nonaccess && !force && !move) { + if (sb == null) { + sb = new StringBuilder(); + sb.append('['); + sb.append(ns); + sb.append("] contains "); + } else { + sb.append(", "); + } + sb.append("permissions"); + } + } + + Result> rrdc = q.roleDAO.readNS(trans, ns); + if (rrdc.isOKhasData()) { + // Since there are now NS roles, we have to count NON-NS roles. + // FYI, if we delete th)em now, and the NS is not deleted, it is in + // an inconsistent state. + int count = rrdc.value.size(); + for (RoleDAO.Data rdd : rrdc.value) { + if ("admin".equals(rdd.name) || "owner".equals(rdd.name)) { + --count; + } + } + if (count > 0 && !force && !move) { + if (sb == null) { + sb = new StringBuilder(); + sb.append('['); + sb.append(ns); + sb.append("] contains "); + } else { + sb.append(", "); + } + sb.append("roles"); + } + } + + // 2c) Deny if dependencies exist that would be moved to root level + // parent is root level parent here. Need to find closest parent ns that + // exists + if (sb != null) { + if (!force && !move) { + sb.append(".\n Delete dependencies and try again. Note: using \"force=true\" will delete all. \"force=move\" will delete Creds, but move Roles and Perms to parent."); + return Result.err(Status.ERR_DependencyExists, sb.toString()); + } + + if (move && (parent == null || parent.type == NsType.COMPANY.type)) { + return Result + .err(Status.ERR_DependencyExists, + "Cannot move users, roles or permissions to [%s].\nDelete dependencies and try again", + parent.name); + } + } else if (move && parent != null) { + sb = new StringBuilder(); + // 3) Change any roles with children matching this NS, and + moveRoles(trans, parent, sb, rrdc); + // 4) Change any Perms with children matching this NS, and + movePerms(trans, parent, sb, rpdc); + } + + if (sb != null && sb.length() > 0) { + return Result.err(Status.ERR_DependencyExists, sb.toString()); + } + + if (er.hasErr()) { + if (trans.debug().isLoggable()) { + trans.debug().log(er.toString()); + } + return Result.err(Status.ERR_DependencyExists, + "Namespace members cannot be deleted for %s", ns); + } + + // 5) OK... good to go for NS Deletion... + if (!rpdc.isEmpty()) { + for (PermDAO.Data perm : rpdc.value) { + deletePerm(trans, perm, true, true); + } + } + if (!rrdc.isEmpty()) { + for (RoleDAO.Data role : rrdc.value) { + deleteRole(trans, role, true, true); + } + } + + return q.nsDAO.delete(trans, nsd, false); + } + + public Result> getOwners(AuthzTrans trans, String ns, + boolean includeExpired) { + return getUsersByRole(trans, ns + Question.DOT_OWNER, includeExpired); + } + + private Result mayAddOwner(AuthzTrans trans, String ns, String id) { + Result rq = q.deriveNs(trans, ns); + if (rq.notOK()) { + return Result.err(rq); + } + + rq = q.mayUser(trans, trans.user(), rq.value, Access.write); + if (rq.notOK()) { + return Result.err(rq); + } + + Identity user; + Organization org = trans.org(); + try { + if ((user = org.getIdentity(trans, id)) == null) { + return Result.err(Status.ERR_Policy, + "%s reports that this is not a valid credential", + org.getName()); + } + if (user.isResponsible()) { + return Result.ok(); + } else { + String reason="This is not a Test Environment"; + if (org.isTestEnv() && (reason = org.validate(trans, Policy.AS_EMPLOYEE, + new CassExecutor(trans, this), id))==null) { + return Result.ok(); + } + return Result.err(Status.ERR_Policy,reason); + } + } catch (Exception e) { + return Result.err(e); + } + } + + private Result mayAddAdmin(AuthzTrans trans, String ns, String id) { + // Does NS Exist? + Result r = checkValidID(trans, new Date(), id); + if (r.notOK()) { + return r; + } + // Is id able to be an Admin + Result rq = q.deriveNs(trans, ns); + if (rq.notOK()) { + return Result.err(rq); + } + + rq = q.mayUser(trans, trans.user(), rq.value, Access.write); + if (rq.notOK()) { + return Result.err(rq); + } + return r; + } + + private Result checkValidID(AuthzTrans trans, Date now, String user) { + Organization org = trans.org(); + if (user.endsWith(org.getRealm())) { + try { + if (org.getIdentity(trans, user) == null) { + return Result.err(Status.ERR_Denied, + "%s reports that %s is a faulty ID", org.getName(), + user); + } + return Result.ok(); + } catch (Exception e) { + return Result.err(Result.ERR_Security, + "%s is not a valid %s Credential", user, org.getName()); + } + } else { + Result> cdr = q.credDAO.readID(trans, user); + if (cdr.notOKorIsEmpty()) { + return Result.err(Status.ERR_Security, + "%s is not a valid AAF Credential", user); + } + + for (CredDAO.Data cd : cdr.value) { + if (cd.expires.after(now)) { + return Result.ok(); + } + } + } + return Result.err(Result.ERR_Security, "%s has expired", user); + } + + public Result delOwner(AuthzTrans trans, String ns, String id) { + Result rq = q.deriveNs(trans, ns); + if (rq.notOK()) { + return Result.err(rq); + } + + rq = q.mayUser(trans, trans.user(), rq.value, Access.write); + if (rq.notOK()) { + return Result.err(rq); + } + + return delUserRole(trans, id, ns,Question.OWNER); + } + + public Result> getAdmins(AuthzTrans trans, String ns, boolean includeExpired) { + return getUsersByRole(trans, ns + Question.DOT_ADMIN, includeExpired); + } + + public Result delAdmin(AuthzTrans trans, String ns, String id) { + Result rq = q.deriveNs(trans, ns); + if (rq.notOK()) { + return Result.err(rq); + } + + rq = q.mayUser(trans, trans.user(), rq.value, Access.write); + if (rq.notOK()) { + return Result.err(rq); + } + + return delUserRole(trans, id, ns, Question.ADMIN); + } + + /** + * Helper function that moves permissions from a namespace being deleted to + * its parent namespace + * + * @param trans + * @param parent + * @param sb + * @param rpdc + * - list of permissions in namespace being deleted + */ + private void movePerms(AuthzTrans trans, NsDAO.Data parent, + StringBuilder sb, Result> rpdc) { + + Result rv; + Result pd; + + if (rpdc.isOKhasData()) { + for (PermDAO.Data pdd : rpdc.value) { + String delP2 = pdd.type; + if ("access".equals(delP2)) { + continue; + } + // Remove old Perm from Roles, save them off + List lrdd = new ArrayList(); + + for(String rl : pdd.roles(false)) { + Result rrdd = RoleDAO.Data.decode(trans,q,rl); + if(rrdd.isOKhasData()) { + RoleDAO.Data rdd = rrdd.value; + lrdd.add(rdd); + q.roleDAO.delPerm(trans, rdd, pdd); + } else{ + trans.error().log(rrdd.errorString()); + } + } + + // Save off Old keys + String delP1 = pdd.ns; + NsSplit nss = new NsSplit(parent, pdd.fullType()); + pdd.ns = nss.ns; + pdd.type = nss.name; + // Use direct Create/Delete, because switching namespaces + if ((pd = q.permDAO.create(trans, pdd)).isOK()) { + // Put Role back into Perm, with correct info + for(RoleDAO.Data rdd : lrdd) { + q.roleDAO.addPerm(trans, rdd, pdd); + } + + pdd.ns = delP1; + pdd.type = delP2; + if ((rv = q.permDAO.delete(trans, pdd, false)).notOK()) { + sb.append(rv.details); + sb.append('\n'); + // } else { + // Need to invalidate directly, because we're switching + // places in NS, not normal cache behavior + // q.permDAO.invalidate(trans,pdd); + } + } else { + sb.append(pd.details); + sb.append('\n'); + } + } + } + } + + /** + * Helper function that moves roles from a namespace being deleted to its + * parent namespace + * + * @param trans + * @param parent + * @param sb + * @param rrdc + * - list of roles in namespace being deleted + */ + private void moveRoles(AuthzTrans trans, NsDAO.Data parent, + StringBuilder sb, Result> rrdc) { + + Result rv; + Result rd; + + if (rrdc.isOKhasData()) { + for (RoleDAO.Data rdd : rrdc.value) { + String delP2 = rdd.name; + if ("admin".equals(delP2) || "owner".equals(delP2)) { + continue; + } + // Remove old Role from Perms, save them off + List lpdd = new ArrayList(); + for(String p : rdd.perms(false)) { + Result rpdd = PermDAO.Data.decode(trans,q,p); + if(rpdd.isOKhasData()) { + PermDAO.Data pdd = rpdd.value; + lpdd.add(pdd); + q.permDAO.delRole(trans, pdd, rdd); + } else{ + trans.error().log(rpdd.errorString()); + } + } + + // Save off Old keys + String delP1 = rdd.ns; + + NsSplit nss = new NsSplit(parent, rdd.fullName()); + rdd.ns = nss.ns; + rdd.name = nss.name; + // Use direct Create/Delete, because switching namespaces + if ((rd = q.roleDAO.create(trans, rdd)).isOK()) { + // Put Role back into Perm, with correct info + for(PermDAO.Data pdd : lpdd) { + q.permDAO.addRole(trans, pdd, rdd); + } + + rdd.ns = delP1; + rdd.name = delP2; + if ((rv = q.roleDAO.delete(trans, rdd, true)).notOK()) { + sb.append(rv.details); + sb.append('\n'); + // } else { + // Need to invalidate directly, because we're switching + // places in NS, not normal cache behavior + // q.roleDAO.invalidate(trans,rdd); + } + } else { + sb.append(rd.details); + sb.append('\n'); + } + } + } + } + + /** + * Create Permission (and any missing Permission between this and Parent) if + * we have permission + * + * Pass in the desired Management Permission for this Permission + * + * If Force is set, then Roles listed will be created, if allowed, + * pre-granted. + */ + public Result createPerm(AuthzTrans trans, PermDAO.Data perm, boolean fromApproval) { + String user = trans.user(); + // Next, see if User is allowed to Manage Parent Permission + + Result rnsd; + if (!fromApproval) { + rnsd = q.mayUser(trans, user, perm, Access.write); + if (rnsd.notOK()) { + return Result.err(rnsd); + } + } else { + rnsd = q.deriveNs(trans, perm.ns); + } + + // Does Child exist? + if (!trans.forceRequested()) { + if (q.permDAO.read(trans, perm).isOKhasData()) { + return Result.err(Status.ERR_ConflictAlreadyExists, + "Permission [%s.%s|%s|%s] already exists.", perm.ns, + perm.type, perm.instance, perm.action); + } + } + + // Attempt to add perms to roles, creating as possible + Set roles; + String pstring = perm.encode(); + + // For each Role + for (String role : roles = perm.roles(true)) { + Result rdd = RoleDAO.Data.decode(trans,q,role); + if(rdd.isOKhasData()) { + RoleDAO.Data rd = rdd.value; + if (!fromApproval) { + // May User write to the Role in question. + Result rns = q.mayUser(trans, user, rd, + Access.write); + if (rns.notOK()) { + // Remove the role from Add, because + roles.remove(role); // Don't allow adding + trans.warn() + .log("User [%s] does not have permission to relate Permissions to Role [%s]", + user, role); + } + } + + Result> rlrd; + if ((rlrd = q.roleDAO.read(trans, rd)).notOKorIsEmpty()) { + rd.perms(true).add(pstring); + if (q.roleDAO.create(trans, rd).notOK()) { + roles.remove(role); // Role doesn't exist, and can't be + // created + } + } else { + rd = rlrd.value.get(0); + if (!rd.perms.contains(pstring)) { + q.roleDAO.addPerm(trans, rd, perm); + } + } + } + } + + Result pdr = q.permDAO.create(trans, perm); + if (pdr.isOK()) { + return Result.ok(); + } else { + return Result.err(pdr); + } + } + + public Result deletePerm(final AuthzTrans trans, final PermDAO.Data perm, boolean force, boolean fromApproval) { + String user = trans.user(); + + // Next, see if User is allowed to Manage Permission + Result rnsd; + if (!fromApproval) { + rnsd = q.mayUser(trans, user, perm, Access.write); + if (rnsd.notOK()) { + return Result.err(rnsd); + } + } + // Does Perm exist? + Result> pdr = q.permDAO.read(trans, perm); + if (pdr.notOKorIsEmpty()) { + return Result.err(Status.ERR_PermissionNotFound,"Permission [%s.%s|%s|%s] does not exist.", + perm.ns,perm.type, perm.instance, perm.action); + } + // Get perm, but with rest of data. + PermDAO.Data fullperm = pdr.value.get(0); + + // Attached to any Roles? + if (fullperm.roles != null) { + if (force) { + for (String role : fullperm.roles) { + Result rv = null; + Result rrdd = RoleDAO.Data.decode(trans, q, role); + if(rrdd.isOKhasData()) { + trans.debug().log("Removing", role, "from", fullperm, "on Perm Delete"); + if ((rv = q.roleDAO.delPerm(trans, rrdd.value, fullperm)).notOK()) { + if (rv.notOK()) { + trans.error().log("Error removing Role during delFromPermRole: ", + trans.getUserPrincipal(), + rv.errorString()); + } + } + } else { + return Result.err(rrdd); + } + } + } else if (!fullperm.roles.isEmpty()) { + return Result + .err(Status.ERR_DependencyExists, + "Permission [%s.%s|%s|%s] cannot be deleted as it is attached to 1 or more roles.", + fullperm.ns, fullperm.type, fullperm.instance, fullperm.action); + } + } + + return q.permDAO.delete(trans, fullperm, false); + } + + public Result deleteRole(final AuthzTrans trans, final RoleDAO.Data role, boolean force, boolean fromApproval) { + String user = trans.user(); + + // Next, see if User is allowed to Manage Role + Result rnsd; + if (!fromApproval) { + rnsd = q.mayUser(trans, user, role, Access.write); + if (rnsd.notOK()) { + return Result.err(rnsd); + } + } + + // Are there any Users Attached to Role? + Result> urdr = q.userRoleDAO.readByRole(trans,role.fullName()); + if (force) { + if (urdr.isOKhasData()) { + for (UserRoleDAO.Data urd : urdr.value) { + q.userRoleDAO.delete(trans, urd, false); + } + } + } else if (urdr.isOKhasData()) { + return Result.err(Status.ERR_DependencyExists, + "Role [%s.%s] cannot be deleted as it is used by 1 or more Users.", + role.ns, role.name); + } + + // Does Role exist? + Result> rdr = q.roleDAO.read(trans, role); + if (rdr.notOKorIsEmpty()) { + return Result.err(Status.ERR_RoleNotFound, + "Role [%s.%s] does not exist", role.ns, role.name); + } + RoleDAO.Data fullrole = rdr.value.get(0); // full key search + + // Remove Self from Permissions... always, force or not. Force only applies to Dependencies (Users) + if (fullrole.perms != null) { + for (String perm : fullrole.perms(false)) { + Result rpd = PermDAO.Data.decode(trans,q,perm); + if (rpd.isOK()) { + trans.debug().log("Removing", perm, "from", fullrole,"on Role Delete"); + + Result r = q.permDAO.delRole(trans, rpd.value, fullrole); + if (r.notOK()) { + trans.error().log("ERR_FDR1 unable to remove",fullrole,"from",perm,':',r.status,'-',r.details); + } + } else { + trans.error().log("ERR_FDR2 Could not remove",perm,"from",fullrole); + } + } + } + return q.roleDAO.delete(trans, fullrole, false); + } + + /** + * Only owner of Permission may add to Role + * + * If force set, however, Role will be created before Grant, if User is + * allowed to create. + * + * @param trans + * @param role + * @param pd + * @return + */ + public Result addPermToRole(AuthzTrans trans, RoleDAO.Data role,PermDAO.Data pd, boolean fromApproval) { + String user = trans.user(); + + if (!fromApproval) { + Result rRoleCo = q.deriveFirstNsForType(trans, role.ns, NsType.COMPANY); + if(rRoleCo.notOK()) { + return Result.err(rRoleCo); + } + Result rPermCo = q.deriveFirstNsForType(trans, pd.ns, NsType.COMPANY); + if(rPermCo.notOK()) { + return Result.err(rPermCo); + } + + // Not from same company + if(!rRoleCo.value.name.equals(rPermCo.value.name)) { + Result r; + // Only grant if User ALSO has Write ability in Other Company + if((r = q.mayUser(trans, user, role, Access.write)).notOK()) { + return Result.err(r); + } + } + + + // Must be Perm Admin, or Granted Special Permission + Result ucp = q.mayUser(trans, user, pd, Access.write); + if (ucp.notOK()) { + // Don't allow CLI potential Grantees to change their own AAF + // Perms, + if ((Define.ROOT_NS.equals(pd.ns) && Question.NS.equals(pd.type)) + || !q.isGranted(trans, trans.user(),Define.ROOT_NS,Question.PERM, rPermCo.value.name, "grant")) { + // Not otherwise granted + // TODO Needed? + return Result.err(ucp); + } + // Final Check... Don't allow Grantees to add to Roles they are + // part of + Result> rlurd = q.userRoleDAO + .readByUser(trans, trans.user()); + if (rlurd.isOK()) { + for (UserRoleDAO.Data ur : rlurd.value) { + if (role.ns.equals(ur.ns) && role.name.equals(ur.rname)) { + return Result.err(ucp); + } + } + } + } + } + + Result> rlpd = q.permDAO.read(trans, pd); + if (rlpd.notOKorIsEmpty()) { + return Result.err(Status.ERR_PermissionNotFound, + "Permission must exist to add to Role"); + } + + Result> rlrd = q.roleDAO.read(trans, role); // Already + // Checked + // for + // can + // change + // Role + Result rv; + + if (rlrd.notOKorIsEmpty()) { + if (trans.forceRequested()) { + Result ucr = q.mayUser(trans, user, role, + Access.write); + if (ucr.notOK()) { + return Result + .err(Status.ERR_Denied, + "Role [%s.%s] does not exist. User [%s] cannot create.", + role.ns, role.name, user); + } + + role.perms(true).add(pd.encode()); + Result rdd = q.roleDAO.create(trans, role); + if (rdd.isOK()) { + rv = Result.ok(); + } else { + rv = Result.err(rdd); + } + } else { + return Result.err(Status.ERR_RoleNotFound, + "Role [%s.%s] does not exist.", role.ns, role.name); + } + } else { + role = rlrd.value.get(0); + if (role.perms(false).contains(pd.encode())) { + return Result.err(Status.ERR_ConflictAlreadyExists, + "Permission [%s.%s] is already a member of role [%s,%s]", + pd.ns, pd.type, role.ns, role.name); + } + role.perms(true).add(pd.encode()); // this is added for Caching + // access purposes... doesn't + // affect addPerm + rv = q.roleDAO.addPerm(trans, role, pd); + } + if (rv.status == Status.OK) { + return q.permDAO.addRole(trans, pd, role); + // exploring how to add information message to successful http + // request + } + return rv; + } + + /** + * Either Owner of Role or Permission may delete from Role + * + * @param trans + * @param role + * @param pd + * @return + */ + public Result delPermFromRole(AuthzTrans trans, RoleDAO.Data role,PermDAO.Data pd, boolean fromApproval) { + String user = trans.user(); + if (!fromApproval) { + Result ucr = q.mayUser(trans, user, role, Access.write); + Result ucp = q.mayUser(trans, user, pd, Access.write); + + // If Can't change either Role or Perm, then deny + if (ucr.notOK() && ucp.notOK()) { + return Result.err(Status.ERR_Denied, + "User [" + trans.user() + + "] does not have permission to delete [" + + pd.encode() + "] from Role [" + + role.fullName() + ']'); + } + } + + Result> rlr = q.roleDAO.read(trans, role); + if (rlr.notOKorIsEmpty()) { + // If Bad Data, clean out + Result> rlp = q.permDAO.read(trans, pd); + if (rlp.isOKhasData()) { + for (PermDAO.Data pv : rlp.value) { + q.permDAO.delRole(trans, pv, role); + } + } + return Result.err(rlr); + } + String perm1 = pd.encode(); + boolean notFound; + if (trans.forceRequested()) { + notFound = false; + } else { // only check if force not set. + notFound = true; + for (RoleDAO.Data r : rlr.value) { + if (r.perms != null) { + for (String perm : r.perms) { + if (perm1.equals(perm)) { + notFound = false; + break; + } + } + if(!notFound) { + break; + } + } + } + } + if (notFound) { // Need to check both, in case of corruption + return Result.err(Status.ERR_PermissionNotFound, + "Permission [%s.%s|%s|%s] not associated with any Role", + pd.ns,pd.type,pd.instance,pd.action); + } + + // Read Perm for full data + Result> rlp = q.permDAO.read(trans, pd); + Result rv = null; + if (rlp.isOKhasData()) { + for (PermDAO.Data pv : rlp.value) { + if ((rv = q.permDAO.delRole(trans, pv, role)).isOK()) { + if ((rv = q.roleDAO.delPerm(trans, role, pv)).notOK()) { + trans.error().log( + "Error removing Perm during delFromPermRole:", + trans.getUserPrincipal(), rv.errorString()); + } + } else { + trans.error().log( + "Error removing Role during delFromPermRole:", + trans.getUserPrincipal(), rv.errorString()); + } + } + } else { + rv = q.roleDAO.delPerm(trans, role, pd); + if (rv.notOK()) { + trans.error().log("Error removing Role during delFromPermRole", + rv.errorString()); + } + } + return rv == null ? Result.ok() : rv; + } + + public Result delPermFromRole(AuthzTrans trans, String role,PermDAO.Data pd) { + Result nss = q.deriveNsSplit(trans, role); + if (nss.notOK()) { + return Result.err(nss); + } + RoleDAO.Data rd = new RoleDAO.Data(); + rd.ns = nss.value.ns; + rd.name = nss.value.name; + return delPermFromRole(trans, rd, pd, false); + } + + /** + * Add a User to Role + * + * 1) Role must exist 2) User must be a known Credential (i.e. mechID ok if + * Credential) or known Organizational User + * + * @param trans + * @param org + * @param urData + * @return + * @throws DAOException + */ + public Result addUserRole(AuthzTrans trans,UserRoleDAO.Data urData) { + Result rv; + if(Question.ADMIN.equals(urData.rname)) { + rv = mayAddAdmin(trans, urData.ns, urData.user); + } else if(Question.OWNER.equals(urData.rname)) { + rv = mayAddOwner(trans, urData.ns, urData.user); + } else { + rv = checkValidID(trans, new Date(), urData.user); + } + if(rv.notOK()) { + return rv; + } + + // Check if record exists + if (q.userRoleDAO.read(trans, urData).isOKhasData()) { + return Result.err(Status.ERR_ConflictAlreadyExists, + "User Role exists"); + } + if (q.roleDAO.read(trans, urData.ns, urData.rname).notOKorIsEmpty()) { + return Result.err(Status.ERR_RoleNotFound, + "Role [%s.%s] does not exist", urData.ns, urData.rname); + } + + urData.expires = trans.org().expiration(null, Expiration.UserInRole, urData.user).getTime(); + + + Result udr = q.userRoleDAO.create(trans, urData); + switch (udr.status) { + case OK: + return Result.ok(); + default: + return Result.err(udr); + } + } + + public Result addUserRole(AuthzTrans trans, String user, String ns, String rname) { + UserRoleDAO.Data urdd = new UserRoleDAO.Data(); + urdd.ns = ns; + urdd.role(ns, rname); + urdd.user = user; + return addUserRole(trans,urdd); + } + + /** + * Extend User Role. + * + * extend the Expiration data, according to Organization rules. + * + * @param trans + * @param org + * @param urData + * @return + */ + public Result extendUserRole(AuthzTrans trans, UserRoleDAO.Data urData, boolean checkForExist) { + // Check if record still exists + if (checkForExist && q.userRoleDAO.read(trans, urData).notOKorIsEmpty()) { + return Result.err(Status.ERR_UserRoleNotFound, + "User Role does not exist"); + } + if (q.roleDAO.read(trans, urData.ns, urData.rname).notOKorIsEmpty()) { + return Result.err(Status.ERR_RoleNotFound, + "Role [%s.%s] does not exist", urData.ns,urData.rname); + } + // Special case for "Admin" roles. Issue brought forward with Prod + // problem 9/26 + + urData.expires = trans.org().expiration(null, Expiration.UserInRole).getTime(); // get + // Full + // time + // starting + // today + return q.userRoleDAO.update(trans, urData); + } + + // //////////////////////////////////////////////////// + // Special User Role Functions + // These exist, because User Roles have Expiration dates, which must be + // accounted for + // Also, as of July, 2015, Namespace Owners and Admins are now regular User + // Roles + // //////////////////////////////////////////////////// + public Result> getUsersByRole(AuthzTrans trans, String role, boolean includeExpired) { + Result> rurdd = q.userRoleDAO.readByRole(trans,role); + if (rurdd.notOK()) { + return Result.err(rurdd); + } + Date now = new Date(); + List list = rurdd.value; + List rv = new ArrayList(list.size()); // presize + for (UserRoleDAO.Data urdd : rurdd.value) { + if (includeExpired || urdd.expires.after(now)) { + rv.add(urdd.user); + } + } + return Result.ok(rv); + } + + public Result delUserRole(AuthzTrans trans, String user, String ns, String rname) { + UserRoleDAO.Data urdd = new UserRoleDAO.Data(); + urdd.user = user; + urdd.role(ns,rname); + Result> r = q.userRoleDAO.read(trans, urdd); + if (r.status == 404 || r.isEmpty()) { + return Result.err(Status.ERR_UserRoleNotFound, + "UserRole [%s] [%s.%s]", user, ns, rname); + } + if (r.notOK()) { + return Result.err(r); + } + + return q.userRoleDAO.delete(trans, urdd, false); + } + + public Result> createFuture(AuthzTrans trans, FutureDAO.Data data, String id, String user, + NsDAO.Data nsd, String op) { + // Create Future Object + List approvers=null; + Result fr = q.futureDAO.create(trans, data, id); + if (fr.isOK()) { + // User Future ID as ticket for Approvals + final UUID ticket = fr.value.id; + ApprovalDAO.Data ad; + try { + Organization org = trans.org(); + approvers = org.getApprovers(trans, user); + for (Identity u : approvers) { + ad = new ApprovalDAO.Data(); + // Note ad.id is set by ApprovalDAO Create + ad.ticket = ticket; + ad.user = user; + ad.approver = u.id(); + ad.status = ApprovalDAO.PENDING; + ad.memo = data.memo; + ad.type = org.getApproverType(); + ad.operation = op; + // Note ad.updated is created in System + Result ar = q.approvalDAO.create(trans,ad); + if (ar.notOK()) { + return Result.err(Status.ERR_ActionNotCompleted, + "Approval for %s, %s could not be created: %s", + ad.user, ad.approver, ar.details); + } + } + if (nsd != null) { + Result> rrbr = q.userRoleDAO + .readByRole(trans, nsd.name + Question.DOT_OWNER); + if (rrbr.isOK()) { + for (UserRoleDAO.Data urd : rrbr.value) { + ad = new ApprovalDAO.Data(); + // Note ad.id is set by ApprovalDAO Create + ad.ticket = ticket; + ad.user = user; + ad.approver = urd.user; + ad.status = ApprovalDAO.PENDING; + ad.memo = data.memo; + ad.type = "owner"; + ad.operation = op; + // Note ad.updated is created in System + Result ar = q.approvalDAO.create(trans, ad); + if (ar.notOK()) { + return Result.err(Status.ERR_ActionNotCompleted, + "Approval for %s, %s could not be created: %s", + ad.user, ad.approver, + ar.details); + } + } + } + } + } catch (Exception e) { + return Result.err(e); + } + } + + return Result.ok(approvers); + } + + public Result performFutureOp(AuthzTrans trans, ApprovalDAO.Data cd) { + Result> fd = q.futureDAO.read(trans, cd.ticket); + Result> allApprovalsForTicket = q.approvalDAO + .readByTicket(trans, cd.ticket); + Result rv = Result.ok(); + for (FutureDAO.Data curr : fd.value) { + if ("approved".equalsIgnoreCase(cd.status)) { + if (allApprovalsForTicket.value.size() <= 1) { + // should check if any other pendings before performing + // actions + try { + if (FOP_ROLE.equalsIgnoreCase(curr.target)) { + RoleDAO.Data data = new RoleDAO.Data(); + data.reconstitute(curr.construct); + if ("C".equalsIgnoreCase(cd.operation)) { + Result rd; + if ((rd = q.roleDAO.dao().create(trans, data)).notOK()) { + rv = Result.err(rd); + } + } else if ("D".equalsIgnoreCase(cd.operation)) { + rv = deleteRole(trans, data, true, true); + } + + } else if (FOP_PERM.equalsIgnoreCase(curr.target)) { + PermDAO.Data pdd = new PermDAO.Data(); + pdd.reconstitute(curr.construct); + if ("C".equalsIgnoreCase(cd.operation)) { + rv = createPerm(trans, pdd, true); + } else if ("D".equalsIgnoreCase(cd.operation)) { + rv = deletePerm(trans, pdd, true, true); + } else if ("G".equalsIgnoreCase(cd.operation)) { + Set roles = pdd.roles(true); + Result rrdd = null; + for (String roleStr : roles) { + rrdd = RoleDAO.Data.decode(trans, q, roleStr); + if (rrdd.isOKhasData()) { + rv = addPermToRole(trans, rrdd.value, pdd, true); + } else { + trans.error().log(rrdd.errorString()); + } + } + } else if ("UG".equalsIgnoreCase(cd.operation)) { + Set roles = pdd.roles(true); + Result rrdd; + for (String roleStr : roles) { + rrdd = RoleDAO.Data.decode(trans, q, roleStr); + if (rrdd.isOKhasData()) { + rv = delPermFromRole(trans, rrdd.value, pdd, true); + } else { + trans.error().log(rrdd.errorString()); + } + } + } + + } else if (FOP_USER_ROLE.equalsIgnoreCase(curr.target)) { + UserRoleDAO.Data data = new UserRoleDAO.Data(); + data.reconstitute(curr.construct); + // if I am the last to approve, create user role + if ("C".equalsIgnoreCase(cd.operation)) { + rv = addUserRole(trans, data); + } else if ("U".equals(cd.operation)) { + rv = extendUserRole(trans, data, true); + } + + } else if (FOP_NS.equalsIgnoreCase(curr.target)) { + Namespace namespace = new Namespace(); + namespace.reconstitute(curr.construct); + + if ("C".equalsIgnoreCase(cd.operation)) { + rv = createNS(trans, namespace, true); + } + + } else if (FOP_DELEGATE.equalsIgnoreCase(curr.target)) { + DelegateDAO.Data data = new DelegateDAO.Data(); + data.reconstitute(curr.construct); + if ("C".equalsIgnoreCase(cd.operation)) { + Result dd; + if ((dd = q.delegateDAO.create(trans, data)).notOK()) { + rv = Result.err(dd); + } + } else if ("U".equalsIgnoreCase(cd.operation)) { + rv = q.delegateDAO.update(trans, data); + } + } else if (FOP_CRED.equalsIgnoreCase(curr.target)) { + CredDAO.Data data = new CredDAO.Data(); + data.reconstitute(curr.construct); + if ("C".equalsIgnoreCase(cd.operation)) { + Result rd; + if ((rd = q.credDAO.dao().create(trans, data)).notOK()) { + rv = Result.err(rd); + } + } + } + } catch (IOException e) { + trans.error().log("IOException: ", e.getMessage(), + " \n occurred while performing", cd.memo, + " from approval ", cd.id.toString()); + } + } + } else if ("denied".equalsIgnoreCase(cd.status)) { + for (ApprovalDAO.Data ad : allApprovalsForTicket.value) { + q.approvalDAO.delete(trans, ad, false); + } + q.futureDAO.delete(trans, curr, false); + if (FOP_USER_ROLE.equalsIgnoreCase(curr.target)) { + // if I am the last to approve, create user role + if ("U".equals(cd.operation)) { + UserRoleDAO.Data data = new UserRoleDAO.Data(); + try { + data.reconstitute(curr.construct); + } catch (IOException e) { + trans.error().log("Cannot reconstitue",curr.memo); + } + rv = delUserRole(trans, data.user, data.ns, data.rname); + } + } + + } + + // if I am the last to approve, delete the future object + if (rv.isOK() && allApprovalsForTicket.value.size() <= 1) { + q.futureDAO.delete(trans, curr, false); + } + + } // end for each + return rv; + + } + + public Executor newExecutor(AuthzTrans trans) { + return new CassExecutor(trans, this); + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/hl/PermLookup.java b/authz-cass/src/main/java/com/att/dao/aaf/hl/PermLookup.java new file mode 100644 index 00000000..f2564fc0 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/hl/PermLookup.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.hl; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.Status; +import com.att.dao.aaf.cass.UserRoleDAO; + +/** + * PermLookup is a Storage class for the various pieces of looking up Permission + * during Transactions to avoid duplicate processing + * + * + */ +// Package on purpose +class PermLookup { + private AuthzTrans trans; + private String user; + private Question q; + private Result> userRoles = null; + private Result> roles = null; + private Result> permNames = null; + private Result> perms = null; + + private PermLookup() {} + + static PermLookup get(AuthzTrans trans, Question q, String user) { + PermLookup lp=null; + Map permMap = trans.get(Question.PERMS, null); + if (permMap == null) { + trans.put(Question.PERMS, permMap = new HashMap()); + } else { + lp = permMap.get(user); + } + + if (lp == null) { + lp = new PermLookup(); + lp.trans = trans; + lp.user = user; + lp.q = q; + permMap.put(user, lp); + } + return lp; + } + + public Result> getUserRoles() { + if(userRoles==null) { + userRoles = q.userRoleDAO.readByUser(trans,user); + if(userRoles.isOKhasData()) { + List lurdd = new ArrayList(); + Date now = new Date(); + for(UserRoleDAO.Data urdd : userRoles.value) { + if(urdd.expires.after(now)) { // Remove Expired + lurdd.add(urdd); + } + } + if(lurdd.size()==0) { + return userRoles = Result.err(Status.ERR_UserNotFound, + "%s not found or not associated with any Roles: ", + user); + } else { + return userRoles = Result.ok(lurdd); + } + } else { + return userRoles; + } + } else { + return userRoles; + } + } + + public Result> getRoles() { + if(roles==null) { + Result> rur = getUserRoles(); + if(rur.isOK()) { + List lrdd = new ArrayList(); + for (UserRoleDAO.Data urdata : rur.value) { + // Gather all permissions from all Roles + if(urdata.ns==null || urdata.rname==null) { + trans.error().printf("DB Content Error: nulls in User Role %s %s", urdata.user,urdata.role); + } else { + Result> rlrd = q.roleDAO.read( + trans, urdata.ns, urdata.rname); + if(rlrd.isOK()) { + lrdd.addAll(rlrd.value); + } + } + } + return roles = Result.ok(lrdd); + } else { + return roles = Result.err(rur); + } + } else { + return roles; + } + } + + public Result> getPermNames() { + if(permNames==null) { + Result> rlrd = getRoles(); + if (rlrd.isOK()) { + Set pns = new TreeSet(); + for (RoleDAO.Data rdata : rlrd.value) { + pns.addAll(rdata.perms(false)); + } + return permNames = Result.ok(pns); + } else { + return permNames = Result.err(rlrd); + } + } else { + return permNames; + } + } + + public Result> getPerms(boolean lookup) { + if(perms==null) { + // Note: It should be ok for a Valid user to have no permissions - + // 8/12/2013 + Result> rss = getPermNames(); + if(rss.isOK()) { + List lpdd = new ArrayList(); + for (String perm : rss.value) { + if(lookup) { + Result ap = PermDAO.Data.decodeToArray(trans, q, perm); + if(ap.isOK()) { + Result> rlpd = q.permDAO.read(perm,trans,ap); + if (rlpd.isOKhasData()) { + for (PermDAO.Data pData : rlpd.value) { + lpdd.add(pData); + } + } + } else { + trans.error().log("In getPermsByUser, for", user, perm); + } + } else { + Result pr = PermDAO.Data.decode(trans, q, perm); + if (pr.notOK()) { + trans.error().log("In getPermsByUser, for", user, pr.errorString()); + } else { + lpdd.add(pr.value); + } + } + + } + return perms = Result.ok(lpdd); + } else { + return perms = Result.err(rss); + } + } else { + return perms; + } + } +} diff --git a/authz-cass/src/main/java/com/att/dao/aaf/hl/Question.java b/authz-cass/src/main/java/com/att/dao/aaf/hl/Question.java new file mode 100644 index 00000000..ce868fbc --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/aaf/hl/Question.java @@ -0,0 +1,1087 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.hl; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import com.att.authz.common.Define; +import com.att.authz.env.AuthzTrans; +import com.att.authz.env.AuthzTransFilter; +import com.att.authz.layer.Result; +import com.att.authz.org.Organization; +import com.att.authz.org.Organization.Identity; +import com.att.cadi.Hash; +import com.att.cadi.aaf.PermEval; +import com.att.dao.AbsCassDAO; +import com.att.dao.CachedDAO; +import com.att.dao.DAOException; +import com.att.dao.aaf.cached.CachedCertDAO; +import com.att.dao.aaf.cached.CachedCredDAO; +import com.att.dao.aaf.cached.CachedNSDAO; +import com.att.dao.aaf.cached.CachedPermDAO; +import com.att.dao.aaf.cached.CachedRoleDAO; +import com.att.dao.aaf.cached.CachedUserRoleDAO; +import com.att.dao.aaf.cass.ApprovalDAO; +import com.att.dao.aaf.cass.CacheInfoDAO; +import com.att.dao.aaf.cass.CertDAO; +import com.att.dao.aaf.cass.CredDAO; +import com.att.dao.aaf.cass.DelegateDAO; +import com.att.dao.aaf.cass.FutureDAO; +import com.att.dao.aaf.cass.HistoryDAO; +import com.att.dao.aaf.cass.NsDAO; +import com.att.dao.aaf.cass.NsDAO.Data; +import com.att.dao.aaf.cass.NsSplit; +import com.att.dao.aaf.cass.NsType; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.Status; +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + +/** + * Question HL DAO + * + * A Data Access Combination Object which asks Security and other Questions + * + * + */ +public class Question { + // DON'T CHANGE FROM lower Case!!! + public static enum Type { + ns, role, perm, cred + }; + + public static final String OWNER="owner"; + public static final String ADMIN="admin"; + public static final String DOT_OWNER=".owner"; + public static final String DOT_ADMIN=".admin"; + static final String ASTERIX = "*"; + + public static enum Access { + read, write, create + }; + + public static final String READ = Access.read.name(); + public static final String WRITE = Access.write.name(); + public static final String CREATE = Access.create.name(); + + public static final String ROLE = Type.role.name(); + public static final String PERM = Type.perm.name(); + public static final String NS = Type.ns.name(); + public static final String CRED = Type.cred.name(); + private static final String DELG = "delg"; + public static final String ATTRIB = "attrib"; + + + public static final int MAX_SCOPE = 10; + public static final int APP_SCOPE = 3; + public static final int COMPANY_SCOPE = 2; + static Slot PERMS; + + private static Set specialLog = null; + public static final SecureRandom random = new SecureRandom(); + private static long traceID = random.nextLong(); + private static final String SPECIAL_LOG_SLOT = "SPECIAL_LOG_SLOT"; + private static Slot specialLogSlot = null; + private static Slot transIDSlot = null; + + + public final HistoryDAO historyDAO; + public final CachedNSDAO nsDAO; + public final CachedRoleDAO roleDAO; + public final CachedPermDAO permDAO; + public final CachedUserRoleDAO userRoleDAO; + public final CachedCredDAO credDAO; + public final CachedCertDAO certDAO; + public final DelegateDAO delegateDAO; + public final FutureDAO futureDAO; + public final ApprovalDAO approvalDAO; + private final CacheInfoDAO cacheInfoDAO; + + // final ContactDAO contDAO; + // private static final String DOMAIN = "@aaf.att.com"; + // private static final int DOMAIN_LENGTH = 0; + + public Question(AuthzTrans trans, Cluster cluster, String keyspace, boolean startClean) throws APIException, IOException { + PERMS = trans.slot("USER_PERMS"); + trans.init().log("Instantiating DAOs"); + historyDAO = new HistoryDAO(trans, cluster, keyspace); + + // Deal with Cached Entries + cacheInfoDAO = new CacheInfoDAO(trans, historyDAO); + + nsDAO = new CachedNSDAO(new NsDAO(trans, historyDAO, cacheInfoDAO), + cacheInfoDAO); + permDAO = new CachedPermDAO( + new PermDAO(trans, historyDAO, cacheInfoDAO), cacheInfoDAO); + roleDAO = new CachedRoleDAO( + new RoleDAO(trans, historyDAO, cacheInfoDAO), cacheInfoDAO); + userRoleDAO = new CachedUserRoleDAO(new UserRoleDAO(trans, historyDAO, + cacheInfoDAO), cacheInfoDAO); + credDAO = new CachedCredDAO( + new CredDAO(trans, historyDAO, cacheInfoDAO), cacheInfoDAO); + certDAO = new CachedCertDAO( + new CertDAO(trans, historyDAO, cacheInfoDAO), cacheInfoDAO); + + futureDAO = new FutureDAO(trans, historyDAO); + delegateDAO = new DelegateDAO(trans, historyDAO); + approvalDAO = new ApprovalDAO(trans, historyDAO); + + // Only want to aggressively cleanse User related Caches... The others, + // just normal refresh + if(startClean) { + CachedDAO.startCleansing(trans.env(), credDAO, userRoleDAO); + CachedDAO.startRefresh(trans.env(), cacheInfoDAO); + } + // Set a Timer to Check Caches to send messages for Caching changes + + if(specialLogSlot==null) { + specialLogSlot = trans.slot(SPECIAL_LOG_SLOT); + transIDSlot = trans.slot(AuthzTransFilter.TRANS_ID_SLOT); + } + + AbsCassDAO.primePSIs(trans); + } + + + public void close(AuthzTrans trans) { + historyDAO.close(trans); + cacheInfoDAO.close(trans); + nsDAO.close(trans); + permDAO.close(trans); + roleDAO.close(trans); + userRoleDAO.close(trans); + credDAO.close(trans); + certDAO.close(trans); + delegateDAO.close(trans); + futureDAO.close(trans); + approvalDAO.close(trans); + } + + public Result permFrom(AuthzTrans trans, String type, + String instance, String action) { + Result rnd = deriveNs(trans, type); + if (rnd.isOK()) { + return Result.ok(new PermDAO.Data(new NsSplit(rnd.value, type), + instance, action)); + } else { + return Result.err(rnd); + } + } + + /** + * getPermsByUser + * + * Because this call is frequently called internally, AND because we already + * look for it in the initial Call, we cache within the Transaction + * + * @param trans + * @param user + * @return + */ + public Result> getPermsByUser(AuthzTrans trans, String user, boolean lookup) { + return PermLookup.get(trans, this, user).getPerms(lookup); + } + + public Result> getPermsByUserFromRolesFilter(AuthzTrans trans, String user, String forUser) { + PermLookup plUser = PermLookup.get(trans, this, user); + Result> plPermNames = plUser.getPermNames(); + if(plPermNames.notOK()) { + return Result.err(plPermNames); + } + + Set nss; + if(forUser.equals(user)) { + nss = null; + } else { + // Setup a TreeSet to check on Namespaces to + nss = new TreeSet(); + PermLookup fUser = PermLookup.get(trans, this, forUser); + Result> forUpn = fUser.getPermNames(); + if(forUpn.notOK()) { + return Result.err(forUpn); + } + + for(String pn : forUpn.value) { + Result decoded = PermDAO.Data.decodeToArray(trans, this, pn); + if(decoded.isOKhasData()) { + nss.add(decoded.value[0]); + } else { + trans.error().log(pn,", derived from a Role, is invalid:",decoded.errorString()); + } + } + } + + List rlpUser = new ArrayList(); + Result rpdd; + PermDAO.Data pdd; + for(String pn : plPermNames.value) { + rpdd = PermDAO.Data.decode(trans, this, pn); + if(rpdd.isOKhasData()) { + pdd=rpdd.value; + if(nss==null || nss.contains(pdd.ns)) { + rlpUser.add(pdd); + } + } else { + trans.error().log(pn,", derived from a Role, is invalid. Run Data Cleanup:",rpdd.errorString()); + } + } + return Result.ok(rlpUser); + } + + public Result> getPermsByType(AuthzTrans trans, String perm) { + Result nss = deriveNsSplit(trans, perm); + if (nss.notOK()) { + return Result.err(nss); + } + return permDAO.readByType(trans, nss.value.ns, nss.value.name); + } + + public Result> getPermsByName(AuthzTrans trans, + String type, String instance, String action) { + Result nss = deriveNsSplit(trans, type); + if (nss.notOK()) { + return Result.err(nss); + } + return permDAO.read(trans, nss.value.ns, nss.value.name, instance,action); + } + + public Result> getPermsByRole(AuthzTrans trans, String role, boolean lookup) { + Result nss = deriveNsSplit(trans, role); + if (nss.notOK()) { + return Result.err(nss); + } + + Result> rlrd = roleDAO.read(trans, nss.value.ns, + nss.value.name); + if (rlrd.notOKorIsEmpty()) { + return Result.err(rlrd); + } + // Using Set to avoid duplicates + Set permNames = new HashSet(); + if (rlrd.isOKhasData()) { + for (RoleDAO.Data drr : rlrd.value) { + permNames.addAll(drr.perms(false)); + } + } + + // Note: It should be ok for a Valid user to have no permissions - + // 8/12/2013 + List perms = new ArrayList(); + for (String perm : permNames) { + Result pr = PermDAO.Data.decode(trans, this, perm); + if (pr.notOK()) { + return Result.err(pr); + } + + if(lookup) { + Result> rlpd = permDAO.read(trans, pr.value); + if (rlpd.isOKhasData()) { + for (PermDAO.Data pData : rlpd.value) { + perms.add(pData); + } + } + } else { + perms.add(pr.value); + } + } + + return Result.ok(perms); + } + + public Result> getRolesByName(AuthzTrans trans, + String role) { + Result nss = deriveNsSplit(trans, role); + if (nss.notOK()) { + return Result.err(nss); + } + String r = nss.value.name; + if (r.endsWith(".*")) { // do children Search + return roleDAO.readChildren(trans, nss.value.ns, + r.substring(0, r.length() - 2)); + } else if (ASTERIX.equals(r)) { + return roleDAO.readChildren(trans, nss.value.ns, ASTERIX); + } else { + return roleDAO.read(trans, nss.value.ns, r); + } + } + + /** + * Derive NS + * + * Given a Child Namespace, figure out what the best Namespace parent is. + * + * For instance, if in the NS table, the parent "com.att" exists, but not + * "com.att.child" or "com.att.a.b.c", then passing in either + * "com.att.child" or "com.att.a.b.c" will return "com.att" + * + * Uses recursive search on Cached DAO data + * + * @param trans + * @param child + * @return + */ + public Result deriveNs(AuthzTrans trans, String child) { + Result> r = nsDAO.read(trans, child); + + if (r.isOKhasData()) { + return Result.ok(r.value.get(0)); + } else { + int dot = child == null ? -1 : child.lastIndexOf('.'); + if (dot < 0) { + return Result.err(Status.ERR_NsNotFound, + "No Namespace for [%s]", child); + } else { + return deriveNs(trans, child.substring(0, dot)); + } + } + } + + public Result deriveFirstNsForType(AuthzTrans trans, String str, NsType type) { + NsDAO.Data nsd; + + System.out.println("value of str before for loop ---------0---++++++++++++++++++" +str); + for(int idx = str.indexOf('.');idx>=0;idx=str.indexOf('.',idx+1)) { + // System.out.println("printing value of str-----------------1------------++++++++++++++++++++++" +str); + Result> rld = nsDAO.read(trans, str.substring(0,idx)); + System.out.println("value of idx is -----------------++++++++++++++++++++++++++" +idx); + System.out.println("printing value of str.substring-----------------1------------++++++++++++++++++++++" + (str.substring(0,idx))); + System.out.println("value of ResultListData ------------------2------------+++++++++++++++++++++++++++" +rld); + if(rld.isOKhasData()) { + System.out.println("In if loop -----------------3-------------- ++++++++++++++++"); + System.out.println("value of nsd=rld.value.get(0).type -----------4------++++++++++++++++++++++++++++++++++++" +(nsd=rld.value.get(0)).type); + System.out.println("value of rld.value.get(0).name.toString()+++++++++++++++++++++++++++++++ " +rld.value.get(0).name); + if(type.type == (nsd=rld.value.get(0)).type) { + return Result.ok(nsd); + } + } else { + System.out.println("In else loop ----------------4------------+++++++++++++++++++++++"); + return Result.err(Status.ERR_NsNotFound,"There is no valid Company Namespace for %s",str.substring(0,idx)); + } + } + return Result.err(Status.ERR_NotFound, str + " does not contain type " + type.name()); + } + + public Result deriveNsSplit(AuthzTrans trans, String child) { + Result ndd = deriveNs(trans, child); + if (ndd.isOK()) { + NsSplit nss = new NsSplit(ndd.value, child); + if (nss.isOK()) { + return Result.ok(nss); + } else { + return Result.err(Status.ERR_NsNotFound, + "Cannot split [%s] into valid namespace elements", + child); + } + } + return Result.err(ndd); + } + + /** + * Translate an ID into it's domain + * + * i.e. myid1234@myapp.att.com results in domain of com.att.myapp + * + * @param id + * @return + */ + public static String domain2ns(String id) { + int at = id.indexOf('@'); + if (at >= 0) { + String[] domain = id.substring(at + 1).split("\\."); + StringBuilder ns = new StringBuilder(id.length()); + boolean first = true; + for (int i = domain.length - 1; i >= 0; --i) { + if (first) { + first = false; + } else { + ns.append('.'); + } + ns.append(domain[i]); + } + return ns.toString(); + } else { + return ""; + } + + } + + /** + * Validate Namespace of ID@Domain + * + * Namespace is reverse order of Domain. + * + * i.e. myid1234@myapp.att.com results in domain of com.att.myapp + * + * @param trans + * @param id + * @return + */ + public Result validNSOfDomain(AuthzTrans trans, String id) { + // Take domain, reverse order, and check on NS + String ns; + if(id.indexOf('@')<0) { // it's already an ns, not an ID + ns = id; + } else { + ns = domain2ns(id); + } + if (ns.length() > 0) { + if(!trans.org().getDomain().equals(ns)) { + Result> rlnsd = nsDAO.read(trans, ns); + if (rlnsd.isOKhasData()) { + return Result.ok(rlnsd.value.get(0)); + } + } + } + return Result.err(Status.ERR_NsNotFound, + "A Namespace is not available for %s", id); + } + + public Result mayUser(AuthzTrans trans, String user,NsDAO.Data ndd, Access access) { + // .access|:role:| + String ns = ndd.name; + int last; + do { + if (isGranted(trans, user, ns, "access", ":ns", access.name())) { + return Result.ok(ndd); + } + if ((last = ns.lastIndexOf('.')) >= 0) { + ns = ns.substring(0, last); + } + } while (last >= 0); + // .ns|::ns| + // AAF-724 - Make consistent response for May User", and not take the + // last check... too confusing. + Result rv = mayUserVirtueOfNS(trans, user, ndd, ":" + ndd.name + ":ns", access.name()); + if (rv.isOK()) { + return rv; + } else if(rv.status==Result.ERR_Backend) { + return Result.err(rv); + } else { + return Result.err(Status.ERR_Denied, "[%s] may not %s in NS [%s]", + user, access.name(), ndd.name); + } + } + + public Result mayUser(AuthzTrans trans, String user, RoleDAO.Data rdd, Access access) { + Result rnsd = deriveNs(trans, rdd.ns); + if (rnsd.isOK()) { + return mayUser(trans, user, rnsd.value, rdd, access); + } + return rnsd; + } + + public Result mayUser(AuthzTrans trans, String user, NsDAO.Data ndd, RoleDAO.Data rdd, Access access) { + // 1) Is User in the Role? + Result> rurd = userRoleDAO.readUserInRole(trans, user, rdd.fullName()); + if (rurd.isOKhasData()) { + return Result.ok(ndd); + } + + String roleInst = ":role:" + rdd.name; + // .access|:role:| + String ns = rdd.ns; + int last; + do { + if (isGranted(trans, user, ns,"access", roleInst, access.name())) { + return Result.ok(ndd); + } + if ((last = ns.lastIndexOf('.')) >= 0) { + ns = ns.substring(0, last); + } + } while (last >= 0); + + // Check if Access by Global Role perm + // .ns|::role:name| + Result rnsd = mayUserVirtueOfNS(trans, user, ndd, ":" + + rdd.ns + roleInst, access.name()); + if (rnsd.isOK()) { + return rnsd; + } else if(rnsd.status==Result.ERR_Backend) { + return Result.err(rnsd); + } + + // Check if Access to Whole NS + // AAF-724 - Make consistent response for May User", and not take the + // last check... too confusing. + Result rv = mayUserVirtueOfNS(trans, user, ndd, + ":" + rdd.ns + ":ns", access.name()); + if (rv.isOK()) { + return rv; + } else if(rnsd.status==Result.ERR_Backend) { + return Result.err(rnsd); + } else { + return Result.err(Status.ERR_Denied, "[%s] may not %s Role [%s]", + user, access.name(), rdd.fullName()); + } + + } + + public Result mayUser(AuthzTrans trans, String user,PermDAO.Data pdd, Access access) { + Result rnsd = deriveNs(trans, pdd.ns); + if (rnsd.isOK()) { + return mayUser(trans, user, rnsd.value, pdd, access); + } + return rnsd; + } + + public Result mayUser(AuthzTrans trans, String user,NsDAO.Data ndd, PermDAO.Data pdd, Access access) { + if (isGranted(trans, user, pdd.ns, pdd.type, pdd.instance, pdd.action)) { + return Result.ok(ndd); + } + String permInst = ":perm:" + pdd.type + ':' + pdd.instance + ':' + pdd.action; + // .access|:role:| + String ns = ndd.name; + int last; + do { + if (isGranted(trans, user, ns, "access", permInst, access.name())) { + return Result.ok(ndd); + } + if ((last = ns.lastIndexOf('.')) >= 0) { + ns = ns.substring(0, last); + } + } while (last >= 0); + + // Check if Access by NS perm + // .ns|::role:name| + Result rnsd = mayUserVirtueOfNS(trans, user, ndd, ":" + pdd.ns + permInst, access.name()); + if (rnsd.isOK()) { + return rnsd; + } else if(rnsd.status==Result.ERR_Backend) { + return Result.err(rnsd); + } + + // Check if Access to Whole NS + // AAF-724 - Make consistent response for May User", and not take the + // last check... too confusing. + Result rv = mayUserVirtueOfNS(trans, user, ndd, ":" + pdd.ns + ":ns", access.name()); + if (rv.isOK()) { + return rv; + } else { + return Result.err(Status.ERR_Denied, + "[%s] may not %s Perm [%s|%s|%s]", user, access.name(), + pdd.fullType(), pdd.instance, pdd.action); + } + + } + + public Result mayUser(AuthzTrans trans, DelegateDAO.Data dd, Access access) { + try { + boolean isUser = trans.user().equals(dd.user); + boolean isDelegate = dd.delegate != null + && (dd.user.equals(dd.delegate) || trans.user().equals( + dd.delegate)); + Organization org = trans.org(); + switch (access) { + case create: + if (org.getIdentity(trans, dd.user) == null) { + return Result.err(Status.ERR_UserNotFound, + "[%s] is not a user in the company database.", + dd.user); + } + if (!dd.user.equals(dd.delegate) && org.getIdentity(trans, dd.delegate) == null) { + return Result.err(Status.ERR_UserNotFound, + "[%s] is not a user in the company database.", + dd.delegate); + } + if (!trans.forceRequested() && dd.user != null && dd.user.equals(dd.delegate)) { + return Result.err(Status.ERR_BadData, + "[%s] cannot be a delegate for self", dd.user); + } + if (!isUser && !isGranted(trans, trans.user(), Define.ROOT_NS,DELG, + org.getDomain(), Question.CREATE)) { + return Result.err(Status.ERR_Denied, + "[%s] may not create a delegate for [%s]", + trans.user(), dd.user); + } + break; + case read: + case write: + if (!isUser && !isDelegate && + !isGranted(trans, trans.user(), Define.ROOT_NS,DELG,org.getDomain(), access.name())) { + return Result.err(Status.ERR_Denied, + "[%s] may not %s delegates for [%s]", trans.user(), + access.name(), dd.user); + } + break; + default: + return Result.err(Status.ERR_BadData,"Unknown Access type [%s]", access.name()); + } + } catch (Exception e) { + return Result.err(e); + } + return Result.ok(); + } + + /* + * Check (recursively, if necessary), if able to do something based on NS + */ + private Result mayUserVirtueOfNS(AuthzTrans trans, String user, NsDAO.Data nsd, String ns_and_type, String access) { + String ns = nsd.name; + + // If an ADMIN of the Namespace, then allow + + Result> rurd; + if ((rurd = userRoleDAO.readUserInRole(trans, user, nsd.name+ADMIN)).isOKhasData()) { + return Result.ok(nsd); + } else if(rurd.status==Result.ERR_Backend) { + return Result.err(rurd); + } + + // If Specially granted Global Permission + if (isGranted(trans, user, Define.ROOT_NS,NS, ns_and_type, access)) { + return Result.ok(nsd); + } + + // Check recur + + int dot = ns.length(); + if ((dot = ns.lastIndexOf('.', dot - 1)) >= 0) { + Result rnsd = deriveNs(trans, ns.substring(0, dot)); + if (rnsd.isOK()) { + rnsd = mayUserVirtueOfNS(trans, user, rnsd.value, ns_and_type,access); + } else if(rnsd.status==Result.ERR_Backend) { + return Result.err(rnsd); + } + if (rnsd.isOK()) { + return Result.ok(nsd); + } else if(rnsd.status==Result.ERR_Backend) { + return Result.err(rnsd); + } + } + return Result.err(Status.ERR_Denied, "%s may not %s %s", user, access, + ns_and_type); + } + + + /** + * isGranted + * + * Important function - Check internal Permission Schemes for Permission to + * do things + * + * @param trans + * @param type + * @param instance + * @param action + * @return + */ + public boolean isGranted(AuthzTrans trans, String user, String ns, String type,String instance, String action) { + Result> perms = getPermsByUser(trans, user, false); + if (perms.isOK()) { + for (PermDAO.Data pd : perms.value) { + if (ns.equals(pd.ns)) { + if (type.equals(pd.type)) { + if (PermEval.evalInstance(pd.instance, instance)) { + if(PermEval.evalAction(pd.action, action)) { // don't return action here, might miss other action + return true; + } + } + } + } + } + } + return false; + } + + public Result doesUserCredMatch(AuthzTrans trans, String user, byte[] cred) throws DAOException { + Result> result; + TimeTaken tt = trans.start("Read DB Cred", Env.REMOTE); + try { + result = credDAO.readID(trans, user); + } finally { + tt.done(); + } + + Result rv = null; + if(result.isOK()) { + if (result.isEmpty()) { + rv = Result.err(Status.ERR_UserNotFound, user); + if (willSpecialLog(trans,user)) { + trans.audit().log("Special DEBUG:", user, " does not exist in DB"); + } + } else { + Date now = new Date();//long now = System.currentTimeMillis(); + ByteBuffer md5=null; + + // Bug noticed 6/22. Sorting on the result can cause Concurrency Issues. + List cddl; + if(result.value.size() > 1) { + cddl = new ArrayList(result.value.size()); + for(CredDAO.Data old : result.value) { + if(old.type==CredDAO.BASIC_AUTH || old.type==CredDAO.BASIC_AUTH_SHA256) { + cddl.add(old); + } + } + if(cddl.size()>1) { + Collections.sort(cddl,new Comparator() { + @Override + public int compare(com.att.dao.aaf.cass.CredDAO.Data a, + com.att.dao.aaf.cass.CredDAO.Data b) { + return b.expires.compareTo(a.expires); + } + }); + } + } else { + cddl = result.value; + } + + for (CredDAO.Data cdd : cddl) { + if (cdd.expires.after(now)) { + try { + switch(cdd.type) { + case CredDAO.BASIC_AUTH: + if(md5==null) { + md5=ByteBuffer.wrap(Hash.encryptMD5(cred)); + } + if(md5.compareTo(cdd.cred)==0) { + return Result.ok(cdd.expires); + } else if (willSpecialLog(trans,user)) { + trans.audit().log("Special DEBUG:", user, "Client sent: ", trans.encryptor().encrypt(new String(cred)) ,cdd.expires); + } + break; + case CredDAO.BASIC_AUTH_SHA256: + ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE + cred.length); + bb.putInt(cdd.other); + bb.put(cred); + byte[] hash = Hash.hashSHA256(bb.array()); + + ByteBuffer sha256 = ByteBuffer.wrap(hash); + if(sha256.compareTo(cdd.cred)==0) { + return Result.ok(cdd.expires); + } else if (willSpecialLog(trans,user)) { + trans.audit().log("Special DEBUG:", user, "Client sent: ", trans.encryptor().encrypt(new String(cred)) ,cdd.expires); + } + break; + default: + trans.error().log("Unknown Credential Type %s for %s, %s",Integer.toString(cdd.type),cdd.id, Chrono.dateTime(cdd.expires)); + } + } catch (NoSuchAlgorithmException e) { + trans.error().log(e); + } + } else { + rv = Result.err(Status.ERR_Security, + "Credentials expired " + cdd.expires.toString()); + } + } // end for each + } + } else { + return Result.err(result); + } + return rv == null ? Result.create((Date) null, Status.ERR_Security, + "Wrong credential") : rv; + } + + + public Result userCredSetup(AuthzTrans trans, CredDAO.Data cred) { + if(cred.type==CredDAO.RAW) { + TimeTaken tt = trans.start("Hash Cred", Env.SUB); + try { + cred.type = CredDAO.BASIC_AUTH_SHA256; + cred.other = random.nextInt(); + ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE + cred.cred.capacity()); + bb.putInt(cred.other); + bb.put(cred.cred); + byte[] hash = Hash.hashSHA256(bb.array()); + cred.cred = ByteBuffer.wrap(hash); + return Result.ok(cred); + } catch (NoSuchAlgorithmException e) { + return Result.err(Status.ERR_General,e.getLocalizedMessage()); + } finally { + tt.done(); + } + + } + return Result.err(Status.ERR_Security,"invalid/unreadable credential"); + } + + + public static final String APPROVED = "APPROVE"; + public static final String REJECT = "REJECT"; + public static final String PENDING = "PENDING"; + + public Result canAddUser(AuthzTrans trans, UserRoleDAO.Data data, + List approvals) { + // get the approval policy for the organization + + // get the list of approvals with an accept status + + // validate the approvals against the policy + + // for now check if all approvals are received and return + // SUCCESS/FAILURE/SKIP + boolean bReject = false; + boolean bPending = false; + + for (ApprovalDAO.Data approval : approvals) { + if (approval.status.equals(REJECT)) { + bReject = true; + } else if (approval.status.equals(PENDING)) { + bPending = true; + } + } + if (bReject) { + return Result.err(Status.ERR_Policy, + "Approval Polocy not conformed"); + } + if (bPending) { + return Result.err(Status.ERR_ActionNotCompleted, + "Required Approvals not received"); + } + + return Result.ok(); + } + + private static final String NO_CACHE_NAME = "No Cache Data named %s"; + + public Result clearCache(AuthzTrans trans, String cname) { + boolean all = "all".equals(cname); + Result rv = null; + + if (all || NsDAO.TABLE.equals(cname)) { + int seg[] = series(NsDAO.CACHE_SEG); + for(int i: seg) {cacheClear(trans, NsDAO.TABLE,i);} + rv = cacheInfoDAO.touch(trans, NsDAO.TABLE, seg); + } + if (all || PermDAO.TABLE.equals(cname)) { + int seg[] = series(NsDAO.CACHE_SEG); + for(int i: seg) {cacheClear(trans, PermDAO.TABLE,i);} + rv = cacheInfoDAO.touch(trans, PermDAO.TABLE,seg); + } + if (all || RoleDAO.TABLE.equals(cname)) { + int seg[] = series(NsDAO.CACHE_SEG); + for(int i: seg) {cacheClear(trans, RoleDAO.TABLE,i);} + rv = cacheInfoDAO.touch(trans, RoleDAO.TABLE,seg); + } + if (all || UserRoleDAO.TABLE.equals(cname)) { + int seg[] = series(NsDAO.CACHE_SEG); + for(int i: seg) {cacheClear(trans, UserRoleDAO.TABLE,i);} + rv = cacheInfoDAO.touch(trans, UserRoleDAO.TABLE,seg); + } + if (all || CredDAO.TABLE.equals(cname)) { + int seg[] = series(NsDAO.CACHE_SEG); + for(int i: seg) {cacheClear(trans, CredDAO.TABLE,i);} + rv = cacheInfoDAO.touch(trans, CredDAO.TABLE,seg); + } + if (all || CertDAO.TABLE.equals(cname)) { + int seg[] = series(NsDAO.CACHE_SEG); + for(int i: seg) {cacheClear(trans, CertDAO.TABLE,i);} + rv = cacheInfoDAO.touch(trans, CertDAO.TABLE,seg); + } + + if (rv == null) { + rv = Result.err(Status.ERR_BadData, NO_CACHE_NAME, cname); + } + return rv; + } + + public Result cacheClear(AuthzTrans trans, String cname,Integer segment) { + Result rv; + if (NsDAO.TABLE.equals(cname)) { + rv = nsDAO.invalidate(segment); + } else if (PermDAO.TABLE.equals(cname)) { + rv = permDAO.invalidate(segment); + } else if (RoleDAO.TABLE.equals(cname)) { + rv = roleDAO.invalidate(segment); + } else if (UserRoleDAO.TABLE.equals(cname)) { + rv = userRoleDAO.invalidate(segment); + } else if (CredDAO.TABLE.equals(cname)) { + rv = credDAO.invalidate(segment); + } else if (CertDAO.TABLE.equals(cname)) { + rv = certDAO.invalidate(segment); + } else { + rv = Result.err(Status.ERR_BadData, NO_CACHE_NAME, cname); + } + return rv; + } + + private int[] series(int max) { + int[] series = new int[max]; + for (int i = 0; i < max; ++i) + series[i] = i; + return series; + } + + public boolean isDelegated(AuthzTrans trans, String user, String approver) { + Result> userDelegatedFor = delegateDAO + .readByDelegate(trans, user); + for (DelegateDAO.Data curr : userDelegatedFor.value) { + if (curr.user.equals(approver) && curr.delegate.equals(user) + && curr.expires.after(new Date())) { + return true; + } + } + return false; + } + + public static boolean willSpecialLog(AuthzTrans trans, String user) { + Boolean b = trans.get(specialLogSlot, null); + if(b==null) { + if(specialLog==null) { + return false; + } else { + b = specialLog.contains(user); + trans.put(specialLogSlot, b); + } + } + return b; + } + + public static void logEncryptTrace(AuthzTrans trans, String data) { + long ti; + trans.put(transIDSlot, ti=nextTraceID()); + trans.trace().log("id="+Long.toHexString(ti)+",data=\""+trans.env().encryptor().encrypt(data)+'"'); + } + + private synchronized static long nextTraceID() { + return ++traceID; + } + + public static synchronized boolean specialLogOn(AuthzTrans trans, String id) { + if (specialLog == null) { + specialLog = new HashSet(); + } + boolean rc = specialLog.add(id); + if(rc) { + trans.trace().log("Trace on for",id); + } + return rc; + } + + public static synchronized boolean specialLogOff(AuthzTrans trans, String id) { + if(specialLog==null) { + return false; + } + boolean rv = specialLog.remove(id); + if (specialLog.isEmpty()) { + specialLog = null; + } + if(rv) { + trans.trace().log("Trace off for",id); + } + return rv; + } + + /** + * canMove + * Which Types can be moved + * @param nsType + * @return + */ + public boolean canMove(NsType nsType) { + boolean rv; + switch(nsType) { + case DOT: + case ROOT: + case COMPANY: + case UNKNOWN: + rv = false; + break; + default: + rv = true; + } + return rv; + } + + public Result isOwnerSponsor(AuthzTrans trans, String user, String ns, Identity mechID) { + + Identity caller; + Organization org = trans.org(); + try { + caller = org.getIdentity(trans, user); + if(caller==null || !caller.isFound()) { + return Result.err(Status.ERR_NotFound,"%s is not a registered %s entity",user,org.getName()); + } + } catch (Exception e) { + return Result.err(e); + } + String sponsor = mechID.responsibleTo(); + Result> rur = userRoleDAO.read(trans, user,ns+DOT_OWNER); + boolean isOwner = false; + if(rur.isOKhasData()) {for(UserRoleDAO.Data urdd : rur.value){ + if(urdd.expires.after(new Date())) { + isOwner = true; + } + }}; + if(!isOwner) { + return Result.err(Status.ERR_Policy,"%s is not a current owner of %s",user,ns); + } + + if(!caller.id().equals(sponsor)) { + return Result.err(Status.ERR_Denied,"%s is not the sponsor of %s",user,mechID.id()); + } + return Result.ok(sponsor); + } + + public boolean isAdmin(AuthzTrans trans, String user, String ns) { + Date now = new Date(); + Result> rur = userRoleDAO.read(trans, user,ns+ADMIN); + if(rur.isOKhasData()) {for(UserRoleDAO.Data urdd : rur.value){ + if(urdd.expires.after(now)) { + return true; + } + }}; + return false; + } + + public boolean isOwner(AuthzTrans trans, String user, String ns) { + Result> rur = userRoleDAO.read(trans, user,ns+DOT_OWNER); + Date now = new Date(); + if(rur.isOKhasData()) {for(UserRoleDAO.Data urdd : rur.value){ + if(urdd.expires.after(now)) { + return true; + } + }}; + return false; + } + + public int countOwner(AuthzTrans trans, String user, String ns) { + Result> rur = userRoleDAO.read(trans, user,ns+DOT_OWNER); + Date now = new Date(); + int count = 0; + if(rur.isOKhasData()) {for(UserRoleDAO.Data urdd : rur.value){ + if(urdd.expires.after(now)) { + ++count; + } + }}; + return count; + } + +} diff --git a/authz-cass/src/main/java/com/att/dao/session/SessionFilter.java b/authz-cass/src/main/java/com/att/dao/session/SessionFilter.java new file mode 100644 index 00000000..6f835194 --- /dev/null +++ b/authz-cass/src/main/java/com/att/dao/session/SessionFilter.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.session; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import com.att.cssa.rserv.TransFilter; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.EnvStore; +import com.att.inno.env.Slot; +import com.att.inno.env.TransStore; +import com.att.inno.env.util.Pool; +import com.att.inno.env.util.Pool.Creator; +import com.att.inno.env.util.Pool.Pooled; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; + +public class SessionFilter implements Filter { + public static final String SESSION_SLOT = "__SESSION__"; + private static Slot sessionSlot; + private static Pool pool; + + public SessionFilter(EnvStore env, Cluster cluster, String keyspace) { + synchronized(env) { + if(sessionSlot==null) { + sessionSlot = env.slot(SESSION_SLOT); + } + if(pool==null) { + pool = new Pool(new SessionCreator(env,cluster,keyspace)); + } + } + } + + @Override + public void init(FilterConfig fc) throws ServletException { + // Session does not need any sort of configuration from Filter + } + + @Override + public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { + @SuppressWarnings("unchecked") + TRANS trans = (TRANS)req.getAttribute(TransFilter.TRANS_TAG); + try { + Pooled psess = pool.get(); + try { + trans.put(sessionSlot, psess.content); + chain.doFilter(req, resp); + } finally { + psess.done(); + } + } catch (APIException e) { + throw new ServletException(e); + } + } + + public Pooled load(TRANS trans) throws APIException { + Pooled psess = pool.get(); + trans.put(sessionSlot, psess.content); + return psess; + } + + + /** + * Clear will drain the pool, so that new Sessions will be constructed. + * + * Suitable for Management calls. + */ + public static void clear() { + if(pool!=null) { + pool.drain(); + } + } + + @Override + public void destroy() { + pool.drain(); + } + + private class SessionCreator implements Creator { + private Cluster cluster; + private String keyspace; + private Env env; + + public SessionCreator(Env env, Cluster cluster, String keyspace) { + this.cluster = cluster; + this.keyspace = keyspace; + this.env = env; + } + + @Override + public Session create() throws APIException { + env.info().log("Creating a Cassandra Session"); + return cluster.connect(keyspace); + } + + @Override + public void destroy(Session t) { + env.info().log("Shutting down a Cassandra Session"); + t.close(); + } + + @Override + public boolean isValid(Session t) { + return true; + } + + @Override + public void reuse(Session t) { + // Nothing is needed to reuse this Session + } + + } +} diff --git a/authz-cass/src/test/java/com/att/authz/cass/hl/JU_Question.java b/authz-cass/src/test/java/com/att/authz/cass/hl/JU_Question.java new file mode 100644 index 00000000..941c86e2 --- /dev/null +++ b/authz-cass/src/test/java/com/att/authz/cass/hl/JU_Question.java @@ -0,0 +1,501 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cass.hl; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; + +import java.security.Principal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.NsDAO; +import com.att.dao.aaf.cass.NsDAO.Data; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.dao.aaf.hl.Question; +import com.att.dao.aaf.hl.Question.Access; +import com.att.dao.aaf.test.AbsJUCass; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +public class JU_Question extends AbsJUCass { + + private static final int EXPIRES_IN = 60000000; + private static final String COM_TEST_JU = "com.test.ju_question"; + private static final String JU9999_JU_TEST_COM = "ju9999@ju.test.com"; + private static final String JU9998_JU_TEST_COM = "ju9998@ju.test.com"; + private static final String READ = "read"; + private static final int NFR_1 = 80; + private static final int NFR_2 = 4000; + private static final int ROLE_LEVEL1 = 1000; + private static final int PERM_LEVEL1 = 1000; +// private static final int PERM_LEVEL2 = 20; + private static Question q; + private static NsDAO.Data ndd; + + @BeforeClass + public static void startupBeforeClass() throws Exception { + details=false; + AuthzTrans trans = env.newTransNoAvg(); + q = new Question(trans,cluster,AUTHZ, false); + ndd = new NsDAO.Data(); + ndd.name=COM_TEST_JU; + ndd.type=3; // app + ndd.parent="com.test"; + ndd.description="Temporary Namespace for JU_Question"; + q.nsDAO.create(trans, ndd); + } + + @AfterClass + public static void endAfterClass() throws Exception { + q.nsDAO.delete(trans, ndd,false); + } +// @Test + public void mayUserRead_EmptyPerm() { + PermDAO.Data pdd = new PermDAO.Data(); + Result result = q.mayUser(trans,JU9999_JU_TEST_COM,pdd,Access.read); + assertFalse(result.isOK()); + } + +// @Test + public void mayUserRead_OnePermNotExist() { + Result result = q.mayUser(trans,JU9999_JU_TEST_COM,newPerm(0,0,READ),Access.read); + assertFalse(result.isOK()); + assertEquals("Denied - ["+ JU9999_JU_TEST_COM +"] may not read Perm [" + COM_TEST_JU + ".myPerm0|myInstance0|read]",result.errorString()); + } + +// @Test + public void mayUserRead_OnePermExistDenied() { + PermDAO.Data perm = newPerm(0,0,READ); + q.permDAO.create(trans,perm); + try { + Result result; + TimeTaken tt = trans.start("q.mayUser...", Env.SUB); + try { + result = q.mayUser(trans,JU9999_JU_TEST_COM,perm,Access.read); + } finally { + tt.done(); + assertTrue("NFR time < "+ NFR_1 + "ms",tt.millis() result; + TimeTaken tt = trans.start("q.mayUser...", Env.SUB); + try { + result = q.mayUser(trans,JU9999_JU_TEST_COM,perm,Access.read); + } finally { + tt.done(); + assertTrue("NFR time < "+ NFR_1 + "ms",tt.millis()> pres; + TimeTaken tt = trans.start("q.getPerms...", Env.SUB); + try { + pres = q.getPermsByUserFromRolesFilter(trans, JU9999_JU_TEST_COM, JU9999_JU_TEST_COM); + } finally { + tt.done(); + trans.info().log("filter_OnePermOneRleExistOK",tt); + assertTrue("NFR time < "+ NFR_1 + "ms",tt.millis() lrole = new ArrayList(); + List lur = new ArrayList(); + try { + q.permDAO.create(trans,perm); + for(int i=0;i result; + TimeTaken tt = trans.start("mayUserRead_OnePermMultiRoleExistOK", Env.SUB); + try { + result = q.mayUser(trans,JU9999_JU_TEST_COM,perm,Access.read); + } finally { + tt.done(); + env.info().log(tt,ROLE_LEVEL1,"iterations"); + assertTrue("NFR time < "+ NFR_2 + "ms",tt.millis() lperm = new ArrayList(); + try { + for(int i=0;i result; + TimeTaken tt = trans.start("mayUserRead_MultiPermOneRoleExistOK", Env.SUB); + try { + result = q.mayUser(trans,JU9999_JU_TEST_COM,lperm.get(PERM_LEVEL1-1),Access.read); + } finally { + tt.done(); + env.info().log(tt,PERM_LEVEL1,"iterations"); + assertTrue("NFR time < "+ NFR_2 + "ms",tt.millis() lperm = new ArrayList(); +// List lrole = new ArrayList(); +// List lur = new ArrayList(); +// +// try { +// RoleDAO.Data role; +// UserRoleDAO.Data ur; +// for(int i=0;i result; +// TimeTaken tt = trans.start("mayUserRead_MultiPermMultiRoleExistOK", Env.SUB); +// try { +// result = q.mayUser(trans,JU9999_JU_TEST_COM,lperm.get(ROLE_LEVEL1*PERM_LEVEL2-1),Access.read); +// } finally { +// tt.done(); +// env.info().log(tt,lperm.size(),"perms",", ",lrole.size(),"role"); +// assertTrue("NFR time < "+ NFR_2 + "ms",tt.millis() lperm = new ArrayList(); + List lrole = new ArrayList(); + List lur = new ArrayList(); + load(roleLevel, permLevel, lperm,lrole,lur); + + + Result> pres; + trans.setUser(new Principal() { + @Override + public String getName() { + return JU9999_JU_TEST_COM; + } + }); + + try { + TimeTaken group = trans.start(" Original Security Method (1st time)", Env.SUB); + try { + TimeTaken tt = trans.start(" Get User Perms for "+JU9998_JU_TEST_COM, Env.SUB); + try { + pres = q.getPermsByUser(trans,JU9998_JU_TEST_COM,true); + } finally { + tt.done(); + env.info().log(tt," Looked up (full) getPermsByUser for",JU9998_JU_TEST_COM); + } + assertTrue(pres.isOK()); + tt = trans.start(" q.mayUser", Env.SUB); + List reduced = new ArrayList(); + + try { + for(PermDAO.Data p : pres.value) { + Result r = q.mayUser(trans,JU9999_JU_TEST_COM,p,Access.read); + if(r.isOK()) { + reduced.add(p); + } + } + } finally { + tt.done(); + env.info().log(tt," reduced" + pres.value.size(),"perms","to",reduced.size()); + // assertTrue("NFR time < "+ NFR_2 + "ms",tt.millis() lperm = new ArrayList(); + List lrole = new ArrayList(); + List lur = new ArrayList(); + load(roleLevel, permLevel, lperm,lrole,lur); + + try { + + Result> pres; + TimeTaken tt = trans.start(" mayUserRead_MultiPermMultiRoleExist_New New Filter", Env.SUB); + try { + pres = q.getPermsByUserFromRolesFilter(trans, JU9999_JU_TEST_COM, JU9998_JU_TEST_COM); + } finally { + tt.done(); + env.info().log(tt,lperm.size(),"perms",", ",lrole.size(),"role", lur.size(), "UserRoles"); +// assertTrue("NFR time < "+ NFR_2 + "ms",tt.millis() lperm , List lrole, List lur) { + RoleDAO.Data role; + UserRoleDAO.Data ur; + PermDAO.Data perm; + + int onethirdR=roleLevel/3; + int twothirdR=onethirdR*2; + int onethirdP=permLevel/3; + int twothirdP=onethirdP*2; + + for(int i=0;i lperm , List lrole, List lur) { + for(PermDAO.Data perm : lperm) { + q.permDAO.delete(trans, perm, false); + } + for(RoleDAO.Data role : lrole) { + q.roleDAO.delete(trans, role, false); + } + for(UserRoleDAO.Data ur : lur) { + q.userRoleDAO.delete(trans, ur, false); + } + + } + private PermDAO.Data newPerm(int permNum, int instNum, String action, RoleDAO.Data ... grant) { + PermDAO.Data pdd = new PermDAO.Data(); + pdd.ns=COM_TEST_JU; + pdd.type="myPerm"+permNum; + pdd.instance="myInstance"+instNum; + pdd.action=action; + for(RoleDAO.Data r : grant) { + pdd.roles(true).add(r.fullName()); + r.perms(true).add(pdd.encode()); + } + return pdd; + } + + private RoleDAO.Data newRole(int roleNum, PermDAO.Data ... grant) { + RoleDAO.Data rdd = new RoleDAO.Data(); + rdd.ns = COM_TEST_JU+roleNum; + rdd.name = "myRole"+roleNum; + for(PermDAO.Data p : grant) { + rdd.perms(true).add(p.encode()); + p.roles(true).add(rdd.fullName()); + } + return rdd; + } + + private UserRoleDAO.Data newUserRole(RoleDAO.Data role,String user, long offset) { + UserRoleDAO.Data urd = new UserRoleDAO.Data(); + urd.user=user; + urd.role(role); + urd.expires=new Date(System.currentTimeMillis()+offset); + return urd; + } + + +} diff --git a/authz-cass/src/test/java/com/att/dao/JU_Cached.java b/authz-cass/src/test/java/com/att/dao/JU_Cached.java new file mode 100644 index 00000000..4e6bf7d7 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/JU_Cached.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import static org.junit.Assert.*; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Timer; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cache.Cache; +import com.att.cache.Cache.Dated; +import com.att.dao.Cached.Getter; +//import com.att.dao.Cached.Refresh; +import com.att.inno.env.Trans; + +@RunWith(PowerMockRunner.class) +public class JU_Cached { + Cached cached; + @Mock + CIDAO ciDaoMock; + @Mock + AuthzEnv authzEnvMock; + @Mock + CIDAO cidaoATMock; + + String name = "nameString"; + + @Before + public void setUp(){ + cached = new Cached(ciDaoMock, name, 0); + } + + @Test(expected=ArithmeticException.class) + public void testCachedIdx(){ + int Result = cached.cacheIdx("1234567890"); + } + + @Test(expected=ArithmeticException.class) + public void testInvalidate(){ + int Res = cached.invalidate(name); + } + + @SuppressWarnings("static-access") + @Test + public void testStopTimer(){ + cached.stopTimer(); + assertTrue(true); + } + + @SuppressWarnings("static-access") + @Test + public void testStartRefresh(){ + cached.startRefresh(authzEnvMock, cidaoATMock); + assertTrue(true); + } +// @Mock +// Trans transMock; +// @Mock +// Getter getterMock; +// +// @Test +// public void testGet(){ +// cached.get(transMock, name, getterMock); +// fail("not implemented"); +// } +// +// @SuppressWarnings("unchecked") +// public Result> get(TRANS trans, String key, Getter getter) { +// List ld = null; +// Result> rld = null; +// +// int cacheIdx = cacheIdx(key); +// Map map = ((Map)cache[cacheIdx]); +// +// // Check for saved element in cache +// Dated cached = map.get(key); +// // Note: These Segment Timestamps are kept up to date with DB +// Date dbStamp = info.get(trans, name,cacheIdx); +// +// // Check for cache Entry and whether it is still good (a good Cache Entry is same or after DBEntry, so we use "before" syntax) +// if(cached!=null && dbStamp.before(cached.timestamp)) { +// ld = (List)cached.data; +// rld = Result.ok(ld); +// } else { +// rld = getter.get(); +// if(rld.isOK()) { // only store valid lists +// map.put(key, new Dated(rld.value)); // successful item found gets put in cache +//// } else if(rld.status == Result.ERR_Backend){ +//// map.remove(key); +// } +// } +// return rld; +// } +} diff --git a/authz-cass/src/test/java/com/att/dao/JU_CachedDAO.java b/authz-cass/src/test/java/com/att/dao/JU_CachedDAO.java new file mode 100644 index 00000000..4cd38f26 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/JU_CachedDAO.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.inno.env.Trans; + +@RunWith(PowerMockRunner.class) +public class JU_CachedDAO { + CachedDAO cachedDAO; + @Mock + DAO daoMock; + @Mock + CIDAO ciDAOMock; + int segsize=1; + Object[ ] objs = new Object[2]; + + @Before + public void setUp(){ + objs[0] = "helo"; + objs[1] = "polo"; + cachedDAO = new CachedDAO(daoMock, ciDAOMock, segsize); + } + + @Test + public void testKeyFromObjs(){ + String result = cachedDAO.keyFromObjs(objs); + System.out.println("value of resut " +result); + assertTrue(true); + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/JU_CassAccess.java b/authz-cass/src/test/java/com/att/dao/JU_CassAccess.java new file mode 100644 index 00000000..b9c55a28 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/JU_CassAccess.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +//import com.att.dao.CassAccess.Resettable; +import com.datastax.driver.core.Cluster.Builder; + +@RunWith(PowerMockRunner.class) +public class JU_CassAccess { + CassAccess cassAccess; + + public static final String KEYSPACE = "authz"; + public static final String CASSANDRA_CLUSTERS = "cassandra.clusters"; + public static final String CASSANDRA_CLUSTERS_PORT = "cassandra.clusters.port"; + public static final String CASSANDRA_CLUSTERS_USER_NAME = "cassandra.clusters.user"; + public static final String CASSANDRA_CLUSTERS_PASSWORD = "cassandra.clusters.password"; + public static final String CASSANDRA_RESET_EXCEPTIONS = "cassandra.reset.exceptions"; + public static final String LATITUDE = "LATITUDE"; + public static final String LONGITUDE = "LONGITUDE"; + //private static final List resetExceptions = new ArrayList(); + public static final String ERR_ACCESS_MSG = "Accessing Backend"; + private static Builder cb = null; + @Mock + Env envMock; + String prefix=null; + + @Before + public void setUp(){ + cassAccess = new CassAccess(); + } + + + @Test(expected=APIException.class) + public void testCluster() throws APIException, IOException { + cassAccess.cluster(envMock, prefix); + + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/JU_CassDAOImpl.java b/authz-cass/src/test/java/com/att/dao/JU_CassDAOImpl.java new file mode 100644 index 00000000..6abf1987 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/JU_CassDAOImpl.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.authz.env.AuthzTrans; +import com.att.inno.env.Data; +import com.att.inno.env.Trans; +import com.att.inno.env.TransStore; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ConsistencyLevel; + +@RunWith(PowerMockRunner.class) +public class JU_CassDAOImpl { + +public static final String CASS_READ_CONSISTENCY="cassandra.readConsistency"; +public static final String CASS_WRITE_CONSISTENCY="cassandra.writeConsistency"; + +CassDAOImpl cassDAOImpl; + + +@Mock +TransStore transStoreMock; +@SuppressWarnings("rawtypes") +Class dcMock; +@SuppressWarnings("rawtypes") +Loader loaderMock; +Cluster clusterMock; +Class classDataMock; +ConsistencyLevel consistencyLevelMock; +Trans transMock; + +@Mock +AuthzTrans authzTransMock; + + + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Before + public void setUp() + { + String name = "name"; + String keySpace = "keySpace"; + String table = "table"; + cassDAOImpl = new CassDAOImpl(transStoreMock, name, clusterMock, keySpace, classDataMock, table, consistencyLevelMock, consistencyLevelMock); + } + + + @Test + public void testReadConsistency() { + String table = "users"; + PowerMockito.when(authzTransMock.getProperty(CASS_READ_CONSISTENCY+'.'+table)).thenReturn("TWO"); + ConsistencyLevel consistencyLevel = cassDAOImpl.readConsistency(authzTransMock, table); + System.out.println("Consistency level" + consistencyLevel.name()); + assertEquals("TWO", consistencyLevel.name()); + } + + @Test + public void testWriteConsistency() { + String table = "users"; + PowerMockito.when(authzTransMock.getProperty(CASS_WRITE_CONSISTENCY+'.'+table)).thenReturn(null); + ConsistencyLevel consistencyLevel = cassDAOImpl.writeConsistency(authzTransMock, table); + System.out.println("Consistency level" + consistencyLevel.name()); + assertEquals("ONE", consistencyLevel.name()); + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/JU_DAOException.java b/authz-cass/src/test/java/com/att/dao/JU_DAOException.java new file mode 100644 index 00000000..fb634182 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/JU_DAOException.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class JU_DAOException { +DAOException daoException; + + //DAOException daoException = new DAOException(); + String message = "message"; + Throwable cause; + @Before + public void setUp(){ + daoException = new DAOException(); + } + + @Test + public void test(){ + assertTrue(true); + } +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/AbsJUCass.java b/authz-cass/src/test/java/com/att/dao/aaf/test/AbsJUCass.java new file mode 100644 index 00000000..0f1994c8 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/AbsJUCass.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.security.NoSuchAlgorithmException; +import java.util.Properties; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.cadi.Hash; +import com.att.cadi.Symm; +import com.att.dao.CassAccess; +import com.att.dao.CassDAOImpl; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Trans.Metric; +import com.datastax.driver.core.Cluster; + +import junit.framework.Assert; + +/** + * Do Setup of Cassandra for Cassandra JUnit Testing + * + * + */ +public class AbsJUCass { + protected static final String AUTHZ = "authz"; + protected static Cluster cluster; + protected static AuthzEnv env; + protected static int iterations = 0; + protected static float totals=0.0f; + protected static float remote = 0.0f; + protected static float json = 0.0f; + protected static AuthzTrans trans; + protected static boolean details = true; + + @BeforeClass + public static void startup() throws APIException, IOException { + synchronized(AUTHZ) { + if(env==null) { + final String resource = "cadi.properties"; + File f = new File("etc" + resource); + InputStream is=null; + Properties props = new Properties(); + try { + if(f.exists()) { + is = new FileInputStream(f); + } else { + URL rsrc = ClassLoader.getSystemResource(resource); + is = rsrc.openStream(); + } + props.load(is); + } finally { + if(is==null) { + env= new AuthzEnv(); + Assert.fail(resource + " must exist in etc dir, or in Classpath"); + } + is.close(); + } + env = new AuthzEnv(props); + } + } + cluster = CassAccess.cluster(env,"LOCAL"); + + env.info().log("Connecting to Cluster"); + try { + cluster.connect(AUTHZ); + } catch(Exception e) { + cluster=null; + env.error().log(e); + Assert.fail("Not able to connect to DB: " + e.getLocalizedMessage()); + } + env.info().log("Connected"); + + // Load special data here + + // WebPhone + env.setProperty("java.naming.provider.url","ldap://ldap.webphone.att.com:389"); + env.setProperty("com.sun.jndi.ldap.connect.pool","true"); + + iterations = 0; + + } + + @AfterClass + public static void shutdown() { + if(cluster!=null) { + cluster.close(); + cluster = null; + } + } + + @Before + public void newTrans() { + trans = env.newTrans(); + + trans.setProperty(CassDAOImpl.USER_NAME, System.getProperty("user.name")); + } + + @After + public void auditTrail() { + if(totals==0) { // "updateTotals()" was not called... just do one Trans + StringBuilder sb = new StringBuilder(); + Metric metric = trans.auditTrail(4, sb, Env.JSON, Env.REMOTE); + if(details) { + env.info().log( + sb, + "Total time:", + totals += metric.total, + "JSON time: ", + metric.buckets[0], + "REMOTE time: ", + metric.buckets[1] + ); + } else { + totals += metric.total; + } + } + } + + protected void updateTotals() { + Metric metric = trans.auditTrail(0, null, Env.JSON, Env.REMOTE); + totals+=metric.total; + json +=metric.buckets[0]; + remote+=metric.buckets[1]; + } + + + @AfterClass + public static void print() { + float transTime; + if(iterations==0) { + transTime=totals; + } else { + transTime=totals/iterations; + } + env.info().log( + "Total time:", + totals, + "JSON time:", + json, + "REMOTE time:", + remote, + "Iterations:", + iterations, + "Transaction time:", + transTime + ); + } + + /** + * Take a User/Pass and turn into an MD5 Hashed BasicAuth + * + * @param user + * @param pass + * @return + * @throws IOException + * @throws NoSuchAlgorithmException + */ + public static byte[] userPassToBytes(String user, String pass) + throws IOException, NoSuchAlgorithmException { + // Take the form of BasicAuth, so as to allow any character in Password + // (this is an issue in 1.0) + // Also, it makes it quicker to evaluate Basic Auth direct questions + String ba = Symm.base64url.encode(user + ':' + pass); + // Take MD5 Hash, so that data in DB can't be reversed out. + return Hash.encryptMD5(ba.getBytes()); + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_ApprovalDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_ApprovalDAO.java new file mode 100644 index 00000000..3a884b43 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_ApprovalDAO.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.ApprovalDAO; +import com.att.dao.aaf.cass.ApprovalDAO.Data; + +public class JU_ApprovalDAO extends AbsJUCass { + @Test + public void testCRUD() throws Exception { + ApprovalDAO rrDAO = new ApprovalDAO(trans, cluster, AUTHZ); + ApprovalDAO.Data data = new ApprovalDAO.Data(); + + data.ticket = UUID.randomUUID(); // normally, read from Future object + data.user = "testid@test.com"; + data.approver = "mySuper@att.com"; + data.type = "supervisor"; + data.status = "pending"; + data.operation = "C"; + data.updated = new Date(); + + try { + // Test create + rrDAO.create(trans, data); + + // Test Read by Ticket + Result> rlad; + rlad = rrDAO.readByTicket(trans, data.ticket); + assertTrue(rlad.isOK()); + assertEquals(1,rlad.value.size()); + compare(data,rlad.value.get(0)); + + // Hold onto original ID for deletion, and read tests + UUID id = rlad.value.get(0).id; + + try { + // Test Read by User + rlad = rrDAO.readByUser(trans, data.user); + assertTrue(rlad.isOKhasData()); + boolean ok = false; + for(ApprovalDAO.Data a : rlad.value) { + if(a.id.equals(id)) { + ok = true; + compare(data,a); + } + } + assertTrue(ok); + + // Test Read by Approver + rlad = rrDAO.readByApprover(trans, data.approver); + assertTrue(rlad.isOKhasData()); + ok = false; + for(ApprovalDAO.Data a : rlad.value) { + if(a.id.equals(id)) { + ok = true; + compare(data,a); + } + } + assertTrue(ok); + + // Test Read by ID + rlad = rrDAO.read(trans, id); + assertTrue(rlad.isOKhasData()); + ok = false; + for(ApprovalDAO.Data a : rlad.value) { + if(a.id.equals(id)) { + ok = true; + compare(data,a); + } + } + assertTrue(ok); + + // Test Update + data.status = "approved"; + data.id = id; + assertTrue(rrDAO.update(trans, data).isOK()); + + rlad = rrDAO.read(trans, id); + assertTrue(rlad.isOKhasData()); + ok = false; + for(ApprovalDAO.Data a : rlad.value) { + if(a.id.equals(id)) { + ok = true; + compare(data,a); + } + } + assertTrue(ok); + + } finally { + // Delete + data.id = id; + rrDAO.delete(trans, data, true); + rlad = rrDAO.read(trans, id); + assertTrue(rlad.isOK()); + assertTrue(rlad.isEmpty()); + } + + } finally { + rrDAO.close(trans); + } + } + + private void compare(Data d1, Data d2) { + assertNotSame(d1.id,d2.id); + assertEquals(d1.ticket,d2.ticket); + assertEquals(d1.user,d2.user); + assertEquals(d1.approver,d2.approver); + assertEquals(d1.type,d2.type); + assertEquals(d1.status,d2.status); + assertEquals(d1.operation,d2.operation); + assertNotSame(d1.updated,d2.updated); + } + + + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_ArtiDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_ArtiDAO.java new file mode 100644 index 00000000..219d302a --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_ArtiDAO.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.List; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.ArtiDAO; +import com.att.dao.aaf.cass.ArtiDAO.Data; + +/** + * UserDAO unit test. + * User: tp007s + * Date: 7/19/13 + */ +public class JU_ArtiDAO extends AbsJUCass { + @Test + public void test() throws IOException, NoSuchAlgorithmException { + ArtiDAO adao = new ArtiDAO(trans,cluster,"authz"); + try { + // Create + ArtiDAO.Data data = new ArtiDAO.Data(); + data.mechid="m55555@perturbed.att.com"; + data.machine="perturbed1232.att.com"; + data.type(false).add("file"); + data.type(false).add("jks"); + data.sponsor="Fred Flintstone"; + data.ca="devl"; + data.dir="/opt/app/aft/keys"; + data.appName="kumquat"; + data.os_user="aft"; + data.notify="email:myname@bogus.email.com"; + data.expires=new Date(); + +// Bytification + ByteBuffer bb = data.bytify(); + Data bdata = new ArtiDAO.Data(); + bdata.reconstitute(bb); + checkData1(data, bdata); + + +// DB work + adao.create(trans,data); + try { + // Validate Read with key fields in Data + Result> rlcd = adao.read(trans,data); + assertTrue(rlcd.isOKhasData()); + for(ArtiDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + // Validate Read with key fields in Data + rlcd = adao.read(trans,data.mechid, data.machine); + assertTrue(rlcd.isOKhasData()); + for(ArtiDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + // By Machine + rlcd = adao.readByMachine(trans,data.machine); + assertTrue(rlcd.isOKhasData()); + for(ArtiDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + // By MechID + rlcd = adao.readByMechID(trans,data.mechid); + assertTrue(rlcd.isOKhasData()); + for(ArtiDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + // Update + data.sponsor = "Wilma Flintstone"; + adao.update(trans,data); + rlcd = adao.read(trans,data); + assertTrue(rlcd.isOKhasData()); + for(ArtiDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + } finally { + // Always delete data, even if failure. + adao.delete(trans,data, true); + } + } finally { + adao.close(trans); + } + + + } + + private void checkData1(Data data, Data d) { + assertEquals(data.mechid,d.mechid); + assertEquals(data.machine,d.machine); + assertEquals(data.type(false).size(),d.type(false).size()); + for(String s: data.type(false)) { + assertTrue(d.type(false).contains(s)); + } + assertEquals(data.sponsor,d.sponsor); + assertEquals(data.ca,d.ca); + assertEquals(data.dir,d.dir); + assertEquals(data.appName,d.appName); + assertEquals(data.os_user,d.os_user); + assertEquals(data.notify,d.notify); + assertEquals(data.expires,d.expires); + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_Bytification.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_Bytification.java new file mode 100644 index 00000000..34bfc3e6 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_Bytification.java @@ -0,0 +1,268 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Date; + +import org.junit.Test; + +import com.att.dao.aaf.cass.CredDAO; +import com.att.dao.aaf.cass.NsDAO; +import com.att.dao.aaf.cass.NsType; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.UserRoleDAO; + +public class JU_Bytification { + + @Test + public void testNS() throws IOException { + + // Normal + NsDAO.Data ns = new NsDAO.Data(); + ns.name = "com.att."; + ns.type = NsType.APP.type; + + ByteBuffer bb = ns.bytify(); + + NsDAO.Data nsr = new NsDAO.Data(); + nsr.reconstitute(bb); + check(ns,nsr); + + // Empty admin +// ns.admin(true).clear(); + bb = ns.bytify(); + nsr = new NsDAO.Data(); + nsr.reconstitute(bb); + check(ns,nsr); + + // Empty responsible +// ns.responsible(true).clear(); + bb = ns.bytify(); + nsr = new NsDAO.Data(); + nsr.reconstitute(bb); + check(ns,nsr); + + bb = ns.bytify(); + nsr = new NsDAO.Data(); + nsr.reconstitute(bb); + check(ns,nsr); + } + + private void check(NsDAO.Data a, NsDAO.Data b) { + assertEquals(a.name,b.name); + assertEquals(a.type,b.type); +// assertEquals(a.admin.size(),b.admin.size()); + +// for(String s: a.admin) { +// assertTrue(b.admin.contains(s)); +// } +// +// assertEquals(a.responsible.size(),b.responsible.size()); +// for(String s: a.responsible) { +// assertTrue(b.responsible.contains(s)); +// } + } + + @Test + public void testRole() throws IOException { + RoleDAO.Data rd1 = new RoleDAO.Data(); + rd1.ns = "com.att."; + rd1.name = "my.role"; + rd1.perms(true).add("com.att..my.Perm|myInstance|myAction"); + rd1.perms(true).add("com.att..my.Perm|myInstance|myAction2"); + + // Normal + ByteBuffer bb = rd1.bytify(); + RoleDAO.Data rd2 = new RoleDAO.Data(); + rd2.reconstitute(bb); + check(rd1,rd2); + + // Overshoot Buffer + StringBuilder sb = new StringBuilder(300); + sb.append("role|instance|veryLongAction..."); + for(int i=0;i<280;++i) { + sb.append('a'); + } + rd1.perms(true).add(sb.toString()); + bb = rd1.bytify(); + rd2 = new RoleDAO.Data(); + rd2.reconstitute(bb); + check(rd1,rd2); + + // No Perms + rd1.perms.clear(); + + bb = rd1.bytify(); + rd2 = new RoleDAO.Data(); + rd2.reconstitute(bb); + check(rd1,rd2); + + // 1000 Perms + for(int i=0;i<1000;++i) { + rd1.perms(true).add("com|inst|action"+ i); + } + + bb = rd1.bytify(); + rd2 = new RoleDAO.Data(); + rd2.reconstitute(bb); + check(rd1,rd2); + + } + + private void check(RoleDAO.Data a, RoleDAO.Data b) { + assertEquals(a.ns,b.ns); + assertEquals(a.name,b.name); + + assertEquals(a.perms.size(),b.perms.size()); + for(String s: a.perms) { + assertTrue(b.perms.contains(s)); + } + } + + @Test + public void testPerm() throws IOException { + PermDAO.Data pd1 = new PermDAO.Data(); + pd1.ns = "com.att."; + pd1.type = "my.perm"; + pd1.instance = "instance"; + pd1.action = "read"; + pd1.roles(true).add("com.att..my.Role"); + pd1.roles(true).add("com.att..my.Role2"); + + // Normal + ByteBuffer bb = pd1.bytify(); + PermDAO.Data rd2 = new PermDAO.Data(); + rd2.reconstitute(bb); + check(pd1,rd2); + + // No Perms + pd1.roles.clear(); + + bb = pd1.bytify(); + rd2 = new PermDAO.Data(); + rd2.reconstitute(bb); + check(pd1,rd2); + + // 1000 Perms + for(int i=0;i<1000;++i) { + pd1.roles(true).add("com.att..my.Role"+ i); + } + + bb = pd1.bytify(); + rd2 = new PermDAO.Data(); + rd2.reconstitute(bb); + check(pd1,rd2); + + } + + private void check(PermDAO.Data a, PermDAO.Data b) { + assertEquals(a.ns,b.ns); + assertEquals(a.type,b.type); + assertEquals(a.instance,b.instance); + assertEquals(a.action,b.action); + + assertEquals(a.roles.size(),b.roles.size()); + for(String s: a.roles) { + assertTrue(b.roles.contains(s)); + } + } + + @Test + public void testUserRole() throws IOException { + UserRoleDAO.Data urd1 = new UserRoleDAO.Data(); + urd1.user = "myname@abc.att.com"; + urd1.role("com.att.","my.role"); + urd1.expires = new Date(); + + // Normal + ByteBuffer bb = urd1.bytify(); + UserRoleDAO.Data urd2 = new UserRoleDAO.Data(); + urd2.reconstitute(bb); + check(urd1,urd2); + + // A null + urd1.expires = null; + urd1.role = null; + + bb = urd1.bytify(); + urd2 = new UserRoleDAO.Data(); + urd2.reconstitute(bb); + check(urd1,urd2); + } + + private void check(UserRoleDAO.Data a, UserRoleDAO.Data b) { + assertEquals(a.user,b.user); + assertEquals(a.role,b.role); + assertEquals(a.expires,b.expires); + } + + + @Test + public void testCred() throws IOException { + CredDAO.Data cd = new CredDAO.Data(); + cd.id = "m55555@abc.att.com"; + cd.ns = "com.att.abc"; + cd.type = 2; + cd.cred = ByteBuffer.wrap(new byte[]{1,34,5,3,25,0,2,5,3,4}); + cd.expires = new Date(); + + // Normal + ByteBuffer bb = cd.bytify(); + CredDAO.Data cd2 = new CredDAO.Data(); + cd2.reconstitute(bb); + check(cd,cd2); + + // nulls + cd.expires = null; + cd.cred = null; + + bb = cd.bytify(); + cd2 = new CredDAO.Data(); + cd2.reconstitute(bb); + check(cd,cd2); + + } + + private void check(CredDAO.Data a, CredDAO.Data b) { + assertEquals(a.id,b.id); + assertEquals(a.ns,b.ns); + assertEquals(a.type,b.type); + if(a.cred==null) { + assertEquals(a.cred,b.cred); + } else { + int l = a.cred.limit(); + assertEquals(l,b.cred.limit()); + for (int i=0;i id = new CacheInfoDAO(trans, cluster, AUTHZ); + Date date = new Date(); + + id.touch(trans, RoleDAO.TABLE,1); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + } + Result rid = id.check(trans); + Assert.assertEquals(rid.status,Status.OK); + Date[] dates = CacheInfoDAO.info.get(RoleDAO.TABLE); + if(dates.length>0 && dates[1]!=null) { + System.out.println(Chrono.dateStamp(dates[1])); + System.out.println(Chrono.dateStamp(date)); + Assert.assertTrue(Math.abs(dates[1].getTime() - date.getTime())<20000); // allow for 4 seconds, given Remote DB + } + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_CertDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_CertDAO.java new file mode 100644 index 00000000..52238ef3 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_CertDAO.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.security.NoSuchAlgorithmException; +import java.util.List; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.CertDAO; +import com.att.dao.aaf.cass.CertDAO.Data; +import com.att.inno.env.APIException; + +/** + * UserDAO unit test. + * User: tp007s + * Date: 7/19/13 + */ +public class JU_CertDAO extends AbsJUCass { + @Test + public void test() throws IOException, NoSuchAlgorithmException, APIException { + CertDAO cdao = new CertDAO(trans,cluster,"authz"); + try { + // Create + CertDAO.Data data = new CertDAO.Data(); + data.serial=new BigInteger("11839383"); + data.id = "m55555@tguard.att.com"; + data.x500="CN=ju_cert.dao.att.com, OU=AAF, O=\"ATT Services, Inc.\", L=Southfield, ST=Michigan, C=US"; + data.x509="I'm a cert"; + data.ca = "aaf"; + cdao.create(trans,data); + +// Bytification + ByteBuffer bb = data.bytify(); + Data bdata = new CertDAO.Data(); + bdata.reconstitute(bb); + checkData1(data, bdata); + + // Validate Read with key fields in Data + Result> rlcd = cdao.read(trans,data); + assertTrue(rlcd.isOKhasData()); + for(CertDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + // Validate Read with key fields in Data + rlcd = cdao.read(trans,data.ca,data.serial); + assertTrue(rlcd.isOKhasData()); + for(CertDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + // Update + data.id = "m66666.tguard.att.com"; + cdao.update(trans,data); + rlcd = cdao.read(trans,data); + assertTrue(rlcd.isOKhasData()); + for(CertDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + cdao.delete(trans,data, true); + } finally { + cdao.close(trans); + } + + + } + + private void checkData1(Data data, Data d) { + assertEquals(data.ca,d.ca); + assertEquals(data.serial,d.serial); + assertEquals(data.id,d.id); + assertEquals(data.x500,d.x500); + assertEquals(data.x509,d.x509); + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_CredDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_CredDAO.java new file mode 100644 index 00000000..5cd6d4cb --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_CredDAO.java @@ -0,0 +1,253 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.List; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.CredDAO; +import com.att.dao.aaf.cass.CredDAO.Data; +import com.att.inno.env.APIException; + +/** + * UserDAO unit test. + * User: tp007s + * Date: 7/19/13 + */ +public class JU_CredDAO extends AbsJUCass { + @Test + public void test() throws IOException, NoSuchAlgorithmException, APIException { + CredDAO udao = new CredDAO(trans,cluster,"authz"); + try { + // Create + CredDAO.Data data = new CredDAO.Data(); + data.id = "m55555@aaf.att.com"; + data.type = CredDAO.BASIC_AUTH; + data.notes = "temp pass"; + data.cred = ByteBuffer.wrap(userPassToBytes("m55555","mypass")); + data.other = 12; + data.expires = new Date(System.currentTimeMillis() + 60000*60*24*90); + udao.create(trans,data); + +// Bytification + ByteBuffer bb = data.bytify(); + Data bdata = new CredDAO.Data(); + bdata.reconstitute(bb); + checkData1(data, bdata); + + // Validate Read with key fields in Data + Result> rlcd = udao.read(trans,data); + assertTrue(rlcd.isOKhasData()); + for(CredDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + // Update + data.cred = ByteBuffer.wrap(userPassToBytes("m55555","mynewpass")); + udao.update(trans,data); + rlcd = udao.read(trans,data); + assertTrue(rlcd.isOKhasData()); + for(CredDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + udao.delete(trans,data, true); + } finally { + udao.close(trans); + } + + + } + + private void checkData1(Data data, Data d) { + assertEquals(data.id,d.id); + assertEquals(data.type,d.type); + assertEquals(data.ns,d.ns); + assertEquals(data.notes,d.notes); + assertEquals(data.cred,d.cred); + assertEquals(data.other,d.other); + assertEquals(data.expires,d.expires); + } + +// private String CONST_myName = "MyName"; +// public static final java.nio.ByteBuffer CONST_MY_CRED = get_CONST_MY_CRED(); +// public static final int CONST_CRED_TYPE = 11; +// +// public static final Date CONST_UPDATE_DATE = new Date(System.currentTimeMillis()+60000*24); +// @Test +// public void test() { +// UserDAO ud = new UserDAO(trans, cluster,"authz"); +// try { +// UserDAO.Data data = createPrototypeUserData(); +// ud.create(trans, data); +// +// // Validate Read with key fields in Data +// for(UserDAO.Data d : ud.read(trans, data)) { +// checkData1(data,d); +// } +// +// // Validate readByName +// for(UserDAO.Data d : ud.read(trans, CONST_myName)) { +// checkData1(data,d); +// } +// +// ud.delete(trans, data); +// List d_2 = ud.read(trans, CONST_myName); +// +// // Validate that data was deleted +// assertEquals("User should not be found after deleted", 0, d_2.size() ); +// +// data = new UserDAO.Data(); +// data.name = CONST_myName; +// data.cred = CONST_MY_CRED; +// data.cred_type= CONST_CRED_TYPE; +// data.expires = new Date(System.currentTimeMillis()+60000*24); +// final Result user = ud.r_create(trans, data); +// assertEquals("ud.createUser should work", Result.Status.OK, user.status); +// +// checkDataIgnoreDateDiff(data, user.value); +// +// // finally leave system in consistent state by deleting user again +// ud.delete(trans,data); +// +// } catch (DAOException e) { +// e.printStackTrace(); +// fail("Fail due to Exception"); +// } finally { +// ud.close(trans); +// } +// } +// +// private UserDAO.Data createPrototypeUserData() { +// UserDAO.Data data = new UserDAO.Data(); +// data.name = CONST_myName; +// +// data.cred_type = CONST_CRED_TYPE; +// data.cred = CONST_MY_CRED; +// data.expires = CONST_UPDATE_DATE; +// return data; +// } +// +// // @Test +// // public void testReadByUser() throws Exception { +// // // this test was done above in our super test, since it uses the same setup +// // } +// +// @Test +// public void testFunctionCreateUser() throws Exception { +// String name = "roger_rabbit"; +// Integer credType = CONST_CRED_TYPE; +// java.nio.ByteBuffer cred = CONST_MY_CRED; +// final UserDAO ud = new UserDAO(trans, cluster,"authz"); +// final UserDAO.Data data = createPrototypeUserData(); +// Result ret = ud.r_create(trans, data); +// Result> byUserNameLookup = ud.r_read(trans, name); +// +// assertEquals("sanity test w/ different username (different than other test cases) failed", name, byUserNameLookup.value.get(0).name); +// assertEquals("delete roger_rabbit failed", true, ud.delete(trans, byUserNameLookup.value.get(0))); +// } +// +// @Test +// public void testLowLevelCassandraCreateData_Given_UserAlreadyPresent_ShouldPass() throws Exception { +// UserDAO ud = new UserDAO(trans, cluster,"authz"); +// +// final UserDAO.Data data = createPrototypeUserData(); +// final UserDAO.Data data1 = ud.create(trans, data); +// final UserDAO.Data data2 = ud.create(trans, data); +// +// assertNotNull(data1); +// assertNotNull(data2); +// +// assertEquals(CONST_myName, data1.name); +// assertEquals(CONST_myName, data2.name); +// } +// +// @Test +// public void testCreateUser_Given_UserAlreadyPresent_ShouldFail() throws Exception { +// UserDAO ud = new UserDAO(trans, cluster,"authz"); +// +// final UserDAO.Data data = createPrototypeUserData(); +// +// // make sure that some prev test did not leave the user in the DB +// ud.delete(trans, data); +// +// // attempt to create same user twice !!! +// +// final Result data1 = ud.r_create(trans, data); +// final Result data2 = ud.r_create(trans, data); +// +// assertNotNull(data1); +// assertNotNull(data2); +// +// assertEquals(true, Result.Status.OK == data1.status); +// assertEquals(false, Result.Status.OK == data2.status); +// } +// +// private void checkData1(UserDAO.Data data, UserDAO.Data d) { +// data.name = CONST_myName; +// +// data.cred_type = CONST_CRED_TYPE; +// data.cred = CONST_MY_CRED; +// data.expires = CONST_UPDATE_DATE; +// +// assertEquals(data.name, d.name); +// assertEquals(data.cred_type, d.cred_type); +// assertEquals(data.cred, d.cred); +// assertEquals(data.expires, d.expires); +// +// } +// +// private void checkDataIgnoreDateDiff(UserDAO.Data data, UserDAO.Data d) { +// data.name = CONST_myName; +// +// data.cred_type = CONST_CRED_TYPE; +// data.cred = CONST_MY_CRED; +// data.expires = CONST_UPDATE_DATE; +// +// assertEquals(data.name, d.name); +// assertEquals(data.cred_type, d.cred_type); +// assertEquals(data.cred, d.cred); +// // we allow dates to be different, e.g. high level calls e.g. createUser sets the date itself. +// //assertEquals(data.updated, d.updated); +// +// } +// +// /** +// * Get a CONST_MY_CRED ByteBuffer, which is the java type for a cass blob. +// * @return +// */ +// private static java.nio.ByteBuffer get_CONST_MY_CRED() { +// return ByteBuffer.wrap("Hello".getBytes()); +// } +// +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_DelegateDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_DelegateDAO.java new file mode 100644 index 00000000..cb71fafe --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_DelegateDAO.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.nio.ByteBuffer; +import java.util.Date; +import java.util.List; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.DelegateDAO; +import com.att.dao.aaf.cass.DelegateDAO.Data; + + +public class JU_DelegateDAO extends AbsJUCass { + @Test + public void testCRUD() throws Exception { + DelegateDAO dao = new DelegateDAO(trans, cluster, AUTHZ); + DelegateDAO.Data data = new DelegateDAO.Data(); + data.user = "myname"; + data.delegate = "yourname"; + data.expires = new Date(); + +// Bytification + ByteBuffer bb = data.bytify(); + Data bdata = new DelegateDAO.Data(); + bdata.reconstitute(bb); + compare(data, bdata); + + try { + // Test create + Result ddcr = dao.create(trans,data); + assertTrue(ddcr.isOK()); + + + // Read by User + Result> records = dao.read(trans,data.user); + assertTrue(records.isOKhasData()); + for(DelegateDAO.Data rdata : records.value) + compare(data,rdata); + + // Read by Delegate + records = dao.readByDelegate(trans,data.delegate); + assertTrue(records.isOKhasData()); + for(DelegateDAO.Data rdata : records.value) + compare(data,rdata); + + // Update + data.delegate = "hisname"; + data.expires = new Date(); + assertTrue(dao.update(trans, data).isOK()); + + // Read by User + records = dao.read(trans,data.user); + assertTrue(records.isOKhasData()); + for(DelegateDAO.Data rdata : records.value) + compare(data,rdata); + + // Read by Delegate + records = dao.readByDelegate(trans,data.delegate); + assertTrue(records.isOKhasData()); + for(DelegateDAO.Data rdata : records.value) + compare(data,rdata); + + // Test delete + dao.delete(trans,data, true); + records = dao.read(trans,data.user); + assertTrue(records.isEmpty()); + + + } finally { + dao.close(trans); + } + } + + private void compare(Data d1, Data d2) { + assertEquals(d1.user, d2.user); + assertEquals(d1.delegate, d2.delegate); + assertEquals(d1.expires,d2.expires); + } + + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_FastCalling.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_FastCalling.java new file mode 100644 index 00000000..120b6f02 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_FastCalling.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.List; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.CredDAO; +import com.att.dao.aaf.cass.CredDAO.Data; +import com.att.inno.env.APIException; + +public class JU_FastCalling extends AbsJUCass { + + @Test + public void test() throws IOException, NoSuchAlgorithmException, APIException { + trans.setProperty("cassandra.writeConsistency.cred","ONE"); + + CredDAO udao = new CredDAO(env.newTransNoAvg(),cluster,"authz"); + System.out.println("Starting calls"); + for(iterations=0;iterations<8;++iterations) { + try { + // Create + CredDAO.Data data = new CredDAO.Data(); + data.id = "m55555@aaf.att.com"; + data.type = CredDAO.BASIC_AUTH; + data.cred = ByteBuffer.wrap(userPassToBytes("m55555","mypass")); + data.expires = new Date(System.currentTimeMillis() + 60000*60*24*90); + udao.create(trans,data); + + // Validate Read with key fields in Data + Result> rlcd = udao.read(trans,data); + assertTrue(rlcd.isOKhasData()); + for(CredDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + // Update + data.cred = ByteBuffer.wrap(userPassToBytes("m55555","mynewpass")); + udao.update(trans,data); + rlcd = udao.read(trans,data); + assertTrue(rlcd.isOKhasData()); + for(CredDAO.Data d : rlcd.value) { + checkData1(data,d); + } + + udao.delete(trans,data, true); + } finally { + updateTotals(); + newTrans(); + } + } + + } + + private void checkData1(Data data, Data d) { + assertEquals(data.id,d.id); + assertEquals(data.type,d.type); + assertEquals(data.cred,d.cred); + assertEquals(data.expires,d.expires); + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_HistoryDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_HistoryDAO.java new file mode 100644 index 00000000..605b1327 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_HistoryDAO.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Random; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.HistoryDAO; + +public class JU_HistoryDAO extends AbsJUCass { + + @Test + public void testCreate() throws Exception { + HistoryDAO historyDAO = new HistoryDAO(trans, cluster, AUTHZ); + HistoryDAO.Data data = createHistoryData(); + + try { + historyDAO.create(trans,data); + Thread.sleep(200);// History Create is Async + Result> records = historyDAO.readByUser(trans,data.user,data.yr_mon); + assertTrue(records.isOKhasData()); + for(HistoryDAO.Data d : records.value) { + assertHistory(data, d); + } + } finally { + historyDAO.close(trans); + } + } + + @Test + public void tesReadByUser() throws Exception { + HistoryDAO historyDAO = new HistoryDAO(trans,cluster, AUTHZ); + HistoryDAO.Data data = createHistoryData(); + + try { + historyDAO.create(trans,data); + Thread.sleep(200);// History Create is Async + Result> records = historyDAO.readByUser(trans, data.user,data.yr_mon); + assertTrue(records.isOKhasData()); + for(HistoryDAO.Data d : records.value) { + assertHistory(data, d); + } + } finally { + historyDAO.close(trans); + } + } + +/* + @Test + public void readByUserAndMonth() throws Exception { + HistoryDAO historyDAO = new HistoryDAO(trans,cluster, AUTHZ); + HistoryDAO.Data data = createHistoryData(); + + try { + historyDAO.create(trans,data); + Thread.sleep(200);// History Create is Async + Result> records = historyDAO.readByUserAndMonth(trans, + data.user, Integer.valueOf(String.valueOf(data.yr_mon).substring(0, 4)), + Integer.valueOf(String.valueOf(data.yr_mon).substring(4, 6))); + assertTrue(records.isOKhasData()); + for(HistoryDAO.Data d : records.value) { + assertHistory(data, d); + } + } finally { + historyDAO.close(trans); + } + } +*/ + //TODO readadd this +// @Test +// public void readByUserAndDay() throws Exception { +// HistoryDAO historyDAO = new HistoryDAO(trans, cluster, AUTHZ); +// HistoryDAO.Data data = createHistoryData(); +// +// try { +// historyDAO.create(trans, data); +// Thread.sleep(200);// History Create is Async +// +// String dayTime = String.valueOf(data.day_time); +// String day = null; +// if (dayTime.length() < 8) +// day = dayTime.substring(0, 1); +// else +// day = dayTime.substring(0, 2); +// +// List records = historyDAO.readByUserBetweenDates(trans, +// data.user, Integer.valueOf(String.valueOf(data.yr_mon).substring(0, 4)), +// Integer.valueOf(String.valueOf(data.yr_mon).substring(4, 6)), +// Integer.valueOf(day), 0); +// assertEquals(1,records.size()); +// for(HistoryDAO.Data d : records) { +// assertHistory(data, d); +// } +// } finally { +// historyDAO.close(trans); +// } +// } + private HistoryDAO.Data createHistoryData() { + HistoryDAO.Data data = HistoryDAO.newInitedData(); + Random random = new Random(); + data.user = "test" + random.nextInt(); + data.action = "add"; + data.target = "history"; + data.memo = "adding a row into history table"; +// data.detail().put("id", "test"); +// data.detail().put("name", "test"); + //String temp = "Test Blob Message"; + data.reconstruct = ByteBuffer.wrap("Temp Blob Message".getBytes()); + return data; + } + + private void assertHistory(HistoryDAO.Data ip, HistoryDAO.Data op) { + assertEquals(ip.yr_mon, op.yr_mon); +// assertEquals(ip.day_time, op.day_time); + assertEquals(ip.user, op.user); + assertEquals(ip.action, op.action); + assertEquals(ip.target, op.target); + assertEquals(ip.memo, op.memo); + //TODO : have to see if third party assert utility can be used +// assertTrue(CollectionUtils.isEqualCollection(ip.detail, op.detail)); +// for (String key : ip.detail().keySet()) { +// assertNotNull(op.detail().get(key)); +// } + assertNotNull(op.reconstruct); + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_NsDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_NsDAO.java new file mode 100644 index 00000000..562694ce --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_NsDAO.java @@ -0,0 +1,188 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.NsDAO; +import com.att.dao.aaf.cass.NsDAO.Data; +import com.att.dao.aaf.cass.NsType; +import com.att.inno.env.APIException; + + +public class JU_NsDAO extends AbsJUCass { + private static final String CRM = "ju_crm"; + private static final String SWM = "ju_swm"; + + @Test + public void test() throws APIException, IOException { + NsDAO nsd = new NsDAO(trans, cluster, AUTHZ); + try { + final String nsparent = "com.test"; + final String ns1 = nsparent +".ju_ns"; + final String ns2 = nsparent + ".ju_ns2"; + + Map oAttribs = new HashMap(); + oAttribs.put(SWM, "swm_data"); + oAttribs.put(CRM, "crm_data"); + Data data = new NsDAO.Data(); + data.name = ns1; + data.type = NsType.APP.type; + data.attrib(true).putAll(oAttribs); + + + Result> rdrr; + + // CREATE + Result rdc = nsd.create(trans, data); + assertTrue(rdc.isOK()); + + try { +// Bytification + ByteBuffer bb = data.bytify(); + Data bdata = new NsDAO.Data(); + bdata.reconstitute(bb); + compare(data, bdata); + + // Test READ by Object + rdrr = nsd.read(trans, data); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),1); + Data d = rdrr.value.get(0); + assertEquals(d.name,data.name); + assertEquals(d.type,data.type); + attribsEqual(d.attrib(false),data.attrib(false)); + attribsEqual(oAttribs,data.attrib(false)); + + // Test Read by Key + rdrr = nsd.read(trans, data.name); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),1); + d = rdrr.value.get(0); + assertEquals(d.name,data.name); + assertEquals(d.type,data.type); + attribsEqual(d.attrib(false),data.attrib(false)); + attribsEqual(oAttribs,data.attrib(false)); + + // Read NS by Type + Result> rtypes = nsd.readNsByAttrib(trans, SWM); + Set types; + if(rtypes.notOK()) { + throw new IOException(rtypes.errorString()); + } else { + types = rtypes.value; + } + assertEquals(1,types.size()); + assertEquals(true,types.contains(ns1)); + + // Add second NS to test list of data returned + Data data2 = new NsDAO.Data(); + data2.name = ns2; + data2.type = 3; // app + Result rdc2 = nsd.create(trans, data2); + assertTrue(rdc2.isOK()); + + // Interrupt - test PARENT + Result> rdchildren = nsd.getChildren(trans, "com.test"); + assertTrue(rdchildren.isOKhasData()); + boolean child1 = false; + boolean child2 = false; + for(Data dchild : rdchildren.value) { + if(ns1.equals(dchild.name))child1=true; + if(ns2.equals(dchild.name))child2=true; + } + assertTrue(child1); + assertTrue(child2); + + // FINISH DATA 2 by deleting + Result rddr = nsd.delete(trans, data2, true); + assertTrue(rddr.isOK()); + + // ADD DESCRIPTION + String description = "This is my test Namespace"; + assertFalse(description.equalsIgnoreCase(data.description)); + + Result addDesc = nsd.addDescription(trans, data.name, description); + assertTrue(addDesc.isOK()); + rdrr = nsd.read(trans, data); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),1); + assertEquals(rdrr.value.get(0).description,description); + + // UPDATE + String newDescription = "zz1234 Owns This Namespace Now"; + oAttribs.put("mso", "mso_data"); + data.attrib(true).put("mso", "mso_data"); + data.description = newDescription; + Result update = nsd.update(trans, data); + assertTrue(update.isOK()); + rdrr = nsd.read(trans, data); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),1); + assertEquals(rdrr.value.get(0).description,newDescription); + attribsEqual(oAttribs, rdrr.value.get(0).attrib); + + + } catch (IOException e) { + e.printStackTrace(); + } finally { + // DELETE + Result rddr = nsd.delete(trans, data, true); + assertTrue(rddr.isOK()); + rdrr = nsd.read(trans, data); + assertTrue(rdrr.isOK() && rdrr.isEmpty()); + assertEquals(rdrr.value.size(),0); + } + } finally { + nsd.close(trans); + } + } + + private void compare(NsDAO.Data d, NsDAO.Data data) { + assertEquals(d.name,data.name); + assertEquals(d.type,data.type); + attribsEqual(d.attrib(false),data.attrib(false)); + attribsEqual(d.attrib(false),data.attrib(false)); + } + + private void attribsEqual(Map aa, Map ba) { + assertEquals(aa.size(),ba.size()); + for(Entry es : aa.entrySet()) { + assertEquals(es.getValue(),ba.get(es.getKey())); + } + } +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_NsType.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_NsType.java new file mode 100644 index 00000000..c2508628 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_NsType.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static org.junit.Assert.assertEquals; + +import org.junit.AfterClass; +import org.junit.Test; + +import com.att.dao.aaf.cass.NsType; + +public class JU_NsType { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Test + public void test() { + NsType nt,nt2; + String[] tests = new String[] {"DOT","ROOT","COMPANY","APP","STACKED_APP","STACK"}; + for(String s : tests) { + nt = NsType.valueOf(s); + assertEquals(s,nt.name()); + + nt2 = NsType.fromString(s); + assertEquals(nt,nt2); + + int t = nt.type; + nt2 = NsType.fromType(t); + assertEquals(nt,nt2); + } + + nt = NsType.fromType(Integer.MIN_VALUE); + assertEquals(nt,NsType.UNKNOWN); + nt = NsType.fromString("Garbage"); + assertEquals(nt,NsType.UNKNOWN); + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_PermDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_PermDAO.java new file mode 100644 index 00000000..7022a816 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_PermDAO.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Set; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.PermDAO.Data; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.inno.env.APIException; + +/** + * Test the PermissionDAO + * + * Utilize AbsJUCass to initialize and pre-load Cass + * + * + */ +public class JU_PermDAO extends AbsJUCass{ + + @Test + public void test() throws APIException, IOException { + PermDAO pd = new PermDAO(trans,cluster,"authz"); + try { + PermDAO.Data data = new PermDAO.Data(); + data.ns = "com.test.ju_perm"; + data.type = "MyType"; + data.instance = "MyInstance"; + data.action = "MyAction"; + data.roles(true).add(data.ns + ".dev"); + + + + // CREATE + Result rpdc = pd.create(trans,data); + assertTrue(rpdc.isOK()); + + Result> rlpd; + try { +// Bytification + ByteBuffer bb = data.bytify(); + Data bdata = new PermDAO.Data(); + bdata.reconstitute(bb); + compare(data, bdata); + + // Validate Read with key fields in Data + if((rlpd = pd.read(trans,data)).isOK()) + for(PermDAO.Data d : rlpd.value) { + checkData1(data,d); + } + + // Validate readByName + if((rlpd = pd.readByType(trans,data.ns, data.type)).isOK()) + for(PermDAO.Data d : rlpd.value) { + checkData1(data,d); + } + + // Add Role + RoleDAO.Data role = new RoleDAO.Data(); + role.ns = data.ns; + role.name = "test"; + + Result rvpd = pd.addRole(trans, data, role.fullName()); + assertTrue(rvpd.isOK()); + // Validate Read with key fields in Data + if((rlpd = pd.read(trans,data)).isOK()) + for(PermDAO.Data d : rlpd.value) { + checkData2(data,d); + } + + // Remove Role + rvpd = pd.delRole(trans, data, role.fullName()); + assertTrue(rvpd.isOK()); + if((rlpd = pd.read(trans,data)).isOK()) + for(PermDAO.Data d : rlpd.value) { + checkData1(data,d); + } + + // Add Child + Data data2 = new Data(); + data2.ns = data.ns; + data2.type = data.type + ".2"; + data2.instance = data.instance; + data2.action = data.action; + + rpdc = pd.create(trans, data2); + assertTrue(rpdc.isOK()); + try { + rlpd = pd.readChildren(trans, data.ns,data.type); + assertTrue(rlpd.isOKhasData()); + assertEquals(rlpd.value.size(),1); + assertEquals(rlpd.value.get(0).fullType(),data2.fullType()); + } finally { + // Delete Child + pd.delete(trans, data2,true); + + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + // DELETE + Result rpdd = pd.delete(trans,data,true); + assertTrue(rpdd.isOK()); + rlpd = pd.read(trans, data); + assertTrue(rlpd.isOK() && rlpd.isEmpty()); + assertEquals(rlpd.value.size(),0); + } + } finally { + pd.close(trans); + } + } + + private void compare(Data a, Data b) { + assertEquals(a.ns,b.ns); + assertEquals(a.type,b.type); + assertEquals(a.instance,b.instance); + assertEquals(a.action,b.action); + assertEquals(a.roles(false).size(),b.roles(false).size()); + for(String s: a.roles(false)) { + assertTrue(b.roles(false).contains(s)); + } + } + private void checkData1(Data data, Data d) { + assertEquals(data.ns,d.ns); + assertEquals(data.type,d.type); + assertEquals(data.instance,d.instance); + assertEquals(data.action,d.action); + + Set ss = d.roles(true); + assertEquals(1,ss.size()); + assertTrue(ss.contains(data.ns+".dev")); + } + + private void checkData2(Data data, Data d) { + assertEquals(data.ns,d.ns); + assertEquals(data.type,d.type); + assertEquals(data.instance,d.instance); + assertEquals(data.action,d.action); + + Set ss = d.roles(true); + assertEquals(2,ss.size()); + assertTrue(ss.contains(data.ns+".dev")); + assertTrue(ss.contains(data.ns+".test")); + } + + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/JU_RoleDAO.java b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_RoleDAO.java new file mode 100644 index 00000000..d797cfb9 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/JU_RoleDAO.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; + +import org.junit.Test; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.RoleDAO.Data; +import com.att.inno.env.APIException; + + +public class JU_RoleDAO extends AbsJUCass { + + @Test + public void test() throws IOException, APIException { + RoleDAO rd = new RoleDAO(trans, cluster, AUTHZ); + try { + Data data = new RoleDAO.Data(); + data.ns = "com.test.ju_role"; + data.name = "role1"; + +// Bytification + ByteBuffer bb = data.bytify(); + Data bdata = new RoleDAO.Data(); + bdata.reconstitute(bb); + compare(data, bdata); + + // CREATE + Result rdc = rd.create(trans, data); + assertTrue(rdc.isOK()); + Result> rdrr; + try { + // READ + rdrr = rd.read(trans, data); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),1); + Data d = rdrr.value.get(0); + assertEquals(d.perms.size(),0); + assertEquals(d.name,data.name); + assertEquals(d.ns,data.ns); + + PermDAO.Data perm = new PermDAO.Data(); + perm.ns = data.ns; + perm.type = "Perm"; + perm.instance = "perm1"; + perm.action = "write"; + + // ADD Perm + Result rdar = rd.addPerm(trans, data, perm); + assertTrue(rdar.isOK()); + rdrr = rd.read(trans, data); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),1); + assertEquals(rdrr.value.get(0).perms.size(),1); + assertTrue(rdrr.value.get(0).perms.contains(perm.encode())); + + // DEL Perm + rdar = rd.delPerm(trans, data,perm); + assertTrue(rdar.isOK()); + rdrr = rd.read(trans, data); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),1); + assertEquals(rdrr.value.get(0).perms.size(),0); + + // Add Child + Data data2 = new Data(); + data2.ns = data.ns; + data2.name = data.name + ".2"; + + rdc = rd.create(trans, data2); + assertTrue(rdc.isOK()); + try { + rdrr = rd.readChildren(trans, data.ns,data.name); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),1); + assertEquals(rdrr.value.get(0).name,data.name + ".2"); + + rdrr = rd.readChildren(trans, data.ns,"*"); + assertTrue(rdrr.isOKhasData()); + assertEquals(rdrr.value.size(),2); + + } finally { + // Delete Child + rd.delete(trans, data2, true); + } + + } finally { + // DELETE + Result rddr = rd.delete(trans, data, true); + assertTrue(rddr.isOK()); + rdrr = rd.read(trans, data); + assertTrue(rdrr.isOK() && rdrr.isEmpty()); + assertEquals(rdrr.value.size(),0); + } + } finally { + rd.close(trans); + } + } + + private void compare(Data a, Data b) { + assertEquals(a.name,b.name); + assertEquals(a.description, b.description); + assertEquals(a.ns,b.ns); + assertEquals(a.perms(false).size(),b.perms(false).size()); + for(String p : a.perms(false)) { + assertTrue(b.perms(false).contains(p)); + } + } + +} diff --git a/authz-cass/src/test/java/com/att/dao/aaf/test/NS_ChildUpdate.java b/authz-cass/src/test/java/com/att/dao/aaf/test/NS_ChildUpdate.java new file mode 100644 index 00000000..dc3f13e8 --- /dev/null +++ b/authz-cass/src/test/java/com/att/dao/aaf/test/NS_ChildUpdate.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.dao.aaf.test; + +import com.att.authz.env.AuthzEnv; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; + +public class NS_ChildUpdate { + + public static void main(String[] args) { + if(args.length < 3 ) { + System.out.println("usage: NS_ChildUpdate machine mechid (encrypted)passwd"); + } else { + try { + AuthzEnv env = new AuthzEnv(); + env.setLog4JNames("log.properties","authz","authz","audit","init","trace"); + + Cluster cluster = Cluster.builder() + .addContactPoint(args[0]) + .withCredentials(args[1],env.decrypt(args[2], false)) + .build(); + + Session session = cluster.connect("authz"); + try { + ResultSet result = session.execute("SELECT name,parent FROM ns"); + int count = 0; + for(Row r : result.all()) { + ++count; + String name = r.getString(0); + String parent = r.getString(1); + if(parent==null) { + int idx = name.lastIndexOf('.'); + + parent = idx>0?name.substring(0, idx):"."; + System.out.println("UPDATE " + name + " to " + parent); + session.execute("UPDATE ns SET parent='" + parent + "' WHERE name='" + name + "';"); + } + } + System.out.println("Processed " + count + " records"); + } finally { + session.close(); + cluster.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + +} diff --git a/authz-cass/src/test/resources/cadi.properties b/authz-cass/src/test/resources/cadi.properties new file mode 100644 index 00000000..4f38cf54 --- /dev/null +++ b/authz-cass/src/test/resources/cadi.properties @@ -0,0 +1,53 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START==================================================== +# * org.onap.aai +# * =========================================================================== +# * Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# * Copyright © 2017 Amdocs +# * =========================================================================== +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END==================================================== +# * +# * ECOMP is a trademark and service mark of AT&T Intellectual Property. +# * +#------------------------------------------------------------------------------- +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +## +## AUTHZ API (authz-service) Properties +## + +cadi_prop_file=com.att.aaf.props;com.att.aaf.common.props + +#cadi_trust_all_x509=true +#cadi_alias=aaf.att +https.protocols=TLSv1.1,TLSv1.2 + +cm_url=https://XXX:8150 + +basic_realm=localized +basic_warn=false +localhost_deny=false + +cass_group_name=com.att.aaf +cass_cluster_name=mithrilcsp.sbc.com +aaf_default_realm=com.att.csp + +aaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE +aaf_id=??? +aaf_password=enc:XXX + +aaf_user_expires=3000 +aaf_clean_interval=4000 + diff --git a/authz-certman/.gitignore b/authz-certman/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-certman/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-certman/pom.xml b/authz-certman/pom.xml new file mode 100644 index 00000000..53e07816 --- /dev/null +++ b/authz-certman/pom.xml @@ -0,0 +1,179 @@ + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-certman + AAF Certification Managmenent + Certificate Manager API + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + + 45 + + + + + com.att.authz + authz-core + + + + com.att.authz + authz-cass + + + + + + com.att.cadi + cadi-aaf + + + + com.google.code.jscep + jscep + 2.4.0 + + + + org.slf4j + slf4j-log4j12 + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + **/*.class + + + 2.3.1 + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + + + + + + ossrhdme + https://oss.sonatype.org/content/repositories/snapshots + + + ossrhdme + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + https://github.com/att/AAF.git + ${project.scm.connection} + http://github.com/att/AAF/tree/master + + diff --git a/authz-certman/src/main/config/certman.props b/authz-certman/src/main/config/certman.props new file mode 100644 index 00000000..496d8c37 --- /dev/null +++ b/authz-certman/src/main/config/certman.props @@ -0,0 +1,25 @@ +## +## AUTHZ Certman (authz-certman) Properties +## + +hostname=_HOSTNAME_ + +## DISCOVERY (DME2) Parameters on the Command Line +AFT_LATITUDE=_AFT_LATITUDE_ +AFT_LONGITUDE=_AFT_LONGITUDE_ +AFT_ENVIRONMENT=_AFT_ENVIRONMENT_ +DEPLOYED_VERSION=_ARTIFACT_VERSION_ + +## Pull in common/security properties + +cadi_prop_files=_COMMON_DIR_/com.att.aaf.common.props;_COMMON_DIR_/com.att.aaf.props + +##DME2 related parameters +DMEServiceName=service=com.att.authz.certman/version=_MAJOR_VER_._MINOR_VER_._PATCH_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ +AFT_DME2_PORT_RANGE=_AUTHZ_CERTMAN_PORT_RANGE_ + +# Turn on both AAF TAF & LUR 2.0 +aaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=_MAJOR_VER_._MINOR_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ + + + diff --git a/authz-certman/src/main/config/log4j.properties b/authz-certman/src/main/config/log4j.properties new file mode 100644 index 00000000..ad853f54 --- /dev/null +++ b/authz-certman/src/main/config/log4j.properties @@ -0,0 +1,79 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START==================================================== +# * org.onap.aai +# * =========================================================================== +# * Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# * Copyright © 2017 Amdocs +# * =========================================================================== +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END==================================================== +# * +# * ECOMP is a trademark and service mark of AT&T Intellectual Property. +# * +#------------------------------------------------------------------------------- +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +log4j.appender.INIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.INIT.File=_LOG_DIR_/${LOG4J_FILENAME_init} +log4j.appender.INIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.INIT.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.INIT.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.INIT.layout=org.apache.log4j.PatternLayout +log4j.appender.INIT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %m %n + + +log4j.appender.CM=org.apache.log4j.DailyRollingFileAppender +log4j.appender.CM.File=_LOG_DIR_/${LOG4J_FILENAME_cm} +log4j.appender.CM.DatePattern='.'yyyy-MM-dd +#log4j.appender.CM.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.CM.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.CM.layout=org.apache.log4j.PatternLayout +log4j.appender.CM.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %p [%c] %m %n + +log4j.appender.AUDIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.AUDIT.File=_LOG_DIR_/${LOG4J_FILENAME_audit} +log4j.appender.AUDIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.AUDIT.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.AUDIT.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.AUDIT.layout=org.apache.log4j.PatternLayout +log4j.appender.AUDIT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %m %n + + +# General Apache libraries +log4j.rootLogger=INFO,CM +log4j.logger.org.apache=WARN,INIT +log4j.logger.dme2=WARN,INIT +log4j.logger.init=INFO,INIT +log4j.logger.authz=_LOG4J_LEVEL_,CM +log4j.logger.audit=INFO,AUDIT +log4j.category.org.jscep=INFO + diff --git a/authz-certman/src/main/config/lrm-authz-certman.xml b/authz-certman/src/main/config/lrm-authz-certman.xml new file mode 100644 index 00000000..689c2db3 --- /dev/null +++ b/authz-certman/src/main/config/lrm-authz-certman.xml @@ -0,0 +1,83 @@ + + + + + + com.att.authz._ARTIFACT_ID_ + + _MAJOR_VER_ + _MINOR_VER_ + _PATCH_VER_ + + _ROUTE_OFFER_ + + Java + com.att.authz.cm.service.CertManAPI + + process.workdir + _ROOT_DIR_ + + + jvm.version + 1.8 + + + jvm.args + -DAFT_LATITUDE=_AFT_LATITUDE_ -DAFT_LONGITUDE=_AFT_LONGITUDE_ -DAFT_ENVIRONMENT=_AFT_ENVIRONMENT_ -Dplatform=_SCLD_PLATFORM_ -Dcom.sun.jndi.ldap.connect.pool.maxsize=20 -Dcom.sun.jndi.ldap.connect.pool.prefsize=10 -Dcom.sun.jndi.ldap.connect.pool.timeout=3000 + + + jvm.classpath + _ROOT_DIR_/etc:_ROOT_DIR_/lib/*: + + + jvm.heap.min + 1024m + + + jvm.heap.max + 2048m + + + start.class + com.att.authz.cm.service.CertManAPI + + + stdout.redirect + _ROOT_DIR_/logs/SystemOut.log + + + stderr.redirect + _ROOT_DIR_/logs/SystemErr.log + + aft + AUTO + 2 + _RESOURCE_MIN_COUNT_ + _RESOURCE_MAX_COUNT_ + _RESOURCE_REGISTRATION_ + com.att.authz:_ARTIFACT_ID_ + _ARTIFACT_VERSION_ + + diff --git a/authz-certman/src/main/java/com/att/authz/cm/api/API_Artifact.java b/authz-certman/src/main/java/com/att/authz/cm/api/API_Artifact.java new file mode 100644 index 00000000..be417515 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/api/API_Artifact.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.api; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.authz.cm.mapper.Mapper.API; +import com.att.authz.cm.service.CertManAPI; +import com.att.authz.cm.service.Code; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cssa.rserv.HttpMethods; + +/** + * API Deployment Artifact Apis.. using Redirect for mechanism + * + * + */ +public class API_Artifact { + private static final String GET_ARTIFACTS = "Get Artifacts"; + + /** + * Normal Init level APIs + * + * @param cmAPI + * @param facade + * @throws Exception + */ + public static void init(final CertManAPI cmAPI) throws Exception { + cmAPI.route(HttpMethods.POST, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,"Create Artifacts") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + Result r = context.createArtifacts(trans, req, resp); + if(r.isOK()) { + resp.setStatus(HttpStatus.CREATED_201); + } else { + context.error(trans,resp,r); + } + } + }); + + cmAPI.route(HttpMethods.GET, "/cert/artifacts/:mechid/:machine", API.ARTIFACTS, new Code(cmAPI,GET_ARTIFACTS) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + + Result r = context.readArtifacts(trans, resp, pathParam(req,":mechid"), pathParam(req,":machine")); + if(r.isOK()) { + resp.setStatus(HttpStatus.CREATED_201); + } else { + context.error(trans,resp,r); + } + } + }); + + cmAPI.route(HttpMethods.GET, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,GET_ARTIFACTS) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + Result r = context.readArtifacts(trans, req, resp); + if(r.isOK()) { + resp.setStatus(HttpStatus.CREATED_201); + } else { + context.error(trans,resp,r); + } + } + }); + + cmAPI.route(HttpMethods.PUT, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,"Update Artifacts") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + Result r = context.updateArtifacts(trans, req, resp); + if(r.isOK()) { + resp.setStatus(HttpStatus.OK_200); + } else { + context.error(trans,resp,r); + } + } + }); + + cmAPI.route(HttpMethods.DELETE, "/cert/artifacts/:mechid/:machine", API.VOID, new Code(cmAPI,"Delete Artifacts") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + Result r = context.deleteArtifacts(trans, resp, + pathParam(req, ":mechid"), pathParam(req,":machine")); + if(r.isOK()) { + resp.setStatus(HttpStatus.OK_200); + } else { + context.error(trans,resp,r); + } + } + }); + + + cmAPI.route(HttpMethods.DELETE, "/cert/artifacts", API.VOID, new Code(cmAPI,"Delete Artifacts") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + Result r = context.deleteArtifacts(trans, req, resp); + if(r.isOK()) { + resp.setStatus(HttpStatus.OK_200); + } else { + context.error(trans,resp,r); + } + } + }); + + + } +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/api/API_Cert.java b/authz-certman/src/main/java/com/att/authz/cm/api/API_Cert.java new file mode 100644 index 00000000..3a7bbe16 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/api/API_Cert.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.api; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.authz.cm.ca.CA; +import com.att.authz.cm.mapper.Mapper.API; +import com.att.authz.cm.service.CertManAPI; +import com.att.authz.cm.service.Code; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.Slot; +import com.att.inno.env.TransStore; + +/** + * API Apis.. using Redirect for mechanism + * + * + */ +public class API_Cert { + public static final String CERT_AUTH = "CertAuthority"; + private static Slot sCertAuth; + + /** + * Normal Init level APIs + * + * @param cmAPI + * @param facade + * @throws Exception + */ + public static void init(final CertManAPI cmAPI) throws Exception { + // Check for Created Certificate Authorities in TRANS + sCertAuth = ((TransStore) cmAPI.env).slot(CERT_AUTH); + + //////// + // Overall APIs + /////// + cmAPI.route(HttpMethods.PUT,"/cert/:ca",API.CERT_REQ,new Code(cmAPI,"Request Certificate") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + String key = pathParam(req, ":ca"); + CA ca; + if((ca = cmAPI.getCA(key))==null) { + context.error(trans,resp,Result.ERR_BadData,"CA %s is not supported",key); + } else { + trans.put(sCertAuth, ca); + + Result r = context.requestCert(trans, req, resp, req.getParameter("withTrust")!=null); + if(r.isOK()) { + resp.setStatus(HttpStatus.OK_200); + } else { + context.error(trans,resp,r); + } + } + } + }); + + /** + * + */ + cmAPI.route(HttpMethods.GET, "/cert/may/:perm", API.VOID, new Code(cmAPI,"Check Permission") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + Result r = context.check(trans, resp, pathParam(req,"perm")); + if(r.isOK()) { + resp.setStatus(HttpStatus.OK_200); + } else { + trans.checkpoint(r.errorString()); + context.error(trans,resp,Result.err(Result.ERR_Denied,"%s does not have Permission.",trans.user())); + } + } + }); + + } +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/ca/AppCA.java b/authz-certman/src/main/java/com/att/authz/cm/ca/AppCA.java new file mode 100644 index 00000000..761867d7 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/ca/AppCA.java @@ -0,0 +1,357 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.ca; + +import java.io.File; +import java.io.IOException; +import java.net.Authenticator; +import java.net.MalformedURLException; +import java.net.PasswordAuthentication; +import java.net.URL; +import java.security.cert.CertStore; +import java.security.cert.CertStoreException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.pkcs.PKCS10CertificationRequest; +import org.jscep.client.Client; +import org.jscep.client.ClientException; +import org.jscep.client.EnrollmentResponse; +import org.jscep.client.verification.CertificateVerifier; +import org.jscep.transaction.TransactionException; + +import com.att.authz.cm.cert.BCFactory; +import com.att.authz.cm.cert.CSRMeta; +import com.att.authz.cm.cert.StandardFields; +import com.att.authz.common.Define; +import com.att.cadi.cm.CertException; +import com.att.cadi.cm.Factory; +import com.att.cadi.config.Config; +import com.att.cadi.routing.GreatCircle; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.inno.env.util.Split; + +public class AppCA extends CA { + public static final String CA_PERM_TYPE = Define.ROOT_NS+".ca"; // Permission Type for validation + private static final String AAF_DATA_DIR = "aaf_data_dir"; + private static final String CA_PREFIX = "http://"; + private static final String CA_POSTFIX="/certsrv/mscep_admin/mscep.dll"; + + private final static String MS_PROFILE="1"; + private static final String CM_TRUST_CAS = "cm_trust_cas"; + private Clients clients; + + private static class AAFStdFields implements StandardFields { + private final String env; + public AAFStdFields(Trans trans) throws CertException { + env = trans.getProperty(Config.AAF_ENV); + if(env==null) { + throw new CertException(Config.AAF_ENV + " must be set to create Certificates"); + } + } + @Override + public void set(CSRMeta csr) { + // Environment + csr.environment(env); + // Standard Fields + csr.o("ATT Services,Inc."); + csr.l("St Louis"); + csr.st("Missouri"); + csr.c("US"); + } + } + + public AppCA(final Trans trans, final String name, final String urlstr, final String id, final String pw) throws IOException, CertificateException, CertException { + super(name,new AAFStdFields(trans), CA_PERM_TYPE); + + clients = new Clients(trans,urlstr); + + + // Set this for NTLM password Microsoft + Authenticator.setDefault(new Authenticator() { + public PasswordAuthentication getPasswordAuthentication () { + return new PasswordAuthentication ( + id, + trans.decryptor().decrypt(pw).toCharArray()); + } + }); + + + + try { + StringBuilder sb = new StringBuilder("CA Reported Trusted Certificates"); + List trustCerts = new ArrayList(); + for(Client client : clients) { + CertStore cs = client.getCaCertificate(MS_PROFILE); + + Collection cc = cs.getCertificates(null); + for(Certificate c : cc) { + X509Certificate xc = (X509Certificate)c; + // Avoid duplicate Certificates from multiple servers + X509Certificate match = null; + for(X509Certificate t : trustCerts) { + if(t.getSerialNumber().equals(xc.getSerialNumber())) { + match = xc; + break; + } + } + if(match==null && xc.getSubjectDN().getName().startsWith("CN=ATT ")) { + sb.append("\n\t"); + sb.append(xc.getSubjectDN()); + sb.append("\n\t\tSerial Number: "); + String bi = xc.getSerialNumber().toString(16); + for(int i=0;i1 && i%2==0) { + sb.append(':'); + } + sb.append(bi.charAt(i)); + } + sb.append("\n\t\tIssuer: "); + sb.append(xc.getIssuerDN()); + sb.append("\n\t\tNot Before: "); + sb.append(xc.getNotBefore()); + sb.append("\n\t\tNot After: "); + sb.append(xc.getNotAfter()); + sb.append("\n\t\tSigAlgorithm: "); + sb.append(xc.getSigAlgName()); + sb.append("\n\t\tType: "); + sb.append(xc.getType()); + sb.append("\n\t\tVersion: "); + sb.append(xc.getVersion()); + + trustCerts.add(xc); + } + } + } + trans.init().log(sb); + // Add Additional ones from Property + String data_dir = trans.getProperty(AAF_DATA_DIR); + if(data_dir!=null) { + File data = new File(data_dir); + if(data.exists()) { + String trust_cas = trans.getProperty(CM_TRUST_CAS); + byte[] bytes; + if(trust_cas!=null) { + for(String fname : Split.split(';', trust_cas)) { + File crt = new File(data,fname); + if(crt.exists()) { + bytes = Factory.decode(crt); + try { + Collection cc = Factory.toX509Certificate(bytes); + for(Certificate c : cc) { + trustCerts.add((X509Certificate)c); + } + } catch (CertificateException e) { + throw new CertException(e); + } + } + } + } + } + } + + String[] trustChain = new String[trustCerts.size()]; + int i=-1; + for( Certificate cert : trustCerts) { + trustChain[++i]=BCFactory.toString(trans,cert); + } + + setTrustChain(trustChain); + } catch (ClientException | CertStoreException e) { + // Note: Cannot validly start without all Clients, because we need to read all Issuing Certificates + // This is acceptable risk for most things, as we're not real time in general + throw new CertException(e); + } + } + + + @Override + public X509Certificate sign(Trans trans, CSRMeta csrmeta) throws IOException, CertException { + TimeTaken tt = trans.start("Generating CSR and Keys for New Certificate", Env.SUB); + PKCS10CertificationRequest csr; + try { + csr = csrmeta.generateCSR(trans); + if(trans.info().isLoggable()) { + trans.info().log(BCFactory.toString(trans, csr)); + } + if(trans.info().isLoggable()) { + trans.info().log(csr); + } + } finally { + tt.done(); + } + + tt = trans.start("Enroll CSR", Env.SUB); + Client client = null; + try { + client = clients.best(); + EnrollmentResponse er = client.enrol( + csrmeta.initialConversationCert(trans), + csrmeta.keypair(trans).getPrivate(), + csr, + MS_PROFILE /* profile... MS can't deal with blanks*/); + while(true) { + if(er.isSuccess()) { + for( Certificate cert : er.getCertStore().getCertificates(null)) { + return (X509Certificate)cert; + } + break; + } else if (er.isPending()) { + trans.checkpoint("Polling, waiting on CA to complete"); + Thread.sleep(3000); + } else if (er.isFailure()) { + throw new CertException(er.getFailInfo().toString()); + } + } + } catch (ClientException e) { + trans.error().log(e,"SCEP Client Error, Temporarily Invalidating Client"); + if(client!=null) { + clients.invalidate(client); + } + } catch (InterruptedException|TransactionException|CertificateException|OperatorCreationException | CertStoreException e) { + trans.error().log(e); + } finally { + tt.done(); + } + + return null; + } + + + private class Clients implements Iterable{ + /** + * CSO Servers are in Dallas and St Louis + * GEO_LOCATION LATITUDE LONGITUDE ZIPCODE TIMEZONE + * ------------ -------- --------- ------- -------- + * DLLSTXCF 32.779295 -96.800014 75202 America/Chicago + * STLSMORC 38.627345 -90.193774 63101 America/Chicago + * + * The online production issuing CA servers are: + * AAF - CADI Issuing CA 01 135.41.45.152 MOSTLS1AAFXXA02 + * AAF - CADI Issuing CA 02 135.31.72.154 TXDLLS2AAFXXA02 + */ + + private final Client[] client; + private final Date[] failure; + private int preferred; + + public Clients(Trans trans, String urlstr) throws MalformedURLException { + String[] urlstrs = Split.split(',', urlstr); + client = new Client[urlstrs.length]; + failure = new Date[urlstrs.length]; + double distance = Double.MAX_VALUE; + String localLat = trans.getProperty("AFT_LATITUDE","39.833333"); //Note: Defaulting to GEO center of US + String localLong = trans.getProperty("AFT_LONGITUDE","-98.583333"); + for(int i=0;i iterator() { + return new Iterator() { + private int iter = 0; + @Override + public boolean hasNext() { + return iter < Clients.this.client.length; + } + + @Override + public Client next() { + return Clients.this.client[iter++]; + } + + }; + } + } +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/ca/CA.java b/authz-certman/src/main/java/com/att/authz/cm/ca/CA.java new file mode 100644 index 00000000..fab89941 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/ca/CA.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.ca; + +import java.io.IOException; +import java.security.MessageDigest; +import java.security.cert.X509Certificate; + +import com.att.authz.cm.cert.CSRMeta; +import com.att.authz.cm.cert.StandardFields; +import com.att.cadi.cm.CertException; +import com.att.inno.env.Trans; + +public abstract class CA { + private final String name; + private String[] trustChain; + private final StandardFields stdFields; + private MessageDigest messageDigest; + private final String permType; + + protected CA(String name, StandardFields sf, String permType) { + this.name = name; + stdFields = sf; + this.permType = permType; + } + + /* + * NOTE: These two functions must be called in Protected Constructors during their Construction. + */ + protected void setTrustChain(String[] trustChain) { + this.trustChain = trustChain; + } + + protected void setMessageDigest(MessageDigest md) { + messageDigest = md; + } + + /* + * End Required Constructor calls + */ + + public String getName() { + return name; + } + + public String[] getTrustChain() { + return trustChain; + } + + public String getPermType() { + return permType; + } + + public StandardFields stdFields() { + return stdFields; + } + + public abstract X509Certificate sign(Trans trans, CSRMeta csrmeta) throws IOException, CertException; + + public MessageDigest messageDigest() { + return messageDigest; + } +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/ca/DevlCA.java b/authz-certman/src/main/java/com/att/authz/cm/ca/DevlCA.java new file mode 100644 index 00000000..bc999f29 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/ca/DevlCA.java @@ -0,0 +1,227 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.ca; + +import java.io.File; +import java.io.IOException; +import java.math.BigInteger; +import java.security.GeneralSecurityException; +import java.security.KeyFactory; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.security.interfaces.RSAPrivateKey; +import java.security.spec.PKCS8EncodedKeySpec; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; +import java.security.SecureRandom; + +import org.bouncycastle.asn1.ASN1Sequence; +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.asn1.x500.X500NameBuilder; +import org.bouncycastle.asn1.x500.style.BCStyle; +import org.bouncycastle.asn1.x509.BasicConstraints; +import org.bouncycastle.asn1.x509.ExtendedKeyUsage; +import org.bouncycastle.asn1.x509.Extension; +import org.bouncycastle.asn1.x509.GeneralName; +import org.bouncycastle.asn1.x509.GeneralNames; +import org.bouncycastle.asn1.x509.KeyPurposeId; +import org.bouncycastle.asn1.x509.KeyUsage; +import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; +import org.bouncycastle.cert.X509v3CertificateBuilder; +import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; +import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils; +import org.bouncycastle.operator.OperatorCreationException; + +import com.att.authz.cm.cert.BCFactory; +import com.att.authz.cm.cert.CSRMeta; +import com.att.authz.cm.cert.StandardFields; +import com.att.authz.common.Define; +import com.att.cadi.cm.CertException; +import com.att.cadi.cm.Factory; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; + +public class DevlCA extends CA { + + // Extensions + private static final KeyPurposeId[] ASN_WebUsage = new KeyPurposeId[] { + KeyPurposeId.id_kp_serverAuth, // WebServer + KeyPurposeId.id_kp_clientAuth};// WebClient + + private X509Certificate caCert; + private final RSAPrivateKey caKey; + private final X500Name issuer; + private final SecureRandom random = new SecureRandom(); + private byte[] serialish = new byte[24]; + + public DevlCA(Trans trans, String name, String dirString) throws IOException, CertException { + super(name, new StandardFields() { + @Override + public void set(CSRMeta csr) { + // Standard Fields + csr.o("ATT Services, Inc."); + csr.l("St Louis"); + csr.st("Missouri"); + csr.c("US"); + } + }, Define.ROOT_NS+".ca" // Permission Type for validation + ); + File dir = new File(dirString); + if(!dir.exists()) { + throw new CertException(dirString + " does not exist"); + } + + File ca = new File(dir,"ca.crt"); + if(ca.exists()) { + byte[] bytes = Factory.decode(ca); + Collection certs; + try { + certs = Factory.toX509Certificate(bytes); + } catch (CertificateException e) { + throw new CertException(e); + } + List lTrust = new ArrayList(); + caCert=null; + for(Certificate c : certs) { + if(caCert==null) { + caCert = (X509Certificate)c; + } else { + lTrust.add(Factory.toString(trans,c)); + } + break; + } + } + + this.setTrustChain(new String[]{Factory.toString(trans,caCert)}); + + /* + * Private key needs to be converted to "DER" format, with no password. + * Use chmod 400 on key + * + * openssl pkcs8 -topk8 -outform DER -nocrypt -in ca.key -out ca.der + * + */ + ca = new File(dir,"ca.der"); + if(ca.exists()) { + byte[] bytes = Factory.binary(ca); + +// EncryptedPrivateKeyInfo ekey=new EncryptedPrivateKeyInfo(bytes); +// Cipher cip=Cipher.getInstance(ekey.getAlgName()); +// PBEKeySpec pspec=new PBEKeySpec("password".toCharArray()); +// SecretKeyFactory skfac=SecretKeyFactory.getInstance(ekey.getAlgName()); +// Key pbeKey=skfac.generateSecret(pspec); +// AlgorithmParameters algParams=ekey.getAlgParameters(); +// cip.init(Cipher.DECRYPT_MODE,pbeKey,algParams); + + KeyFactory keyFactory; + try { + keyFactory = KeyFactory.getInstance("RSA"); + PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(bytes); + + caKey = (RSAPrivateKey) keyFactory.generatePrivate(privSpec); + } catch (GeneralSecurityException e) { + throw new CertException(e); + } + + X500NameBuilder xnb = new X500NameBuilder(); + xnb.addRDN(BCStyle.C,"US"); + xnb.addRDN(BCStyle.ST,"Missouri"); + xnb.addRDN(BCStyle.L,"Arnold"); + xnb.addRDN(BCStyle.O,"ATT Services, Inc."); + xnb.addRDN(BCStyle.OU,"AAF"); + xnb.addRDN(BCStyle.CN,"aaf.att.com"); + xnb.addRDN(BCStyle.EmailAddress,"DL-aaf-support@att.com"); + issuer = xnb.build(); + } else { + throw new CertException(ca.getPath() + " does not exist"); + } + } + + /* (non-Javadoc) + * @see com.att.authz.cm.service.CA#sign(org.bouncycastle.pkcs.PKCS10CertificationRequest) + */ + @Override + public X509Certificate sign(Trans trans, CSRMeta csrmeta) throws IOException, CertException { + GregorianCalendar gc = new GregorianCalendar(); + Date start = gc.getTime(); + gc.add(GregorianCalendar.DAY_OF_MONTH, 1); + Date end = gc.getTime(); + X509Certificate x509; + TimeTaken tt = trans.start("Create/Sign Cert",Env.SUB); + try { + BigInteger bi; + synchronized(serialish) { + random.nextBytes(serialish); + bi = new BigInteger(serialish); + } + + X509v3CertificateBuilder xcb = new X509v3CertificateBuilder( + issuer, + bi, // replace with Serialnumber scheme + start, + end, + csrmeta.x500Name(), +// SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(caCert.getPublicKey().getEn) + new SubjectPublicKeyInfo(ASN1Sequence.getInstance(caCert.getPublicKey().getEncoded())) + ); + List lsan = new ArrayList(); + for(String s : csrmeta.sans()) { + lsan.add(new GeneralName(GeneralName.dNSName,s)); + } + GeneralName[] sans = new GeneralName[lsan.size()]; + lsan.toArray(sans); + + JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils(); + xcb .addExtension(Extension.basicConstraints, + false, new BasicConstraints(false)) + .addExtension(Extension.keyUsage, + true, new KeyUsage(KeyUsage.digitalSignature + | KeyUsage.keyEncipherment)) + .addExtension(Extension.extendedKeyUsage, + true, new ExtendedKeyUsage(ASN_WebUsage)) + + .addExtension(Extension.authorityKeyIdentifier, + false, extUtils.createAuthorityKeyIdentifier(caCert)) + .addExtension(Extension.subjectKeyIdentifier, + false, extUtils.createSubjectKeyIdentifier(caCert.getPublicKey())) + .addExtension(Extension.subjectAlternativeName, + false, new GeneralNames(sans)) + ; + + x509 = new JcaX509CertificateConverter().getCertificate( + xcb.build(BCFactory.contentSigner(caKey))); + } catch (GeneralSecurityException|OperatorCreationException e) { + throw new CertException(e); + } finally { + tt.done(); + } + return x509; + } + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/cert/BCFactory.java b/authz-certman/src/main/java/com/att/authz/cm/cert/BCFactory.java new file mode 100644 index 00000000..52621e54 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/cert/BCFactory.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.cert; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.lang.reflect.Field; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.SignatureException; +import java.util.List; + +import org.bouncycastle.asn1.ASN1Object; +import org.bouncycastle.operator.ContentSigner; +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; +import org.bouncycastle.pkcs.PKCS10CertificationRequest; + +import com.att.authz.cm.ca.CA; +import com.att.authz.cm.validation.Validator; +import com.att.cadi.Symm; +import com.att.cadi.cm.CertException; +import com.att.cadi.cm.Factory; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; + + +/** + * Additional Factory mechanisms for CSRs, and BouncyCastle. The main Factory + * utilizes only Java abstractions, and is useful in Client code. + * + + * + */ +public class BCFactory extends Factory { + private static final JcaContentSignerBuilder jcsb; + + + static { + // Bouncy + jcsb = new JcaContentSignerBuilder(Factory.SIG_ALGO); + } + + public static ContentSigner contentSigner(PrivateKey pk) throws OperatorCreationException { + return jcsb.build(pk); + } + + public static String toString(Trans trans, PKCS10CertificationRequest csr) throws IOException, CertException { + TimeTaken tt = trans.start("CSR to String", Env.SUB); + try { + if(csr==null) { + throw new CertException("x509 Certificate Request not built"); + } + return textBuilder("CERTIFICATE REQUEST",csr.getEncoded()); + }finally { + tt.done(); + } + } + + public static PKCS10CertificationRequest toCSR(Trans trans, File file) throws IOException { + TimeTaken tt = trans.start("Reconstitute CSR", Env.SUB); + try { + FileReader fr = new FileReader(file); + return new PKCS10CertificationRequest(decode(strip(fr))); + } finally { + tt.done(); + } + } + + public static byte[] sign(Trans trans, ASN1Object toSign, PrivateKey pk) throws IOException, InvalidKeyException, SignatureException, NoSuchAlgorithmException { + TimeTaken tt = trans.start("Encode Security Object", Env.SUB); + try { + return sign(trans,toSign.getEncoded(),pk); + } finally { + tt.done(); + } + } + + public static CSRMeta createCSRMeta(CA ca,final String args[]) throws IllegalArgumentException, IllegalAccessException, CertException { + CSRMeta csr = new CSRMeta(); + ca.stdFields().set(csr); + //TODO should we checkDigest? +// digest = ca.messageDigest(); + + Field[] fld = CSRMeta.class.getDeclaredFields(); + for(int i=0;i+1 fqdns) throws CertException { + CSRMeta csr = new CSRMeta(); + boolean first = true; + // Set CN (and SAN) + for(String fqdn : fqdns) { + if(first) { + first = false; + csr.cn(fqdn); + } else { + csr.san(fqdn); + } + } + + csr.challenge(new String(Symm.randomGen(24))); + ca.stdFields().set(csr); + csr.mechID(mechid); + csr.email(sponsorEmail); + String errs = validate(csr); + if(errs!=null) { + throw new CertException(errs); + } + return csr; + } + + private static String validate(CSRMeta csr) { + Validator v = new Validator(); + if(v.nullOrBlank("cn", csr.cn()) + .nullOrBlank("mechID", csr.mechID()) + .nullOrBlank("email", csr.email()) + .nullOrBlank("o",csr.o()) + .nullOrBlank("l",csr.l()) + .nullOrBlank("st",csr.st()) + .nullOrBlank("c",csr.c()) + .err()) { + return v.errs(); + } else { + return null; + } + } + + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/cert/CSRMeta.java b/authz-certman/src/main/java/com/att/authz/cm/cert/CSRMeta.java new file mode 100644 index 00000000..91168dc9 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/cert/CSRMeta.java @@ -0,0 +1,330 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.cert; + +import java.io.IOException; +import java.math.BigInteger; +import java.security.KeyPair; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; + +import org.bouncycastle.asn1.ASN1Sequence; +import org.bouncycastle.asn1.DERPrintableString; +import org.bouncycastle.asn1.pkcs.Attribute; +import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.asn1.x500.X500NameBuilder; +import org.bouncycastle.asn1.x500.style.BCStyle; +import org.bouncycastle.asn1.x509.Extension; +import org.bouncycastle.asn1.x509.Extensions; +import org.bouncycastle.asn1.x509.GeneralName; +import org.bouncycastle.asn1.x509.GeneralNames; +import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; +import org.bouncycastle.cert.X509v3CertificateBuilder; +import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.pkcs.PKCS10CertificationRequest; +import org.bouncycastle.pkcs.PKCS10CertificationRequestBuilder; +import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder; + +import com.att.cadi.cm.CertException; +import com.att.cadi.cm.Factory; +import com.att.inno.env.Trans; + +public class CSRMeta { + private String environment; + private String cn; + private String mechID; + private String email; + private String o; + private String l; + private String st; + private String c; + private String challenge; + + private ArrayList sanList = new ArrayList(); + + private KeyPair keyPair; + private X500Name name = null; + private SecureRandom random = new SecureRandom(); + + public X500Name x500Name() throws IOException { + if(name==null) { + X500NameBuilder xnb = new X500NameBuilder(); + xnb.addRDN(BCStyle.CN,cn); + xnb.addRDN(BCStyle.E,email); + if(environment==null) { + xnb.addRDN(BCStyle.OU,mechID); + } else { + xnb.addRDN(BCStyle.OU,mechID+':'+environment); + } + xnb.addRDN(BCStyle.O,o); + xnb.addRDN(BCStyle.L,l); + xnb.addRDN(BCStyle.ST,st); + xnb.addRDN(BCStyle.C,c); + name = xnb.build(); + } + return name; + } + + + public PKCS10CertificationRequest generateCSR(Trans trans) throws IOException, CertException { + PKCS10CertificationRequestBuilder builder = new JcaPKCS10CertificationRequestBuilder(x500Name(),keypair(trans).getPublic()); + if(challenge!=null) { + DERPrintableString password = new DERPrintableString(challenge); + builder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_challengePassword, password); + } + + if(sanList.size()>0) { + GeneralName[] gna = new GeneralName[sanList.size()]; + int i=-1; + for(String s : sanList) { + gna[++i]=new GeneralName(GeneralName.dNSName,s); + } + + builder.addAttribute( + PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, + new Extensions(new Extension[] { + new Extension(Extension.subjectAlternativeName,false,new GeneralNames(gna).getEncoded()) + }) + ); + } +// builder.addAttribute(Extension.basicConstraints,new BasicConstraints(false)) +// .addAttribute(Extension.keyUsage, new KeyUsage(KeyUsage.digitalSignature +// | KeyUsage.keyEncipherment)); + try { + return builder.build(BCFactory.contentSigner(keypair(trans).getPrivate())); + } catch (OperatorCreationException e) { + throw new CertException(e); + } + } + + @SuppressWarnings("deprecation") + public static void dump(PKCS10CertificationRequest csr) { + Attribute[] certAttributes = csr.getAttributes(); + for (Attribute attribute : certAttributes) { + if (attribute.getAttrType().equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) { + Extensions extensions = Extensions.getInstance(attribute.getAttrValues().getObjectAt(0)); +// Extension ext = extensions.getExtension(Extension.subjectAlternativeName); + GeneralNames gns = GeneralNames.fromExtensions(extensions,Extension.subjectAlternativeName); + GeneralName[] names = gns.getNames(); + for(int k=0; k < names.length; k++) { + String title = ""; + if(names[k].getTagNo() == GeneralName.dNSName) { + title = "dNSName"; + } + else if(names[k].getTagNo() == GeneralName.iPAddress) { + title = "iPAddress"; + // Deprecated, but I don't see anything better to use. + names[k].toASN1Object(); + } + else if(names[k].getTagNo() == GeneralName.otherName) { + title = "otherName"; + } + System.out.println(title + ": "+ names[k].getName()); + } + } + } + } + + public X509Certificate initialConversationCert(Trans trans) throws IOException, CertificateException, OperatorCreationException { + GregorianCalendar gc = new GregorianCalendar(); + Date start = gc.getTime(); + gc.add(GregorianCalendar.DAY_OF_MONTH,2); + Date end = gc.getTime(); + X509v3CertificateBuilder xcb = new X509v3CertificateBuilder( + x500Name(), + new BigInteger(12,random), // replace with Serialnumber scheme + start, + end, + x500Name(), +// SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(caCert.getPublicKey().getEn) + new SubjectPublicKeyInfo(ASN1Sequence.getInstance(keypair(trans).getPublic().getEncoded())) + ); + return new JcaX509CertificateConverter().getCertificate( + xcb.build(BCFactory.contentSigner(keypair(trans).getPrivate()))); + } + + public CSRMeta san(String v) { + sanList.add(v); + return this; + } + + public List sans() { + return sanList; + } + + + public KeyPair keypair(Trans trans) { + if(keyPair == null) { + keyPair = Factory.generateKeyPair(trans); + } + return keyPair; + } + + /** + * @return the cn + */ + public String cn() { + return cn; + } + + + /** + * @param cn the cn to set + */ + public void cn(String cn) { + this.cn = cn; + } + + /** + * Environment of Service MechID is good for + */ + public void environment(String env) { + environment = env; + } + + /** + * + * @return + */ + public String environment() { + return environment; + } + + /** + * @return the mechID + */ + public String mechID() { + return mechID; + } + + + /** + * @param mechID the mechID to set + */ + public void mechID(String mechID) { + this.mechID = mechID; + } + + + /** + * @return the email + */ + public String email() { + return email; + } + + + /** + * @param email the email to set + */ + public void email(String email) { + this.email = email; + } + + + /** + * @return the o + */ + public String o() { + return o; + } + + + /** + * @param o the o to set + */ + public void o(String o) { + this.o = o; + } + + /** + * + * @return the l + */ + public String l() { + return l; + } + + /** + * @param l the l to set + */ + public void l(String l) { + this.l=l; + } + + /** + * @return the st + */ + public String st() { + return st; + } + + + /** + * @param st the st to set + */ + public void st(String st) { + this.st = st; + } + + + /** + * @return the c + */ + public String c() { + return c; + } + + + /** + * @param c the c to set + */ + public void c(String c) { + this.c = c; + } + + + /** + * @return the challenge + */ + public String challenge() { + return challenge; + } + + + /** + * @param challenge the challenge to set + */ + public void challenge(String challenge) { + this.challenge = challenge; + } + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/cert/StandardFields.java b/authz-certman/src/main/java/com/att/authz/cm/cert/StandardFields.java new file mode 100644 index 00000000..e9c2457a --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/cert/StandardFields.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.cert; + +import com.att.cadi.cm.CertException; + +public interface StandardFields { + public void set(CSRMeta csr) throws CertException; +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/data/CertDrop.java b/authz-certman/src/main/java/com/att/authz/cm/data/CertDrop.java new file mode 100644 index 00000000..c0a219db --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/data/CertDrop.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.data; + +public class CertDrop { + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/data/CertRenew.java b/authz-certman/src/main/java/com/att/authz/cm/data/CertRenew.java new file mode 100644 index 00000000..4c13ab40 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/data/CertRenew.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.data; + +public class CertRenew { + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/data/CertReq.java b/authz-certman/src/main/java/com/att/authz/cm/data/CertReq.java new file mode 100644 index 00000000..6806a588 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/data/CertReq.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.data; + +import java.util.List; + +import javax.xml.datatype.XMLGregorianCalendar; + +import com.att.authz.cm.ca.CA; +import com.att.authz.cm.cert.BCFactory; +import com.att.authz.cm.cert.CSRMeta; +import com.att.cadi.cm.CertException; + +public class CertReq { + // These cannot be null + public CA certAuthority; + public String mechid; + public List fqdns; + // Notify + public List emails; + + + // These may be null + public String sponsor; + public XMLGregorianCalendar start, end; + + public CSRMeta getCSRMeta() throws CertException { + return BCFactory.createCSRMeta(certAuthority, mechid, sponsor,fqdns); + } +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/data/CertResp.java b/authz-certman/src/main/java/com/att/authz/cm/data/CertResp.java new file mode 100644 index 00000000..8257e5cf --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/data/CertResp.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.data; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.security.KeyPair; +import java.security.cert.X509Certificate; + +import com.att.authz.cm.cert.CSRMeta; +import com.att.cadi.cm.CertException; +import com.att.cadi.cm.Factory; +import com.att.inno.env.Trans; + +public class CertResp { + public CertResp(Trans trans, X509Certificate x509, CSRMeta csrMeta, String[] notes) throws IOException, GeneralSecurityException, CertException { + keyPair = csrMeta.keypair(trans); + privateKey = Factory.toString(trans, keyPair.getPrivate()); + certString = Factory.toString(trans,x509); + challenge=csrMeta.challenge(); + this.notes = notes; + } + private KeyPair keyPair; + private String challenge; + + private String privateKey, certString; + private String[] notes; + + + public String asCertString() { + return certString; + } + + public String privateString() throws IOException { + return privateKey; + } + + public String challenge() { + return challenge==null?"":challenge; + } + + public String[] notes() { + return notes; + } +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/facade/Facade.java b/authz-certman/src/main/java/com/att/authz/cm/facade/Facade.java new file mode 100644 index 00000000..249f218e --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/facade/Facade.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.facade; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.cm.mapper.Mapper; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; + + +/** + * + * + */ +public interface Facade { + +///////////////////// STANDARD ELEMENTS ////////////////// + /** + * @param trans + * @param response + * @param result + */ + void error(AuthzTrans trans, HttpServletResponse response, Result result); + + /** + * + * @param trans + * @param response + * @param status + */ + void error(AuthzTrans trans, HttpServletResponse response, int status, String msg, String ... detail); + + /** + * Permission checker + * + * @param trans + * @param resp + * @param perm + * @return + * @throws IOException + */ + Result check(AuthzTrans trans, HttpServletResponse resp, String perm) throws IOException; + + /** + * + * @return + */ + public Mapper mapper(); + +///////////////////// STANDARD ELEMENTS ////////////////// + + /** + * + * @param trans + * @param resp + * @param rservlet + * @return + */ + public abstract Result requestCert(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, boolean withTrust); + + /** + * + * @param trans + * @param req + * @param resp + * @return + */ + public abstract Result renewCert(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, boolean withTrust); + + /** + * + * @param trans + * @param req + * @param resp + * @return + */ + public abstract Result dropCert(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + /** + * + * @param trans + * @param req + * @param resp + * @return + */ + Result createArtifacts(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + /** + * + * @param trans + * @param req + * @param resp + * @return + */ + Result readArtifacts(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + /** + * + * @param trans + * @param resp + * @param mechid + * @param machine + * @return + */ + Result readArtifacts(AuthzTrans trans, HttpServletResponse resp, String mechid, String machine); + + /** + * + * @param trans + * @param req + * @param resp + * @return + */ + Result updateArtifacts(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + /** + * + * @param trans + * @param req + * @param resp + * @return + */ + Result deleteArtifacts(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + /** + * + * @param trans + * @param resp + * @param mechid + * @param machine + * @return + */ + Result deleteArtifacts(AuthzTrans trans, HttpServletResponse resp, String mechid, String machine); + + + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/facade/Facade1_0.java b/authz-certman/src/main/java/com/att/authz/cm/facade/Facade1_0.java new file mode 100644 index 00000000..6dd012dd --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/facade/Facade1_0.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.facade; + +import com.att.authz.cm.mapper.Mapper; +import com.att.authz.cm.service.CMService; +import com.att.authz.cm.service.CertManAPI; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; + +import aaf.v2_0.Error; +import certman.v1_0.Artifacts; +import certman.v1_0.BaseRequest; +import certman.v1_0.CertInfo; + +/** + * + */ +public class Facade1_0 extends FacadeImpl { + public Facade1_0(CertManAPI certman, + CMService service, + Mapper mapper, + Data.TYPE type) throws APIException { + super(certman, service, mapper, type); + } +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/facade/FacadeFactory.java b/authz-certman/src/main/java/com/att/authz/cm/facade/FacadeFactory.java new file mode 100644 index 00000000..e9e5d54a --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/facade/FacadeFactory.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.facade; + +import com.att.authz.cm.mapper.Mapper1_0; +import com.att.authz.cm.service.CertManAPI; +import com.att.authz.cm.service.CMService; +import com.att.authz.env.AuthzTrans; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; + + +public class FacadeFactory { + public static Facade1_0 v1_0(CertManAPI certman, AuthzTrans trans, CMService service, Data.TYPE type) throws APIException { + return new Facade1_0( + certman, + service, + new Mapper1_0(), + type); + } + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/facade/FacadeImpl.java b/authz-certman/src/main/java/com/att/authz/cm/facade/FacadeImpl.java new file mode 100644 index 00000000..22421442 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/facade/FacadeImpl.java @@ -0,0 +1,493 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.facade; + +import static com.att.authz.layer.Result.ERR_ActionNotCompleted; +import static com.att.authz.layer.Result.ERR_BadData; +import static com.att.authz.layer.Result.ERR_ConflictAlreadyExists; +import static com.att.authz.layer.Result.ERR_Denied; +import static com.att.authz.layer.Result.ERR_NotFound; +import static com.att.authz.layer.Result.ERR_NotImplemented; +import static com.att.authz.layer.Result.ERR_Policy; +import static com.att.authz.layer.Result.ERR_Security; +import static com.att.authz.layer.Result.OK; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.cm.api.API_Cert; +import com.att.authz.cm.ca.CA; +import com.att.authz.cm.data.CertResp; +import com.att.authz.cm.mapper.Mapper; +import com.att.authz.cm.mapper.Mapper.API; +import com.att.authz.cm.service.CMService; +import com.att.authz.cm.service.CertManAPI; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cadi.aaf.AAFPermission; +import com.att.dao.aaf.cass.ArtiDAO; +import com.att.dao.aaf.cass.Status; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Split; +import com.att.rosetta.env.RosettaDF; +import com.att.rosetta.env.RosettaData; + +/** + * AuthzFacade + * + * This Service Facade encapsulates the essence of the API Service can do, and provides + * a single created object for elements such as RosettaDF. + * + * The Responsibilities of this class are to: + * 1) Interact with the Service Implementation (which might be supported by various kinds of Backend Storage) + * 2) Validate incoming data (if applicable) + * 3) Convert the Service response into the right Format, and mark the Content Type + * a) In the future, we may support multiple Response Formats, aka JSON or XML, based on User Request. + * 4) Log Service info, warnings and exceptions as necessary + * 5) When asked by the API layer, this will create and write Error content to the OutputStream + * + * Note: This Class does NOT set the HTTP Status Code. That is up to the API layer, so that it can be + * clearly coordinated with the API Documentation + * + * + */ +public abstract class FacadeImpl extends com.att.authz.layer.FacadeImpl implements Facade + { + private static final String REQUEST_CERT = "Request New Certificate"; + private static final String RENEW_CERT = "Renew Certificate"; + private static final String DROP_CERT = "Drop Certificate"; + private static final String CREATE_ARTIFACTS = "Create Deployment Artifact"; + private static final String READ_ARTIFACTS = "Read Deployment Artifact"; + private static final String UPDATE_ARTIFACTS = "Update Deployment Artifact"; + private static final String DELETE_ARTIFACTS = "Delete Deployment Artifact"; + + private CMService service; + + private final RosettaDF errDF; + private final RosettaDF certRequestDF, certRenewDF, certDropDF; + private final RosettaDF certDF; + private final RosettaDF artiDF; + private Mapper mapper; + private Slot sCertAuth; + private CertManAPI certman; + private final String voidResp; + + public FacadeImpl(CertManAPI certman, + CMService service, + Mapper mapper, + Data.TYPE dataType) throws APIException { + this.service = service; + this.mapper = mapper; + this.certman = certman; + AuthzEnv env = certman.env; + (errDF = env.newDataFactory(mapper.getClass(API.ERROR))).in(dataType).out(dataType); + (certRequestDF = env.newDataFactory(mapper.getClass(API.CERT_REQ))).in(dataType).out(dataType); + (certRenewDF = env.newDataFactory(mapper.getClass(API.CERT_RENEW))).in(dataType).out(dataType); + (certDropDF = env.newDataFactory(mapper.getClass(API.CERT_DROP))).in(dataType).out(dataType); + (certDF = env.newDataFactory(mapper.getClass(API.CERT))).in(dataType).out(dataType); + (artiDF = env.newDataFactory(mapper.getClass(API.ARTIFACTS))).in(dataType).out(dataType); + sCertAuth = env.slot(API_Cert.CERT_AUTH); + if(artiDF.getOutType().name().contains("xml")) { + voidResp = "application/Void+xml;charset=utf-8;version=1.0,application/xml;version=1.0,*/*"; + } else { + voidResp = "application/Void+json;charset=utf-8;version=1.0,application/json;version=1.0,*/*"; + } + } + + public Mapper mapper() { + return mapper; + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#error(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, int) + * + * Note: Conforms to AT&T TSS RESTful Error Structure + */ + @Override + public void error(AuthzTrans trans, HttpServletResponse response, Result result) { + error(trans, response, result.status, + result.details==null?"":result.details.trim(), + result.variables==null?new String[0]:result.variables); + } + + @Override + public void error(AuthzTrans trans, HttpServletResponse response, int status, final String _msg, final String ... _detail) { + String msgId; + String prefix; + switch(status) { + case 202: + case ERR_ActionNotCompleted: + msgId = "SVC1202"; + prefix = "Accepted, Action not complete"; + response.setStatus(/*httpstatus=*/202); + break; + + case 403: + case ERR_Policy: + case ERR_Security: + case ERR_Denied: + msgId = "SVC1403"; + prefix = "Forbidden"; + response.setStatus(/*httpstatus=*/403); + break; + + case 404: + case ERR_NotFound: + msgId = "SVC1404"; + prefix = "Not Found"; + response.setStatus(/*httpstatus=*/404); + break; + + case 406: + case ERR_BadData: + msgId="SVC1406"; + prefix = "Not Acceptable"; + response.setStatus(/*httpstatus=*/406); + break; + + case 409: + case ERR_ConflictAlreadyExists: + msgId = "SVC1409"; + prefix = "Conflict Already Exists"; + response.setStatus(/*httpstatus=*/409); + break; + + case 501: + case ERR_NotImplemented: + msgId = "SVC1501"; + prefix = "Not Implemented"; + response.setStatus(/*httpstatus=*/501); + break; + + + default: + msgId = "SVC1500"; + prefix = "General Service Error"; + response.setStatus(/*httpstatus=*/500); + break; + } + + try { + StringBuilder holder = new StringBuilder(); + errDF.newData(trans).load( + mapper().errorFromMessage(holder, msgId,prefix + ": " + _msg,_detail)).to(response.getOutputStream()); + + holder.append(']'); + trans.checkpoint( + "ErrResp [" + + holder, + Env.ALWAYS); + } catch (Exception e) { + trans.error().log(e,"unable to send response for",_msg); + } + } + + @Override + public Result check(AuthzTrans trans, HttpServletResponse resp, String perm) throws IOException { + String[] p = Split.split('|',perm); + if(p.length!=3) { + return Result.err(Result.ERR_BadData,"Invalid Perm String"); + } + AAFPermission ap = new AAFPermission(p[0],p[1],p[2]); + if(certman.aafLurPerm.fish(trans.getUserPrincipal(), ap)) { + resp.setContentType(voidResp); + resp.getOutputStream().write(0); + return Result.ok(); + } else { + return Result.err(Result.ERR_Denied,"%s does not have %s",trans.user(),ap.getKey()); + } + } + + /* (non-Javadoc) + * @see com.att.auth.certman.facade.Facade#requestCert(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public Result requestCert(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, boolean withTrust) { + TimeTaken tt = trans.start(REQUEST_CERT, Env.SUB|Env.ALWAYS); + try { + REQ request; + try { + Data rd = certRequestDF.newData().load(req.getInputStream()); + request = rd.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,REQUEST_CERT); + return Result.err(Result.ERR_BadData,"Invalid Input"); + } + + Result rcr = service.requestCert(trans,mapper.toReq(trans,request)); + if(rcr.notOK()) { + return Result.err(rcr); + } + + CA certAuth = trans.get(sCertAuth,null); + Result rc = mapper.toCert(trans, rcr, withTrust?certAuth.getTrustChain():null); + switch(rc.status) { + case OK: + RosettaData data = certDF.newData(trans).load(rc.value); + data.to(resp.getOutputStream()); + + setContentType(resp,certDF.getOutType()); + return Result.ok(); + default: + return Result.err(rc); + } + + } catch (Exception e) { + trans.error().log(e,IN,REQUEST_CERT); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result renewCert(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, boolean withTrust) { + TimeTaken tt = trans.start(RENEW_CERT, Env.SUB|Env.ALWAYS); + try { + REQ request; + try { + Data rd = certRenewDF.newData().load(req.getInputStream()); + request = rd.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,RENEW_CERT); + return Result.err(Result.ERR_BadData,"Invalid Input"); + } + + String certAuth = trans.get(sCertAuth,null); + Result rcr = service.renewCert(trans,mapper.toRenew(trans,request)); + Result rc = mapper.toCert(trans, rcr, certman.getTrustChain(certAuth)); + + switch(rc.status) { + case OK: + RosettaData data = certDF.newData(trans).load(rc.value); + data.to(resp.getOutputStream()); + + setContentType(resp,certDF.getOutType()); + return Result.ok(); + default: + return Result.err(rc); + } + } catch (Exception e) { + trans.error().log(e,IN,RENEW_CERT); + return Result.err(e); + } finally { + tt.done(); + } + + } + + @Override + public Result dropCert(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(DROP_CERT, Env.SUB|Env.ALWAYS); + try { + REQ request; + try { + Data rd = certDropDF.newData().load(req.getInputStream()); + request = rd.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,DROP_CERT); + return Result.err(Result.ERR_BadData,"Invalid Input"); + } + + Result rv = service.dropCert(trans,mapper.toDrop(trans, request)); + switch(rv.status) { + case OK: + setContentType(resp,certRequestDF.getOutType()); + return Result.ok(); + default: + return Result.err(rv); + } + } catch (Exception e) { + trans.error().log(e,IN,DROP_CERT); + return Result.err(e); + } finally { + tt.done(); + } + } + + //////////////////////////// + // Artifacts + //////////////////////////// + @Override + public Result createArtifacts(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(CREATE_ARTIFACTS, Env.SUB); + try { + ARTIFACTS arti; + try { + Data rd = artiDF.newData().load(req.getInputStream()); + arti = rd.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,CREATE_ARTIFACTS); + return Result.err(Result.ERR_BadData,"Invalid Input"); + } + + return service.createArtifact(trans,mapper.toArtifact(trans,arti)); + } catch (Exception e) { + + trans.error().log(e,IN,CREATE_ARTIFACTS); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result readArtifacts(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(READ_ARTIFACTS, Env.SUB); + try { + String mechid = req.getParameter("mechid"); + String machine = req.getParameter("machine"); + + Result ra; + if( machine !=null && mechid == null) { + ra = mapper.fromArtifacts(service.readArtifactsByMachine(trans, machine)); + } else if(mechid!=null && machine==null) { + ra = mapper.fromArtifacts(service.readArtifactsByMechID(trans, mechid)); + } else if(mechid!=null && machine!=null) { + ArtiDAO.Data add = new ArtiDAO.Data(); + add.mechid = mechid; + add.machine = machine; + ra = mapper.fromArtifacts(service.readArtifacts(trans,add)); + } else { + ra = Result.err(Status.ERR_BadData,"Invalid request inputs"); + } + + if(ra.isOK()) { + RosettaData data = artiDF.newData(trans).load(ra.value); + data.to(resp.getOutputStream()); + setContentType(resp,artiDF.getOutType()); + return Result.ok(); + } else { + return Result.err(ra); + } + + } catch (Exception e) { + trans.error().log(e,IN,READ_ARTIFACTS); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result readArtifacts(AuthzTrans trans, HttpServletResponse resp, String mechid, String machine) { + TimeTaken tt = trans.start(READ_ARTIFACTS, Env.SUB); + try { + ArtiDAO.Data add = new ArtiDAO.Data(); + add.mechid = mechid; + add.machine = machine; + Result ra = mapper.fromArtifacts(service.readArtifacts(trans,add)); + if(ra.isOK()) { + RosettaData data = artiDF.newData(trans).load(ra.value); + data.to(resp.getOutputStream()); + setContentType(resp,artiDF.getOutType()); + return Result.ok(); + } else { + return Result.err(ra); + } + } catch (Exception e) { + trans.error().log(e,IN,READ_ARTIFACTS); + return Result.err(e); + } finally { + tt.done(); + } + } + + + @Override + public Result updateArtifacts(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(UPDATE_ARTIFACTS, Env.SUB); + try { + ARTIFACTS arti; + try { + Data rd = artiDF.newData().load(req.getInputStream()); + arti = rd.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,UPDATE_ARTIFACTS); + return Result.err(Result.ERR_BadData,"Invalid Input"); + } + + return service.updateArtifact(trans,mapper.toArtifact(trans,arti)); + } catch (Exception e) { + trans.error().log(e,IN,UPDATE_ARTIFACTS); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deleteArtifacts(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(DELETE_ARTIFACTS, Env.SUB); + try { + ARTIFACTS arti; + try { + Data rd = artiDF.newData().load(req.getInputStream()); + arti = rd.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,DELETE_ARTIFACTS); + return Result.err(Result.ERR_BadData,"Invalid Input"); + } + + Result rv = service.deleteArtifact(trans,mapper.toArtifact(trans,arti)); + switch(rv.status) { + case OK: + setContentType(resp,artiDF.getOutType()); + } + return rv; + } catch (Exception e) { + trans.error().log(e,IN,DELETE_ARTIFACTS); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deleteArtifacts(AuthzTrans trans, HttpServletResponse resp, String mechid, String machine) { + TimeTaken tt = trans.start(DELETE_ARTIFACTS, Env.SUB); + try { + Result rv = service.deleteArtifact(trans, mechid, machine); + switch(rv.status) { + case OK: + setContentType(resp,artiDF.getOutType()); + } + return rv; + } catch (Exception e) { + trans.error().log(e,IN,DELETE_ARTIFACTS); + return Result.err(e); + } finally { + tt.done(); + } + } + + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/mapper/Mapper.java b/authz-certman/src/main/java/com/att/authz/cm/mapper/Mapper.java new file mode 100644 index 00000000..7218b150 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/mapper/Mapper.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.mapper; + +import java.io.IOException; +import java.util.List; + +import com.att.authz.cm.data.CertDrop; +import com.att.authz.cm.data.CertRenew; +import com.att.authz.cm.data.CertReq; +import com.att.authz.cm.data.CertResp; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.ArtiDAO; + +public interface Mapper +{ + public enum API{ERROR,VOID,CERT,CERT_REQ,CERT_RENEW,CERT_DROP,ARTIFACTS}; + + public Class getClass(API api); + public A newInstance(API api); + + public ERROR errorFromMessage(StringBuilder holder, String msgID, String text, String... detail); + + public Result toCert(AuthzTrans trans, Result in, String[] trustChain) throws IOException; + public Result toReq(AuthzTrans trans, REQ req); + public Result toRenew(AuthzTrans trans, REQ req); + public Result toDrop(AuthzTrans trans, REQ req); + + public List toArtifact(AuthzTrans trans, ARTIFACTS arti); + public Result fromArtifacts(Result> readArtifactsByMachine); +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/mapper/Mapper1_0.java b/authz-certman/src/main/java/com/att/authz/cm/mapper/Mapper1_0.java new file mode 100644 index 00000000..63c4f6a9 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/mapper/Mapper1_0.java @@ -0,0 +1,246 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.mapper; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import aaf.v2_0.Error; +import certman.v1_0.Artifacts; +import certman.v1_0.Artifacts.Artifact; +import certman.v1_0.BaseRequest; +import certman.v1_0.CertInfo; +import certman.v1_0.CertificateDrop; +import certman.v1_0.CertificateRenew; +import certman.v1_0.CertificateRequest; + +import com.att.authz.cm.data.CertDrop; +import com.att.authz.cm.data.CertRenew; +import com.att.authz.cm.data.CertReq; +import com.att.authz.cm.data.CertResp; +import com.att.authz.cm.validation.Validator; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cadi.aaf.v2_0.AAFCon; +import com.att.cadi.util.Vars; +import com.att.dao.aaf.cass.ArtiDAO; +import com.att.dao.aaf.cass.ArtiDAO.Data; + + +public class Mapper1_0 implements Mapper { + + @Override + public Class getClass(API api) { + switch(api) { + case CERT_REQ: return CertificateRequest.class; + case CERT_RENEW: return CertificateRenew.class; + case CERT_DROP: return CertificateDrop.class; + case CERT: return CertInfo.class; + case ARTIFACTS: return Artifacts.class; + case ERROR: return Error.class; + case VOID: return Void.class; + } + return null; + } + + @SuppressWarnings("unchecked") + @Override + public A newInstance(API api) { + switch(api) { + case CERT_REQ: return (A) new CertificateRequest(); + case CERT_RENEW: return (A) new CertificateRenew(); + case CERT_DROP: return (A) new CertificateDrop(); + case CERT: return (A) new CertInfo(); + case ARTIFACTS: return (A) new Artifacts(); + case ERROR: return (A)new Error(); + case VOID: return null; + } + return null; + } + + ////////////// Mapping Functions ///////////// + @Override + public Error errorFromMessage(StringBuilder holder, String msgID, String text, String... var) { + Error err = new Error(); + err.setMessageId(msgID); + // AT&T Restful Error Format requires numbers "%" placements + err.setText(Vars.convert(holder, text, var)); + for(String s : var) { + err.getVariables().add(s); + } + return err; + } + + /* (non-Javadoc) + * @see com.att.authz.certman.mapper.Mapper#toCert(com.att.authz.env.AuthzTrans, com.att.authz.layer.Result) + */ + @Override + public Result toCert(AuthzTrans trans, Result in, String[] trustChain) throws IOException { + if(in.isOK()) { + CertResp cin = in.value; + CertInfo cout = newInstance(API.CERT); + cout.setPrivatekey(cin.privateString()); + String value; + if((value=cin.challenge())!=null) { + cout.setChallenge(value); + } + cout.getCerts().add(cin.asCertString()); + if(trustChain!=null) { + for(String c : trustChain) { + cout.getCerts().add(c); + } + } + if(cin.notes()!=null) { + boolean first = true; + StringBuilder sb = new StringBuilder(); + for(String n : cin.notes()) { + if(first) { + first = false; + } else { + sb.append('\n'); + } + sb.append(n); + } + cout.setNotes(sb.toString()); + } + return Result.ok(cout); + } else { + return Result.err(in); + } + } + + /* (non-Javadoc) + * @see com.att.authz.certman.mapper.Mapper#toReq(com.att.authz.env.AuthzTrans, java.lang.Object) + */ + @Override + public Result toReq(AuthzTrans trans, BaseRequest req) { + CertificateRequest in; + try { + in = (CertificateRequest)req; + } catch(ClassCastException e) { + return Result.err(Result.ERR_BadData,"Request is not a CertificateRequest"); + } + + CertReq out = new CertReq(); + Validator v = new Validator(); + if(v.isNull("CertRequest", req) + .nullOrBlank("MechID", out.mechid=in.getMechid()) + .nullBlankMin("FQDNs", out.fqdns=in.getFqdns(),1) + .err()) { + return Result.err(Result.ERR_BadData, v.errs()); + } + out.emails = in.getEmail(); + out.sponsor=in.getSponsor(); + out.start = in.getStart(); + out.end = in.getEnd(); + return Result.ok(out); + } + + /* (non-Javadoc) + * @see com.att.authz.certman.mapper.Mapper#toRenew(com.att.authz.env.AuthzTrans, java.lang.Object) + */ + @Override + public Result toRenew(AuthzTrans trans, BaseRequest req) { + return Result.err(Result.ERR_NotImplemented,"Not Implemented... yet"); + } + + /* (non-Javadoc) + * @see com.att.authz.certman.mapper.Mapper#toDrop(com.att.authz.env.AuthzTrans, java.lang.Object) + */ + @Override + public Result toDrop(AuthzTrans trans, BaseRequest req) { + return Result.err(Result.ERR_NotImplemented,"Not Implemented... yet"); + } + + /* (non-Javadoc) + * @see com.att.authz.cm.mapper.Mapper#toArtifact(com.att.authz.env.AuthzTrans, java.lang.Object) + */ + @Override + public List toArtifact(AuthzTrans trans, Artifacts artifacts) { + List ladd = new ArrayList(); + for(Artifact arti : artifacts.getArtifact()) { + ArtiDAO.Data data = new ArtiDAO.Data(); + data.mechid = arti.getMechid(); + data.machine = arti.getMachine(); + data.type(true).addAll(arti.getType()); + data.ca = arti.getCa(); + data.dir = arti.getDir(); + data.os_user = arti.getOsUser(); + // Optional (on way in) + data.appName = arti.getAppName(); + data.renewDays = arti.getRenewDays(); + data.notify = arti.getNotification(); + + // Ignored on way in for create/update + data.sponsor = arti.getSponsor(); + data.expires = null; + + // Derive Optional Data from Machine (Domain) if exists + if(data.machine!=null) { + if(data.ca==null) { + if(data.machine.endsWith(".att.com")) { + data.ca = "aaf"; // default + } + } + if(data.appName==null ) { + data.appName=AAFCon.reverseDomain(data.machine); + } + } + + ladd.add(data); + } + return ladd; + } + + /* (non-Javadoc) + * @see com.att.authz.cm.mapper.Mapper#fromArtifacts(com.att.authz.layer.Result) + */ + @Override + public Result fromArtifacts(Result> lArtiDAO) { + if(lArtiDAO.isOK()) { + Artifacts artis = new Artifacts(); + for(ArtiDAO.Data arti : lArtiDAO.value) { + Artifact a = new Artifact(); + a.setMechid(arti.mechid); + a.setMachine(arti.machine); + a.setSponsor(arti.sponsor); + a.setAppName(arti.appName); + a.setCa(arti.ca); + a.setDir(arti.dir); + a.getType().addAll(arti.type(false)); + a.setOsUser(arti.os_user); + a.setRenewDays(arti.renewDays); + a.setNotification(arti.notify); + artis.getArtifact().add(a); + } + return Result.ok(artis); + } else { + return Result.err(lArtiDAO); + } + } + + + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/service/CMService.java b/authz-certman/src/main/java/com/att/authz/cm/service/CMService.java new file mode 100644 index 00000000..9e6d5fa9 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/service/CMService.java @@ -0,0 +1,515 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.service; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import com.att.authz.cm.api.API_Cert; +import com.att.authz.cm.ca.CA; +import com.att.authz.cm.cert.BCFactory; +import com.att.authz.cm.cert.CSRMeta; +import com.att.authz.cm.data.CertDrop; +import com.att.authz.cm.data.CertRenew; +import com.att.authz.cm.data.CertReq; +import com.att.authz.cm.data.CertResp; +import com.att.authz.cm.validation.Validator; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.authz.org.Organization; +import com.att.authz.org.Organization.Identity; +import com.att.authz.org.OrganizationException; +import com.att.cadi.Hash; +import com.att.cadi.aaf.AAFPermission; +import com.att.cadi.aaf.v2_0.AAFCon; +import com.att.cadi.cm.Factory; +import com.att.dao.CassAccess; +import com.att.dao.DAO; +import com.att.dao.aaf.cass.ArtiDAO; +import com.att.dao.aaf.cass.CacheInfoDAO; +import com.att.dao.aaf.cass.CertDAO; +import com.att.dao.aaf.cass.CredDAO; +import com.att.dao.aaf.cass.HistoryDAO; +import com.att.dao.aaf.cass.Status; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.att.inno.env.Slot; +import com.att.inno.env.util.Chrono; +import com.datastax.driver.core.Cluster; + + +public class CMService { + // If we add more CAs, may want to parameterize + private static final int STD_RENEWAL = 30; + private static final int MAX_RENEWAL = 60; + private static final int MIN_RENEWAL = 10; + + public static final String REQUEST = "request"; + public static final String RENEW = "renew"; + public static final String DROP = "drop"; + public static final String SANS = "san"; + + private static final String[] NO_NOTES = new String[0]; + private Slot sCertAuth; + private final CertDAO certDAO; + private final CredDAO credDAO; + private final ArtiDAO artiDAO; + private DAO[] daos; + + @SuppressWarnings("unchecked") + public CMService(AuthzTrans trans, CertManAPI certman) throws APIException, IOException { + + sCertAuth = certman.env.slot(API_Cert.CERT_AUTH); + Cluster cluster; + try { + cluster = com.att.dao.CassAccess.cluster(certman.env,null); + } catch (IOException e) { + throw new APIException(e); + } + + // jg 4/2015 SessionFilter unneeded... DataStax already deals with Multithreading well + + HistoryDAO hd = new HistoryDAO(trans, cluster, CassAccess.KEYSPACE); + CacheInfoDAO cid = new CacheInfoDAO(trans, hd); + certDAO = new CertDAO(trans, hd, cid); + credDAO = new CredDAO(trans, hd, cid); + artiDAO = new ArtiDAO(trans, hd, cid); + + daos =(DAO[]) new DAO[] { + hd,cid,certDAO,credDAO,artiDAO + }; + + // Setup Shutdown Hooks for Cluster and Pooled Sessions + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + for(DAO dao : daos) { + dao.close(trans); + } + +// sessionFilter.destroy(); + cluster.close(); + } + }); + } + + public Result requestCert(AuthzTrans trans,Result req) { + if(req.isOK()) { + CA ca = trans.get(sCertAuth, null); + if(ca==null) { + return Result.err(Result.err(Result.ERR_BadData, "Invalid Cert Authority requested")); + } + + // Allow only AAF CA without special permission + if(!ca.getName().equals("aaf") && !trans.fish( new AAFPermission(ca.getPermType(), ca.getName(), REQUEST))) { + return Result.err(Status.ERR_Denied, "'%s' does not have permission to request Certificates from Certificate Authority '%s'", + trans.user(),ca.getName()); + } + + List notes = null; + List fqdns; + String email = null; + + try { + Organization org = trans.org(); + + // Policy 1: Requests are only by Pre-Authorized Configurations + ArtiDAO.Data add = null; + try { + for(InetAddress ia : InetAddress.getAllByName(trans.ip())) { + Result> ra = artiDAO.read(trans, req.value.mechid,ia.getHostName()); + if(ra.isOKhasData()) { + add = ra.value.get(0); + break; + } + } + } catch (UnknownHostException e1) { + return Result.err(Result.ERR_BadData,"There is no host for %s",trans.ip()); + } + + if(add==null) { + return Result.err(Result.ERR_BadData,"There is no configuration for %s",req.value.mechid); + } + + // Policy 2: If Config marked as Expired, do not create or renew + Date now = new Date(); + if(add.expires!=null && now.after(add.expires)) { + return Result.err(Result.ERR_Policy,"Configuration for %s %s is expired %s",add.mechid,add.machine,Chrono.dateFmt.format(add.expires)); + } + + // Policy 3: MechID must be current + Identity muser = org.getIdentity(trans, add.mechid); + if(muser == null) { + return Result.err(Result.ERR_Policy,"MechID must exist in %s",org.getName()); + } + + // Policy 4: Sponsor must be current + Identity ouser = muser.owner(); + if(ouser==null) { + return Result.err(Result.ERR_Policy,"%s does not have a current sponsor at %s",add.mechid,org.getName()); + } else if(!ouser.isFound() || !ouser.isResponsible()) { + return Result.err(Result.ERR_Policy,"%s reports that %s cannot be responsible for %s",org.getName(),trans.user()); + } + + // Set Email from most current Sponsor + email = ouser.email(); + + // Policy 5: keep Artifact data current + if(!ouser.fullID().equals(add.sponsor)) { + add.sponsor = ouser.fullID(); + artiDAO.update(trans, add); + } + + // Policy 6: Requester must be granted Change permission in Namespace requested + String mechNS = AAFCon.reverseDomain(req.value.mechid); + if(mechNS==null) { + return Result.err(Status.ERR_Denied, "%s does not reflect a valid AAF Namespace",req.value.mechid); + } + + // Policy 7: Caller must be the MechID or have specifically delegated permissions + if(!trans.user().equals(req.value.mechid) && !trans.fish(new AAFPermission(mechNS + ".certman", ca.getName() , "request"))) { + return Result.err(Status.ERR_Denied, "%s must have access to modify x509 certs in NS %s",trans.user(),mechNS); + } + + + // Policy 8: SANs only allowed by Exception... need permission + fqdns = new ArrayList(); + fqdns.add(add.machine); // machine is first + if(req.value.fqdns.size()>1 && !trans.fish(new AAFPermission(ca.getPermType(), ca.getName(), SANS))) { + if(notes==null) {notes = new ArrayList();} + notes.add("Warning: Subject Alternative Names only allowed by Permission: Get CSO Exception. This Certificate will be created, but without SANs"); + } else { + for(String m : req.value.fqdns) { + if(!add.machine.equals(m)) { + fqdns.add(m); + } + } + } + + } catch (Exception e) { + trans.error().log(e); + return Result.err(Status.ERR_Denied,"MechID Sponsorship cannot be determined at this time. Try later"); + } + + CSRMeta csrMeta; + try { + csrMeta = BCFactory.createCSRMeta( + ca, + req.value.mechid, + email, + fqdns); + X509Certificate x509 = ca.sign(trans, csrMeta); + if(x509==null) { + return Result.err(Result.ERR_ActionNotCompleted,"x509 Certificate not signed by CA"); + } + CertDAO.Data cdd = new CertDAO.Data(); + cdd.ca=ca.getName(); + cdd.serial=x509.getSerialNumber(); + cdd.id=req.value.mechid; + cdd.x500=x509.getSubjectDN().getName(); + cdd.x509=Factory.toString(trans, x509); + certDAO.create(trans, cdd); + + CredDAO.Data crdd = new CredDAO.Data(); + crdd.other = Question.random.nextInt(); + crdd.cred=getChallenge256SaltedHash(csrMeta.challenge(),crdd.other); + crdd.expires = x509.getNotAfter(); + crdd.id = req.value.mechid; + crdd.ns = Question.domain2ns(crdd.id); + crdd.type = CredDAO.CERT_SHA256_RSA; + credDAO.create(trans, crdd); + + CertResp cr = new CertResp(trans,x509,csrMeta, compileNotes(notes)); + return Result.ok(cr); + } catch (Exception e) { + trans.error().log(e); + return Result.err(Result.ERR_ActionNotCompleted,e.getMessage()); + } + } else { + return Result.err(req); + } + } + + public Result renewCert(AuthzTrans trans, Result renew) { + if(renew.isOK()) { + return Result.err(Result.ERR_NotImplemented,"Not implemented yet"); + } else { + return Result.err(renew); + } + } + + public Result dropCert(AuthzTrans trans, Result drop) { + if(drop.isOK()) { + return Result.err(Result.ERR_NotImplemented,"Not implemented yet"); + } else { + return Result.err(drop); + } + } + + /////////////// + // Artifact + ////////////// + public Result createArtifact(AuthzTrans trans, List list) { + Validator v = new Validator().artisRequired(list, 1); + if(v.err()) { + return Result.err(Result.ERR_BadData,v.errs()); + } + for(ArtiDAO.Data add : list) { + try { + // Policy 1: MechID must exist in Org + Identity muser = trans.org().getIdentity(trans, add.mechid); + if(muser == null) { + return Result.err(Result.ERR_Denied,"%s is not valid for %s", add.mechid,trans.org().getName()); + } + + // Policy 2: MechID must have valid Organization Owner + Identity ouser = muser.owner(); + if(ouser == null) { + return Result.err(Result.ERR_Denied,"%s is not a valid Sponsor for %s at %s", + trans.user(),add.mechid,trans.org().getName()); + } + + // Policy 3: Calling ID must be MechID Owner + if(!trans.user().equals(ouser.fullID())) { + return Result.err(Result.ERR_Denied,"%s is not the Sponsor for %s at %s", + trans.user(),add.mechid,trans.org().getName()); + } + + // Policy 4: Renewal Days are between 10 and 60 (constants, may be parameterized) + if(add.renewDaysMAX_RENEWAL) { + add.renewDays = MAX_RENEWAL; + } + + // Policy 5: If Notify is blank, set to Owner's Email + if(add.notify==null || add.notify.length()==0) { + add.notify = "mailto:"+ouser.email(); + } + + // Set Sponsor from Golden Source + add.sponsor = ouser.fullID(); + + + } catch (OrganizationException e) { + return Result.err(e); + } + // Add to DB + Result rv = artiDAO.create(trans, add); + // TODO come up with Partial Reporting Scheme, or allow only one at a time. + if(rv.notOK()) { + return Result.err(rv); + } + } + return Result.ok(); + } + + public Result> readArtifacts(AuthzTrans trans, ArtiDAO.Data add) throws OrganizationException { + Validator v = new Validator().keys(add); + if(v.err()) { + return Result.err(Result.ERR_BadData,v.errs()); + } + String ns = AAFCon.reverseDomain(add.mechid); + + if( trans.user().equals(add.mechid) + || trans.fish(new AAFPermission(ns + ".access", "*", "read")) + || (trans.org().validate(trans,Organization.Policy.OWNS_MECHID,null,add.mechid))==null) { + return artiDAO.read(trans, add); + } else { + return Result.err(Result.ERR_Denied,"%s is not %s, is not the sponsor, and doesn't have delegated permission.",trans.user(),add.mechid); // note: reason is set by 2nd case, if 1st case misses + } + + } + + public Result> readArtifactsByMechID(AuthzTrans trans, String mechid) throws OrganizationException { + Validator v = new Validator().nullOrBlank("mechid", mechid); + if(v.err()) { + return Result.err(Result.ERR_BadData,v.errs()); + } + String ns = AAFCon.reverseDomain(mechid); + + String reason; + if(trans.fish(new AAFPermission(ns + ".access", "*", "read")) + || (reason=trans.org().validate(trans,Organization.Policy.OWNS_MECHID,null,mechid))==null) { + return artiDAO.readByMechID(trans, mechid); + } else { + return Result.err(Result.ERR_Denied,reason); // note: reason is set by 2nd case, if 1st case misses + } + + } + + public Result> readArtifactsByMachine(AuthzTrans trans, String machine) { + Validator v = new Validator().nullOrBlank("machine", machine); + if(v.err()) { + return Result.err(Result.ERR_BadData,v.errs()); + } + + // TODO do some checks? + + Result> rv = artiDAO.readByMachine(trans, machine); + return rv; + } + + public Result updateArtifact(AuthzTrans trans, List list) throws OrganizationException { + Validator v = new Validator().artisRequired(list, 1); + if(v.err()) { + return Result.err(Result.ERR_BadData,v.errs()); + } + + // Check if requesting User is Sponsor + //TODO - Shall we do one, or multiples? + for(ArtiDAO.Data add : list) { + // Policy 1: MechID must exist in Org + Identity muser = trans.org().getIdentity(trans, add.mechid); + if(muser == null) { + return Result.err(Result.ERR_Denied,"%s is not valid for %s", add.mechid,trans.org().getName()); + } + + // Policy 2: MechID must have valid Organization Owner + Identity ouser = muser.owner(); + if(ouser == null) { + return Result.err(Result.ERR_Denied,"%s is not a valid Sponsor for %s at %s", + trans.user(),add.mechid,trans.org().getName()); + } + + // Policy 3: Renewal Days are between 10 and 60 (constants, may be parameterized) + if(add.renewDaysMAX_RENEWAL) { + add.renewDays = MAX_RENEWAL; + } + + // Policy 4: Data is always updated with the latest Sponsor + // Add to Sponsor, to make sure we are always up to date. + add.sponsor = ouser.fullID(); + + // Policy 5: If Notify is blank, set to Owner's Email + if(add.notify==null || add.notify.length()==0) { + add.notify = "mailto:"+ouser.email(); + } + + // Policy 4: only Owner may update info + if(trans.user().equals(add.sponsor)) { + return artiDAO.update(trans, add); + } else { + return Result.err(Result.ERR_Denied,"%s may not update info for %s",trans.user(),muser.fullID()); + } + + } + return Result.err(Result.ERR_BadData,"No Artifacts to update"); + } + + public Result deleteArtifact(AuthzTrans trans, String mechid, String machine) throws OrganizationException { + Validator v = new Validator() + .nullOrBlank("mechid", mechid) + .nullOrBlank("machine", machine); + if(v.err()) { + return Result.err(Result.ERR_BadData,v.errs()); + } + + Result> rlad = artiDAO.read(trans, mechid, machine); + if(rlad.notOKorIsEmpty()) { + return Result.err(Result.ERR_NotFound,"Artifact for %s %s does not exist.",mechid,machine); + } + + return deleteArtifact(trans,rlad.value.get(0)); + } + + private Result deleteArtifact(AuthzTrans trans, ArtiDAO.Data add) throws OrganizationException { + // Policy 1: Record should be delete able only by Existing Sponsor. + String sponsor=null; + Identity muser = trans.org().getIdentity(trans, add.mechid); + if(muser != null) { + Identity ouser = muser.owner(); + if(ouser!=null) { + sponsor = ouser.fullID(); + } + } + // Policy 1.a: If Sponsorship is deleted in system of Record, then + // accept deletion by sponsor in Artifact Table + if(sponsor==null) { + sponsor = add.sponsor; + } + + String ns = AAFCon.reverseDomain(add.mechid); + + if(trans.fish(new AAFPermission(ns + ".access", "*", "write")) + || trans.user().equals(sponsor)) { + return artiDAO.delete(trans, add, false); + } + return null; + } + + public Result deleteArtifact(AuthzTrans trans, List list) { + Validator v = new Validator().artisRequired(list, 1); + if(v.err()) { + return Result.err(Result.ERR_BadData,v.errs()); + } + + try { + boolean partial = false; + Result result=null; + for(ArtiDAO.Data add : list) { + result = deleteArtifact(trans, add); + if(result.notOK()) { + partial = true; + } + } + if(result == null) { + result = Result.err(Result.ERR_BadData,"No Artifacts to delete"); + } else if(partial) { + result.partialContent(true); + } + return result; + } catch(Exception e) { + return Result.err(e); + } + } + + private String[] compileNotes(List notes) { + String[] rv; + if(notes==null) { + rv = NO_NOTES; + } else { + rv = new String[notes.size()]; + notes.toArray(rv); + } + return rv; + } + + private ByteBuffer getChallenge256SaltedHash(String challenge, int salt) throws NoSuchAlgorithmException { + ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE + challenge.length()); + bb.putInt(salt); + bb.put(challenge.getBytes()); + byte[] hash = Hash.hashSHA256(bb.array()); + return ByteBuffer.wrap(hash); + } +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/service/CertManAPI.java b/authz-certman/src/main/java/com/att/authz/cm/service/CertManAPI.java new file mode 100644 index 00000000..fa8ac6fd --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/service/CertManAPI.java @@ -0,0 +1,286 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.service; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +import com.att.aft.dme2.api.DME2Exception; +//import com.att.aft.dme2.api.DME2FilterHolder; +//import com.att.aft.dme2.api.DME2FilterHolder.RequestDispatcherType; +import com.att.aft.dme2.api.DME2Manager; +import com.att.aft.dme2.api.DME2Server; +import com.att.aft.dme2.api.DME2ServerProperties; +import com.att.aft.dme2.api.DME2ServiceHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder.RequestDispatcherType; +import com.att.aft.dme2.api.util.DME2ServletHolder; +//import com.att.aft.dme2.api.DME2ServletHolder; +import com.att.authz.cm.api.API_Artifact; +import com.att.authz.cm.api.API_Cert; +import com.att.authz.cm.ca.CA; +import com.att.authz.cm.facade.Facade1_0; +import com.att.authz.cm.facade.FacadeFactory; +import com.att.authz.cm.mapper.Mapper.API; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.env.AuthzTransFilter; +import com.att.authz.server.AbsServer; +import com.att.cache.Cache; +import com.att.cache.Cache.Dated; +import com.att.cadi.Access; +import com.att.cadi.Access.Level; +import com.att.cadi.CadiException; +import com.att.cadi.TrustChecker; +import com.att.cadi.aaf.v2_0.AAFAuthn; +import com.att.cadi.aaf.v2_0.AAFCon; +import com.att.cadi.aaf.v2_0.AAFConHttp; +import com.att.cadi.aaf.v2_0.AAFLurPerm; +import com.att.cadi.aaf.v2_0.AAFTrustChecker; +import com.att.cadi.config.Config; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; +import com.att.inno.env.Env; +import com.att.inno.env.Trans; +import com.att.inno.env.util.Split; + +public class CertManAPI extends AbsServer { + + private static final String USER_PERMS = "userPerms"; + private static final Map certAuths = new TreeMap(); + private static final String AAF_CERTMAN_CA_PREFIX = null; + public Facade1_0 facade1_0; // this is the default Facade + public Facade1_0 facade1_0_XML; // this is the XML Facade + public Map cacheUser; + public AAFAuthn aafAuthn; + public AAFLurPerm aafLurPerm; + + private String[] EMPTY; + private AAFCon aafcon; + + /** + * Construct AuthzAPI with all the Context Supporting Routes that Authz needs + * + * @param env + * @param si + * @param dm + * @param decryptor + * @throws APIException + */ + public CertManAPI(AuthzEnv env) throws Exception { + super(env,"CertMan"); + env.setLog4JNames("log4j.properties","authz","cm","audit","init","trace"); + + //aafcon = new AAFConHttp(env); + + aafLurPerm = aafcon.newLur(); + // Note: If you need both Authn and Authz construct the following: + aafAuthn = aafcon.newAuthn(aafLurPerm); + + String aaf_env = env.getProperty(Config.AAF_ENV); + if(aaf_env==null) { + throw new APIException("aaf_env needs to be set"); + } + + // Initialize Facade for all uses + AuthzTrans trans = env.newTrans(); + + // Load Supported Certificate Authorities by property + for(String key : env.existingStaticSlotNames()) { + if(key.startsWith(AAF_CERTMAN_CA_PREFIX)) { + int idx = key.indexOf('.'); + String[] params = Split.split(';', env.getProperty(key)); + if(params.length>1) { + @SuppressWarnings("unchecked") + Class cac = (Class)Class.forName((String)params[0]); + Class ptype[] = new Class[params.length+1]; + ptype[0]=Trans.class; + ptype[1]=String.class; + Object pinst[] = new Object[params.length+1]; + pinst[0]=trans; + pinst[1]= key.substring(idx+1); + for(int i=1;i cons = cac.getConstructor(ptype); + CA ca = cons.newInstance(pinst); + certAuths.put(ca.getName(),ca); + } + } + } + if(certAuths.size()==0) { + throw new APIException("No Certificate Authorities have been configured in CertMan"); + } + + CMService service = new CMService(trans, this); + // note: Service knows how to shutdown Cluster on Shutdown, etc. See Constructor + facade1_0 = FacadeFactory.v1_0(this,trans, service,Data.TYPE.JSON); // Default Facade + facade1_0_XML = FacadeFactory.v1_0(this,trans,service,Data.TYPE.XML); + + + synchronized(env) { + if(cacheUser == null) { + cacheUser = Cache.obtain(USER_PERMS); + Cache.startCleansing(env, USER_PERMS); + Cache.addShutdownHook(); // Setup Shutdown Hook to close cache + } + } + + //////////////////////////////////////////////////////////////////////////// + // APIs + //////////////////////////////////////////////////////////////////////// + API_Cert.init(this); + API_Artifact.init(this); + + StringBuilder sb = new StringBuilder(); + trans.auditTrail(2, sb); + trans.init().log(sb); + } + + public CA getCA(String key) { + return certAuths.get(key); + } + + public String[] getTrustChain(String key) { + CA ca = certAuths.get(key); + if(ca==null) { + return EMPTY; + } else { + return ca.getTrustChain(); + } + } + + /** + * Setup XML and JSON implementations for each supported Version type + * + * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties + * to do Versions and Content switches + * + */ + public void route(HttpMethods meth, String path, API api, Code code) throws Exception { + String version = "1.0"; + // Get Correct API Class from Mapper + Class respCls = facade1_0.mapper().getClass(api); + if(respCls==null) throw new Exception("Unknown class associated with " + api.getClass().getName() + ' ' + api.name()); + // setup Application API HTML ContentTypes for JSON and Route + String application = applicationJSON(respCls, version); + route(env,meth,path,code,application,"application/json;version="+version,"*/*"); + + // setup Application API HTML ContentTypes for XML and Route + application = applicationXML(respCls, version); + route(env,meth,path,code.clone(facade1_0_XML),application,"application/xml;version="+version); + + // Add other Supported APIs here as created + } + + public void routeAll(HttpMethods meth, String path, API api, Code code) throws Exception { + route(env,meth,path,code,""); // this will always match + } + + + /** + * Start up AuthzAPI as DME2 Service + * @param env + * @param props + * @throws DME2Exception + * @throws CadiException + */ + public void startDME2(Properties props) throws DME2Exception, CadiException { + DME2Manager dme2 = new DME2Manager("AAF Certman DME2Manager", props); + + + DME2ServiceHolder svcHolder; + List slist = new ArrayList(); + svcHolder = new DME2ServiceHolder(); + String serviceName = env.getProperty("DMEServiceName",null); + if(serviceName!=null) { + svcHolder.setServiceURI(serviceName); + svcHolder.setManager(dme2); + svcHolder.setContext("/"); + + + + DME2ServletHolder srvHolder = new DME2ServletHolder(this, new String[]{"/cert"}); + srvHolder.setContextPath("/*"); + slist.add(srvHolder); + + EnumSet edlist = EnumSet.of( + RequestDispatcherType.REQUEST, + RequestDispatcherType.FORWARD, + RequestDispatcherType.ASYNC + ); + + /////////////////////// + // Apply Filters + /////////////////////// + List flist = new ArrayList(); + + // Secure all GUI interactions with AuthzTransFilter + flist.add(new DME2FilterHolder( + new AuthzTransFilter(env,aafcon,TrustChecker.NOTRUST), + "/*", edlist)); + + + svcHolder.setFilters(flist); + svcHolder.setServletHolders(slist); + + DME2Server dme2svr = dme2.getServer(); + DME2ServerProperties dsprops = dme2svr.getServerProperties(); + dsprops.setGracefulShutdownTimeMs(1000); + + env.init().log("Starting AAF Certman Jetty/DME2 server..."); + dme2svr.start(); + try { +// if(env.getProperty("NO_REGISTER",null)!=null) + dme2.bindService(svcHolder); + env.init().log("DME2 is available as HTTP"+(dsprops.isSslEnable()?"/S":""),"on port:",dsprops.getPort()); + while(true) { // Per DME2 Examples... + Thread.sleep(5000); + } + } catch(InterruptedException e) { + env.init().log("AAF Jetty Server interrupted!"); + } catch(Exception e) { // Error binding service doesn't seem to stop DME2 or Process + env.init().log(e,"DME2 Initialization Error"); + dme2svr.stop(); + System.exit(1); + } + } else { + env.init().log("Properties must contain DMEServiceName"); + } + } + + public static void main(String[] args) { + setup(CertManAPI.class, "certman.props"); + + } + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/service/Code.java b/authz-certman/src/main/java/com/att/authz/cm/service/Code.java new file mode 100644 index 00000000..c29404e2 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/service/Code.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.service; + +import com.att.authz.cm.facade.Facade1_0; +import com.att.authz.env.AuthzTrans; +import com.att.cssa.rserv.HttpCode; + +public abstract class Code extends HttpCode implements Cloneable { + + public Code(CertManAPI cma, String description, String ... roles) { + super(cma.facade1_0, description, roles); + // Note, the first "Code" will be created with default Facade, "JSON". + // use clone for another Code with XML + } + + + public D clone(Facade1_0 facade) throws Exception { + @SuppressWarnings("unchecked") + D d = (D)clone(); + d.context = facade; + return d; + } + +} diff --git a/authz-certman/src/main/java/com/att/authz/cm/validation/Validator.java b/authz-certman/src/main/java/com/att/authz/cm/validation/Validator.java new file mode 100644 index 00000000..85163f09 --- /dev/null +++ b/authz-certman/src/main/java/com/att/authz/cm/validation/Validator.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.validation; + +import java.util.List; + +import com.att.authz.layer.Result; +import com.att.dao.aaf.cass.ArtiDAO; +import com.att.dao.aaf.cass.ArtiDAO.Data; + +/** + * Validator + * Consistently apply content rules for content (incoming) + * + * Note: We restrict content for usability in URLs (because RESTful service), and avoid + * issues with Regular Expressions, and other enabling technologies. + * + */ +public class Validator { + // Repeated Msg fragments + private static final String MECHID = "mechid"; + private static final String MACHINE = "machine"; + private static final String ARTIFACT_LIST_IS_NULL = "Artifact List is null."; + private static final String Y = "y."; + private static final String IES = "ies."; + private static final String ENTR = " entr"; + private static final String MUST_HAVE_AT_LEAST = " must have at least "; + private static final String IS_NULL = " is null."; + private static final String ARTIFACTS_MUST_HAVE_AT_LEAST = "Artifacts must have at least "; + private StringBuilder msgs; + + public Validator nullOrBlank(String name, String str) { + if(str==null) { + msg(name + IS_NULL); + } else if(str.length()==0) { + msg(name + " is blank."); + } + return this; + } + + private void msg(String ... strs) { + if(msgs==null) { + msgs=new StringBuilder(); + } + for(String str : strs) { + msgs.append(str); + } + msgs.append('\n'); + } + + public boolean err() { + return msgs!=null; + } + + public String errs() { + return msgs.toString(); + } + + public Validator notOK(Result res) { + if(res==null) { + msgs.append("Result object is blank"); + } else if(res.notOK()) { + msgs.append(res.getClass().getSimpleName() + " is not OK"); + } + return this; + } + + public Validator isNull(String name, Object obj) { + if(obj==null) { + msg(name + IS_NULL); + } + return this; + } + + public Validator nullBlankMin(String name, List list, int min) { + if(list==null) { + msg(name + IS_NULL); + } else { + if(list.size() list, int min) { + if(list==null) { + msg(ARTIFACT_LIST_IS_NULL); + } else { + if(list.size() list, int min) { + if(list==null) { + msg(ARTIFACT_LIST_IS_NULL); + } else { + if(list.size() getNonCriticalExtensionOIDs() { + + return null; + } + + @Override + public byte[] getExtensionValue(String oid) { + + return null; + } + + @Override + public Set getCriticalExtensionOIDs() { + + return null; + } + + @Override + public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, SignatureException { + + + } + + @Override + public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + + + } + + @Override + public String toString() { + + return null; + } + + @Override + public PublicKey getPublicKey() { + + return null; + } + + @Override + public byte[] getEncoded() throws CertificateEncodingException { + + return null; + } + + @Override + public int getVersion() { + + return 0; + } + + @Override + public byte[] getTBSCertificate() throws CertificateEncodingException { + + return null; + } + + @Override + public boolean[] getSubjectUniqueID() { + + return null; + } + + @Override + public Principal getSubjectDN() { + + return null; + } + + @Override + public byte[] getSignature() { + + return null; + } + + @Override + public byte[] getSigAlgParams() { + + return null; + } + + @Override + public String getSigAlgOID() { + + return null; + } + + @Override + public String getSigAlgName() { + + return null; + } + + @Override + public BigInteger getSerialNumber() { + + return null; + } + + @Override + public Date getNotBefore() { + + return null; + } + + @Override + public Date getNotAfter() { + + return null; + } + + @Override + public boolean[] getKeyUsage() { + + return null; + } + + @Override + public boolean[] getIssuerUniqueID() { + + return null; + } + + @Override + public Principal getIssuerDN() { + + return null; + } + + @Override + public int getBasicConstraints() { + + return 0; + } + + @Override + public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException { + + + } + + @Override + public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException { + + } + }; + when(appCA.sign(Mockito.any(Trans.class), Mockito.any(CSRMeta.class))).thenReturn(cert); + certDAO = mock(CachedCertDAO.class, CALLS_REAL_METHODS); + } + + @Test + public void identity_True() throws CertificateException, IOException, CertException { + assertNotNull(appCA.sign(trans, csrMeta)); + } + + + @Test + public void identityNull() throws CertificateException { + try { + assertNotNull(appCA.sign(null, csrMeta)); + } catch (IOException e) { + + e.printStackTrace(); + } catch (CertException e) { + + e.printStackTrace(); + } + } + + @Test + public void identityBothNull() throws CertificateException { + try { + assertNotNull(appCA.sign(null, null)); + } catch (IOException e) { + + e.printStackTrace(); + } catch (CertException e) { + + e.printStackTrace(); + } + } + +} diff --git a/authz-certman/src/test/java/com/att/authz/cm/ca/JU_DevlCA.java b/authz-certman/src/test/java/com/att/authz/cm/ca/JU_DevlCA.java new file mode 100644 index 00000000..c18afe5c --- /dev/null +++ b/authz-certman/src/test/java/com/att/authz/cm/ca/JU_DevlCA.java @@ -0,0 +1,287 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.ca; + +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.junit.Assert.*; + +import java.io.IOException; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.X509Certificate; +import java.util.Date; +import java.util.Set; + +import javax.security.auth.x500.X500Principal; +import javax.servlet.http.HttpServletRequest; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.aft.dme2.api.http.HttpResponse; +import com.att.aft.dme2.request.HttpRequest; +import com.att.authz.cm.cert.CSRMeta; +import com.att.cadi.cm.CertException; +import com.att.dao.aaf.cached.CachedCertDAO; +import com.att.dao.aaf.cass.CertDAO; +import com.att.inno.env.Trans; + + +@RunWith(MockitoJUnitRunner.class) +public class JU_DevlCA { + + @Mock + private static CachedCertDAO certDAO; + + @Mock + private static HttpServletRequest req; + + @Mock + private static CSRMeta csrMeta; + + static Trans trans; + + static X509Certificate cert; + static byte [] name = {1,23,4,54,6,56}; + + private static DevlCA devICA; + + @BeforeClass + public static void setUp() throws CertificateException, CertException, IOException { + String str = "core java api"; + byte[] b = str.getBytes(); + Principal prc = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); + req = mock(HttpServletRequest.class); + devICA = mock(DevlCA.class); + X509Certificate cert = new X509Certificate() { + + @Override + public boolean hasUnsupportedCriticalExtension() { + return false; + } + + @Override + public Set getNonCriticalExtensionOIDs() { + + return null; + } + + @Override + public byte[] getExtensionValue(String oid) { + + return null; + } + + @Override + public Set getCriticalExtensionOIDs() { + + return null; + } + + @Override + public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, SignatureException { + + + } + + @Override + public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + + + } + + @Override + public String toString() { + + return null; + } + + @Override + public PublicKey getPublicKey() { + + return null; + } + + @Override + public byte[] getEncoded() throws CertificateEncodingException { + + return null; + } + + @Override + public int getVersion() { + + return 0; + } + + @Override + public byte[] getTBSCertificate() throws CertificateEncodingException { + + return null; + } + + @Override + public boolean[] getSubjectUniqueID() { + + return null; + } + + @Override + public Principal getSubjectDN() { + + return null; + } + + @Override + public byte[] getSignature() { + + return null; + } + + @Override + public byte[] getSigAlgParams() { + + return null; + } + + @Override + public String getSigAlgOID() { + + return null; + } + + @Override + public String getSigAlgName() { + + return null; + } + + @Override + public BigInteger getSerialNumber() { + + return null; + } + + @Override + public Date getNotBefore() { + + return null; + } + + @Override + public Date getNotAfter() { + + return null; + } + + @Override + public boolean[] getKeyUsage() { + + return null; + } + + @Override + public boolean[] getIssuerUniqueID() { + + return null; + } + + @Override + public Principal getIssuerDN() { + + return null; + } + + @Override + public int getBasicConstraints() { + + return 0; + } + + @Override + public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException { + + + } + + @Override + public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException { + + } + }; + when(devICA.sign(Mockito.any(Trans.class), Mockito.any(CSRMeta.class))).thenReturn(cert); + certDAO = mock(CachedCertDAO.class, CALLS_REAL_METHODS); + } + + @Test + public void identity_True() throws CertificateException, IOException, CertException { + assertNotNull(devICA.sign(trans, csrMeta)); + } + + + @Test + public void identityNull() throws CertificateException { + try { + assertNotNull(devICA.sign(null, csrMeta)); + } catch (IOException e) { + + e.printStackTrace(); + } catch (CertException e) { + + e.printStackTrace(); + } + } + + @Test + public void identityBothNull() throws CertificateException { + try { + assertNotNull(devICA.sign(null, null)); + } catch (IOException e) { + + e.printStackTrace(); + } catch (CertException e) { + + e.printStackTrace(); + } + } + +} diff --git a/authz-certman/src/test/java/com/att/authz/cm/cert/JU_BCFactory.java b/authz-certman/src/test/java/com/att/authz/cm/cert/JU_BCFactory.java new file mode 100644 index 00000000..b504f6a8 --- /dev/null +++ b/authz-certman/src/test/java/com/att/authz/cm/cert/JU_BCFactory.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.cert; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.security.Key; +import java.security.PrivateKey; +import java.security.PublicKey; + +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.pkcs.PKCS10CertificationRequest; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.cm.CertException; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; + +@RunWith(MockitoJUnitRunner.class) +public class JU_BCFactory { + + private static BCFactory bcFactory = new BCFactory(); + + private static BCFactory bcFact; + + private static PrivateKey pk; + + + private static Trans trans; + + + private static PKCS10CertificationRequest req; + + @BeforeClass + public static void setUp() throws IOException { + pk = new XYZKey(); + trans = mock(Trans.class); + req = mock(PKCS10CertificationRequest.class); + when(req.getEncoded()).thenReturn(new byte[1]); + when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken(null, 0) { + + @Override + public void output(StringBuilder sb) { + // TODO Auto-generated method stub + + } + }); + bcFact = mock(BCFactory.class); + } + + @Test + public void toStrin() throws OperatorCreationException, IOException, CertException { + assertNotNull(bcFactory.toString(trans, req)); + } + + @Test + public void toStrinMoc() throws OperatorCreationException, IOException, CertException { + assertNotNull(bcFact.toString(trans, req)); + } + + @Rule + public ExpectedException thrown= ExpectedException.none(); + + @Test + public void toCSR() { + try { + assertNotNull(bcFactory.toCSR(trans, new File("/random/path"))); + thrown.expect(FileNotFoundException.class); + } catch (IOException e) { + + e.printStackTrace(); + } + } + +} + +class XYZKey implements Key, PublicKey, PrivateKey { + + int rotValue; + public XYZKey() { + rotValue = 1200213; + } + public String getAlgorithm() { + return "XYZ"; + } + + public String getFormat() { + return "XYZ Special Format"; + } + + public byte[] getEncoded() { + byte b[] = new byte[4]; + b[3] = (byte) ((rotValue << 24) & 0xff); + b[2] = (byte) ((rotValue << 16) & 0xff); + b[1] = (byte) ((rotValue << 8) & 0xff); + b[0] = (byte) ((rotValue << 0) & 0xff); + return b; + } +} diff --git a/authz-certman/src/test/java/com/att/authz/cm/cert/JU_CSRMeta.java b/authz-certman/src/test/java/com/att/authz/cm/cert/JU_CSRMeta.java new file mode 100644 index 00000000..541d5fb7 --- /dev/null +++ b/authz-certman/src/test/java/com/att/authz/cm/cert/JU_CSRMeta.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.cert; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import java.io.IOException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.pkcs.PKCS10CertificationRequest; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.cm.CertException; +import com.att.inno.env.Trans; + +@RunWith(MockitoJUnitRunner.class) +public class JU_CSRMeta { + + private static CSRMeta csrmeta; + private static Trans trans; + private static PKCS10CertificationRequest req; + + @BeforeClass + public static void setUp() { + trans = mock(Trans.class); + csrmeta = new CSRMeta(); + csrmeta.cn("CN"); + csrmeta.email("pupleti@ht.com"); + csrmeta.mechID("HAKJH787"); + csrmeta.o("O"); + csrmeta.l("L"); + csrmeta.st("ST"); + csrmeta.c("C"); + csrmeta.challenge("Challenge"); + csrmeta.san("CA"); + } + + @Test + public void x500Name() throws IOException { + + X500Name x500 = csrmeta.x500Name(); + assertEquals(x500.toString(),"CN=CN,E=pupleti@ht.com,OU=HAKJH787,O=O,L=L,ST=ST,C=C"); + } + + @Test + public void initialConversationCert() throws CertificateException, OperatorCreationException, IOException { + X509Certificate cert = csrmeta.initialConversationCert(trans); + assertEquals(cert.getBasicConstraints(),-1); + } + + @Test + public void generateCSR() throws IOException, CertException { + req = csrmeta.generateCSR(trans); + assertNotNull(req); + } + + @Rule + public ExpectedException thrown= ExpectedException.none(); + + @Test + public void dump() throws IOException, CertException { + req = csrmeta.generateCSR(trans); + csrmeta.dump(req); + } + +} diff --git a/authz-certman/src/test/java/com/att/authz/cm/data/JU_CertReq.java b/authz-certman/src/test/java/com/att/authz/cm/data/JU_CertReq.java new file mode 100644 index 00000000..f40268d9 --- /dev/null +++ b/authz-certman/src/test/java/com/att/authz/cm/data/JU_CertReq.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.data; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.authz.cm.ca.CA; +import com.att.authz.cm.cert.BCFactory; +import com.att.authz.cm.cert.CSRMeta; +import com.att.authz.cm.cert.StandardFields; +import com.att.cadi.cm.CertException; +import com.att.inno.env.Trans; + +@RunWith(MockitoJUnitRunner.class) +public class JU_CertReq { + + private static BCFactory bcFact; + + private static CSRMeta value; + + private static CertReq req; + + @BeforeClass + public static void setUp() { + bcFact = mock(BCFactory.class); + value = mock(CSRMeta.class); + req = mock(CertReq.class); + + } + + @Test + public void getCSRMeta() throws CertException { + //req = new CertReq(); + req.mechid = "1213"; + List fqdnsas = new ArrayList(); + fqdnsas.add("String1"); + List emails = new ArrayList(); + emails.add("pupleti@hotmail.com"); + req.emails = emails; + req.fqdns = fqdnsas; + StandardFields sf = mock(StandardFields.class); + req.certAuthority = new CA("testName", sf, "ALL") { + + @Override + public X509Certificate sign(Trans trans, CSRMeta csrmeta) throws IOException, CertException { + + return null; + } + }; + req.sponsor = "asa@df.co"; + assertNull(req.getCSRMeta()); + } +} diff --git a/authz-certman/src/test/java/com/att/authz/cm/facade/JU_FacadeImpl.java b/authz-certman/src/test/java/com/att/authz/cm/facade/JU_FacadeImpl.java new file mode 100644 index 00000000..e613e594 --- /dev/null +++ b/authz-certman/src/test/java/com/att/authz/cm/facade/JU_FacadeImpl.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.facade; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.authz.cm.mapper.Mapper; +import com.att.authz.cm.service.CMService; +import com.att.authz.cm.service.CertManAPI; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.cadi.aaf.AAFPermission; +import com.att.authz.layer.Result; +import com.att.cadi.aaf.v2_0.AAFLurPerm; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; +import com.att.inno.env.LogTarget; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.rosetta.env.RosettaDF; +import com.att.rosetta.env.RosettaData; + + +@RunWith(MockitoJUnitRunner.class) +public class JU_FacadeImpl { + + private static AuthzTrans trans; + private static HttpServletResponse resp; + private static CertManAPI certman; + private static FacadeImpl hImpl; + private static CMService service; + private Mapper mapper; + private Data.TYPE dataType; + private static AuthzEnv env; + + private static FacadeImpl fImpl; + private static HttpServletRequest req; + + @Before + public void setUp() throws APIException, IOException { + fImpl = mock(FacadeImpl.class); + env = mock(AuthzEnv.class); + resp = mock(HttpServletResponse.class); + req = mock(HttpServletRequest.class); + hImpl = mock(FacadeImpl.class, CALLS_REAL_METHODS); + Result rvd = (Result) mock(Result.class); + trans = mock(AuthzTrans.class); + when(trans.error()).thenReturn(new LogTarget() { + + @Override + public void printf(String fmt, Object... vars) {} + + @Override + public void log(Throwable e, Object... msgs) { + e.getMessage(); + e.printStackTrace(); + msgs.toString(); + + } + + @Override + public void log(Object... msgs) { + } + + @Override + public boolean isLoggable() { + + return false; + } + }); + when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken("Now", 1) { + + @Override + public void output(StringBuilder sb) { + + } + }); + when(fImpl.check(Mockito.any(AuthzTrans.class), Mockito.any(HttpServletResponse.class), Mockito.anyString())).thenReturn(rvd); + when(resp.getOutputStream()).thenReturn(new ServletOutputStream() { + + @Override + public void write(int b) throws IOException { + + + } + }); + + } + + @Test + public void check() throws IOException { + AAFPermission ap = new AAFPermission("str1","str3","str2"); + String perms = ap.getInstance(); + assertNotNull(hImpl.check(trans, resp, perms)); + } + + @Test + public void checkNull() throws IOException { + AAFPermission ap = new AAFPermission(null,"Str3","str2"); + String perms = ap.getInstance(); + assertNotNull(hImpl.check(trans, resp, perms)); + } + + @Test + public void checkTwoNull() throws IOException { + AAFPermission ap = new AAFPermission(null,null,"str2"); + String perms = ap.getInstance(); + assertNotNull(fImpl.check(trans, resp, perms)); + } + + @Test + public void checkAllNull() throws IOException { + AAFPermission ap = new AAFPermission(null,null,null); + String perms = ap.getInstance(); + assertNotNull(fImpl.check(trans, resp, perms)); + } + + @Test + public void checkTrans_null() throws IOException { + AAFPermission ap = new AAFPermission("str1","str3","str2"); + String perms = ap.getInstance(); + assertNotNull(hImpl.check(null, resp, perms)); + } + + @Test + public void checkRespNull() throws IOException { + AAFPermission ap = new AAFPermission("str1","str3","str2"); + String perms = ap.getInstance(); + assertNotNull(hImpl.check(trans, null, perms)); + } + + @Test + public void requestCert() { + assertNotNull(hImpl.requestCert(trans, req, resp, true)); + } + + @Test + public void renewCert() { + assertNotNull(hImpl.renewCert(trans, req, resp, true)); + } + + @Test + public void dropCert() { + assertNotNull(hImpl.renewCert(trans, req, resp, true)); + } + + @Test + public void createArtifacts() { + assertNotNull(hImpl.createArtifacts(trans, req, resp)); + } + + @Test + public void readArtifacts() { + assertNotNull(hImpl.readArtifacts(trans, req, resp)); + } +} diff --git a/authz-certman/src/test/java/com/att/authz/cm/validation/JU_Validator.java b/authz-certman/src/test/java/com/att/authz/cm/validation/JU_Validator.java new file mode 100644 index 00000000..e3a428aa --- /dev/null +++ b/authz-certman/src/test/java/com/att/authz/cm/validation/JU_Validator.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cm.validation; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.dao.aaf.cass.ArtiDAO; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Validator { + + private static Validator validator; + + @BeforeClass + public static void setUp() { + validator = new Validator(); + } + + @Test + public void nullCheck() { + assertNotNull(validator.nullOrBlank("TestName", null).errs()); + } + + @Test + public void blankCheck() { + assertNotNull(validator.nullOrBlank("TestName", "").err()); + } + + @Test + public void notOK_null() { + assertNotNull(validator.notOK(null)); + } + + @Test + public void isNullCheck() { + assertNotNull(validator.isNull("TestName", null).errs()); + } + + @Test + public void nullBlankMin() { + assertNotNull(validator.nullBlankMin("TestName", null, 0)); + } + + @Test + public void artistsRequired() { + assertNotNull(validator.artisRequired(null, 0)); + } + + @Test + public void artistRequired() { + assertNotNull(validator.artisRequired(new ArrayList(), -1)); + } + + @Test + public void artistRequired_Null() { + assertNotNull(validator.artisRequired(null, -1)); + } + + @Test + public void artistkeys() { + assertNotNull(validator.artisKeys(new ArrayList(), -1)); + } + + @Test + public void artistKeys_Null() { + assertNotNull(validator.artisKeys(null, -1)); + } + + @Test + public void keys() { + assertNotNull(validator.keys(new ArtiDAO.Data())); + } +} diff --git a/authz-client/.gitignore b/authz-client/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-client/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-client/pom.xml b/authz-client/pom.xml new file mode 100644 index 00000000..9dbb288d --- /dev/null +++ b/authz-client/pom.xml @@ -0,0 +1,208 @@ + + + + 4.0.0 + + + authz-client + Authz Client + Client and XSD Generated code for Authz + com.att.authz + 2.6 + jar + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + UTF-8 + /opt/app/aft/${project.artifactId}/${project.version} + true + + + + + junit + junit + 4.10 + test + + + + + + + + org.codehaus.mojo + jaxb2-maven-plugin + 1.3 + + + generate-sources + + xjc + + + + + src/main/xsd + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.5 + + false + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.codehaus.mojo + + + jaxb2-maven-plugin + + + [1.3,) + + + xjc + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + + + ossrhdme + https://oss.sonatype.org/content/repositories/snapshots + + + ossrhdme + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + https://github.com/att/AAF.git + ${project.scm.connection} + http://github.com/att/AAF/tree/master + + + + diff --git a/authz-client/src/main/xsd/aaf_2_0.xsd b/authz-client/src/main/xsd/aaf_2_0.xsd new file mode 100644 index 00000000..4b04d6c1 --- /dev/null +++ b/authz-client/src/main/xsd/aaf_2_0.xsd @@ -0,0 +1,467 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/authz-client/src/main/xsd/certman_1_0.xsd b/authz-client/src/main/xsd/certman_1_0.xsd new file mode 100644 index 00000000..d99c144b --- /dev/null +++ b/authz-client/src/main/xsd/certman_1_0.xsd @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/authz-cmd/.gitignore b/authz-cmd/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-cmd/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-cmd/aafcli.sh b/authz-cmd/aafcli.sh new file mode 100644 index 00000000..89e9a4ea --- /dev/null +++ b/authz-cmd/aafcli.sh @@ -0,0 +1,9 @@ +DIR=`pwd` +DME2REG=$DIR/../dme2reg +CLASSPATH=etc:target/authz-cmd-2.0.15-jar-with-dependencies.jar + +java -cp $CLASSPATH \ + -Dcadi_prop_files=../authz-service/src/main/sample/authAPI.props \ + -DDME2_EP_REGISTRY_CLASS=DME2FS -DAFT_DME2_EP_REGISTRY_FS_DIR=$DME2REG \ + com.att.cmd.AAFcli $* + diff --git a/authz-cmd/etc/log4j.properties b/authz-cmd/etc/log4j.properties new file mode 100644 index 00000000..054ad57a --- /dev/null +++ b/authz-cmd/etc/log4j.properties @@ -0,0 +1,55 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START==================================================== +# * org.onap.aai +# * =========================================================================== +# * Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# * Copyright © 2017 Amdocs +# * =========================================================================== +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END==================================================== +# * +# * ECOMP is a trademark and service mark of AT&T Intellectual Property. +# * +#------------------------------------------------------------------------------- +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +log4j.appender.SVR=org.apache.log4j.RollingFileAppender +log4j.appender.SVR.File=${user.home}/.aaf/authz-cmd.log +log4j.appender.SVR.MaxFileSize=10000KB +log4j.appender.SVR.MaxBackupIndex=1 +log4j.appender.SVR.layout=org.apache.log4j.PatternLayout +log4j.appender.SVR.layout.ConversionPattern=%d %p [%c] %m %n + +# General Apache libraries +log4j.rootLogger=WARN,SVR + diff --git a/authz-cmd/pom.xml b/authz-cmd/pom.xml new file mode 100644 index 00000000..c79adfcf --- /dev/null +++ b/authz-cmd/pom.xml @@ -0,0 +1,177 @@ + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-cmd + Authz Command + Command Line Processor for Authz + jar + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + false + 21 + + + + + com.att.cadi + cadi-aaf + + + + com.att.authz + authz-core + + + + jline + jline + 2.14.2 + + + + org.slf4j + slf4j-log4j12 + + + + + + + + + maven-assembly-plugin + 2.4 + + tests + + + true + + + + + + full + package + + single + + + + src/main/assemble/authz-cmd.xml + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + + + + + diff --git a/authz-cmd/src/main/assemble/authz-cmd.xml b/authz-cmd/src/main/assemble/authz-cmd.xml new file mode 100644 index 00000000..4fa723eb --- /dev/null +++ b/authz-cmd/src/main/assemble/authz-cmd.xml @@ -0,0 +1,48 @@ + + + + jar-with-dependencies + + jar + + + false + + + true + compile + + + + + + src/main/xsd + + + etc + + + diff --git a/authz-cmd/src/main/assemble/swm.xml b/authz-cmd/src/main/assemble/swm.xml new file mode 100644 index 00000000..089cfbe5 --- /dev/null +++ b/authz-cmd/src/main/assemble/swm.xml @@ -0,0 +1,35 @@ + + + swm + + zip + + ${artifactId} + + + target/swm + + + diff --git a/authz-cmd/src/main/config/log4j.properties b/authz-cmd/src/main/config/log4j.properties new file mode 100644 index 00000000..054ad57a --- /dev/null +++ b/authz-cmd/src/main/config/log4j.properties @@ -0,0 +1,55 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START==================================================== +# * org.onap.aai +# * =========================================================================== +# * Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# * Copyright © 2017 Amdocs +# * =========================================================================== +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END==================================================== +# * +# * ECOMP is a trademark and service mark of AT&T Intellectual Property. +# * +#------------------------------------------------------------------------------- +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +log4j.appender.SVR=org.apache.log4j.RollingFileAppender +log4j.appender.SVR.File=${user.home}/.aaf/authz-cmd.log +log4j.appender.SVR.MaxFileSize=10000KB +log4j.appender.SVR.MaxBackupIndex=1 +log4j.appender.SVR.layout=org.apache.log4j.PatternLayout +log4j.appender.SVR.layout.ConversionPattern=%d %p [%c] %m %n + +# General Apache libraries +log4j.rootLogger=WARN,SVR + diff --git a/authz-cmd/src/main/config/logging.props b/authz-cmd/src/main/config/logging.props new file mode 100644 index 00000000..4d0f0f10 --- /dev/null +++ b/authz-cmd/src/main/config/logging.props @@ -0,0 +1,38 @@ +| ############################################################ +# Default Logging Configuration File +# +# You can use a different file by specifying a filename +# with the java.util.logging.config.file system property. +# For example java -Djava.util.logging.config.file=myfile +############################################################ + +############################################################ +# Global properties +############################################################ + +# "handlers" specifies a comma separated list of log Handler +# classes. These handlers will be installed during VM startup. +# Note that these classes must be on the system classpath. +# By default we only configure a ConsoleHandler, which will only +# show messages at the INFO and above levels. +handlers=java.util.logging.FileHandler + +# Default global logging level. +# This specifies which kinds of events are logged across +# all loggers. For any given facility this global level +# can be overriden by a facility specific level +# Note that the ConsoleHandler also has a separate level +# setting to limit messages printed to the console. +.level=INFO + +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +############################################################ +java.util.logging.FileHandler.properties=autoFlush,fileName,dataPattern,name +java.util.logging.FileHandler.fileName=%h/.aaf/dme2.log +java.util.logging.FileHandlerFileHandler.autoFlush=true +java.util.logging.FileHandlerFileHandler.name=DailyRollingFileHandler +java.util.logging.FileHandlerFileHandler.datePattern='.'yyyy-MM-dd +com.att.aft.dme2.events.server.summary=WARN + diff --git a/authz-cmd/src/main/java/com/att/cmd/AAFcli.java b/authz-cmd/src/main/java/com/att/cmd/AAFcli.java new file mode 100644 index 00000000..e499aa48 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/AAFcli.java @@ -0,0 +1,723 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import java.io.BufferedReader; +import java.io.Console; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.net.HttpURLConnection; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.log4j.PropertyConfigurator; + +import com.att.aft.dme2.api.DME2Manager; +import com.att.authz.env.AuthzEnv; +import com.att.cadi.Access.Level; +import com.att.cadi.CadiException; +import com.att.cadi.Locator; +import com.att.cadi.SecuritySetter; +import com.att.cadi.client.PropertyLocator; +import com.att.cadi.client.Retryable; +import com.att.cadi.config.Config; +import com.att.cadi.config.SecurityInfo; +import com.att.cadi.config.SecurityInfoC; +import com.att.cadi.dme2.DME2Locator; +import com.att.cadi.filter.AccessGetter; +import com.att.cadi.http.HBasicAuthSS; +import com.att.cadi.http.HMangr; +import com.att.cmd.mgmt.Mgmt; +import com.att.cmd.ns.NS; +import com.att.cmd.perm.Perm; +import com.att.cmd.role.Role; +import com.att.cmd.user.User; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.impl.Log4JLogTarget; +import com.att.inno.env.util.Split; + +import jline.console.ConsoleReader; + +public class AAFcli { + + public static final String AAF_DEFAULT_REALM = "aaf_default_realm"; + protected static PrintWriter pw; + protected HMangr hman; + // Storage for last reused client. We can do this + // because we're technically "single" threaded calls. + public Retryable prevCall; + + protected SecuritySetter ss; + protected AuthzEnv env; + private boolean close; + private List cmds; + + // Lex State + private ArrayList expect = new ArrayList(); + private boolean verbose = true; + private int delay; + private SecurityInfo si; + private boolean request = false; + private String force = null; + private boolean gui = false; + + private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF); + private static boolean isConsole = false; + private static boolean isTest = false; + private static boolean showDetails = false; + private static boolean ignoreDelay = false; + private static int globalDelay=0; + + public static int timeout() { + return TIMEOUT; + } + + public AAFcli(AuthzEnv env, Writer wtr, HMangr hman, SecurityInfo si, SecuritySetter ss) throws APIException { + this.env = env; + this.ss = ss; + this.hman = hman; + this.si = si; + if (wtr instanceof PrintWriter) { + pw = (PrintWriter) wtr; + close = false; + } else { + pw = new PrintWriter(wtr); + close = true; + } + + + // client = new DRcli(new URI(aafurl), new + // BasicAuth(user,toPass(pass,true))) + // .apiVersion("2.0") + // .timeout(TIMEOUT); + + /* + * Create Cmd Tree + */ + cmds = new ArrayList(); + + Role role = new Role(this); + cmds.add(new Help(this, cmds)); + cmds.add(new Version(this)); + cmds.add(new Perm(role)); + cmds.add(role); + cmds.add(new User(this)); + cmds.add(new NS(this)); + cmds.add(new Mgmt(this)); + } + + public void verbose(boolean v) { + verbose = v; + } + + public void close() { + if (hman != null) { + hman.close(); + hman = null; + } + if (close) { + pw.close(); + } + } + + public boolean eval(String line) throws Exception { + if (line.length() == 0) { + return true; + } else if (line.startsWith("#")) { + pw.println(line); + return true; + } + + String[] largs = argEval(line); + int idx = 0; + + // Variable replacement + StringBuilder sb = null; + while (idx < largs.length) { + int e = 0; + for (int v = largs[idx].indexOf("@["); v >= 0; v = largs[idx].indexOf("@[", v + 1)) { + if (sb == null) { + sb = new StringBuilder(); + } + sb.append(largs[idx], e, v); + if ((e = largs[idx].indexOf(']', v)) >= 0) { + String p = env.getProperty(largs[idx].substring(v + 2, e++)); + if (p != null) { + sb.append(p); + } + } + } + if (sb != null && sb.length() > 0) { + sb.append(largs[idx], e, largs[idx].length()); + largs[idx] = sb.toString(); + sb.setLength(0); + } + ++idx; + } + + idx = 0; + boolean rv = true; + while (rv && idx < largs.length) { + // Allow Script to change Credential + if (!gui) { + if("as".equalsIgnoreCase(largs[idx])) { + if (largs.length > ++idx) { + // get Password from Props with ID as Key + String user = largs[idx++]; + int colon = user.indexOf(':'); + String pass; + if (colon > 0) { + pass = user.substring(colon + 1); + user = user.substring(0, colon); + } else { + pass = env.getProperty(user); + } + + if (pass != null) { + pass = env.decrypt(pass, false); + env.setProperty(user, pass); + ss = new HBasicAuthSS(user, pass,(SecurityInfoC) si); + pw.println("as " + user); + } else { // get Pass from System Properties, under name of + // Tag + pw.println("ERROR: No password set for " + user); + rv = false; + } + continue; + } + } else if ("expect".equalsIgnoreCase(largs[idx])) { + expect.clear(); + if (largs.length > idx++) { + if (!"nothing".equals(largs[idx])) { + for (String str : largs[idx].split(",")) { + try { + if ("Exception".equalsIgnoreCase(str)) { + expect.add(-1); + } else { + expect.add(Integer.parseInt(str)); + } + } catch (NumberFormatException e) { + throw new CadiException("\"expect\" should be followed by Number"); + } + } + ++idx; + } + } + continue; + // Sleep, typically for reports, to allow DB to update + // Milliseconds + + } else if ("sleep".equalsIgnoreCase(largs[idx])) { + Integer t = Integer.parseInt(largs[++idx]); + pw.println("sleep " + t); + Thread.sleep(t); + ++idx; + continue; + } else if ("delay".equalsIgnoreCase(largs[idx])) { + delay = Integer.parseInt(largs[++idx]); + pw.println("delay " + delay); + ++idx; + continue; + } else if ("pause".equalsIgnoreCase(largs[idx])) { + pw.println("Press to continue..."); + ++idx; + new BufferedReader(new InputStreamReader(System.in)).readLine(); + continue; + } else if ("exit".equalsIgnoreCase(largs[idx])) { + pw.println("Exiting..."); + return false; + } + + } + + if("REQUEST".equalsIgnoreCase(largs[idx])) { + request=true; + ++idx; + } else if("FORCE".equalsIgnoreCase(largs[idx])) { + force="true"; + ++idx; + } else if ("set".equalsIgnoreCase(largs[idx])) { + while (largs.length > ++idx) { + int equals = largs[idx].indexOf('='); + if (equals < 0) { + break; + } + String tag = largs[idx].substring(0, equals); + String value = largs[idx].substring(++equals); + pw.println("set " + tag + ' ' + value); + boolean isTrue = "TRUE".equalsIgnoreCase(value); + if("FORCE".equalsIgnoreCase(tag)) { + force = value; + } else if("REQUEST".equalsIgnoreCase(tag)) { + request = isTrue; + } else if("DETAILS".equalsIgnoreCase(tag)) { + showDetails = isTrue; + } else { + env.setProperty(tag, value); + } + } + continue; + // Allow Script to indicate if Failure is what is expected + } + + int ret = 0; + for (Cmd c : cmds) { + if (largs[idx].equalsIgnoreCase(c.getName())) { + if (verbose) { + pw.println(line); + if (expect.size() > 0) { + pw.print("** Expect "); + boolean first = true; + for (Integer i : expect) { + if (first) { + first = false; + } else { + pw.print(','); + } + pw.print(i); + } + pw.println(" **"); + } + } + try { + ret = c.exec(++idx, largs); + if (delay+globalDelay > 0) { + Thread.sleep(delay+globalDelay); + } + } catch (Exception e) { + if (expect.contains(-1)) { + pw.println(e.getMessage()); + ret = -1; + } else { + throw e; + } + } finally { + clearSingleLineProperties(); + } + rv = expect.isEmpty() ? true : expect.contains(ret); + if (verbose) { + if (rv) { + pw.println(); + } else { + pw.print("!!! Unexpected Return Code: "); + pw.print(ret); + pw.println(", VALIDATE OUTPUT!!!"); + } + } + return rv; + } + } + pw.write("Unknown Instruction \""); + pw.write(largs[idx]); + pw.write("\"\n"); + idx = largs.length;// always end after one command + } + return rv; + } + + private String[] argEval(String line) { + StringBuilder sb = new StringBuilder(); + ArrayList arr = new ArrayList(); + boolean start = true; + char quote = 0; + for (int i = 0; i < line.length(); ++i) { + char ch; + if (Character.isWhitespace(ch = line.charAt(i))) { + if (start) { + continue; // trim + } else if (quote != 0) { + sb.append(ch); + } else { + arr.add(sb.toString()); + sb.setLength(0); + start = true; + } + } else if (ch == '\'' || ch == '"') { // toggle + if (quote == ch) { + quote = 0; + } else { + quote = ch; + } + } else { + start = false; + sb.append(ch); + } + } + if (sb.length() > 0) { + arr.add(sb.toString()); + } + + String[] rv = new String[arr.size()]; + arr.toArray(rv); + return rv; + } + + public static void keyboardHelp() { + System.out.println("'C-' means hold the ctrl key down while pressing the next key."); + System.out.println("'M-' means hold the alt key down while pressing the next key."); + System.out.println("For instance, C-b means hold ctrl key and press b, M-b means hold alt and press b\n"); + + System.out.println("Basic Keybindings:"); + System.out.println("\tC-l - clear screen"); + System.out.println("\tC-a - beginning of line"); + System.out.println("\tC-e - end of line"); + System.out.println("\tC-b - backward character (left arrow also works)"); + System.out.println("\tM-b - backward word"); + System.out.println("\tC-f - forward character (right arrow also works)"); + System.out.println("\tM-f - forward word"); + System.out.println("\tC-d - delete character under cursor"); + System.out.println("\tM-d - delete word forward"); + System.out.println("\tM-backspace - delete word backward"); + System.out.println("\tC-k - delete from cursor to end of line"); + System.out.println("\tC-u - delete entire line, regardless of cursor position\n"); + + System.out.println("Command History:"); + System.out.println("\tC-r - search backward in history (repeating C-r continues the search)"); + System.out.println("\tC-p - move backwards through history (up arrow also works)"); + System.out.println("\tC-n - move forwards through history (down arrow also works)\n"); + + } + + /** + * @param args + */ + public static void main(String[] args) { + int rv = 0; + // Cover for bash's need to escape *... (\\*) + for (int i = 0; i < args.length; ++i) { + if ("\\*".equals(args[i])) { + args[i] = "*"; + } + } + + System.setProperty("java.util.logging.config.file", "etc/logging.props"); + final AuthzEnv env = new AuthzEnv(System.getProperties()); + + // Stop the (exceedingly annoying) DME2/other logs from printing console + InputStream is; + + // Load Log4j too... sigh + is = ClassLoader.getSystemResourceAsStream("log4j.properties"); + if(is==null) { + env.log(Level.WARN, "Cannot find 'log4j.properties' in Classpath. Best option: add 'etc' directory to classpath"); + } else { + try { + Properties props = new Properties(); + props.load(is); + PropertyConfigurator.configure(props); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + is.close(); + } catch (IOException e) { + env.debug().log(e); // only logging to avoid Sonar False positives. + } + } + } + + env.loadFromSystemPropsStartsWith("AFT", "DME2", "aaf", "keyfile"); + try { + Log4JLogTarget.setLog4JEnv("aaf", env); + GetProp gp = new GetProp(env); + String user = gp.get(false,Config.AAF_MECHID,"fully qualified id"); + String pass = gp.get(true, Config.AAF_MECHPASS, "password is hidden"); + if(env.getProperty(Config.AAF_URL)==null) { + String p = env.getProperty("DMEServiceName"); + if(p!=null) { + boolean https = "true".equalsIgnoreCase(env.getProperty("AFT_DME2_SSL_ENABLE")); + env.setProperty(Config.AAF_URL, "http"+(https?"s":"")+"://DME2RESOLVE/"+p); + } + } + String aafUrl = gp.get(false, Config.AAF_URL, "https://DME2RESOLVE or Direct URL:port"); + + if(aafUrl!=null && aafUrl.contains("//DME2")) { + //gp.set(Config.AFT_LATITUDE,"Lookup from a Map App or table"); + //gp.set(Config.AFT_LONGITUDE,"Lookup from a Map App or table"); + //gp.set(Config.AFT_ENVIRONMENT,"Check DME2 Installations"); + } + + if (gp.err() != null) { + gp.err().append("to continue..."); + System.err.println(gp.err()); + System.exit(1); + } + + + Reader rdr = null; + boolean exitOnFailure = true; + /* + * Check for "-" options anywhere in command line + */ + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < args.length; ++i) { + if ("-i".equalsIgnoreCase(args[i])) { + rdr = new InputStreamReader(System.in); + // } else if("-o".equalsIgnoreCase(args[i])) { + // // shall we do something different? Output stream is + // already done... + } else if ("-f".equalsIgnoreCase(args[i])) { + if (args.length > i + 1) { + rdr = new FileReader(args[++i]); + } + } else if ("-a".equalsIgnoreCase(args[i])) { + exitOnFailure = false; + } else if ("-c".equalsIgnoreCase(args[i])) { + isConsole = true; + } else if ("-s".equalsIgnoreCase(args[i]) && args.length > i + 1) { + env.setProperty(Cmd.STARTDATE, args[++i]); + } else if ("-e".equalsIgnoreCase(args[i]) && args.length > i + 1) { + env.setProperty(Cmd.ENDDATE, args[++i]); + } else if ("-t".equalsIgnoreCase(args[i])) { + isTest = true; + } else if ("-d".equalsIgnoreCase(args[i])) { + showDetails = true; + } else if ("-n".equalsIgnoreCase(args[i])) { + ignoreDelay = true; + } else { + if (sb.length() > 0) { + sb.append(' '); + } + sb.append(args[i]); + } + } + + SecurityInfo si = new SecurityInfo(env); + env.loadToSystemPropsStartsWith("AAF", "DME2"); + Locator loc; + if(aafUrl.contains("//DME2RESOLVE")) { + DME2Manager dm = new DME2Manager("AAFcli DME2Manager", System.getProperties()); + loc = new DME2Locator(env, dm, aafUrl); + } else { + loc = new PropertyLocator(aafUrl); + } + + //Config.configPropFiles(new AccessGetter(env), env); + + TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); + HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0"); + + //TODO: Consider requiring a default in properties + env.setProperty(Config.AAF_DEFAULT_REALM, System.getProperty(Config.AAF_DEFAULT_REALM,Config.getDefaultRealm())); + + AAFcli aafcli = new AAFcli(env, new OutputStreamWriter(System.out), hman, si, + new HBasicAuthSS(user, env.decrypt(pass,false), (SecurityInfoC) si)); + if(!ignoreDelay) { + File delay = new File("aafcli.delay"); + if(delay.exists()) { + BufferedReader br = new BufferedReader(new FileReader(delay)); + try { + globalDelay = Integer.parseInt(br.readLine()); + } catch(Exception e) { + env.debug().log(e); + } finally { + br.close(); + } + } + } + try { + if (isConsole) { + System.out.println("Type 'help' for short help or 'help -d' for detailed help with aafcli commands"); + System.out.println("Type '?' for help with command line editing"); + System.out.println("Type 'q', 'quit', or 'exit' to quit aafcli\n"); + + ConsoleReader reader = new ConsoleReader(); + try { + reader.setPrompt("aafcli > "); + + String line; + while ((line = reader.readLine()) != null) { + showDetails = (line.contains("-d"))?true:false; + + if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("q") || line.equalsIgnoreCase("exit")) { + break; + } else if (line.equalsIgnoreCase("--help -d") || line.equalsIgnoreCase("help -d") + || line.equalsIgnoreCase("help")) { + line = "--help"; + } else if (line.equalsIgnoreCase("cls")) { + reader.clearScreen(); + continue; + } else if (line.equalsIgnoreCase("?")) { + keyboardHelp(); + continue; + } + try { + aafcli.eval(line); + pw.flush(); + } catch (Exception e) { + pw.println(e.getMessage()); + pw.flush(); + } + } + } finally { + reader.close(); + } + } else if (rdr != null) { + BufferedReader br = new BufferedReader(rdr); + String line; + while ((line = br.readLine()) != null) { + if (!aafcli.eval(line) && exitOnFailure) { + rv = 1; + break; + } + } + } else { // just run the command line + aafcli.verbose(false); + if (sb.length() == 0) { + sb.append("--help"); + } + rv = aafcli.eval(sb.toString()) ? 0 : 1; + } + } finally { + aafcli.close(); + + // Don't close if No Reader, or it's a Reader of Standard In + if (rdr != null && !(rdr instanceof InputStreamReader)) { + rdr.close(); + } + } + } catch (MessageException e) { + System.out.println("MessageException caught"); + + System.err.println(e.getMessage()); + } catch (Exception e) { + e.printStackTrace(System.err); + } + System.exit(rv); + + } + + private static class GetProp { + private Console cons = System.console(); + private StringBuilder err = null; + private AuthzEnv env; + + public GetProp(AuthzEnv env) { + this.env = env; + } + + public String get(final boolean pass, final String tag, final String other) { + String data = env.getProperty(tag,null); + if (data == null) { + if(cons!=null) { + if(pass) { + char[] cp = System.console().readPassword("%s: ",tag); + if(cp!=null) { + data=String.valueOf(cp); + } + } else { + cons.writer().format("%s: ", tag); + cons.flush(); + data = cons.readLine(); + } + } + if(data==null) { + if(err == null) { + err = new StringBuilder("Add -D"); + } else { + err.append(", -D"); + } + err.append(tag); + if(other!=null) { + err.append("=<"); + err.append(other); + err.append('>'); + } + } + } + return data; + } + + public void set(final String tag, final String other) { + String data = env.getProperty(tag,null); + if (data == null) { + if(cons!=null) { + cons.writer().format("%s: ", tag); + cons.flush(); + data = cons.readLine(); + } + if(data==null) { + if(err == null) { + err = new StringBuilder("Add -D"); + } else { + err.append(", -D"); + } + err.append(tag); + if(other!=null) { + err.append("=<"); + err.append(other); + err.append('>'); + } + } + } + if(data!=null) { + System.setProperty(tag, data); + } + } + + public StringBuilder err() { + return err; + } + } + + public boolean isTest() { + return AAFcli.isTest; + } + + public boolean isDetailed() { + return AAFcli.showDetails; + } + + public String typeString(Class cls, boolean json) { + return "application/" + cls.getSimpleName() + "+" + (json ? "json" : "xml") + ";version=" + hman.apiVersion(); + } + + public String forceString() { + return force; + } + + public boolean addRequest() { + return request; + } + + public void clearSingleLineProperties() { + force = null; + request = false; + showDetails = false; + } + + public void gui(boolean b) { + gui = b; + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/BaseCmd.java b/authz-cmd/src/main/java/com/att/cmd/BaseCmd.java new file mode 100644 index 00000000..44724dc5 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/BaseCmd.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import java.util.ArrayList; +import java.util.List; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + + +public class BaseCmd extends Cmd { + protected List cmds; + + public BaseCmd(AAFcli aafcli, String name, Param ... params) { + super(aafcli, null, name, params); + cmds = new ArrayList(); + } + + public BaseCmd(CMD parent, String name, Param ... params) { + super(parent.aafcli, parent, name, params); + cmds = new ArrayList(); + } + + + @Override + public int _exec( int idx, final String ... args) throws CadiException, APIException, LocatorException { + if(args.length-idx<1) { + pw().println(build(new StringBuilder(),null).toString()); + } else { + String s = args[idx]; + String name; + Cmd empty = null; + for(Cmd c: cmds) { + name = c.getName(); + if(name==null && empty==null) { // Mark with Command is null, and take the first one. + empty = c; + } else if(s.equalsIgnoreCase(c.getName())) + return c.exec(idx+1, args); + } + if(empty!=null) { + return empty.exec(idx, args); // If name is null, don't account for it on command line. jg 4-29 + } + pw().println("Instructions not understood."); + } + return 0; + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/BasicAuth.java b/authz-cmd/src/main/java/com/att/cmd/BasicAuth.java new file mode 100644 index 00000000..3dce84c3 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/BasicAuth.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import java.io.IOException; + +import com.att.aft.dme2.api.DME2Client; +import com.att.cadi.SecuritySetter; +import com.att.cadi.Symm; + +public class BasicAuth implements SecuritySetter { + private String cred; + private String user; + + public BasicAuth(String user, String pass) throws IOException { + this.user = user; + cred = "Basic " + Symm.base64.encode(user+':'+pass); + } + + @Override + public void setSecurity(DME2Client client) { + client.addHeader("Authorization" , cred); + } + + @Override + public String getID() { + return user; + } + + //@Override + public int setLastResponse(int respCode) { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/Cmd.java b/authz-cmd/src/main/java/com/att/cmd/Cmd.java new file mode 100644 index 00000000..0439eb86 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/Cmd.java @@ -0,0 +1,499 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import java.io.PrintWriter; +import java.io.StringReader; +import java.sql.Date; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Stack; +import java.util.concurrent.ConcurrentHashMap; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cadi.http.HMangr; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; +import com.att.inno.env.Data.TYPE; +import com.att.inno.env.Env; +import com.att.inno.env.util.Chrono; +import com.att.rosetta.env.RosettaDF; +import com.att.rosetta.env.RosettaEnv; + +import aaf.v2_0.Error; +import aaf.v2_0.History; +import aaf.v2_0.History.Item; +import aaf.v2_0.Request; + + +public abstract class Cmd { + private static final String AAF_DEFAULT_REALM = "aaf_default_realm"; + + private static final DateFormat dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); + protected static final String BLANK = ""; + protected static final String COMMA = ","; // for use in splits + + protected static final int lineLength = 80; + + private final static String hformat = "%-23s %-5s %-20s %-35s\n"; + + public static final String STARTDATE = "startdate"; + public static final String ENDDATE = "enddate"; + + private String name; + private final Param[] params; + private int required; + protected final Cmd parent; + protected final List children; + private final ConcurrentHashMap,RosettaDF> dfs = new ConcurrentHashMap,RosettaDF>(); + public final AAFcli aafcli; + protected Env env; + + public Cmd(AAFcli aafcli, String name, Param ... params) { + this(aafcli,null, name,params); + } + + public Cmd(Cmd parent, String name, Param ... params) { + this(parent.aafcli,parent, name,params); + } + + Cmd(AAFcli aafcli, Cmd parent, String name, Param ... params) { + this.parent = parent; + this.aafcli = aafcli; + this.env = aafcli.env; + if(parent!=null) { + parent.children.add(this); + } + children = new ArrayList(); + this.params = params; + this.name = name; + required=0; + for(Param p : params) { + if(p.required) { + ++required; + } + } + } + + public final int exec(int idx, String ... args) throws CadiException, APIException, LocatorException { + if(args.length-idx cls,boolean head) { + int indent = _indent; + final String meth = hmeth.name(); + if(head) { + sb.append('\n'); + detailLine(sb,indent,"APIs:"); + } + indent+=2; + multiChar(sb,indent,' ',0); + sb.append(meth); + sb.append(' '); + sb.append(pathInfo); + String cliString = aafcli.typeString(cls,true); + if(indent+meth.length()+pathInfo.length()+cliString.length()+2>80) { + sb.append(" ..."); + multiChar(sb,indent+3+meth.length(),' ',0); + } else { // same line + sb.append(' '); + } + sb.append(cliString); + } + + protected void multiChar(StringBuilder sb, int length, char c, int indent) { + sb.append('\n'); + for(int i=0;i ": "] "); + } + + boolean first = true; + for(Cmd child : children) { + if(first) { + first = false; + } else if(detail==null) { + multiChar(sb,indent,' ',0); + } else { + // Write parents for Detailed Report + Stack stack = new Stack(); + for(Cmd c = child.parent;c!=null;c=c.parent) { + if(c.name!=null) { + stack.push(c.name); + } + } + if(!stack.isEmpty()) { + sb.append(" "); + while(!stack.isEmpty()) { + sb.append(stack.pop()); + sb.append(' '); + } + } + } + child.build(sb,detail); + if(detail!=null) { + child.detailedHelp(4, detail); + // If Child wrote something, then add, bracketing by lines + if(detail.length()>0) { + multiChar(sb,80,'-',2); + sb.append(detail); + sb.append('\n'); + multiChar(sb,80,'-',2); + sb.append('\n'); + detail.setLength(0); // reuse + } else { + sb.append('\n'); + } + } + } + return sb; + } + + protected void error(Future future) { + StringBuilder sb = new StringBuilder("Failed"); + String desc = future.body(); + int code = future.code(); + if(desc==null || desc.length()==0) { + withCode(sb,code); + } else if(desc.startsWith("{")) { + StringReader sr = new StringReader(desc); + try { + // Note: 11-18-2013. This rather convoluted Message Structure required by TSS Restful Specs, reflecting "Northbound" practices. + Error err = getDF(Error.class).newData().in(TYPE.JSON).load(sr).asObject(); + sb.append(" ["); + sb.append(err.getMessageId()); + sb.append("]: "); + String messageBody = err.getText(); + List vars = err.getVariables(); + int pipe; + for (int varCounter=0;varCounter= 0) { + if((pipe = var.indexOf('|'))>=0) { // In AAF, we use a PIPE for Choice + if (aafcli.isTest()) { + String expiresStr = var.substring(pipe); + var = var.replace(expiresStr, "[Placeholder]"); + } else { + StringBuilder varsb = new StringBuilder(var); + varsb.deleteCharAt(pipe); + var = varsb.toString(); + } + messageBody = messageBody.replace("%" + varCounter, varCounter-1 + ") " + var); + } else { + messageBody = messageBody.replace("%" + varCounter, var); + } + } + } + sb.append(messageBody); + } catch (Exception e) { + withCode(sb,code); + sb.append(" (Note: Details cannot be obtained from Error Structure)"); + } + } else if(desc.startsWith("")){ // Core Jetty, etc sends HTML for Browsers + withCode(sb,code); + } else { + sb.append(" with code "); + sb.append(code); + sb.append(", "); + sb.append(desc); + } + pw().println(sb); + } + + + private void withCode(StringBuilder sb, Integer code) { + sb.append(" with code "); + sb.append(code); + switch(code) { + case 401: + sb.append(" (HTTP Not Authenticated)"); + break; + case 403: + sb.append(" (HTTP Forbidden)"); + break; + case 404: + sb.append(" (HTTP Not Found)"); + break; + default: + } + } + + /** + * Consistently set start and end dates from Requests (all derived from Request) + * @param req + */ + protected void setStartEnd(Request req) { + // Set Start/End Dates, if exist + String str; + if((str = env.getProperty(Cmd.STARTDATE,null))!=null) { + req.setStart(Chrono.timeStamp(Date.valueOf(str))); + } + + if((str = env.getProperty(Cmd.ENDDATE,null))!=null) { + req.setEnd(Chrono.timeStamp(Date.valueOf(str))); + } + } + + @SuppressWarnings("unchecked") + protected RosettaDF getDF(Class cls) throws APIException { + RosettaDF rdf = (RosettaDF)dfs.get(cls); + if(rdf == null) { + rdf = env().newDataFactory(cls); + dfs.put(cls, rdf); + } + return rdf; + } + + public void activity(History history, String header) { + if (history.getItem().isEmpty()) { + int start = header.indexOf('['); + if (start >= 0) { + pw().println("No Activity Found for " + header.substring(start)); + } + } else { + pw().println(header); + for(int i=0;i items = history.getItem(); + java.util.Collections.sort(items, new Comparator() { + @Override + public int compare(Item o1, Item o2) { + return o2.getTimestamp().compare(o1.getTimestamp()); + } + }); + + for(History.Item item : items) { + GregorianCalendar gc = item.getTimestamp().toGregorianCalendar(); + pw().format(hformat, + dateFmt.format(gc.getTime()), + item.getTarget(), + item.getUser(), + item.getMemo()); + } + } + } + + /** + * Turn String Array into a | delimited String + * @param options + * @return + */ + public static String optionsToString(String[] options) { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for(String s : options) { + if(first) { + first = false; + } else { + sb.append('|'); + } + sb.append(s); + } + return sb.toString(); + } + + /** + * return which index number the Option matches. + * + * throws an Exception if not part of this Option Set + * + * @param options + * @param test + * @return + * @throws Exception + */ + public int whichOption(String[] options, String test) throws CadiException { + for(int i=0;i RET same(Retryable retryable) throws APIException, CadiException, LocatorException { + // We're storing in AAFCli, because we know it's always the same, and single threaded + if(aafcli.prevCall!=null) { + retryable.item(aafcli.prevCall.item()); + retryable.lastClient=aafcli.prevCall.lastClient; + } + + RET ret = aafcli.hman.same(aafcli.ss,retryable); + + // Store last call in AAFcli, because Cmds are all different instances. + aafcli.prevCall = retryable; + return ret; + } + + public RET all(Retryable retryable) throws APIException, CadiException, LocatorException { + this.setQueryParamsOn(retryable.lastClient); + return aafcli.hman.all(aafcli.ss,retryable); + } + + public RET oneOf(Retryable retryable,String host) throws APIException, CadiException, LocatorException { + this.setQueryParamsOn(retryable.lastClient); + return aafcli.hman.oneOf(aafcli.ss,retryable,true,host); + } + + protected PrintWriter pw() { + return AAFcli.pw; + } + + public String getName() { + return name; + } + + public void reportHead(String ... str) { + pw().println(); + boolean first = true; + int i=0; + for(String s : str) { + if(first) { + if(++i>1) { + first = false; + pw().print("["); + } + } else { + pw().print("] ["); + } + pw().print(s); + } + if(!first) { + pw().print(']'); + } + pw().println(); + reportLine(); + } + + public String reportColHead(String format, String ... args) { + pw().format(format,(Object[])args); + reportLine(); + return format; + } + + public void reportLine() { + for(int i=0;i rcli) { + StringBuilder sb=null; + String force; + if((force=aafcli.forceString())!=null) { + sb = new StringBuilder("force="); + sb.append(force); + } + if(aafcli.addRequest()) { + if(sb==null) { + sb = new StringBuilder("request=true"); + } else { + sb.append("&request=true"); + } + } + if(sb!=null && rcli!=null) { + rcli.setQueryParams(sb.toString()); + } + } +// +// /** +// * If Force is set, will return True once only, then revert to "FALSE". +// * +// * @return +// */ +// protected String checkForce() { +// if(TRUE.equalsIgnoreCase(env.getProperty(FORCE, FALSE))) { +// env.setProperty(FORCE, FALSE); +// return "true"; +// } +// return FALSE; +// } + + public String toString() { + StringBuilder sb = new StringBuilder(); + if(parent==null) { // ultimate parent + build(sb,null); + return sb.toString(); + } else { + return parent.toString(); + } + } + + public String getOrgRealm() { + return env.getProperty(AAF_DEFAULT_REALM); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/Help.java b/authz-cmd/src/main/java/com/att/cmd/Help.java new file mode 100644 index 00000000..ae3c4c11 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/Help.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import java.util.List; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +public class Help extends Cmd { + private List cmds; + + public Help(AAFcli aafcli, List cmds) { + super(aafcli, "--help", + new Param("-d (more details)", false), + new Param("command",false)); + this.cmds = cmds; + } + + @Override + public int _exec( int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + boolean first = true; + StringBuilder sb = new StringBuilder("AAF Command Line Tool"); + StringBuilder details; + if(aafcli.isDetailed() ){ + multiChar(sb, 21, '-',0); + details=new StringBuilder();// use for temporary writing of details + } else { + multiChar(sb, 21, '-',0); + details = null; + } + String comp = args.length>idx?args[idx++]:null; + if("help".equalsIgnoreCase(comp)) { + build(sb,null); + detailedHelp(4, sb); + sb.append('\n'); + } else { + for(Cmd c : cmds) { + if(comp!=null) { + if(comp.equals(c.getName())) { + multiChar(sb,2,' ',0); + c.build(sb,details); + } + } else { + if(first) { + first=false; + } else { + multiChar(sb,80,'-',2); + } + multiChar(sb,2,' ',0); + c.build(sb,details); + if(details!=null) { + c.detailedHelp(4, sb); +// multiChar(sb,80,'-',2); + } + } + } + } + pw().println(sb.toString()); + return HttpStatus.OK_200; + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"To print main help, enter \"aafcli\" or \"aafcli --help \""); + detailLine(sb,indent,"To print narrow the help content, enter sub-entries after aafcli,"); + detailLine(sb,indent+2,"i.e. \"aafcli perm\""); + detailLine(sb,indent,"To see version of AAF CLI, enter \"aafcli --version \""); + sb.append('\n'); + detailLine(sb,indent,"State Commands: change variables or credentials between calls."); + indent+=4; + detailLine(sb,indent,"set = - Set any System Property to a new value"); + detailLine(sb,indent,"as - Change Credentials. Password may be encrypted"); + detailLine(sb,indent,"expect [int]* - In test mode, check for proper HTTP Status Codes"); + detailLine(sb,indent,"sleep - Wait for seconds"); + sb.append('\n'); + detailLine(sb,indent-4,"CmdLine Arguments: change behavior of the aafcli program"); + detailLine(sb,indent,"-i - Read commands from Shell Standard Input"); + detailLine(sb,indent,"-f - Read commands from a file"); + detailLine(sb,indent,"-a - In test mode, do not stop execution on unexpected error"); + detailLine(sb,indent,"-t - Test Mode will not print variable fields that could break tc runs"); + detailLine(sb,indent+6,"such as expiration dates of a credential"); + detailLine(sb,indent,"-s - Request specific Start Date (not immediately)"); + detailLine(sb,indent+6,"Format YYYY-MM-DD. Can also be set with \"set " + Cmd.STARTDATE + "=\""); + detailLine(sb,indent,"-e - Set Expiration/End Date, where commands support"); + detailLine(sb,indent+6,"Format YYYY-MM-DD. Can also be set with \"set " + Cmd.ENDDATE + "=\""); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/MessageException.java b/authz-cmd/src/main/java/com/att/cmd/MessageException.java new file mode 100644 index 00000000..329f0194 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/MessageException.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * + */ +package com.att.cmd; + +/** + * An Exception designed simply to give End User message, no stack trace + * + * + */ +public class MessageException extends Exception { + /** + * + */ + private static final long serialVersionUID = 8143933588878259048L; + + /** + * @param Message + */ + public MessageException(String msg) { + super(msg); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/Param.java b/authz-cmd/src/main/java/com/att/cmd/Param.java new file mode 100644 index 00000000..a944859a --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/Param.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +public class Param { + public final String tag; + public final boolean required; + + /** + * + * @param t + * @param b + */ + public Param(String t, boolean required) { + tag = t; + this.required=required; + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/Version.java b/authz-cmd/src/main/java/com/att/cmd/Version.java new file mode 100644 index 00000000..318d223e --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/Version.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.config.Config; +import com.att.inno.env.APIException; + +public class Version extends Cmd { + + + public Version(AAFcli aafcli) { + super(aafcli, "--version"); + } + + @Override + protected int _exec(int idx, String... args) throws CadiException, APIException, LocatorException { + pw().println("AAF Command Line Tool"); + String version = this.env().getProperty(Config.AAF_DEPLOYED_VERSION, "N/A"); + pw().println("Version: " + version); + return HttpStatus.OK_200; + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/mgmt/Cache.java b/authz-cmd/src/main/java/com/att/cmd/mgmt/Cache.java new file mode 100644 index 00000000..2ef030fb --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/mgmt/Cache.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import com.att.cmd.BaseCmd; +import com.att.inno.env.APIException; + +public class Cache extends BaseCmd { + public Cache(Mgmt mgmt) throws APIException { + super(mgmt, "cache"); + cmds.add(new Clear(this)); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/mgmt/Clear.java b/authz-cmd/src/main/java/com/att/cmd/mgmt/Clear.java new file mode 100644 index 00000000..89a99f96 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/mgmt/Clear.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import com.att.authz.common.Define; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +/** + * p + * + */ +public class Clear extends Cmd { + public Clear(Cache parent) { + super(parent,"clear", + new Param("name[,name]*",true)); + } + + @Override + public int _exec(int _idx, String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + int rv=409; + for(final String name : args[idx++].split(COMMA)) { + rv = all(new Retryable() { + @Override + public Integer code(Rcli client) throws APIException, CadiException { + int rv = 409; + Future fp = client.delete( + "/mgmt/cache/"+name, + Void.class + ); + if(fp.get(AAFcli.timeout())) { + pw().println("Cleared Cache for " + name + " on " + client); + rv=200; + } else { + if(rv==409)rv = fp.code(); + error(fp); + } + return rv; + } + }); + } + return rv; + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Clear the cache for certain tables"); + indent+=2; + detailLine(sb,indent,"name - name of table or 'all'"); + detailLine(sb,indent+14,"Must have admin rights to '" + Define.ROOT_NS + '\''); + indent-=2; + api(sb,indent,HttpMethods.DELETE,"mgmt/cache/:name",Void.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/mgmt/Deny.java b/authz-cmd/src/main/java/com/att/cmd/mgmt/Deny.java new file mode 100644 index 00000000..f345cfa7 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/mgmt/Deny.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.inno.env.APIException; + +public class Deny extends BaseCmd { + private final static String[] options = {"add","del"}; + + public Deny(Mgmt mgmt) throws APIException { + super(mgmt, "deny"); + cmds.add(new DenySomething(this,"ip","ipv4or6[,ipv4or6]*")); + cmds.add(new DenySomething(this,"id","identity[,identity]*")); + } + + public class DenySomething extends Cmd { + + private boolean isID; + + public DenySomething(Deny deny, String type, String repeatable) { + super(deny, type, + new Param(optionsToString(options),true), + new Param(repeatable,true)); + isID = "id".equals(type); + } + + @Override + protected int _exec(int _idx, String... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + String action = args[idx++]; + final int option = whichOption(options, action); + int rv=409; + for(final String name : args[idx++].split(COMMA)) { + final String append; + if(isID && name.indexOf("@")<0) { + append='@'+ env.getProperty(AAFcli.AAF_DEFAULT_REALM); + } else { + append = ""; + } + final String path = "/mgmt/deny/"+getName() + '/'+ name + append; + rv = all(new Retryable() { + @Override + public Integer code(Rcli client) throws APIException, CadiException { + int rv = 409; + Future fp; + String resp; + switch(option) { + case 0: + fp = client.create(path, Void.class); + resp = " added"; + break; + default: + fp = client.delete(path, Void.class); + resp = " deleted"; + } + if(fp.get(AAFcli.timeout())) { + pw().println(name + append + resp + " on " + client); + rv=fp.code(); + } else { + if(rv==409)rv = fp.code(); + error(fp); + } + return rv; + } + }); + } + return rv; + } + + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/mgmt/Log.java b/authz-cmd/src/main/java/com/att/cmd/mgmt/Log.java new file mode 100644 index 00000000..aa10c584 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/mgmt/Log.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import com.att.authz.common.Define; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +public class Log extends BaseCmd { + private final static String[] options = {"add","del"}; + + public Log(Mgmt mgmt) throws APIException { + super(mgmt, "log", + new Param(optionsToString(options),true), + new Param("id[,id]*",true)); + } + + @Override + public int _exec(int _idx, String ... args) throws CadiException, APIException, LocatorException { + int rv=409; + int idx = _idx; + final int option = whichOption(options, args[idx++]); + + for(String name : args[idx++].split(COMMA)) { + final String fname; + if(name.indexOf("@")<0) { + fname=name+'@'+ env.getProperty(AAFcli.AAF_DEFAULT_REALM); + } else { + fname = name; + } + + + + rv = all(new Retryable() { + @Override + public Integer code(Rcli client) throws APIException, CadiException { + int rv = 409; + Future fp; + String str = "/mgmt/log/id/"+fname; + String msg; + switch(option) { + case 0: + fp = client.create(str,Void.class); + msg = "Added"; + break; + case 1: + fp = client.delete(str,Void.class); + msg = "Deleted"; + break; + default: + fp = null; + msg = "Ignored"; + } + + if(fp!=null) { + if(fp.get(AAFcli.timeout())) { + pw().println(msg + " Special Log for " + fname + " on " + client); + rv=200; + } else { + if(rv==409)rv = fp.code(); + error(fp); + } + return rv; + } + return rv; + } + }); + } + return rv; + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Clear the cache for certain tables"); + indent+=2; + detailLine(sb,indent,"name - name of table or 'all'"); + detailLine(sb,indent+14,"Must have admin rights to '" + Define.ROOT_NS + '\''); + indent-=2; + api(sb,indent,HttpMethods.DELETE,"mgmt/cache/:name",Void.class,true); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/mgmt/Mgmt.java b/authz-cmd/src/main/java/com/att/cmd/mgmt/Mgmt.java new file mode 100644 index 00000000..b428af80 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/mgmt/Mgmt.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.inno.env.APIException; + +public class Mgmt extends BaseCmd { + public Mgmt(AAFcli aafcli) throws APIException { + super(aafcli, "mgmt"); + cmds.add(new Cache(this)); + cmds.add(new Deny(this)); + cmds.add(new Log(this)); + cmds.add(new Session(this)); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/mgmt/SessClear.java b/authz-cmd/src/main/java/com/att/cmd/mgmt/SessClear.java new file mode 100644 index 00000000..8258422f --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/mgmt/SessClear.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import com.att.authz.common.Define; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +/** + * p + * + */ +public class SessClear extends Cmd { + public SessClear(Session parent) { + super(parent,"clear", + new Param("machine",true)); + } + + @Override + public int _exec(int idx, String ... args) throws CadiException, APIException, LocatorException { + int rv=409; + String machine = args[idx++]; + rv = oneOf(new Retryable() { + @Override + public Integer code(Rcli client) throws APIException, CadiException { + int rv = 409; + Future fp = client.delete( + "/mgmt/dbsession", + Void.class + ); + if(fp.get(AAFcli.timeout())) { + pw().println("Cleared DBSession on " + client); + rv=200; + } else { + if(rv==409)rv = fp.code(); + error(fp); + } + return rv; + } + },machine); + return rv; + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Clear the cache for certain tables"); + indent+=2; + detailLine(sb,indent,"name - name of table or 'all'"); + detailLine(sb,indent+14,"Must have admin rights to '" + Define.ROOT_NS + '\''); + indent-=2; + api(sb,indent,HttpMethods.DELETE,"mgmt/cache/:name",Void.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/mgmt/Session.java b/authz-cmd/src/main/java/com/att/cmd/mgmt/Session.java new file mode 100644 index 00000000..fb60f274 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/mgmt/Session.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import com.att.cmd.BaseCmd; +import com.att.inno.env.APIException; + +public class Session extends BaseCmd { + public Session(Mgmt mgmt) throws APIException { + super(mgmt, "dbsession"); + cmds.add(new SessClear(this)); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/Admin.java b/authz-cmd/src/main/java/com/att/cmd/ns/Admin.java new file mode 100644 index 00000000..a67ff2ee --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/Admin.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +public class Admin extends BaseCmd { + private final static String[] options = {"add","del"}; + + public Admin(NS ns) throws APIException { + super(ns,"admin", + new Param(optionsToString(options),true), + new Param("name",true), + new Param("id[,id]*",true) + ); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final int option = whichOption(options, args[idx++]); + final String ns = args[idx++]; + final String ids[] = args[idx++].split(","); + final String realm = getOrgRealm(); +// int rv = 500; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = null; + for(String id : ids) { + if (id.indexOf('@') < 0 && realm != null) id += '@' + realm; + String verb; + switch(option) { + case 0: + fp = client.create("/authz/ns/"+ns+"/admin/"+id,Void.class); + verb = " added to "; + break; + case 1: + fp = client.delete("/authz/ns/"+ns+"/admin/"+id,Void.class); + verb = " deleted from "; + break; + default: + throw new CadiException("Bad Argument"); + }; + + if(fp.get(AAFcli.timeout())) { + pw().append("Admin "); + pw().append(id); + pw().append(verb); + pw().println(ns); + } else { + error(fp); + return fp.code(); + } + + } + return fp==null?500:fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Add or Delete Administrator to/from Namespace"); + indent+=4; + detailLine(sb,indent,"name - Name of Namespace"); + detailLine(sb,indent,"id - Credential of Person(s) to be Administrator"); + sb.append('\n'); + detailLine(sb,indent,"aafcli will call API on each ID presented."); + indent-=4; + api(sb,indent,HttpMethods.POST,"authz/ns//admin/",Void.class,true); + api(sb,indent,HttpMethods.DELETE,"authz/ns//admin/",Void.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/Attrib.java b/authz-cmd/src/main/java/com/att/cmd/ns/Attrib.java new file mode 100644 index 00000000..ffe9b087 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/Attrib.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +public class Attrib extends BaseCmd { + private final static String[] options = {"add","upd","del"}; + + public Attrib(NS ns) throws APIException { + super(ns,"attrib", + new Param(optionsToString(options),true), + new Param("ns",true), + new Param("key",true), + new Param("value",false) + ); + } + + @Override + public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException { + final int option = whichOption(options, args[idx]); + final String ns = args[idx+1]; + final String key = args[idx+2]; + final String value; + if(option!=2) { + if(args.length<=idx+3) { + throw new CadiException("Not added: Need more Data"); + } + value = args[idx+3]; + } else { + value = ""; + } + + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = null; + String message; + switch(option) { + case 0: + fp = client.create("/authz/ns/"+ns+"/attrib/"+key+'/'+value,Void.class); + message = String.format("Add Attrib %s=%s to %s", + key,value,ns); + break; + case 1: + fp = client.update("/authz/ns/"+ns+"/attrib/"+key+'/'+value); + message = String.format("Update Attrib %s=%s for %s", + key,value,ns); + break; + case 2: + fp = client.delete("/authz/ns/"+ns+"/attrib/"+key,Void.class); + message = String.format("Attrib %s deleted from %s", + key,ns); + break; + default: + throw new CadiException("Bad Argument"); + }; + + if(fp.get(AAFcli.timeout())) { + pw().println(message); + } else { + error(fp); + return fp.code(); + } + + return fp==null?500:fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Add or Delete Administrator to/from Namespace"); + indent+=4; + detailLine(sb,indent,"name - Name of Namespace"); + detailLine(sb,indent,"id - Credential of Person(s) to be Administrator"); + sb.append('\n'); + detailLine(sb,indent,"aafcli will call API on each ID presented."); + indent-=4; + api(sb,indent,HttpMethods.POST,"authz/ns//admin/",Void.class,true); + api(sb,indent,HttpMethods.DELETE,"authz/ns//admin/",Void.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/Create.java b/authz-cmd/src/main/java/com/att/cmd/ns/Create.java new file mode 100644 index 00000000..c314a107 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/Create.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.NsRequest; + +/** + * p + * + */ +public class Create extends Cmd { + private static final String COMMA = ","; + + public Create(NS parent) { + super(parent,"create", + new Param("name",true), + new Param("responsible (id[,id]*)",true), + new Param("admin (id[,id]*)",false)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + + final NsRequest nr = new NsRequest(); + + String realm = getOrgRealm(); + + nr.setName(args[idx++]); + String[] responsible = args[idx++].split(COMMA); + for(String s : responsible) { + if (s.indexOf('@') < 0 && realm != null) s += '@' + realm; + nr.getResponsible().add(s); + } + String[] admin; + if(args.length>idx) { + admin = args[idx++].split(COMMA); + } else { + admin = responsible; + } + for(String s : admin) { + if (s.indexOf('@') < 0 && realm != null) s += '@' + realm; + nr.getAdmin().add(s); + } + + // Set Start/End commands + setStartEnd(nr); + + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + // Requestable + setQueryParamsOn(client); + Future fp = client.create( + "/authz/ns", + getDF(NsRequest.class), + nr + ); + if(fp.get(AAFcli.timeout())) { + pw().println("Created Namespace"); + } else { + if(fp.code()==202) { + pw().println("Namespace Creation Accepted, but requires Approvals before actualizing"); + } else { + error(fp); + } + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Create a Namespace"); + indent+=2; + detailLine(sb,indent,"name - Namespaces are dot-delimited, ex com.att.myapp"); + detailLine(sb,indent+14,"and must be created with parent credentials."); + detailLine(sb,indent+14,"Ex: to create com.att.myapp, you must be admin for com.att"); + detailLine(sb,indent+14,"or com"); + detailLine(sb,indent,"responsible - This is the person(s) who receives Notifications and"); + detailLine(sb,indent+14,"approves Requests regarding this Namespace. Companies have"); + detailLine(sb,indent+14,"Policies as to who may take on this responsibility"); + detailLine(sb,indent,"admin - These are the people who are allowed to make changes on"); + detailLine(sb,indent+14,"the Namespace, including creating Roles, Permissions"); + detailLine(sb,indent+14,"and Credentials"); + sb.append('\n'); + detailLine(sb,indent,"Namespaces can be created even though there are Roles/Permissions which"); + detailLine(sb,indent,"start with the requested sub-namespace. They are reassigned to the"); + detailLine(sb,indent,"Child Namespace"); + indent-=2; + api(sb,indent,HttpMethods.POST,"authz/ns",NsRequest.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/Delete.java b/authz-cmd/src/main/java/com/att/cmd/ns/Delete.java new file mode 100644 index 00000000..a957def6 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/Delete.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +/** + * p + * + */ +public class Delete extends Cmd { + public Delete(NS parent) { + super(parent,"delete", + new Param("name",true)); + } + + @Override + public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int index = idx; + StringBuilder path = new StringBuilder("/authz/ns/"); + path.append(args[index++]); + + // Send "Force" if set + setQueryParamsOn(client); + Future fp = client.delete(path.toString(),Void.class); + + if(fp.get(AAFcli.timeout())) { + pw().println("Deleted Namespace"); + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Delete a Namespace"); + indent+=4; + detailLine(sb,indent,"Namespaces cannot normally be deleted when there are still credentials,"); + detailLine(sb,indent,"permissions or roles associated with them. These can be deleted"); + detailLine(sb,indent,"automatically by setting \"force\" property."); + detailLine(sb,indent,"i.e. set force=true or just starting with \"force\""); + detailLine(sb,indent," (note force is unset after first use)"); + sb.append('\n'); + detailLine(sb,indent,"If \"set force=move\" is set, credentials are deleted, but "); + detailLine(sb,indent,"Permissions and Roles are assigned to the Parent Namespace instead of"); + detailLine(sb,indent,"being deleted. Similarly, Namespaces can be created even though there"); + detailLine(sb,indent,"are Roles/Perms whose type starts with the requested sub-namespace."); + detailLine(sb,indent,"They are simply reassigned to the Child Namespace"); + indent-=4; + api(sb,indent,HttpMethods.DELETE,"authz/ns/[?force=true]",Void.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/Describe.java b/authz-cmd/src/main/java/com/att/cmd/ns/Describe.java new file mode 100644 index 00000000..6e57b094 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/Describe.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.NsRequest; + +public class Describe extends Cmd { + private static final String NS_PATH = "/authz/ns"; + public Describe(NS parent) { + super(parent,"describe", + new Param("name",true), + new Param("description",true)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String name = args[idx++]; + StringBuilder desc = new StringBuilder(); + while (idx < args.length) { + desc.append(args[idx++] + ' '); + } + + NsRequest nsr = new NsRequest(); + nsr.setName(name); + nsr.setDescription(desc.toString()); + + // Set Start/End commands + setStartEnd(nsr); + + Future fn = null; + int rv; + + fn = client.update( + NS_PATH, + getDF(NsRequest.class), + nsr + ); + + if(fn.get(AAFcli.timeout())) { + rv=fn.code(); + pw().println("Description added to Namespace"); + } else { + if((rv=fn.code())==202) { + pw().print("Adding description"); + pw().println(" Accepted, but requires Approvals before actualizing"); + } else { + error(fn); + } + } + return rv; + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,"Add a description to a namespace"); + api(sb,indent,HttpMethods.PUT,"authz/ns",NsRequest.class,true); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/List.java b/authz-cmd/src/main/java/com/att/cmd/ns/List.java new file mode 100644 index 00000000..fe80d62e --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/List.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import java.util.Collections; +import java.util.Comparator; + +import com.att.cadi.client.Future; +import com.att.cmd.BaseCmd; +import com.att.inno.env.util.Chrono; + +import aaf.v2_0.Nss; +import aaf.v2_0.Nss.Ns; +import aaf.v2_0.Nss.Ns.Attrib; +import aaf.v2_0.Perms; +import aaf.v2_0.Roles; +import aaf.v2_0.Users; +import aaf.v2_0.Users.User; + +public class List extends BaseCmd { + + public List(NS parent) { + super(parent,"list"); + cmds.add(new ListByName(this)); + +// TODO: uncomment when on cassandra 2.1.2 if we like cli command to get all ns's +// a user is admin or responsible for + cmds.add(new ListAdminResponsible(this)); + + cmds.add(new ListActivity(this)); + cmds.add(new ListUsers(this)); + cmds.add(new ListChildren(this)); + cmds.add(new ListNsKeysByAttrib(this)); + } + + private static final String sformat = " %-72s\n"; + protected static final String kformat = " %-72s\n"; + + + public void report(Future fp, String ... str) { + reportHead(str); + if(fp==null) { + pw().println(" *** Namespace Not Found ***"); + } + + if(fp!=null && fp.value!=null) { + for(Ns ns : fp.value.getNs()) { + pw().println(ns.getName()); + if (this.aafcli.isDetailed()) { + pw().println(" Description"); + pw().format(sformat,ns.getDescription()==null?"":ns.getDescription()); + } + if(ns.getAdmin().size()>0) { + pw().println(" Administrators"); + for(String admin : ns.getAdmin()) { + pw().format(sformat,admin); + } + } + if(ns.getResponsible().size()>0) { + pw().println(" Responsible Parties"); + for(String responsible : ns.getResponsible()) { + pw().format(sformat,responsible); + } + } + if(ns.getAttrib().size()>0) { + pw().println(" Namespace Attributes"); + for(Attrib attrib : ns.getAttrib()) { + StringBuilder sb = new StringBuilder(attrib.getKey()); + if(attrib.getValue()==null || attrib.getValue().length()>0) { + sb.append('='); + sb.append(attrib.getValue()); + } + pw().format(sformat,sb.toString()); + } + + } + } + } + } + + public void reportName(Future fp, String ... str) { + reportHead(str); + if(fp!=null && fp.value!=null) { + java.util.List nss = fp.value.getNs(); + Collections.sort(nss, new Comparator() { + @Override + public int compare(Ns ns1, Ns ns2) { + return ns1.getName().compareTo(ns2.getName()); + } + }); + + for(Ns ns : nss) { + pw().println(ns.getName()); + if (this.aafcli.isDetailed() && ns.getDescription() != null) { + pw().println(" " + ns.getDescription()); + } + } + } + } + + public void reportRole(Future fr) { + if(fr!=null && fr.value!=null && fr.value.getRole().size()>0) { + pw().println(" Roles"); + for(aaf.v2_0.Role r : fr.value.getRole()) { + pw().format(sformat,r.getName()); + } + } + } + + private static final String pformat = " %-30s %-24s %-15s\n"; + public void reportPerm(Future fp) { + if(fp!=null && fp.value!=null && fp.value.getPerm().size()>0) { + pw().println(" Permissions"); + for(aaf.v2_0.Perm p : fp.value.getPerm()) { + pw().format(pformat,p.getType(),p.getInstance(),p.getAction()); + } + } + } + + + private static final String cformat = " %-30s %-6s %-24s\n"; + public void reportCred(Future fc) { + if(fc!=null && fc.value!=null && fc.value.getUser().size()>0) { + pw().println(" Credentials"); + java.util.List users = fc.value.getUser(); + Collections.sort(users, new Comparator() { + @Override + public int compare(User u1, User u2) { + return u1.getId().compareTo(u2.getId()); + } + }); + for(aaf.v2_0.Users.User u : users) { + if (this.aafcli.isTest()) { + pw().format(sformat,u.getId()); + } else { + String type; + switch(u.getType()) { + case 1: type = "U/P"; break; + case 10: type="Cert"; break; + case 200: type="x509"; break; + default: type = ""; + } + pw().format(cformat,u.getId(),type,Chrono.niceDateStamp(u.getExpires())); + } + } + } + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/ListActivity.java b/authz-cmd/src/main/java/com/att/cmd/ns/ListActivity.java new file mode 100644 index 00000000..afc041fb --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/ListActivity.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.History; + +/** + * + */ +public class ListActivity extends Cmd { + private static final String HEADER = "List Activity of Namespace"; + + public ListActivity(List parent) { + super(parent,"activity", + new Param("name",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String ns = args[idx++]; + + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authz/hist/ns/"+ns, + getDF(History.class) + ); + + if(fp.get(AAFcli.timeout())) { + activity(fp.value, HEADER + " [ " + ns + " ]"); + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/hist/ns/",History.class,true); + } + + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/ListAdminResponsible.java b/authz-cmd/src/main/java/com/att/cmd/ns/ListAdminResponsible.java new file mode 100644 index 00000000..9e559a9c --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/ListAdminResponsible.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Nss; + +public class ListAdminResponsible extends Cmd { + private static final String HEADER="List Namespaces with "; + private final static String[] options = {"admin","responsible"}; + + public ListAdminResponsible(List parent) { + super(parent,null, + new Param(optionsToString(options),true), + new Param("user",true)); + } + + @Override + protected int _exec(final int index, final String... args) throws CadiException, APIException, LocatorException { + + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String title = args[idx++]; + String user = args[idx++]; + if (user.indexOf('@') < 0 && getOrgRealm() != null) user += '@' + getOrgRealm(); + + Future fn = client.read("/authz/nss/"+title+"/"+user,getDF(Nss.class)); + if(fn.get(AAFcli.timeout())) { + ((List)parent).reportName(fn,HEADER + title + " privileges for ",user); + } else if(fn.code()==404) { + ((List)parent).report(null,HEADER + title + " privileges for ",user); + return 200; + } else { + error(fn); + } + return fn.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER + "admin or responsible priveleges for user"); + api(sb,indent,HttpMethods.GET,"authz/nss//",Nss.class,true); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/ListByName.java b/authz-cmd/src/main/java/com/att/cmd/ns/ListByName.java new file mode 100644 index 00000000..7459c221 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/ListByName.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Nss; +import aaf.v2_0.Nss.Ns; +import aaf.v2_0.Perms; +import aaf.v2_0.Roles; +import aaf.v2_0.Users; + +/** + * + */ +public class ListByName extends Cmd { + private static final String HEADER="List Namespaces by Name"; + + public ListByName(List parent) { + super(parent,"name", + new Param("ns",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String ns=args[idx++]; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fn = client.read("/authz/nss/"+ns,getDF(Nss.class)); + if(fn.get(AAFcli.timeout())) { + ((List)parent).report(fn,HEADER,ns); + if(fn.value!=null) { + for(Ns n : fn.value.getNs()) { + Future fr = client.read("/authz/roles/ns/"+n.getName(), getDF(Roles.class)); + if(fr.get(AAFcli.timeout())) { + ((List)parent).reportRole(fr); + } + } + for(Ns n : fn.value.getNs()) { + Future fp = client.read("/authz/perms/ns/"+n.getName(), getDF(Perms.class)); + if(fp.get(AAFcli.timeout())) { + ((List)parent).reportPerm(fp); + } + } + for(Ns n : fn.value.getNs()) { + Future fu = client.read("/authn/creds/ns/"+n.getName(), getDF(Users.class)); + if(fu.get(AAFcli.timeout())) { + ((List)parent).reportCred(fu); + } + } + } + } else if(fn.code()==404) { + ((List)parent).report(null,HEADER,ns); + return 200; + } else { + error(fn); + } + return fn.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/nss/",Nss.class,true); + detailLine(sb,indent,"Indirectly uses:"); + api(sb,indent,HttpMethods.GET,"authz/roles/ns/",Roles.class,false); + api(sb,indent,HttpMethods.GET,"authz/perms/ns/",Perms.class,false); + api(sb,indent,HttpMethods.GET,"authn/creds/ns/",Users.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/ListChildren.java b/authz-cmd/src/main/java/com/att/cmd/ns/ListChildren.java new file mode 100644 index 00000000..7ad60a71 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/ListChildren.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Nss; +import aaf.v2_0.Nss.Ns; + +/** + * p + * + */ +public class ListChildren extends Cmd { + private static final String HEADER="List Child Namespaces"; + + public ListChildren(List parent) { + super(parent,"children", + new Param("ns",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String ns=args[idx++]; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fn = client.read("/authz/nss/children/"+ns,getDF(Nss.class)); + if(fn.get(AAFcli.timeout())) { + parent.reportHead(HEADER); + for(Ns ns : fn.value.getNs()) { + pw().format(List.kformat, ns.getName()); + } + } else if(fn.code()==404) { + ((List)parent).report(null,HEADER,ns); + return 200; + } else { + error(fn); + } + return fn.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/nss/children/",Nss.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/ListNsKeysByAttrib.java b/authz-cmd/src/main/java/com/att/cmd/ns/ListNsKeysByAttrib.java new file mode 100644 index 00000000..3ce9d7de --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/ListNsKeysByAttrib.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Keys; +import aaf.v2_0.Nss; +import aaf.v2_0.Perms; +import aaf.v2_0.Roles; +import aaf.v2_0.Users; + +/** + * p + * + */ +public class ListNsKeysByAttrib extends Cmd { + private static final String HEADER="List Namespace Names by Attribute"; + + public ListNsKeysByAttrib(List parent) { + super(parent,"keys", + new Param("attrib",true)); + } + + @Override + public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException { + final String attrib=args[idx]; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fn = client.read("/authz/ns/attrib/"+attrib,getDF(Keys.class)); + if(fn.get(AAFcli.timeout())) { + parent.reportHead(HEADER); + for(String key : fn.value.getKey()) { + pw().printf(List.kformat, key); + } + } else if(fn.code()==404) { + parent.reportHead(HEADER); + pw().println(" *** No Namespaces Found ***"); + return 200; + } else { + error(fn); + } + return fn.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/nss/",Nss.class,true); + detailLine(sb,indent,"Indirectly uses:"); + api(sb,indent,HttpMethods.GET,"authz/roles/ns/",Roles.class,false); + api(sb,indent,HttpMethods.GET,"authz/perms/ns/",Perms.class,false); + api(sb,indent,HttpMethods.GET,"authn/creds/ns/",Users.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/ListUsers.java b/authz-cmd/src/main/java/com/att/cmd/ns/ListUsers.java new file mode 100644 index 00000000..e77df593 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/ListUsers.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import javax.xml.datatype.XMLGregorianCalendar; + +import com.att.cmd.BaseCmd; + +import aaf.v2_0.Users.User; + +public class ListUsers extends BaseCmd { + + public ListUsers(List parent) { + super(parent,"user"); + cmds.add(new ListUsersWithPerm(this)); + cmds.add(new ListUsersInRole(this)); + } + + public void report(String header, String ns) { + ((List)parent).report(null, header,ns); + } + + public void report(String subHead) { + pw().println(subHead); + } + + private static final String uformat = "%s%-50s expires:%02d/%02d/%04d\n"; + public void report(String prefix, User u) { + XMLGregorianCalendar xgc = u.getExpires(); + pw().format(uformat,prefix,u.getId(),xgc.getMonth()+1,xgc.getDay(),xgc.getYear()); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/ListUsersInRole.java b/authz-cmd/src/main/java/com/att/cmd/ns/ListUsersInRole.java new file mode 100644 index 00000000..d4c5a59d --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/ListUsersInRole.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import java.util.HashSet; +import java.util.Set; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Nss; +import aaf.v2_0.Nss.Ns; +import aaf.v2_0.Role; +import aaf.v2_0.Roles; +import aaf.v2_0.Users; +import aaf.v2_0.Users.User; + +/** + * p + * + */ +public class ListUsersInRole extends Cmd { + private static final String HEADER="List Users in Roles of Namespace "; + + public ListUsersInRole(ListUsers parent) { + super(parent,"role", + new Param("ns",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String ns=args[idx++]; + final boolean detail = aafcli.isDetailed(); + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + ((ListUsers)parent).report(HEADER,ns); + Future fn = client.read("/authz/nss/"+ns,getDF(Nss.class)); + if(fn.get(AAFcli.timeout())) { + if(fn.value!=null) { + Set uset = detail?null:new HashSet(); + for(Ns n : fn.value.getNs()) { + Future fr = client.read("/authz/roles/ns/"+n.getName(), getDF(Roles.class)); + if(fr.get(AAFcli.timeout())) { + for(Role r : fr.value.getRole()) { + if(detail) { + ((ListUsers)parent).report(r.getName()); + } + Future fus = client.read( + "/authz/users/role/"+r.getName(), + getDF(Users.class) + ); + if(fus.get(AAFcli.timeout())) { + for(User u : fus.value.getUser()) { + if(detail) { + ((ListUsers)parent).report(" ",u); + } else { + uset.add(u.getId()); + } + } + } else if(fn.code()==404) { + return 200; + } + } + } + } + if(uset!=null) { + for(String u : uset) { + pw().print(" "); + pw().println(u); + } + } + } + } else if(fn.code()==404) { + return 200; + } else { + error(fn); + } + return fn.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,HEADER); + indent+=4; + detailLine(sb,indent,"Report Users associated with this Namespace's Roles"); + sb.append('\n'); + detailLine(sb,indent,"If \"set details=true\" is specified, then all roles are printed "); + detailLine(sb,indent,"with the associated users and expiration dates"); + indent-=4; + api(sb,indent,HttpMethods.GET,"authz/nss/",Nss.class,true); + api(sb,indent,HttpMethods.GET,"authz/roles/ns/",Roles.class,false); + api(sb,indent,HttpMethods.GET,"authz/users/role/",Users.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/ListUsersWithPerm.java b/authz-cmd/src/main/java/com/att/cmd/ns/ListUsersWithPerm.java new file mode 100644 index 00000000..c8cbe5eb --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/ListUsersWithPerm.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import java.util.HashSet; +import java.util.Set; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Nss; +import aaf.v2_0.Nss.Ns; +import aaf.v2_0.Perm; +import aaf.v2_0.Perms; +import aaf.v2_0.Users; +import aaf.v2_0.Users.User; + +/** + * p + * + */ +public class ListUsersWithPerm extends Cmd { + private static final String HEADER="List Users of Permissions of Namespace "; + + public ListUsersWithPerm(ListUsers parent) { + super(parent,"perm", + new Param("ns",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String ns=args[idx++]; + final boolean detail = aafcli.isDetailed(); + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + ((ListUsers)parent).report(HEADER,ns); + Future fn = client.read("/authz/nss/"+ns,getDF(Nss.class)); + if(fn.get(AAFcli.timeout())) { + if(fn.value!=null) { + Set uset = detail?null:new HashSet(); + + for(Ns n : fn.value.getNs()) { + Future fp = client.read("/authz/perms/ns/"+n.getName(), getDF(Perms.class)); + if(fp.get(AAFcli.timeout())) { + for(Perm p : fp.value.getPerm()) { + String perm = p.getType()+'/'+p.getInstance()+'/'+p.getAction(); + if(detail)((ListUsers)parent).report(perm); + Future fus = client.read( + "/authz/users/perm/"+perm, + getDF(Users.class) + ); + if(fus.get(AAFcli.timeout())) { + for(User u : fus.value.getUser()) { + if(detail) + ((ListUsers)parent).report(" ",u); + else + uset.add(u.getId()); + } + } else if(fn.code()==404) { + return 200; + } + } + } + } + if(uset!=null) { + for(String u : uset) { + pw().print(" "); + pw().println(u); + } + } + } + } else if(fn.code()==404) { + return 200; + } else { + error(fn); + } + return fn.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,HEADER); + indent+=4; + detailLine(sb,indent,"Report Users associated with this Namespace's Permissions"); + sb.append('\n'); + detailLine(sb,indent,"If \"set detail=true\" is specified, then Permissions are printed with the associated"); + detailLine(sb,indent,"users and expiration dates"); + indent-=4; + api(sb,indent,HttpMethods.GET,"authz/nss/",Nss.class,true); + api(sb,indent,HttpMethods.GET,"authz/perms/ns/",Perms.class,false); + api(sb,indent,HttpMethods.GET,"authz/users/perm///",Users.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/NS.java b/authz-cmd/src/main/java/com/att/cmd/ns/NS.java new file mode 100644 index 00000000..7ebe3f9a --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/NS.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.inno.env.APIException; + +public class NS extends BaseCmd { +// final Role role; + + public NS(AAFcli aafcli) throws APIException { + super(aafcli, "ns"); +// this.role = role; + + cmds.add(new Create(this)); + cmds.add(new Delete(this)); + cmds.add(new Admin(this)); + cmds.add(new Responsible(this)); + cmds.add(new Describe(this)); + cmds.add(new Attrib(this)); + cmds.add(new List(this)); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/ns/Responsible.java b/authz-cmd/src/main/java/com/att/cmd/ns/Responsible.java new file mode 100644 index 00000000..b7f4406d --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/ns/Responsible.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +public class Responsible extends BaseCmd { + private final static String[] options = {"add","del"}; + + public Responsible(NS ns) throws APIException { + super(ns,"responsible", + new Param(optionsToString(options),true), + new Param("name",true), + new Param("id[,id]*",true) + ); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + + final int option = whichOption(options, args[idx++]); + final String ns = args[idx++]; + final String ids[] = args[idx++].split(","); + final String realm = getOrgRealm(); + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp=null; + for(String id : ids) { + if (id.indexOf('@') < 0 && realm != null) id += '@' + realm; + String verb; + switch(option) { + case 0: + fp = client.create("/authz/ns/"+ns+"/responsible/"+id,Void.class); + verb = " is now "; + break; + case 1: + fp = client.delete("/authz/ns/"+ns+"/responsible/"+id,Void.class); + verb = " is no longer "; + break; + default: + throw new CadiException("Bad Argument"); + }; + + if(fp.get(AAFcli.timeout())) { + pw().append(id); + pw().append(verb); + pw().append("responsible for "); + pw().println(ns); + } else { + error(fp); + return fp.code(); + } + } + return fp==null?500:fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Add or Delete Responsible person to/from Namespace"); + indent+=2; + detailLine(sb,indent,"Responsible persons receive Notifications and approve Requests "); + detailLine(sb,indent,"regarding this Namespace. Companies have Policies as to who may"); + detailLine(sb,indent,"take on this responsibility"); + + indent+=2; + detailLine(sb,indent,"name - Name of Namespace"); + detailLine(sb,indent,"id - Credential of Person(s) to be made responsible"); + sb.append('\n'); + detailLine(sb,indent,"aafcli will call API on each ID presented."); + indent-=4; + api(sb,indent,HttpMethods.POST,"authz/ns//responsible/",Void.class,true); + api(sb,indent,HttpMethods.DELETE,"authz/ns//responsible/",Void.class,false); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/Create.java b/authz-cmd/src/main/java/com/att/cmd/perm/Create.java new file mode 100644 index 00000000..a6bd6802 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/Create.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.PermRequest; +import aaf.v2_0.RoleRequest; + +/** + * + * + */ +public class Create extends Cmd { + public Create(Perm parent) { + super(parent,"create", + new Param("type",true), + new Param("instance",true), + new Param("action", true), + new Param("role[,role]* (to Grant to)", false) + ); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + final PermRequest pr = new PermRequest(); + pr.setType(args[idx++]); + pr.setInstance(args[idx++]); + pr.setAction(args[idx++]); + String roleCommas = (args.length>idx)?args[idx++]:null; + String[] roles = roleCommas==null?null:roleCommas.split("\\s*,\\s*"); + boolean force = aafcli.forceString()!=null; + int rv; + + if(roles!=null && force) { // Make sure Roles are Created + RoleRequest rr = new RoleRequest(); + for(String role : roles) { + rr.setName(role);; + Future fr = client.create( + "/authz/role", + getDF(RoleRequest.class), + rr + ); + fr.get(AAFcli.timeout()); + switch(fr.code()){ + case 201: + pw().println("Created Role [" + role + ']'); + break; + case 409: + break; + default: + pw().println("Role [" + role + "] does not exist, and cannot be created."); + return HttpStatus.PARTIAL_CONTENT_206; + } + } + } + + // Set Start/End commands + setStartEnd(pr); + setQueryParamsOn(client); + Future fp = client.create( + "/authz/perm", + getDF(PermRequest.class), + pr + ); + if(fp.get(AAFcli.timeout())) { + rv = fp.code(); + pw().println("Created Permission"); + if(roles!=null) { + if(aafcli.forceString()!=null) { // Make sure Roles are Created + RoleRequest rr = new RoleRequest(); + for(String role : roles) { + rr.setName(role);; + Future fr = client.create( + "/authz/role", + getDF(RoleRequest.class), + rr + ); + fr.get(AAFcli.timeout()); + switch(fr.code()){ + case 201: + case 409:break; + default: + + } + } + } + + try { + if(201!=(rv=((Perm)parent)._exec(0, + new String[] {"grant",pr.getType(),pr.getInstance(),pr.getAction(),roleCommas}))) { + rv = HttpStatus.PARTIAL_CONTENT_206; + } + } catch (LocatorException e) { + throw new CadiException(e); + } + } + } else { + rv = fp.code(); + if(rv==409 && force) { + rv = 201; + } else if(rv==202) { + pw().println("Permission Creation Accepted, but requires Approvals before actualizing"); + if (roles!=null) + pw().println("You need to grant the roles after approval."); + } else { + error(fp); + } + } + return rv; + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Create a Permission with:"); + detailLine(sb,indent+=2,"type - A Namespace qualified identifier identifying the kind of"); + detailLine(sb,indent+11,"resource to be protected"); + detailLine(sb,indent,"instance - A name that distinguishes a particular instance of resource"); + detailLine(sb,indent,"action - What kind of action is allowed"); + detailLine(sb,indent,"role(s) - Perms granted to these Comma separated Role(s)"); + detailLine(sb,indent+11,"Nonexistent role(s) will be created, if in same namespace"); + sb.append('\n'); + detailLine(sb,indent+2,"Note: Instance and Action can be a an '*' (enter \\\\* on Unix Shell)"); + api(sb,indent,HttpMethods.POST,"authz/perm",PermRequest.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/Delete.java b/authz-cmd/src/main/java/com/att/cmd/perm/Delete.java new file mode 100644 index 00000000..d5c5401f --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/Delete.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.PermRequest; + +/** + * + */ +public class Delete extends Cmd { + public Delete(Perm parent) { + super(parent,"delete", + new Param("type",true), + new Param("instance",true), + new Param("action", true)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + // Object Style Delete + PermRequest pk = new PermRequest(); + pk.setType(args[idx++]); + pk.setInstance(args[idx++]); + pk.setAction(args[idx++]); + + // Set "Force" if set + setQueryParamsOn(client); + Future fp = client.delete( + "/authz/perm", + getDF(PermRequest.class), + pk); + if(fp.get(AAFcli.timeout())) { + pw().println("Deleted Permission"); + } else { + if(fp.code()==202) { + pw().println("Permission Deletion Accepted, but requires Approvals before actualizing"); + } else { + error(fp); + } + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,"Delete a Permission with type,instance and action"); + detailLine(sb,indent+4,"see Create for definitions"); + api(sb,indent,HttpMethods.DELETE,"authz/perm",PermRequest.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/Describe.java b/authz-cmd/src/main/java/com/att/cmd/perm/Describe.java new file mode 100644 index 00000000..757c0172 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/Describe.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.PermRequest; + +public class Describe extends Cmd { + private static final String PERM_PATH = "/authz/perm"; + public Describe(Perm parent) { + super(parent,"describe", + new Param("type",true), + new Param("instance", true), + new Param("action", true), + new Param("description",true)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String type = args[idx++]; + String instance = args[idx++]; + String action = args[idx++]; + StringBuilder desc = new StringBuilder(); + while (idx < args.length) { + desc.append(args[idx++] + ' '); + } + + PermRequest pr = new PermRequest(); + pr.setType(type); + pr.setInstance(instance); + pr.setAction(action); + pr.setDescription(desc.toString()); + + // Set Start/End commands + setStartEnd(pr); + + Future fp = null; + int rv; + + fp = client.update( + PERM_PATH, + getDF(PermRequest.class), + pr + ); + + if(fp.get(AAFcli.timeout())) { + rv=fp.code(); + pw().println("Description added to Permission"); + } else { + if((rv=fp.code())==202) { + pw().print("Adding description"); + pw().println(" Accepted, but requires Approvals before actualizing"); + } else { + error(fp); + } + } + return rv; + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,"Add a description to a permission"); + api(sb,indent,HttpMethods.PUT,"authz/perm",PermRequest.class,true); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/Grant.java b/authz-cmd/src/main/java/com/att/cmd/perm/Grant.java new file mode 100644 index 00000000..f9780dde --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/Grant.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Pkey; +import aaf.v2_0.RolePermRequest; + +/** + * + * + */ +public class Grant extends Cmd { + private final static String[] options = {"grant","ungrant","setTo"}; + + public Grant(Perm parent) { + super(parent,null, + new Param(optionsToString(options),true), + new Param("type",true), + new Param("instance",true), + new Param("action",true), + new Param("role[,role]* (!REQ S)",false) + ); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String action = args[idx++]; + int option = whichOption(options, action); + + RolePermRequest rpr = new RolePermRequest(); + Pkey pk = new Pkey(); + pk.setType(args[idx++]); + pk.setInstance(args[idx++]); + pk.setAction(args[idx++]); + rpr.setPerm(pk); + setStartEnd(rpr); + + Future frpr = null; + + if (option != 2) { + String[] roles = args[idx++].split(","); + String strA,strB; + for(String role : roles) { + rpr.setRole(role); + if(option==0) { + // You can request to Grant Permission to a Role + setQueryParamsOn(client); + frpr = client.create( + "/authz/role/perm", + getDF(RolePermRequest.class), + rpr + ); + strA = "Granted Permission ["; + strB = "] to Role ["; + } else { + // You can request to UnGrant Permission to a Role + setQueryParamsOn(client); + frpr = client.delete( + "/authz/role/" + role + "/perm", + getDF(RolePermRequest.class), + rpr + ); + strA = "UnGranted Permission ["; + strB = "] from Role ["; + } + if(frpr.get(AAFcli.timeout())) { + pw().println(strA + pk.getType() + '|' + pk.getInstance() + '|' + pk.getAction() + + strB + role +']'); + } else { + if (frpr.code()==202) { + pw().print("Permission Role "); + pw().print(option==0?"Granted":"Ungranted"); + pw().println(" Accepted, but requires Approvals before actualizing"); + } else { + error(frpr); + idx=Integer.MAX_VALUE; + } + } + } + } else { + String allRoles = ""; + if (idx < args.length) + allRoles = args[idx++]; + + rpr.setRole(allRoles); + frpr = client.update( + "/authz/role/perm", + getDF(RolePermRequest.class), + rpr); + if(frpr.get(AAFcli.timeout())) { + pw().println("Set Permission's Roles to [" + allRoles + "]"); + } else { + error(frpr); + } + } + return frpr==null?0:frpr.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,"Grant a Permission to a Role or Roles OR"); + detailLine(sb,indent,"Ungrant a Permission from a Role or Roles OR"); + detailLine(sb,indent,"Set a Permission's roles to roles supplied."); + detailLine(sb,indent+4,"WARNING: Roles supplied with setTo will be the ONLY roles attached to this permission"); + detailLine(sb,indent+8,"If no roles are supplied, permission's roles are reset."); + detailLine(sb,indent,"see Create for definitions of type,instance and action"); + api(sb,indent,HttpMethods.POST,"authz/role/perm",RolePermRequest.class,true); + api(sb,indent,HttpMethods.DELETE,"authz/role//perm",RolePermRequest.class,false); + api(sb,indent,HttpMethods.PUT,"authz/role/perm",RolePermRequest.class,false); + + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/List.java b/authz-cmd/src/main/java/com/att/cmd/perm/List.java new file mode 100644 index 00000000..d65bfcc1 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/List.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.inno.env.APIException; + +import aaf.v2_0.Nss; +import aaf.v2_0.Perms; +import aaf.v2_0.Pkey; + + +public class List extends BaseCmd { +// private static final String LIST_PERM_DETAILS = "list permission details"; + + public List(Perm parent) { + super(parent,"list"); + + cmds.add(new ListByUser(this)); + cmds.add(new ListByName(this)); + cmds.add(new ListByNS(this)); + cmds.add(new ListByRole(this)); + cmds.add(new ListActivity(this)); + } + // Package Level on purpose + abstract class ListPerms extends Retryable { + protected int list(Future fp,Rcli client, String header, String parentPerm) throws CadiException, APIException { + if(fp.get(AAFcli.timeout())) { + ArrayList permNss = null; + if (aafcli.isDetailed()) { + permNss = new ArrayList(); + String permNs = null; + for(Pkey perm : fp.value.getPerm()) { + if (permNs != null && perm.getType().contains(permNs)) { + permNss.add(permNs); + } else { + Future fpn = null; + String permType = perm.getType(); + permNs = permType; + do { + permNs = permType.substring(0,permNs.lastIndexOf('.')); + fpn = client.read("/authz/nss/"+permNs,getDF(Nss.class)); + } while (!fpn.get(AAFcli.timeout())); + permNss.add(permNs); + } + } + } + report(fp,permNss,header, parentPerm); + } else { + error(fp); + } + return fp.code(); + } + } + + private static final Comparator permCompare = new Comparator() { + @Override + public int compare(aaf.v2_0.Perm a, aaf.v2_0.Perm b) { + int rc; + if((rc=a.getType().compareTo(b.getType()))!=0) { + return rc; + } + if((rc=a.getInstance().compareTo(b.getInstance()))!=0) { + return rc; + } + return a.getAction().compareTo(b.getAction()); + } + }; + + void report(Future fp, ArrayList permNss, String ... str) { + reportHead(str); + if (this.aafcli.isDetailed()) { + String format = reportColHead("%-20s %-15s %-30s %-15s\n %-75s\n","PERM NS","Type","Instance","Action", "Description"); + Collections.sort(fp.value.getPerm(),permCompare); + for(aaf.v2_0.Perm p : fp.value.getPerm()) { + String permNs = permNss.remove(0); + pw().format(format, + permNs, + p.getType().substring(permNs.length()+1), + p.getInstance(), + p.getAction(), + p.getDescription()==null?"":p.getDescription()); + } + pw().println(); + } else { + String format = reportColHead("%-30s %-30s %-10s\n","PERM Type","Instance","Action"); + + Collections.sort(fp.value.getPerm(),permCompare); + for(aaf.v2_0.Perm p : fp.value.getPerm()) { + pw().format(format, + p.getType(), + p.getInstance(), + p.getAction()); + } + pw().println(); + } + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/ListActivity.java b/authz-cmd/src/main/java/com/att/cmd/perm/ListActivity.java new file mode 100644 index 00000000..be653fad --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/ListActivity.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.History; + +/** + * + */ +public class ListActivity extends Cmd { + private static final String HEADER = "List Activity of Permission"; + + public ListActivity(List parent) { + super(parent,"activity", + new Param("type",true)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String type = args[idx++]; + Future fp = client.read( + "/authz/hist/perm/"+type, + getDF(History.class) + ); + if(fp.get(AAFcli.timeout())) { + activity(fp.value, HEADER + " [ " + type + " ]"); + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/hist/perm/",History.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/ListByNS.java b/authz-cmd/src/main/java/com/att/cmd/perm/ListByNS.java new file mode 100644 index 00000000..23b1d422 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/ListByNS.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Perms; + +/** + * Return Perms by NS + * + * + */ +public class ListByNS extends Cmd { + private static final String HEADER = "List Perms by NS "; + + public ListByNS(List parent) { + super(parent,"ns", + new Param("name",true)); + } + + public int _exec( int idx, final String ... args) throws CadiException, APIException, LocatorException { + final String ns=args[idx]; + + return same(((List)parent).new ListPerms() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authz/perms/ns/"+ns, + getDF(Perms.class) + ); + return list(fp,client, HEADER, ns); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/perms/ns/",Perms.class,true); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/ListByName.java b/authz-cmd/src/main/java/com/att/cmd/perm/ListByName.java new file mode 100644 index 00000000..d85447cf --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/ListByName.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Perms; + +/** + * + * + */ +public class ListByName extends Cmd { + private static final String HEADER = "List Child Permissions"; + + public ListByName(List parent) { + super(parent,"name", + new Param("root perm name",true)); + } + + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(((List)parent).new ListPerms() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + String parentPerm=args[index]; + + Future fp = client.read( + "/authz/perms/"+parentPerm, + getDF(Perms.class) + ); + return list(fp,client,HEADER,parentPerm); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/perms/",Perms.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/ListByRole.java b/authz-cmd/src/main/java/com/att/cmd/perm/ListByRole.java new file mode 100644 index 00000000..ec76137a --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/ListByRole.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Perms; + +/** + * Return Perms by Role + * + * + */ +public class ListByRole extends Cmd { + private static final String HEADER = "List Perms by Role "; + + public ListByRole(List parent) { + super(parent,"role", + new Param("name",true)); + } + + public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException { + final String role=args[idx]; + + return same(((List)parent).new ListPerms() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + + Future fp = client.read( + "/authz/perms/role/"+role, + getDF(Perms.class) + ); + return list(fp,client, HEADER, role); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/perms/role/",Perms.class,true); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/ListByUser.java b/authz-cmd/src/main/java/com/att/cmd/perm/ListByUser.java new file mode 100644 index 00000000..b1c70557 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/ListByUser.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Perms; + +/** + * + * + */ +public class ListByUser extends Cmd { + private static final String HEADER = "List Permissions by User"; + public ListByUser(List parent) { + super(parent,"user", + new Param("id",true)); + } + + public int _exec( int idx, final String ... args) throws CadiException, APIException, LocatorException { + String user=args[idx]; + String realm = getOrgRealm(); + final String fullUser; + if (user.indexOf('@') < 0 && realm != null) + fullUser = user + '@' + realm; + else + fullUser = user; + + return same(((List)parent).new ListPerms() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authz/perms/user/"+fullUser, + getDF(Perms.class) + ); + return list(fp, client, HEADER, fullUser); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/perms/user/",Perms.class,true); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/Perm.java b/authz-cmd/src/main/java/com/att/cmd/perm/Perm.java new file mode 100644 index 00000000..ecac7ff5 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/Perm.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cmd.BaseCmd; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +public class Perm extends BaseCmd { + Role role; + + public Perm(Role role) throws APIException { + super(role.aafcli, "perm"); + this.role = role; + + cmds.add(new Create(this)); + cmds.add(new Delete(this)); + cmds.add(new Grant(this)); + cmds.add(new Rename(this)); + cmds.add(new Describe(this)); + cmds.add(new List(this)); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/perm/Rename.java b/authz-cmd/src/main/java/com/att/cmd/perm/Rename.java new file mode 100644 index 00000000..05538706 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/perm/Rename.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.PermRequest; + +public class Rename extends Cmd { + public Rename(Perm parent) { + super(parent,"rename", + new Param("type",true), + new Param("instance",true), + new Param("action", true), + new Param("new type",true), + new Param("new instance",true), + new Param("new action", true) + ); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String origType = args[idx++]; + String origInstance = args[idx++]; + String origAction = args[idx++]; + + //Create new permission + PermRequest pr = new PermRequest(); + pr.setType(args[idx++]); + pr.setInstance(args[idx++]); + pr.setAction(args[idx++]); + + // Set Start/End commands + setStartEnd(pr); + Future fp = client.update( + "/authz/perm/"+origType+"/"+origInstance+"/"+origAction, + getDF(PermRequest.class), + pr + ); + int rv; + if(fp.get(AAFcli.timeout())) { + rv = fp.code(); + pw().println("Updated Permission"); + } else { + rv = fp.code(); + if(rv==202) { + pw().println("Permission Update Accepted, but requires Approvals before actualizing"); + } else { + error(fp); + } + } + return rv; + } + }); + + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,"Rename a Permission from:"); + detailLine(sb,indent+2," "); + detailLine(sb,indent,"to:"); + detailLine(sb,indent+2," "); + sb.append('\n'); + detailLine(sb,indent,"Namespace must be the same in and "); + detailLine(sb,indent+4,"see Create for definitions of type,instance and action"); + api(sb,indent,HttpMethods.PUT,"authz/perm///",PermRequest.class,true); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/CreateDelete.java b/authz-cmd/src/main/java/com/att/cmd/role/CreateDelete.java new file mode 100644 index 00000000..9f47c61a --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/CreateDelete.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.RoleRequest; + +/** + * + * + */ +public class CreateDelete extends Cmd { + private static final String ROLE_PATH = "/authz/role"; + private final static String[] options = {"create","delete"}; + public CreateDelete(Role parent) { + super(parent,null, + new Param(optionsToString(options),true), + new Param("name",true)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String action = args[idx++]; + int option = whichOption(options, action); + + RoleRequest rr = new RoleRequest(); + rr.setName(args[idx++]); + + // Set Start/End commands + setStartEnd(rr); + + Future fp = null; + String verb = null; + int rv; + switch(option) { + case 0: + fp = client.create( + ROLE_PATH, + getDF(RoleRequest.class), + rr + ); + verb = "Create"; + break; + case 1: + // Send "Force" if set + setQueryParamsOn(client); + fp = client.delete( + ROLE_PATH, // +args[idx++], + getDF(RoleRequest.class), + rr + ); + verb = "Delete"; + break; + default: // note, if not an option, whichOption throws Exception + break; + + } + boolean rolesSupplied = (args.length>idx); + if(fp.get(AAFcli.timeout())) { + rv=fp.code(); + pw().print(verb); + pw().println("d Role"); + if(rolesSupplied) { + for(;args.length>idx;++idx ) { + try { + if(201!=(rv=((Role)parent)._exec(0,new String[] {"user","add",rr.getName(),args[idx]}))) { + rv = HttpStatus.PARTIAL_CONTENT_206; + } + } catch (LocatorException e) { + throw new CadiException(e); + } + } + } + } else { + if((rv=fp.code())==202) { + pw().print("Role "); + pw().print(verb); + pw().println(" Accepted, but requires Approvals before actualizing"); + } else { + error(fp); + } + } + return rv; + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,"Create OR Delete a Role"); + detailLine(sb,indent+2,"name - Name of Role to create"); + api(sb,indent,HttpMethods.POST,"authz/role",RoleRequest.class,true); + api(sb,indent,HttpMethods.DELETE,"authz/role",RoleRequest.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/Describe.java b/authz-cmd/src/main/java/com/att/cmd/role/Describe.java new file mode 100644 index 00000000..3802cc77 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/Describe.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.RoleRequest; + +public class Describe extends Cmd { + private static final String ROLE_PATH = "/authz/role"; + public Describe(Role parent) { + super(parent,"describe", + new Param("name",true), + new Param("description",true)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String role = args[idx++]; + StringBuilder desc = new StringBuilder(); + while (idx < args.length) { + desc.append(args[idx++] + ' '); + } + + RoleRequest rr = new RoleRequest(); + rr.setName(role); + rr.setDescription(desc.toString()); + + // Set Start/End commands + setStartEnd(rr); + + Future fp = null; + int rv; + + fp = client.update( + ROLE_PATH, + getDF(RoleRequest.class), + rr + ); + + if(fp.get(AAFcli.timeout())) { + rv=fp.code(); + pw().println("Description added to role"); + } else { + if((rv=fp.code())==202) { + pw().print("Adding description"); + pw().println(" Accepted, but requires Approvals before actualizing"); + } else { + error(fp); + } + } + return rv; + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,"Add a description to a role"); + api(sb,indent,HttpMethods.PUT,"authz/role",RoleRequest.class,true); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/List.java b/authz-cmd/src/main/java/com/att/cmd/role/List.java new file mode 100644 index 00000000..72cf2037 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/List.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; + +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.inno.env.APIException; + +import aaf.v2_0.Nss; +import aaf.v2_0.Pkey; +import aaf.v2_0.Roles; + + + +public class List extends BaseCmd { + private static final String LIST_ROLES_BY_NAME = "list roles for role"; + + public List(Role parent) { + super(parent,"list"); + cmds.add(new ListByUser(this)); + cmds.add(new ListByRole(this)); + cmds.add(new ListByNS(this)); + cmds.add(new ListByNameOnly(this)); + cmds.add(new ListByPerm(this)); + cmds.add(new ListActivity(this)); + } + + // Package Level on purpose + abstract class ListRoles extends Retryable { + protected int list(Future fp,Rcli client, String header) throws APIException, CadiException { + if(fp.get(AAFcli.timeout())) { + Future fn = null; + ArrayList roleNss = null; + ArrayList permNss = null; + if (aafcli.isDetailed()) { + roleNss = new ArrayList(); + permNss = new ArrayList(); + for(aaf.v2_0.Role p : fp.value.getRole()) { + String roleNs = p.getName(); + do { + roleNs = p.getName().substring(0,roleNs.lastIndexOf('.')); + fn = client.read("/authz/nss/"+roleNs,getDF(Nss.class)); + } while (!fn.get(AAFcli.timeout())); + roleNss.add(roleNs); + + for(Pkey perm : p.getPerms()) { + if (perm.getType().contains(roleNs)) + permNss.add(roleNs); + else { + Future fpn = null; + String permType = perm.getType(); + String permNs = permType; + do { + permNs = permType.substring(0,permNs.lastIndexOf('.')); + fpn = client.read("/authz/nss/"+permNs,getDF(Nss.class)); + } while (!fpn.get(AAFcli.timeout())); + permNss.add(permNs); + } + } + } + } + report(fp,roleNss,permNss,null,header); + } else { + error(fp); + } + return fp.code(); + } + } + + private final static String roleFormat = "%-50s\n"; + + private static final Comparator roleCompare = new Comparator() { + @Override + public int compare(aaf.v2_0.Role a, aaf.v2_0.Role b) { + return a.getName().compareTo(b.getName()); + } + }; + public void report(Future fp, ArrayList roleNss, ArrayList permNss, + HashMap expiredMap, String ... str) { + reportHead(str); + if (fp != null && aafcli.isDetailed() && str[0].toLowerCase().contains(LIST_ROLES_BY_NAME)) { + String description = fp.value.getRole().get(0).getDescription(); + if (description == null) description = ""; + reportColHead("%-80s\n","Description: " + description); + } + + if(fp==null) { + pw().println(""); + } else if (aafcli.isDetailed()){ + String permFormat = " %-20s %-15s %-30s %-15s\n"; + String fullFormat = roleFormat+permFormat; + reportColHead(fullFormat,"[ROLE NS].Name","PERM NS","Type","Instance","Action"); + Collections.sort(fp.value.getRole(),roleCompare); + for(aaf.v2_0.Role p : fp.value.getRole()) { + String roleNs = roleNss.remove(0); + pw().format(roleFormat, "["+roleNs+"]"+p.getName().substring(roleNs.length())); + for(Pkey perm : p.getPerms()) { + String permNs = permNss.remove(0); + pw().format(permFormat, + permNs, + perm.getType().substring(permNs.length()+1), + perm.getInstance(), + perm.getAction()); + } + } + } else { + String permFormat = " %-30s %-30s %-15s\n"; + String fullFormat = roleFormat+permFormat; + reportColHead(fullFormat,"ROLE Name","PERM Type","Instance","Action"); + Collections.sort(fp.value.getRole(),roleCompare); + for(aaf.v2_0.Role p : fp.value.getRole()) { + if (expiredMap != null) { + String roleName = p.getName(); + Boolean b = expiredMap.get(roleName); + if (b != null && b.booleanValue()) + pw().format(roleFormat, roleName+"*"); + else { + pw().format(roleFormat, roleName); + for(Pkey perm : p.getPerms()) { + pw().format(permFormat, + perm.getType(), + perm.getInstance(), + perm.getAction()); + } + } + } else { + pw().format(roleFormat, p.getName()); + for(Pkey perm : p.getPerms()) { + pw().format(permFormat, + perm.getType(), + perm.getInstance(), + perm.getAction()); + } + } + } + } + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/ListActivity.java b/authz-cmd/src/main/java/com/att/cmd/role/ListActivity.java new file mode 100644 index 00000000..253a5376 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/ListActivity.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.History; + +/** + * + */ +public class ListActivity extends Cmd { + private static final String HEADER = "List Activity of Role"; + + public ListActivity(List parent) { + super(parent,"activity", + new Param("name",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String role = args[idx++]; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authz/hist/role/"+role, + getDF(History.class) + ); + if(fp.get(AAFcli.timeout())) { + activity(fp.value,HEADER + " [ " + role + " ]"); + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/hist/role/",History.class,true); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/ListByNS.java b/authz-cmd/src/main/java/com/att/cmd/role/ListByNS.java new file mode 100644 index 00000000..67c2c508 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/ListByNS.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Roles; + +/** + * Return Roles by NS + * + * + */ +public class ListByNS extends Cmd { + private static final String HEADER = "List Roles by NS "; + + public ListByNS(List parent) { + super(parent,"ns", + new Param("name",true)); + } + + @Override + public int _exec( int idx, final String ... args) throws CadiException, APIException, LocatorException { + final String ns=args[idx]; + + return same(((List)parent).new ListRoles() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authz/roles/ns/"+ns, + getDF(Roles.class) + ); + return list(fp,client, HEADER+"["+ns+"]"); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/roles/name/",Roles.class,true); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/ListByNameOnly.java b/authz-cmd/src/main/java/com/att/cmd/role/ListByNameOnly.java new file mode 100644 index 00000000..b47db017 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/ListByNameOnly.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Roles; + +/** + * Return Roles by NS + * + * + */ +public class ListByNameOnly extends Cmd { + private static final String HEADER = "List Roles by Name "; + + public ListByNameOnly(List parent) { + super(parent,"name", + new Param("name",true)); + } + + @Override + public int _exec( int idx, final String ... args) throws CadiException, APIException, LocatorException { + final String name=args[idx]; + + return same(((List)parent).new ListRoles() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authz/roles/name/"+name, + getDF(Roles.class) + ); + return list(fp,client, HEADER+"["+name+"]"); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/roles/name/",Roles.class,true); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/ListByPerm.java b/authz-cmd/src/main/java/com/att/cmd/role/ListByPerm.java new file mode 100644 index 00000000..50dff9bb --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/ListByPerm.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Roles; + +/** + * Return Roles by NS + * + * + */ +public class ListByPerm extends Cmd { + private static final String HEADER = "List Roles by Perm "; + + public ListByPerm(List parent) { + super(parent,"perm", + new Param("type",true), + new Param("instance", true), + new Param("action", true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String type=args[idx]; + final String instance=args[++idx]; + final String action=args[++idx]; + + return same(((List)parent).new ListRoles() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + + Future fp = client.read( + "/authz/roles/perm/"+type+'/'+instance+'/'+action, + getDF(Roles.class) + ); + return list(fp,client, HEADER+type+'|'+instance+'|'+action); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/roles/user/",Roles.class,true); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/ListByRole.java b/authz-cmd/src/main/java/com/att/cmd/role/ListByRole.java new file mode 100644 index 00000000..fad9347d --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/ListByRole.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Roles; + +/** + * + * + */ +public class ListByRole extends Cmd { + private static final String HEADER="List Roles for Role"; + + public ListByRole(List parent) { + super(parent,"role", + new Param("role",true)); + } + + @Override + public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException { + return same(((List)parent).new ListRoles() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + String role=args[idx]; + Future fp = client.read( + "/authz/roles/"+role, + getDF(Roles.class) + ); + return list(fp,client,HEADER+"["+role+"]"); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/roles/",Roles.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/ListByUser.java b/authz-cmd/src/main/java/com/att/cmd/role/ListByUser.java new file mode 100644 index 00000000..03db10fa --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/ListByUser.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; + +import aaf.v2_0.Nss; +import aaf.v2_0.Pkey; +import aaf.v2_0.Roles; +import aaf.v2_0.Users; + +/** + * p + * + */ +public class ListByUser extends Cmd { + private static final String HEADER = "List Roles for User "; + + public ListByUser(List parent) { + super(parent,"user", + new Param("id",true)); + } + + @Override + public int _exec( int idx, final String ... args) throws CadiException, APIException, LocatorException { + String user=args[idx]; + String realm = getOrgRealm(); + final String fullUser; + if (user.indexOf('@') < 0 && realm != null) { + fullUser = user + '@' + realm; + } else { + fullUser = user; + } + + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + + Future fp = client.read( + "/authz/roles/user/"+fullUser, + getDF(Roles.class) + ); + if(fp.get(AAFcli.timeout())) { + Future fn = null; + ArrayList roleNss = null; + ArrayList permNss = null; + HashMap expiredMap = new HashMap(); + if (aafcli.isDetailed()) { + roleNss = new ArrayList(); + permNss = new ArrayList(); + for(aaf.v2_0.Role p : fp.value.getRole()) { + String roleNs = p.getName(); + do { + roleNs = p.getName().substring(0,roleNs.lastIndexOf('.')); + fn = client.read("/authz/nss/"+roleNs,getDF(Nss.class)); + } while (!fn.get(AAFcli.timeout())); + roleNss.add(roleNs); + + for(Pkey perm : p.getPerms()) { + if (perm.getType().contains(roleNs)) { + permNss.add(roleNs); + } else { + Future fpn = null; + String permType = perm.getType(); + String permNs = permType; + do { + permNs = permType.substring(0,permNs.lastIndexOf('.')); + fpn = client.read("/authz/nss/"+permNs,getDF(Nss.class)); + } while (!fpn.get(AAFcli.timeout())); + permNss.add(permNs); + } + } + } + } + + if (fp.value != null) { + for(aaf.v2_0.Role p : fp.value.getRole()) { + Future fu = client.read( + "/authz/userRole/"+fullUser+"/"+p.getName(), + getDF(Users.class) + ); + if (fu.get(5000)) { + if(fu.value != null) { + for (Users.User u : fu.value.getUser()) { + if(u.getExpires().normalize().compare(Chrono.timeStamp().normalize()) > 0) { + expiredMap.put(p.getName(), new Boolean(false)); + } else { + expiredMap.put(p.getName(), new Boolean(true)); + } + } + } + } + } + } + + ((List)parent).report(fp,roleNss,permNss,expiredMap,HEADER,fullUser); + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/roles/user/",Roles.class,true); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/Role.java b/authz-cmd/src/main/java/com/att/cmd/role/Role.java new file mode 100644 index 00000000..a3336aef --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/Role.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.inno.env.APIException; + +public class Role extends BaseCmd { + public List list; + + public Role(AAFcli aafcli) throws APIException { + super(aafcli, "role"); + cmds.add(new CreateDelete(this)); +// cmds.add(new Delete(this)); + cmds.add(new User(this)); + cmds.add(new Describe(this)); + cmds.add(list = new List(this)); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/role/User.java b/authz-cmd/src/main/java/com/att/cmd/role/User.java new file mode 100644 index 00000000..ea8276c1 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/role/User.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.UserRoleRequest; + +/** + * p + * + */ +public class User extends Cmd { + private final static String[] options = {"add","del","setTo","extend"}; + public User(Role parent) { + super(parent,"user", + new Param(optionsToString(options),true), + new Param("role",true), + new Param("id[,id]* (not required for setTo)",false)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String realm = getOrgRealm(); + String action = args[idx++]; + int option = whichOption(options, action); + UserRoleRequest urr = new UserRoleRequest(); + urr.setRole(args[idx++]); + // Set Start/End commands + setStartEnd(urr); + + Future fp = null; + + if (option != 2) { + String[] ids = args[idx++].split(","); + String verb=null,participle=null; + // You can request to be added or removed from role. + setQueryParamsOn(client); + + for(String id: ids) { + if (id.indexOf('@') < 0 && realm != null) id += '@' + realm; + urr.setUser(id); + switch(option) { + case 0: + fp = client.create( + "/authz/userRole", + getDF(UserRoleRequest.class), + urr); + verb = "Added"; + participle = "] to Role [" ; + break; + case 1: + fp = client.delete( + "/authz/userRole/"+urr.getUser()+'/'+urr.getRole(), + Void.class); + verb = "Removed"; + participle = "] from Role [" ; + break; + case 3: + fp = client.update("/authz/userRole/extend/" + urr.getUser() + '/' + urr.getRole()); + verb = "Extended"; + participle = "] in Role [" ; + break; + + default: // actually, should never get here... + throw new CadiException("Invalid action [" + action + ']'); + } + if(fp.get(AAFcli.timeout())) { + pw().print(verb); + pw().print(" User ["); + pw().print(urr.getUser()); + pw().print(participle); + pw().print(urr.getRole()); + pw().println(']'); + } else { + switch(fp.code()) { + case 202: + pw().print("User Role "); + pw().print(action); + pw().println(" is Accepted, but requires Approvals before actualizing"); + break; + case 404: + if(option==3) { + pw().println("Failed with code 404: UserRole is not found, or you do not have permission to view"); + break; + } + default: + error(fp); + } + } + } + } else { + String allUsers = ""; + if (idx < args.length) + allUsers = args[idx++]; + StringBuilder finalUsers = new StringBuilder(); + for (String u : allUsers.split(",")) { + if (u != "") { + if (u.indexOf('@') < 0 && realm != null) u += '@' + realm; + if (finalUsers.length() > 0) finalUsers.append(","); + finalUsers.append(u); + } + } + + urr.setUser(finalUsers.toString()); + fp = client.update( + "/authz/userRole/role", + getDF(UserRoleRequest.class), + urr); + if(fp.get(AAFcli.timeout())) { + pw().println("Set the Role to Users [" + allUsers + "]"); + } else { + error(fp); + } + } + return fp==null?0:fp.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,"Add OR Delete a User to/from a Role OR"); + detailLine(sb,indent,"Set a User's Roles to the roles supplied"); + detailLine(sb,indent+2,"role - Name of Role to create"); + detailLine(sb,indent+2,"id(s) - ID or IDs to add to the Role"); + sb.append('\n'); + detailLine(sb,indent+2,"Note: this is the same as \"user role add...\" except allows"); + detailLine(sb,indent+2,"assignment of role to multiple userss"); + detailLine(sb,indent+2,"WARNING: Users supplied with setTo will be the ONLY users attached to this role"); + detailLine(sb,indent+2,"If no users are supplied, the users attached to this role are reset."); + api(sb,indent,HttpMethods.POST,"authz/userRole",UserRoleRequest.class,true); + api(sb,indent,HttpMethods.DELETE,"authz/userRole//",Void.class,false); + api(sb,indent,HttpMethods.PUT,"authz/userRole/",UserRoleRequest.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/Cred.java b/authz-cmd/src/main/java/com/att/cmd/user/Cred.java new file mode 100644 index 00000000..13198890 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/Cred.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.CredRequest; + +public class Cred extends Cmd { + private static final String CRED_PATH = "/authn/cred"; + private static final String[] options = {"add","del","reset","extend"/*,"clean"*/}; +// private Clean clean; + public Cred(User parent) { + super(parent,"cred", + new Param(optionsToString(options),true), + new Param("id",true), + new Param("password (! D|E)",false), + new Param("entry# (if multi)",false) + ); +// clean = new Clean(this); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + String key = args[idx++]; + final int option = whichOption(options,key); + + final CredRequest cr = new CredRequest(); + cr.setId(args[idx++]); + if(option!=1 && option!=3) { + if(idx>=args.length) throw new CadiException("Password Required"); + cr.setPassword(args[idx++]); + } + if(args.length>idx) + cr.setEntry(args[idx++]); + + // Set Start/End commands + setStartEnd(cr); +// final int cleanIDX = _idx+1; + Integer ret = same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp=null; + String verb =null; + switch(option) { + case 0: + fp = client.create( + CRED_PATH, + getDF(CredRequest.class), + cr + ); + verb = "Added Credential ["; + break; + case 1: +// if(aafcli.addForce())cr.setForce("TRUE"); + setQueryParamsOn(client); + fp = client.delete(CRED_PATH, + getDF(CredRequest.class), + cr + ); + verb = "Deleted Credential ["; + break; + case 2: + fp = client.update( + CRED_PATH, + getDF(CredRequest.class), + cr + ); + verb = "Reset Credential ["; + break; + case 3: + fp = client.update( + CRED_PATH+"/5", + getDF(CredRequest.class), + cr + ); + verb = "Extended Credential ["; + break; +// case 4: +// return clean.exec(cleanIDX, args); + } + if(fp.get(AAFcli.timeout())) { + pw().print(verb); + pw().print(cr.getId()); + pw().println(']'); + } else if(fp.code()==202) { + pw().println("Credential Action Accepted, but requires Approvals before actualizing"); + } else if(fp.code()==406 && option==1) { + pw().println("You cannot delete this Credential"); + } else { + error(fp); + } + return fp.code(); + } + }); + if(ret==null)ret = -1; + return ret; + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Add, Delete or Reset Credential"); + indent+=2; + detailLine(sb,indent,"id - the ID to create/delete/reset within AAF"); + detailLine(sb,indent,"password - Company Policy compliant Password (not required for Delete)"); + detailLine(sb,indent,"entry - selected option when deleting/resetting a cred with multiple entries"); + sb.append('\n'); + detailLine(sb,indent,"The Domain can be related to any Namespace you have access to *"); + detailLine(sb,indent,"The Domain is in reverse order of Namespace, i.e. "); + detailLine(sb,indent+2,"NS of com.att.myapp can create user of XY1234@myapp.att.com"); + sb.append('\n'); + detailLine(sb,indent,"NOTE: AAF does support multiple creds with the same ID. Check with your org if you"); + detailLine(sb,indent+2,"have this implemented. (For example, this is implemented for MechIDs at AT&T)"); + sb.append('\n'); + detailLine(sb,indent,"Delegates can be listed by the User or by the Delegate"); + indent-=2; + api(sb,indent,HttpMethods.POST,"authn/cred",CredRequest.class,true); + api(sb,indent,HttpMethods.DELETE,"authn/cred",CredRequest.class,false); + api(sb,indent,HttpMethods.PUT,"authn/cred",CredRequest.class,false); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/Delg.java b/authz-cmd/src/main/java/com/att/cmd/user/Delg.java new file mode 100644 index 00000000..af4095f3 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/Delg.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import java.text.ParseException; +import java.util.Date; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; +import com.att.inno.env.util.Chrono; +import com.att.rosetta.env.RosettaDF; + +import aaf.v2_0.DelgRequest; + +public class Delg extends BaseCmd { + static final String AUTHZ_DELG = "/authz/delegate"; + private final static String[] options = {"add","upd","del"}; + + public Delg(User user) throws APIException { + super(user,"delegate", + new Param(optionsToString(options),true), + new Param("from",true), + new Param("to REQ A&U",false), + new Param("until (YYYY-MM-DD) REQ A", false) + ); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String realm = getOrgRealm(); + DelgRequest dr = new DelgRequest(); + setStartEnd(dr); + + int option= whichOption(options, args[idx++]); + String user = args[idx++]; + if (user.indexOf('@') < 0 && realm != null) user += '@' + realm; + dr.setUser(user); + if(option<2) { + String delegate = args[idx++]; + if (delegate.indexOf('@') < 0 && realm != null) delegate += '@' + realm; + dr.setDelegate(delegate); + if(option<2 && args.length>idx) { + Date date; + try { + date = Chrono.dateOnlyFmt.parse(args[idx++]); + } catch (ParseException e) { + throw new CadiException(e); + } + dr.setEnd(Chrono.timeStamp(date)); + } + } + + Future fp; + RosettaDF df = getDF(DelgRequest.class); + String verb; + setQueryParamsOn(client); + + switch(option) { + case 0: + fp = client.create(AUTHZ_DELG, df, dr); + verb = "Added"; + break; + case 1: + fp = client.update(AUTHZ_DELG, df, dr); + verb = "Updated"; + break; + case 2: + fp = client.delete(AUTHZ_DELG, df, dr); + verb = "Deleted"; + break; + default: + throw new CadiException("Bad Argument"); + }; + + if(fp.get(AAFcli.timeout())) { + pw().append("Delegate "); + pw().println(verb); + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,"Add, Update or Delete Delegate"); + indent+=2; + detailLine(sb,indent,"A Delegate is a person who will temporarily cover the Approval and"); + detailLine(sb,indent,"Ownership questions on behalf of the person Responsible."); + sb.append('\n'); + detailLine(sb,indent,"fromID - the person who is the Responsible person of record"); + detailLine(sb,indent,"toID - the person who will be delegated (required for Add/Update)"); + detailLine(sb,indent,"until - the end date for this delegation"); + indent-=2; + api(sb,indent,HttpMethods.POST,AUTHZ_DELG,DelgRequest.class,true); + api(sb,indent,HttpMethods.DELETE,AUTHZ_DELG,DelgRequest.class,false); + api(sb,indent,HttpMethods.PUT,AUTHZ_DELG,DelgRequest.class,false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/List.java b/authz-cmd/src/main/java/com/att/cmd/user/List.java new file mode 100644 index 00000000..d88c15dc --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/List.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import java.util.Collections; +import java.util.Comparator; + +import com.att.cmd.BaseCmd; +import com.att.inno.env.util.Chrono; + +import aaf.v2_0.Approval; +import aaf.v2_0.Approvals; +import aaf.v2_0.Delg; +import aaf.v2_0.Delgs; +import aaf.v2_0.Users; + +public class List extends BaseCmd { + + public List(User parent) { + super(parent,"list"); + cmds.add(new ListForRoles(this)); + cmds.add(new ListForPermission(this)); + cmds.add(new ListForCreds(this)); + cmds.add(new ListDelegates(this)); + cmds.add(new ListApprovals(this)); + cmds.add(new ListActivity(this)); + } + + + void report(Users users, boolean count, String ... str) { + reportHead(str); + String format = reportColHead("%-50s %-30s\n","User","Expires"); + String date = "XXXX-XX-XX"; + int idx = 0; + java.util.List sorted = users.getUser(); + Collections.sort(sorted, new Comparator() { + @Override + public int compare(aaf.v2_0.Users.User u1, aaf.v2_0.Users.User u2) { + if(u2==null || u2 == null) { + return -1; + } + return u1.getId().compareTo(u2.getId()); + } + }); + for(aaf.v2_0.Users.User user : sorted) { + if(!aafcli.isTest()) + date = Chrono.dateOnlyStamp(user.getExpires()); + + pw().format(format, + count? (Integer.valueOf(++idx) + ") " + user.getId()): user.getId(), + date); + } + pw().println(); + } + + public void report(Approvals approvals, String title, String id) { + reportHead(title,id); + String format = reportColHead(" %-20s %-20s %-11s %-6s %12s\n","User","Approver","Type","Status","Updated"); + java.util.List lapp = approvals.getApprovals(); + Collections.sort(lapp, new Comparator() { + @Override + public int compare(Approval a1, Approval a2) { + return a1.getTicket().compareTo(a2.getTicket()); + } + } ); + String ticket = null, prev = null; + for(Approval app : lapp ) { + ticket = app.getTicket(); + if(!ticket.equals(prev)) { + pw().print("Ticket: "); + pw().println(ticket); + } + prev = ticket; + + pw().format(format, + app.getUser(), + app.getApprover(), + app.getType(), + app.getStatus(), + Chrono.niceDateStamp(app.getUpdated()) + ); + } + } + + public void report(Delgs delgs, String title, String id) { + reportHead(title,id); + String format = reportColHead(" %-25s %-25s %-10s\n","User","Delegate","Expires"); + String date = "XXXX-XX-XX"; + for(Delg delg : delgs.getDelgs()) { + if(!this.aafcli.isTest()) + date = Chrono.dateOnlyStamp(delg.getExpires()); + pw().printf(format, + delg.getUser(), + delg.getDelegate(), + date + ); + } + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/ListActivity.java b/authz-cmd/src/main/java/com/att/cmd/user/ListActivity.java new file mode 100644 index 00000000..bf384f6e --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/ListActivity.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.History; + +/** + * + */ +public class ListActivity extends Cmd { + private static final String HEADER = "List Activity of User"; + + public ListActivity(List parent) { + super(parent,"activity", + new Param("user",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + String user = args[idx++]; + String realm = getOrgRealm(); + final String fullUser = (user.indexOf('@') < 0 && realm != null)?user + '@' + realm:user; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + + Future fp = client.read( + "/authz/hist/user/"+fullUser, + getDF(History.class) + ); + if(fp.get(AAFcli.timeout())) { + activity(fp.value,HEADER + " [ " + fullUser + " ]"); + } else { + error(fp); + } + return fp.code(); + } + }); + } + + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb,indent,HEADER); + api(sb,indent,HttpMethods.GET,"authz/hist/user/",History.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/ListApprovals.java b/authz-cmd/src/main/java/com/att/cmd/user/ListApprovals.java new file mode 100644 index 00000000..85569f41 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/ListApprovals.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Approvals; + +/** + * + * + */ +public class ListApprovals extends Cmd { + private static final String HEADER = "List Approvals"; + private final static String[] options = {"user","approver","ticket"}; + public ListApprovals(List parent) { + super(parent,"approvals", + new Param(optionsToString(options),true), + new Param("value",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String type = args[idx++]; + int option = whichOption(options,type); + String value = args[idx++]; + final String fullValue; + if (option != 2) { + String realm = getOrgRealm(); + fullValue = (value.indexOf('@')<0 && realm != null)?value +'@'+realm:value; + } else { + fullValue = value; + } + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authz/approval/"+type+'/'+fullValue, + getDF(Approvals.class) + ); + if(fp.get(AAFcli.timeout())) { + ((List)parent).report(fp.value,HEADER + " by " + type,fullValue); + if(fp.code()==404) { + return 200; + } + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,HEADER); + indent+=2; + detailLine(sb,indent,"Approvals are used when the Requestor does not have the rights"); + detailLine(sb,indent,"to perform the action required. Approvers are those listed as"); + detailLine(sb,indent,"responsible for Namespace associated with the request, and those"); + detailLine(sb,indent,"required by the Company by Policy. This may be, for instance"); + detailLine(sb,indent,"the supervisor of the requestor"); + sb.append('\n'); + detailLine(sb,indent,"Delegates can be listed by User, Approver or Ticket."); + indent-=2; + api(sb,indent,HttpMethods.GET,"authz/approval/user/",Approvals.class,true); + api(sb,indent,HttpMethods.GET,"authz/approval/approver/",Approvals.class,false); + api(sb,indent,HttpMethods.GET,"authz/approval/ticket/",Approvals.class,false); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/ListDelegates.java b/authz-cmd/src/main/java/com/att/cmd/user/ListDelegates.java new file mode 100644 index 00000000..779f6253 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/ListDelegates.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Delgs; + +/** + * + */ +public class ListDelegates extends Cmd { + private static final String HEADER = "List Delegates"; + private static final String[] options = {"user","delegate"}; + public ListDelegates(List parent) { + super(parent,"delegates", + new Param(optionsToString(options),true), + new Param("id",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + String realm = getOrgRealm(); + int idx = _idx; + final String key = args[idx++]; + //int option = whichOption(options,key); + String id = args[idx++]; + final String fullID = (id.indexOf('@') < 0 && realm != null)? id + '@' + realm:id; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + + Future fp = client.read( + "/authz/delegates/" + key + '/' + fullID, + getDF(Delgs.class) + ); + if(fp.get(AAFcli.timeout())) { + ((List)parent).report(fp.value,HEADER + " by " + key, fullID); + if(fp.code()==404)return 200; + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,HEADER); + indent+=2; + detailLine(sb,indent,"Delegates are those people temporarily assigned to cover the"); + detailLine(sb,indent,"responsibility of Approving, etc, while the actual Responsible"); + detailLine(sb,indent,"Party is absent. Typically, this is for Vacation, or Business"); + detailLine(sb,indent,"Travel."); + sb.append('\n'); + detailLine(sb,indent,"Delegates can be listed by the User or by the Delegate"); + indent-=2; + api(sb,indent,HttpMethods.GET,"authz/delegates/user/",Delgs.class,true); + api(sb,indent,HttpMethods.GET,"authz/delegates/delegate/",Delgs.class,false); + } + + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/ListForCreds.java b/authz-cmd/src/main/java/com/att/cmd/user/ListForCreds.java new file mode 100644 index 00000000..8ede1187 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/ListForCreds.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import java.util.Collections; +import java.util.Comparator; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Users; +import aaf.v2_0.Users.User; + +/** + * List for Creds + * + */ +public class ListForCreds extends Cmd { + private final static String[] options = {"ns","id"}; + + private static final String HEADER = "List creds for "; + public ListForCreds(List parent) { + super(parent,"cred", + new Param(optionsToString(options),true), + new Param("value",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final int option = whichOption(options, args[idx++]); + final String which = options[option]; + final String value = args[idx++]; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authn/creds/"+which+'/'+value, + getDF(Users.class) + ); + if(fp.get(AAFcli.timeout())) { + if (aafcli.isTest()) + Collections.sort(fp.value.getUser(), new Comparator() { + @Override + public int compare(User u1, User u2) { + return u1.getId().compareTo(u2.getId()); + } + }); + ((com.att.cmd.user.List)parent).report(fp.value,option==1,HEADER+which,value); + if(fp.code()==404)return 200; + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,HEADER); + indent+=2; + detailLine(sb,indent,"This report lists the users associated to Roles."); + detailLine(sb,indent,"role - the Role name"); + indent-=2; + api(sb,indent,HttpMethods.GET,"authz/users/role/",Users.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/ListForPermission.java b/authz-cmd/src/main/java/com/att/cmd/user/ListForPermission.java new file mode 100644 index 00000000..fb13bbbb --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/ListForPermission.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import java.util.Collections; +import java.util.Comparator; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Users; +import aaf.v2_0.Users.User; + +/** + * p + * + */ +public class ListForPermission extends Cmd { + private static final String HEADER = "List Users for Permission"; + public ListForPermission(List parent) { + super(parent,"perm", + new Param("type",true), + new Param("instance",true), + new Param("action",true)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String type = args[idx++]; + String instance = args[idx++]; + if("\\*".equals(instance))instance="*"; + String action = args[idx++]; + if("\\*".equals(action))action="*"; + Future fp = client.read( + "/authz/users/perm/"+type+'/'+instance+'/'+action, + getDF(Users.class) + ); + if(fp.get(AAFcli.timeout())) { + if (aafcli.isTest()) + Collections.sort(fp.value.getUser(), new Comparator() { + @Override + public int compare(User u1, User u2) { + return u1.getId().compareTo(u2.getId()); + } + }); + ((com.att.cmd.user.List)parent).report(fp.value,false,HEADER,type+"|"+instance+"|"+action); + if(fp.code()==404)return 200; + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,HEADER); + indent+=2; + detailLine(sb,indent,"This report lists the users associated to Permissions. Since Users"); + detailLine(sb,indent,"are associated to Roles, and Roles have Permissions, this report"); + detailLine(sb,indent,"accomodates all these linkages."); + sb.append('\n'); + detailLine(sb,indent,"The URL must contain the Permission's type,instance and action, and "); + detailLine(sb,indent,"may include \"*\"s (type in as \\\\*)."); + detailLine(sb,indent,"See Perm Create Documentation for definitions."); + indent-=2; + api(sb,indent,HttpMethods.GET,"authz/users/perm///",Users.class,true); + } +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/ListForRoles.java b/authz-cmd/src/main/java/com/att/cmd/user/ListForRoles.java new file mode 100644 index 00000000..e2a89905 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/ListForRoles.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import java.util.Collections; +import java.util.Comparator; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.Users; +import aaf.v2_0.Users.User; + +/** + * p + * + */ +public class ListForRoles extends Cmd { + private static final String HEADER = "List Users for Role"; + public ListForRoles(List parent) { + super(parent,"role", new Param("role",true)); + } + + @Override + public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { + int idx = _idx; + final String role = args[idx++]; + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + Future fp = client.read( + "/authz/users/role/"+role, + getDF(Users.class) + ); + if(fp.get(AAFcli.timeout())) { + if (aafcli.isTest()) + Collections.sort(fp.value.getUser(), new Comparator() { + @Override + public int compare(User u1, User u2) { + return u1.getId().compareTo(u2.getId()); + } + }); + ((com.att.cmd.user.List)parent).report(fp.value,false, HEADER,role); + if(fp.code()==404)return 200; + } else { + error(fp); + } + return fp.code(); + } + }); + } + + @Override + public void detailedHelp(int _indent, StringBuilder sb) { + int indent = _indent; + detailLine(sb,indent,HEADER); + indent+=2; + detailLine(sb,indent,"This report lists the users associated to Roles."); + detailLine(sb,indent,"role - the Role name"); + indent-=2; + api(sb,indent,HttpMethods.GET,"authz/users/role/",Users.class,true); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/Role.java b/authz-cmd/src/main/java/com/att/cmd/user/Role.java new file mode 100644 index 00000000..1d660c6c --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/Role.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.cmd.Cmd; +import com.att.cmd.Param; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +import aaf.v2_0.UserRoleRequest; + +/** + * p + * + * + */ +public class Role extends Cmd { + private static final String[] options = {"add", "del", "setTo","extend"}; + public Role(User parent) { + super(parent, "role", new Param(optionsToString(options), true), new Param("user", true), new Param( + "role[,role]* (!REQ S)", false)); + } + + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String key = args[idx++]; + int option = whichOption(options, key); + String user = args[idx++]; + String realm = getOrgRealm(); + + UserRoleRequest urr = new UserRoleRequest(); + if (user.indexOf('@') < 0 && realm != null) user += '@' + realm; + urr.setUser(user); + // Set Start/End commands + setStartEnd(urr); + + Future fp = null; + + if (option != 2) { + if (args.length < 5) { + throw new CadiException(build(new StringBuilder("Too few args: "), null).toString()); + } + String[] roles = args[idx++].split(","); + for (String role : roles) { + String verb = null,participle=null; + urr.setRole(role); + // You can request to be added or removed from role. + setQueryParamsOn(client); + switch(option) { + case 0: + fp = client.create("/authz/userRole", getDF(UserRoleRequest.class), urr); + verb = "Added"; + participle = "] to User [" ; + break; + case 1: + fp = client.delete("/authz/userRole/" + urr.getUser() + '/' + urr.getRole(), Void.class); + verb = "Removed"; + participle = "] from User [" ; + break; + case 3: + fp = client.update("/authz/userRole/extend/" + urr.getUser() + '/' + urr.getRole()); + verb = "Extended"; + participle = "] to User [" ; + break; + default: + throw new CadiException("Invalid action [" + key + ']'); + } + if (fp.get(AAFcli.timeout())) { + pw().print(verb); + pw().print(" Role ["); + pw().print(urr.getRole()); + pw().print(participle); + pw().print(urr.getUser()); + pw().println(']'); + } else { + switch(fp.code()) { + case 202: + pw().print("UserRole "); + pw().print(option == 0 ? "Creation" : option==1?"Deletion":"Extension"); + pw().println(" Accepted, but requires Approvals before actualizing"); + break; + case 404: + if(option==3) { + pw().println("Failed with code 404: UserRole is not found, or you do not have permission to view"); + break; + } + default: + error(fp); + } + } + } + } else { + // option 2 is setTo command (an update call) + String allRoles = ""; + if (idx < args.length) + allRoles = args[idx++]; + + urr.setRole(allRoles); + fp = client.update("/authz/userRole/user", getDF(UserRoleRequest.class), urr); + if (fp.get(AAFcli.timeout())) { + pw().println("Set User's Roles to [" + allRoles + "]"); + } else { + error(fp); + } + } + return fp == null ? 0 : fp.code(); + } + }); + } + + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb, indent, "Add OR Delete a User to/from a Role OR"); + detailLine(sb, indent, "Set a User's Roles to the roles supplied"); + detailLine(sb, indent + 2, "user - ID of User"); + detailLine(sb, indent + 2, "role(s) - Role or Roles to which to add the User"); + sb.append('\n'); + detailLine(sb, indent + 2, "Note: this is the same as \"role user add...\" except allows"); + detailLine(sb, indent + 2, "assignment of user to multiple roles"); + detailLine(sb, indent + 2, "WARNING: Roles supplied with setTo will be the ONLY roles attached to this user"); + detailLine(sb, indent + 2, "If no roles are supplied, user's roles are reset."); + api(sb, indent, HttpMethods.POST, "authz/userRole", UserRoleRequest.class, true); + api(sb, indent, HttpMethods.DELETE, "authz/userRole//", Void.class, false); + api(sb, indent, HttpMethods.PUT, "authz/userRole/", UserRoleRequest.class, false); + } + +} diff --git a/authz-cmd/src/main/java/com/att/cmd/user/User.java b/authz-cmd/src/main/java/com/att/cmd/user/User.java new file mode 100644 index 00000000..13f11117 --- /dev/null +++ b/authz-cmd/src/main/java/com/att/cmd/user/User.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import com.att.cmd.AAFcli; +import com.att.cmd.BaseCmd; +import com.att.inno.env.APIException; + +public class User extends BaseCmd { + public User(AAFcli aafcli) throws APIException { + super(aafcli,"user"); + cmds.add(new Role(this)); + cmds.add(new Cred(this)); + cmds.add(new Delg(this)); + cmds.add(new List(this)); + } +} diff --git a/authz-cmd/src/main/scripts/aaflogin b/authz-cmd/src/main/scripts/aaflogin new file mode 100644 index 00000000..62da1009 --- /dev/null +++ b/authz-cmd/src/main/scripts/aaflogin @@ -0,0 +1,199 @@ +#!/bin/bash +JAVA_HOME=_JAVA_HOME_ +JAVA=${JAVA_HOME}/bin/java +DEFAULT_DOMAIN=XXX_DOMAIN +### +# Give some help hints if first run +# +if [ "`declare -f aaflogout`" = "" ] || [ "$1" = "-h" ]; then + echo + echo " COMMANDS:" + echo " aaflogin -f = Redo Local Login" + echo " aaflogout = Logout from Environment" + echo " aaflogin -r = Reset Password on AAF Service" + echo " aaflogin -h = Help" + echo " aafcli = AAF Management Tool" + echo +fi + +if [ "$1" != "-h" ]; then + + +### +# Load User/Password for aafcli, and create in function. +# +# To use, source aaflogin +# +# ex: . ./aaflogin +# +# -f = force relogin +# -r = reset password sequence +# +# see aaflogout to logout +### + +### +# Gather Classpath - warning, DME2 doesn't work with -Djava.ext.dirs +### +AAF_CP=_ROOT_DIR_/etc +for JAR in `find _ROOT_DIR_/lib -name "*.jar"` ; do + AAF_CP="$AAF_CP:$JAR" +done + +### +# Create Keyfile to use temporarily, if not exists +### +if [ ! -e $HOME/.aaf/keyfile ]; then + mkdir -p $HOME/.aaf + ${JAVA} -cp $AAF_CP com.att.cadi.CmdLine keygen $HOME/.aaf/keyfile + chmod 400 $HOME/.aaf/keyfile +fi + +### +# Obtain User ID from AAF_ID, or SUDO_USER or USER, that order +### +if [ "$AAF_ID" == "" ] || [ "$1" == "-f" ] ; then + if [ "$AAF_ID" == "" ] ; then + if [ "$SUDO_USER" != "" ] ; then + AAF_ID=$SUDO_USER + else if [ "$USER" != "" ] ; then + AAF_ID=$USER + fi + fi + fi + + echo -n "Enter AAF ID [$AAF_ID]: " + read TEMP + if [ "$TEMP" != "" ] ; then + AAF_ID=$TEMP + fi + export AAF_ID +fi + +### +# Add Function to remove AAF Vars and Functions from the Shell +# +function aaflogout { + unset AAF_ID + unset AAF_PASS + unset AAF_CP + unset -f aafcli + unset -f cmcli + unset -f aaflogout + rm -f $HOME/.aaf/keyfile +} + + +### +# Load the Password +### +if [ "$AAF_PASS" == "" ] || [ "$1" == "-f" ] ; then + # Ask for User and Password. Assuming Unix and availability of "stty" + if [[ "$AAF_ID" == *"@$DEFAULT_DOMAIN" ]] || [[ "$AAF_ID" != *"@"* ]] ; then + PASS_PROMPT="AT&T Global Login" + AAF_DEFAULT_DOMAIN="-Daaf_default_domain=$DEFAULT_DOMAIN" + else + PASS_PROMPT="AAF" + AAF_DEFAULT_DOMAIN="" + fi + + + read -ers -p "Enter "$PASS_PROMPT" Password for $AAF_ID: " AAF_PASS + echo + AAF_PASS=enc:`$JAVA -cp $AAF_CP $AAF_DEFAULT_DOMAIN com.att.cadi.CmdLine digest "$AAF_PASS" $HOME/.aaf/keyfile` + export AAF_PASS +fi + + + +### +# load aafcli function in the Shell +### + +function aafcli { + # for separating VM_ARGS in aafcli + AAF_SPACE=" " + THE_ID=$AAF_ID + if [ "${AAF_ID}" = "${AAF_ID/@/%}" ]; then + THE_ID+="@$DEFAULT_DOMAIN" + fi + _JAVA_HOME_/bin/java \ + -cp $AAF_CP \ + -Daaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=_MAJOR_VER_._MINOR_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ \ + -DAFT_LATITUDE=_AFT_LATITUDE_ \ + -DAFT_LONGITUDE=_AFT_LONGITUDE_ \ + -DAFT_ENVIRONMENT=_AFT_ENVIRONMENT_ \ + -Daaf_id=$THE_ID \ + -Daaf_password=$AAF_PASS \ + -Daaf_dme_timeout=60000 \ + -Dcadi_keyfile=$HOME/.aaf/keyfile \ + -Daaf_default_realm=$DEFAULT_DOMAIN \ + -DDEPLOYED_VERSION=_ARTIFACT_VERSION_ \ + _DME2_FS_ \ + com.att.cmd.AAFcli $* + unset THE_ID + unset AAF_SPACE +} + +### +# load cmcli function in the Shell +### + +function cmcli { + # for separating VM_ARGS in cmcli + AAF_SPACE=" " + THE_ID=$AAF_ID + if [ "${AAF_ID}" = "${AAF_ID/@/%}" ]; then + THE_ID+="@$DEFAULT_DOMAIN" + fi + CM_URL=_CM_URL_ + if [ "${CM_URL}" = "" ]; then + CM_URL=https://DME2RESOLVE/service=com.att.authz.Certman/version=_MAJOR_VER_._MINOR_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ + fi + + _JAVA_HOME_/bin/java \ + -cp $AAF_CP \ + -DAFT_LATITUDE=_AFT_LATITUDE_ \ + -DAFT_LONGITUDE=_AFT_LONGITUDE_ \ + -DAFT_ENVIRONMENT=_AFT_ENVIRONMENT_ \ + -Daaf_dme_timeout=60000 \ + -Daaf_default_realm=$DEFAULT_DOMAIN \ + -DDEPLOYED_VERSION=_ARTIFACT_VERSION_ \ + _DME2_FS_ \ + com.att.cadi.cm.CmAgent cm_url=${CM_URL} aaf_id=$THE_ID aaf_password="$AAF_PASS" \ + cadi_keyfile=$HOME/.aaf/keyfile $* + unset THE_ID + unset AAF_SPACE + unset CM_URL +} + + +### +# if "-r" the do Remote Password Reset +### +if [ "$1" == "-r" ] ; then + # Ask for User and Password. Assuming Unix and availability of "stty" + read -ers -p "Enter New AAF Password for $AAF_ID: " AAF_NEWPASS + echo + read -ers -p "Reenter New AAF Password for $AAF_ID: " AAF_NEWPASS2 + echo + if [ "$AAF_NEWPASS" == "$AAF_NEWPASS2" ] ; then + RESP=`aafcli user resetCred "$AAF_ID@aaf.att.com" $AAF_NEWPASS` + echo $RESP + if [ "$RESP" == "Reset Credential [$AAF_ID@aaf.att.com]" ] ; then + export AAF_PASS=enc:`$JAVA -cp $AAF_CP com.att.cadi.CmdLine digest $AAF_NEWPASS $HOME/.aaf/keyfile` + fi + else + echo "Passwords don't match!" + fi +fi + +### +# Export key variables for use in other Scripts +### +export AAF_ID +export AAF_PASS +export AAF_CP +export -f aafcli +export -f aaflogout +fi diff --git a/authz-cmd/src/test/java/com/att/cmd/JU_AAFCli.java b/authz-cmd/src/test/java/com/att/cmd/JU_AAFCli.java new file mode 100644 index 00000000..f3d721ce --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/JU_AAFCli.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.security.GeneralSecurityException; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.authz.env.AuthzEnv; +import com.att.cadi.Locator; +import com.att.cadi.LocatorException; +import com.att.cadi.client.PropertyLocator; +import com.att.cadi.config.Config; +import com.att.cadi.config.SecurityInfo; +import com.att.cadi.http.HBasicAuthSS; +import com.att.cadi.http.HMangr; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_AAFCli { + + private static AAFcli cli; + private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF); + + @BeforeClass + public static void setUp() throws Exception, Exception { + cli = getAAfCli(); + } + + @Test + public void eval() throws Exception { + assertTrue(cli.eval("#startswith")); + } + + @Test + public void eval_empty() throws Exception{ + assertTrue(cli.eval("")); + } + + @Test + public void eval_randomString() throws Exception { + assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage")); + } + + public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException { + final AuthzEnv env = new AuthzEnv(System.getProperties()); + String aafUrl = "https://DME2RESOLVE"; + SecurityInfo si = new SecurityInfo(env); + env.loadToSystemPropsStartsWith("AAF", "DME2"); + Locator loc; + loc = new PropertyLocator(aafUrl); + TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); + HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0"); + + //TODO: Consider requiring a default in properties + env.setProperty(Config.AAF_DEFAULT_REALM, System.getProperty(Config.AAF_DEFAULT_REALM,Config.getDefaultRealm())); + HBasicAuthSS ss = mock(HBasicAuthSS.class); + return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss); + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/JU_BaseCmd.java b/authz-cmd/src/test/java/com/att/cmd/JU_BaseCmd.java new file mode 100644 index 00000000..3e1eefaa --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/JU_BaseCmd.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.security.GeneralSecurityException; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_BaseCmd { + + private static AAFcli cli; + private static BaseCmd bCmd; + + @BeforeClass + public static void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException { + cli = JU_AAFCli.getAAfCli(); + bCmd = new BaseCmd<>(cli, "testString"); + } + + @Test + public void exec() throws CadiException, APIException, LocatorException { + assertEquals(bCmd._exec(0, "add","del","reset","extend"), 0); + + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/JU_BasicAuth.java b/authz-cmd/src/test/java/com/att/cmd/JU_BasicAuth.java new file mode 100644 index 00000000..67a6d225 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/JU_BasicAuth.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class JU_BasicAuth { + + @Test + public void getID () { + try { + BasicAuth bAuth = new BasicAuth("testUser", "nopass"); + assertEquals(bAuth.getID(), "testUser"); + System.out.println(bAuth.getID()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/JU_Help.java b/authz-cmd/src/test/java/com/att/cmd/JU_Help.java new file mode 100644 index 00000000..c5af6f9c --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/JU_Help.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Help { + + private static AAFcli cli; + private static Help help; + + @Mock + private static List cmds; + + @BeforeClass + public static void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException { + cli = JU_AAFCli.getAAfCli(); + cmds = new ArrayList<>(); + help = new Help(cli, cmds); + } + + @Test + public void exec_HTTP_200() { + try { + assertEquals(help._exec(0, "helps"), HttpStatus.OK_200); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/JU_Version.java b/authz-cmd/src/test/java/com/att/cmd/JU_Version.java new file mode 100644 index 00000000..f9c5727a --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/JU_Version.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.security.GeneralSecurityException; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Version { + + private static AAFcli cli; + private static Version version; + + @BeforeClass + public static void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException { + cli = JU_AAFCli.getAAfCli(); + version = new Version(cli); + } + + @Test + public void exec_HTTP_200() throws CadiException, APIException, LocatorException { + assertEquals(version._exec(0, "Version"), HttpStatus.OK_200); + + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_Clear.java b/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_Clear.java new file mode 100644 index 00000000..ce900f7a --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_Clear.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import static org.mockito.Mockito.mock; +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Clear { + + private static Clear clr; + + @BeforeClass + public static void setUp() { + clr = mock(Clear.class); + } + + @Test + public void exec() { + try { + assertEquals(clr._exec(0, "clear"), 0); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_Log.java b/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_Log.java new file mode 100644 index 00000000..78b630ca --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_Log.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import static org.mockito.Mockito.mock; +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Log { + + private static Log log; + + @BeforeClass + public static void setUp() { + log = mock(Log.class); + } + + @Test + public void exec() { + try { + assertEquals(log._exec(0, "session clear"), 0); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_SessClear.java b/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_SessClear.java new file mode 100644 index 00000000..1ab0ae07 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/mgmt/JU_SessClear.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.mgmt; + +import static org.mockito.Mockito.mock; +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_SessClear { + + private static SessClear sessclr; + + @BeforeClass + public static void setUp() { + sessclr = mock(SessClear.class); + } + + @Test + public void exec() { + try { + assertEquals(sessclr._exec(0, "session clear"), 0); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_Admin.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Admin.java new file mode 100644 index 00000000..ab67de38 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Admin.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Admin { + + private static Admin admin; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + admin = new Admin(ns); + } + + @Test + public void exec() { + try { + assertEquals(admin._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_Attrib.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Attrib.java new file mode 100644 index 00000000..7bf84031 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Attrib.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Attrib { + + private static Attrib attrib; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + attrib = new Attrib(ns); + } + + @Test + public void exec() { + try { + assertEquals(attrib._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_Create.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Create.java new file mode 100644 index 00000000..fe07b740 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Create.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Create { + + private static Create create; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + create = new Create(ns); + } + + @Test + public void exec() { + try { + assertEquals(create._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_Delete.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Delete.java new file mode 100644 index 00000000..c2ea19c4 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Delete.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Delete { + + private static Delete del; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + del = new Delete(ns); + } + + @Test + public void exec() { + try { + assertEquals(del._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_Describe.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Describe.java new file mode 100644 index 00000000..85b7b22d --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Describe.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Describe { + + private static Describe desc; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + desc = new Describe(ns); + } + + @Test + public void exec() { + try { + assertEquals(desc._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListActivity.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListActivity.java new file mode 100644 index 00000000..93b7e3d3 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListActivity.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListActivity { + + private static ListActivity lsActivity; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + List ls = new List(ns); + lsActivity = new ListActivity(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsActivity._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListAdminResponsible.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListAdminResponsible.java new file mode 100644 index 00000000..c730069e --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListAdminResponsible.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListAdminResponsible { + + private static ListAdminResponsible lsAdminRes; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + List ls = new List(ns); + lsAdminRes = new ListAdminResponsible(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsAdminRes._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListByName.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListByName.java new file mode 100644 index 00000000..a986ff55 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListByName.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByName { + + private static ListByName lsByName; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + List ls = new List(ns); + lsByName = new ListByName(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByName._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListChildren.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListChildren.java new file mode 100644 index 00000000..b9228b06 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListChildren.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListChildren { + + private static ListChildren lsChildren; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + List ls = new List(ns); + lsChildren = new ListChildren(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsChildren._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListNsKeysByAttrib.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListNsKeysByAttrib.java new file mode 100644 index 00000000..895693c8 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListNsKeysByAttrib.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListNsKeysByAttrib { + + private static ListNsKeysByAttrib lsNsKeys; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + List ls = new List(ns); + lsNsKeys = new ListNsKeysByAttrib(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsNsKeys._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListUsersInRole.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListUsersInRole.java new file mode 100644 index 00000000..4ef73840 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListUsersInRole.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListUsersInRole { + + private static ListUsersInRole lsUserinRole; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + List ls = new List(ns); + ListUsers lsU = new ListUsers(ls); + lsUserinRole = new ListUsersInRole(lsU); + } + + @Test + public void exec() { + try { + assertEquals(lsUserinRole._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListUsersWithPerm.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListUsersWithPerm.java new file mode 100644 index 00000000..78b65da2 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_ListUsersWithPerm.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListUsersWithPerm { + + private static ListUsersWithPerm lsUserWithPerm; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + List ls = new List(ns); + ListUsers lsU = new ListUsers(ls); + lsUserWithPerm = new ListUsersWithPerm(lsU); + } + + @Test + public void exec() { + try { + assertEquals(lsUserWithPerm._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/ns/JU_Responsible.java b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Responsible.java new file mode 100644 index 00000000..9e291c2e --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/ns/JU_Responsible.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.ns; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Responsible { + + private static Responsible respsble; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + respsble = new Responsible(ns); + } + + @Test + public void exec() { + try { + assertEquals(respsble._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_Create.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Create.java new file mode 100644 index 00000000..fa90e5f7 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Create.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Create { + + private static Create create; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + create = new Create(perm); + } + + @Test + public void exec() { + try { + assertEquals(create._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_Delete.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Delete.java new file mode 100644 index 00000000..c2b64630 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Delete.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Delete { + + private static Delete del; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + del = new Delete(perm); + } + + @Test + public void exec() { + try { + assertEquals(del._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_Describe.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Describe.java new file mode 100644 index 00000000..5bcd774c --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Describe.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Describe { + + private static Describe desc; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + desc = new Describe(perm); + } + + @Test + public void exec() { + try { + assertEquals(desc._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_Grant.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Grant.java new file mode 100644 index 00000000..fb789ec0 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Grant.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Grant { + + private static Grant grant; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + grant = new Grant(perm); + } + + @Test + public void exec() { + try { + assertEquals(grant._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListActivity.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListActivity.java new file mode 100644 index 00000000..f4cf7cfa --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListActivity.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListActivity { + + private static ListActivity lsActivity; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + List ls = new List(perm); + lsActivity = new ListActivity(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsActivity._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByNS.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByNS.java new file mode 100644 index 00000000..228b46a5 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByNS.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByNS { + + private static ListByNS lsByNS; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + List ls = new List(perm); + lsByNS = new ListByNS(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByNS._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByName.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByName.java new file mode 100644 index 00000000..b88bc74a --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByName.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByName { + + private static ListByName lsByName; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + List ls = new List(perm); + lsByName = new ListByName(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByName._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByRole.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByRole.java new file mode 100644 index 00000000..7835f22c --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByRole.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByRole { + + private static ListByRole lsByRole; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + List ls = new List(perm); + lsByRole = new ListByRole(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByRole._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByUser.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByUser.java new file mode 100644 index 00000000..a0b6ccd3 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_ListByUser.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByUser { + + private static ListByUser lsByName; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + List ls = new List(perm); + lsByName = new ListByUser(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByName._exec(0, "add","del","reset","extend"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/perm/JU_Rename.java b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Rename.java new file mode 100644 index 00000000..3fffc9da --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/perm/JU_Rename.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.perm; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Rename { + + private static Rename rename; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + Perm perm = new Perm(role); + rename = new Rename(perm); + } + + @Test + public void exec() { + try { + assertEquals(rename._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_CreateDelete.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_CreateDelete.java new file mode 100644 index 00000000..e64fe93c --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_CreateDelete.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_CreateDelete { + + private static CreateDelete createDel; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + createDel = new CreateDelete(role); + } + + @Test + public void exec() { + try { + assertEquals(createDel._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_Describe.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_Describe.java new file mode 100644 index 00000000..c0f3ff5b --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_Describe.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Describe { + + private static Describe desc; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + desc = new Describe(role); + } + + @Test + public void exec() { + try { + assertEquals(desc._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_ListActivity.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListActivity.java new file mode 100644 index 00000000..f18c20a3 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListActivity.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListActivity { + + private static ListActivity lsActivity; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + List ls = new List(role); + lsActivity = new ListActivity(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsActivity._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByNS.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByNS.java new file mode 100644 index 00000000..c088a6b0 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByNS.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByNS { + + private static ListByNS lsByNS; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + List ls = new List(role); + lsByNS = new ListByNS(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByNS._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByNameOnly.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByNameOnly.java new file mode 100644 index 00000000..ccd687c3 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByNameOnly.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByNameOnly { + + private static ListByNameOnly lsByName; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + List ls = new List(role); + lsByName = new ListByNameOnly(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByName._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByPerm.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByPerm.java new file mode 100644 index 00000000..3d5fcad6 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByPerm.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByPerm { + + private static ListByPerm lsByPerm; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + List ls = new List(role); + lsByPerm = new ListByPerm(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByPerm._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByRole.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByRole.java new file mode 100644 index 00000000..750543f4 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByRole.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByRole { + + private static ListByRole lsByRole; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + List ls = new List(role); + lsByRole = new ListByRole(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByRole._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByUser.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByUser.java new file mode 100644 index 00000000..5ef38c3e --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_ListByUser.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListByUser { + + private static ListByUser lsByUser; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + List ls = new List(role); + lsByUser = new ListByUser(ls); + } + + @Test + public void exec() { + try { + assertEquals(lsByUser._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/role/JU_User.java b/authz-cmd/src/test/java/com/att/cmd/role/JU_User.java new file mode 100644 index 00000000..33319a55 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/role/JU_User.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.role; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.cmd.perm.Perm; +import com.att.cmd.role.Role; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_User { + + private static User user; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + Role role = new Role(cli); + user = new User(role); + } + + @Test + public void exec() { + try { + assertEquals(user._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_Cred.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_Cred.java new file mode 100644 index 00000000..279fe2de --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_Cred.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Cred { + + private static Cred testCred; + private static User testUser; + + + @BeforeClass + public static void setUp() { + testCred = mock(Cred.class); + testUser = mock(User.class); + try { + when(testCred._exec(4, "String1","String2","String3","String4")).thenReturn(10); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void exec() throws CadiException, APIException, LocatorException { + assertEquals(testCred._exec(4, "String1","String2","String3","String4"), 10); + } + + + @Test + public void exec_add() { + try { + assertNotNull(testCred._exec(0, "zeroed","add","del","reset","extend")); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void exec_del() { + try { + assertNotNull(testCred._exec(1, "zeroed","add","del","reset","extend")); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void exec_reset() { + try { + assertNotNull(testCred._exec(2, "zeroed","add","del","reset","extend")); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void exec_extend() { + try { + assertNotNull(testCred._exec(3, "zeroed","add","del","reset","extend")); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_Delg.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_Delg.java new file mode 100644 index 00000000..0f80a810 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_Delg.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.mockito.Mockito.mock; +import static org.junit.Assert.*; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Delg { + + private static User testUser; + private static Delg delg; + + @BeforeClass + public static void setUp() throws APIException { + testUser = mock(User.class); + delg = mock(Delg.class); + } + + @Test + public void exec_add() { + try { + assertEquals(delg._exec(0, "zero","add","upd","del"), 0); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void exec_upd() { + try { + assertEquals(delg._exec(1, "zero","add","upd","del"), 0); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void exec_del() { + try { + assertEquals(delg._exec(2, "zero","add","upd","del"), 0); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_ListActivity.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListActivity.java new file mode 100644 index 00000000..e1e2d4bf --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListActivity.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListActivity { + + private static ListActivity lsActivity; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + User usr = new User(cli); + List parent = new List(usr); + lsActivity = new ListActivity(parent); + + } + + @Test + public void exec() { + try { + assertEquals(lsActivity._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + + e.printStackTrace(); + } catch (APIException e) { + + e.printStackTrace(); + } catch (LocatorException e) { + + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_ListApprovals.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListApprovals.java new file mode 100644 index 00000000..cc4f6480 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListApprovals.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListApprovals { + + private static ListApprovals lsApprovals; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + User usr = new User(cli); + List parent = new List(usr); + lsApprovals = new ListApprovals(parent); + + } + + @Test + public void exec() { + try { + assertEquals(lsApprovals._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + + e.printStackTrace(); + } catch (APIException e) { + + e.printStackTrace(); + } catch (LocatorException e) { + + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_ListDelegates.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListDelegates.java new file mode 100644 index 00000000..e1d9149f --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListDelegates.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListDelegates { + + private static ListDelegates lsDelegates; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + User usr = new User(cli); + List parent = new List(usr); + lsDelegates = new ListDelegates(parent); + + } + + @Test + public void exec() { + try { + assertEquals(lsDelegates._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + + e.printStackTrace(); + } catch (APIException e) { + + e.printStackTrace(); + } catch (LocatorException e) { + + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForCreds.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForCreds.java new file mode 100644 index 00000000..5600d5a9 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForCreds.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListForCreds { + + private static ListForCreds lsForCreds; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + User usr = new User(cli); + List parent = new List(usr); + lsForCreds = new ListForCreds(parent); + + } + + @Test + public void exec() { + try { + assertEquals(lsForCreds._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + + e.printStackTrace(); + } catch (APIException e) { + + e.printStackTrace(); + } catch (LocatorException e) { + + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForPermission.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForPermission.java new file mode 100644 index 00000000..51e20c13 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForPermission.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListForPermission { + + private static ListForPermission lsForPermission; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + User usr = new User(cli); + List parent = new List(usr); + lsForPermission = new ListForPermission(parent); + + } + + @Test + public void exec() { + try { + assertEquals(lsForPermission._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + + e.printStackTrace(); + } catch (APIException e) { + + e.printStackTrace(); + } catch (LocatorException e) { + + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForRoles.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForRoles.java new file mode 100644 index 00000000..b68e5973 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_ListForRoles.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_ListForRoles { + + private static ListForRoles lsForRoles; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + User usr = new User(cli); + List parent = new List(usr); + lsForRoles = new ListForRoles(parent); + + } + + @Test + public void exec() { + try { + assertEquals(lsForRoles._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + + e.printStackTrace(); + } catch (APIException e) { + + e.printStackTrace(); + } catch (LocatorException e) { + + e.printStackTrace(); + } + } +} diff --git a/authz-cmd/src/test/java/com/att/cmd/user/JU_Role.java b/authz-cmd/src/test/java/com/att/cmd/user/JU_Role.java new file mode 100644 index 00000000..c24531b8 --- /dev/null +++ b/authz-cmd/src/test/java/com/att/cmd/user/JU_Role.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cmd.user; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cmd.AAFcli; +import com.att.cmd.JU_AAFCli; +import com.att.inno.env.APIException; + +@RunWith(MockitoJUnitRunner.class) +public class JU_Role { + + private static Role role; + + @BeforeClass + public static void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + User usr = new User(cli); + role = new Role(usr); + + } + + @Test + public void exec() { + try { + assertEquals(role._exec(0, "add","del","reset","extend","clear", "rename", "create"),500); + } catch (CadiException e) { + + e.printStackTrace(); + } catch (APIException e) { + + e.printStackTrace(); + } catch (LocatorException e) { + + e.printStackTrace(); + } + } +} diff --git a/authz-core/.gitignore b/authz-core/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-core/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-core/pom.xml b/authz-core/pom.xml new file mode 100644 index 00000000..7120f350 --- /dev/null +++ b/authz-core/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-core + Authz Core + Core Libraries for Authz + jar + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + + com.att.inno + env + + + com.att.inno + log4j + + + com.att.inno + rosetta + + + com.att.cadi + cadi-aaf + + + javax.servlet + servlet-api + + + + + + javax.servlet + servlet-api + + + + + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.6 + + false + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + + + diff --git a/authz-core/src/main/java/com/att/authz/common/Define.java b/authz-core/src/main/java/com/att/authz/common/Define.java new file mode 100644 index 00000000..747ab508 --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/common/Define.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.common; + +import com.att.cadi.CadiException; +import com.att.cadi.config.Config; +import com.att.inno.env.Env; + +public class Define { + public static String ROOT_NS="NS.Not.Set"; + public static String ROOT_COMPANY=ROOT_NS; + + public static void set(Env env) throws CadiException { + ROOT_NS = env.getProperty(Config.AAF_ROOT_NS); + if(ROOT_NS==null) { + throw new CadiException(Config.AAF_ROOT_NS + " property is required."); + } + ROOT_COMPANY = env.getProperty(Config.AAF_ROOT_COMPANY); + if(ROOT_COMPANY==null) { + int last = ROOT_NS.lastIndexOf('.'); + if(last>=0) { + ROOT_COMPANY = ROOT_NS.substring(0, last); + } else { + throw new CadiException(Config.AAF_ROOT_COMPANY + " or " + Config.AAF_ROOT_NS + " property with 3 positions is required."); + } + } + env.init().log("AAF Root NS is " + ROOT_NS + ", and AAF Root Company is " +ROOT_COMPANY); + } + +} diff --git a/authz-core/src/main/java/com/att/authz/env/AuthzEnv.java b/authz-core/src/main/java/com/att/authz/env/AuthzEnv.java new file mode 100644 index 00000000..b5015b0c --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/env/AuthzEnv.java @@ -0,0 +1,265 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.env; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map.Entry; +import java.util.Properties; + +import com.att.cadi.Access; +import com.att.cadi.Symm; +import com.att.cadi.config.Config; +import com.att.inno.env.APIException; +import com.att.inno.env.Decryptor; +import com.att.inno.env.Encryptor; +import com.att.inno.env.impl.Log4JLogTarget; +import com.att.inno.env.log4j.LogFileNamer; +import com.att.rosetta.env.RosettaEnv; + + +/** + * AuthzEnv is the Env tailored to Authz Service + * + * Most of it is derived from RosettaEnv, but it also implements Access, which + * is an Interface that Allows CADI to interact with Container Logging + * + * + */ +public class AuthzEnv extends RosettaEnv implements Access { + private long[] times = new long[20]; + private int idx = 0; + //private int mask = Level.AUDIT.maskOf(); + + public AuthzEnv() { + super(); + } + + public AuthzEnv(String ... args) { + super(args); + } + + public AuthzEnv(Properties props) { + super(Config.CADI_PROP_FILES,props); + } + + + @Override + public AuthzTransImpl newTrans() { + synchronized(this) { + times[idx]=System.currentTimeMillis(); + if(++idx>=times.length)idx=0; + } + return new AuthzTransImpl(this); + } + + /** + * Create a Trans, but do not include in Weighted Average + * @return + */ + public AuthzTrans newTransNoAvg() { + return new AuthzTransImpl(this); + } + + public long transRate() { + int count = 0; + long pot = 0; + long prev = 0; + for(int i=idx;i0) { + if(prev>0) { + ++count; + pot += times[i]-prev; + } + prev = times[i]; + } + } + for(int i=0;i0) { + if(prev>0) { + ++count; + pot += times[i]-prev; + } + prev = times[i]; + } + } + + return count==0?300000L:pot/count; // Return Weighted Avg, or 5 mins, if none avail. + } + + @Override + public ClassLoader classLoader() { + return getClass().getClassLoader(); + } + + @Override + public void load(InputStream is) throws IOException { + Properties props = new Properties(); + props.load(is); + for(Entry es : props.entrySet()) { + String key = es.getKey().toString(); + String value =es.getValue().toString(); + put(staticSlot(key==null?null:key.trim()),value==null?null:value.trim()); + } + } + + @Override + public void log(Level lvl, Object... msgs) { +// if(lvl.inMask(mask)) { +// switch(lvl) { +// case INIT: +// init().log(msgs); +// break; +// case AUDIT: +// audit().log(msgs); +// break; +// case DEBUG: +// debug().log(msgs); +// break; +// case ERROR: +// error().log(msgs); +// break; +// case INFO: +// info().log(msgs); +// break; +// case WARN: +// warn().log(msgs); +// break; +// case NONE: +// break; +// } +// } + } + + @Override + public void log(Exception e, Object... msgs) { + error().log(e,msgs); + } + + //@Override + public void printf(Level level, String fmt, Object... elements) { + if(willLog(level)) { + log(level,String.format(fmt, elements)); + } + } + + /* (non-Javadoc) + * @see com.att.cadi.Access#willLog(com.att.cadi.Access.Level) + */ + @Override + public boolean willLog(Level level) { + +// if(level.inMask(mask)) { +// switch(level) { +// case INIT: +// return init().isLoggable(); +// case AUDIT: +// return audit().isLoggable(); +// case DEBUG: +// return debug().isLoggable(); +// case ERROR: +// return error().isLoggable(); +// case INFO: +// return info().isLoggable(); +// case WARN: +// return warn().isLoggable(); +// case NONE: +// return false; +// } +// } + return false; + } + + @Override + public void setLogLevel(Level level) { + super.debug().isLoggable(); + //level.toggle(mask); + } + + public void setLog4JNames(String path, String root, String _service, String _audit, String _init, String _trace) throws APIException { + LogFileNamer lfn = new LogFileNamer(root); + if(_service==null) { + throw new APIException("AuthzEnv.setLog4JNames \"_service\" required (as default). Others can be null"); + } + String service=_service=lfn.setAppender(_service); // when name is split, i.e. authz|service, the Appender is "authz", and "service" + String audit=_audit==null?service:lfn.setAppender(_audit); // is part of the log-file name + String init=_init==null?service:lfn.setAppender(_init); + String trace=_trace==null?service:lfn.setAppender(_trace); + //TODO Validate path on Classpath + lfn.configure(path); + super.fatal = new Log4JLogTarget(service,org.apache.log4j.Level.FATAL); + super.error = new Log4JLogTarget(service,org.apache.log4j.Level.ERROR); + super.warn = new Log4JLogTarget(service,org.apache.log4j.Level.WARN); + super.audit = new Log4JLogTarget(audit,org.apache.log4j.Level.WARN); + super.init = new Log4JLogTarget(init,org.apache.log4j.Level.WARN); + super.info = new Log4JLogTarget(service,org.apache.log4j.Level.INFO); + super.debug = new Log4JLogTarget(service,org.apache.log4j.Level.DEBUG); + super.trace = new Log4JLogTarget(trace,org.apache.log4j.Level.TRACE); + } + + private static final byte[] ENC="enc:???".getBytes(); + public String decrypt(String encrypted, final boolean anytext) throws IOException { + if(encrypted==null) { + throw new IOException("Password to be decrypted is null"); + } + if(anytext || encrypted.startsWith("enc:")) { + if(decryptor.equals(Decryptor.NULL) && getProperty(Config.CADI_KEYFILE)!=null) { + final Symm s = Symm.obtain(this); + decryptor = new Decryptor() { + private Symm symm = s; + @Override + public String decrypt(String encrypted) { + try { + return (encrypted!=null && (anytext || encrypted.startsWith(Symm.ENC))) + ? symm.depass(encrypted) + : encrypted; + } catch (IOException e) { + return ""; + } + } + }; + encryptor = new Encryptor() { + @Override + public String encrypt(String data) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + baos.write(ENC); + return "enc:???"+s.enpass(data); + } catch (IOException e) { + return ""; + } + } + + }; + } + return decryptor.decrypt(encrypted); + } else { + return encrypted; + } + } + + + +} diff --git a/authz-core/src/main/java/com/att/authz/env/AuthzTrans.java b/authz-core/src/main/java/com/att/authz/env/AuthzTrans.java new file mode 100644 index 00000000..129ddddc --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/env/AuthzTrans.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.env; + +import java.security.Principal; + +import javax.servlet.http.HttpServletRequest; + +import com.att.authz.org.Organization; +import com.att.cadi.Lur; +import com.att.cadi.Permission; +import com.att.inno.env.LogTarget; +import com.att.inno.env.TransStore; + +public interface AuthzTrans extends TransStore { + public abstract AuthzTrans set(HttpServletRequest req); + + public abstract void setUser(Principal p); + + public abstract String user(); + + public abstract Principal getUserPrincipal(); + + public abstract String ip(); + + public abstract int port(); + + public abstract String meth(); + + public abstract String path(); + + public abstract String agent(); + + public abstract AuthzEnv env(); + + public abstract void setLur(Lur lur); + + public abstract boolean fish(Permission p); + + public abstract boolean forceRequested(); + + public abstract Organization org(); + + public abstract boolean moveRequested(); + + public abstract boolean futureRequested(); + + public abstract void logAuditTrail(LogTarget lt); + +} diff --git a/authz-core/src/main/java/com/att/authz/env/AuthzTransFilter.java b/authz-core/src/main/java/com/att/authz/env/AuthzTransFilter.java new file mode 100644 index 00000000..46bec117 --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/env/AuthzTransFilter.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.env; + +import java.security.Principal; + +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; + +import com.att.cadi.CadiException; +import com.att.cadi.Connector; +import com.att.cadi.TrustChecker; +import com.att.cadi.principal.BasicPrincipal; +import com.att.cadi.principal.TrustPrincipal; +import com.att.cadi.principal.X509Principal; +import com.att.cssa.rserv.TransFilter; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans.Metric; + +public class AuthzTransFilter extends TransFilter { + private AuthzEnv env; + public Metric serviceMetric; + public static Slot transIDslot; + + public static final String TRANS_ID_SLOT = "TRANS_ID_SLOT"; + public static final int BUCKETSIZE = 2; + + public AuthzTransFilter(AuthzEnv env, Connector con, TrustChecker tc, Object ... additionalTafLurs) throws CadiException { + super(env,con, tc, additionalTafLurs); + this.env = env; + serviceMetric = new Metric(); + serviceMetric.buckets = new float[BUCKETSIZE]; + if(transIDslot==null) { + transIDslot = env.slot(TRANS_ID_SLOT); + } + } + + @Override + protected AuthzTrans newTrans() { + AuthzTrans at = env.newTrans(); + at.setLur(getLur()); + return at; + } + + @Override + protected TimeTaken start(AuthzTrans trans, ServletRequest request) { + trans.set((HttpServletRequest)request); + return trans.start("Trans " + //(context==null?"n/a":context.toString()) + + " IP: " + trans.ip() + + " Port: " + trans.port() + , Env.SUB); + } + + @Override + protected void authenticated(AuthzTrans trans, Principal p) { + trans.setUser(p); + } + + @Override + protected void tallyHo(AuthzTrans trans) { + if(trans.info().isLoggable()) { + // Transaction is done, now post + StringBuilder sb = new StringBuilder("AuditTrail\n"); + // We'll grabAct sub-metrics for Remote Calls and JSON + // IMPORTANT!!! if you add more entries here, change "BUCKETSIZE"!!! + Metric m = trans.auditTrail(1, sb, Env.REMOTE,Env.JSON); + + // Add current Metrics to total metrics + serviceMetric.total+= m.total; + for(int i=0;i { + private AuthzEnv env; + public Metric serviceMetric; + + public static final int BUCKETSIZE = 2; + + public AuthzTransOnlyFilter(AuthzEnv env) { + this.env = env; + serviceMetric = new Metric(); + serviceMetric.buckets = new float[BUCKETSIZE]; + } + + @Override + protected AuthzTrans newTrans() { + return env.newTrans(); + } + + @Override + protected TimeTaken start(AuthzTrans trans, ServletRequest request) { + trans.set((HttpServletRequest)request); + return trans.start("Trans " + //(context==null?"n/a":context.toString()) + + " IP: " + trans.ip() + + " Port: " + trans.port() + , Env.SUB); + } + + @Override + protected void authenticated(AuthzTrans trans, Principal p) { + trans.setUser(p); + } + + @Override + protected void tallyHo(AuthzTrans trans) { + // Transaction is done, now post + StringBuilder sb = new StringBuilder("AuditTrail\n"); + // We'll grab sub-metrics for Remote Calls and JSON + // IMPORTANT!!! if you add more entries here, change "BUCKETSIZE"!!! + Metric m = trans.auditTrail(1, sb, Env.REMOTE,Env.JSON); + // Add current Metrics to total metrics + serviceMetric.total+= m.total; + for(int i=0;i T get(Slot slot, T deflt) { + return null; + } + @Override + public T get(StaticSlot slot, T dflt) { + return null; + } + @Override + public void setUser(Principal p) { + } + @Override + public Slot slot(String name) { + return null; + } + @Override + public AuthzEnv env() { + return null; + } + @Override + public String agent() { + return null; + } + + @Override + public void setLur(Lur lur) { + } + + @Override + public boolean fish(Permission p) { + return false; + } + + @Override + public boolean forceRequested() { + return false; + } + + @Override + public boolean futureRequested() { + return false; + } + + @Override + public boolean moveRequested() { + return false; + } + + @Override + public Organization org() { + return Organization.NULL; + } + + @Override + public void logAuditTrail(LogTarget lt) { + } + + @Override + public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int... flag) { + // TODO Auto-generated method stub + return null; + } + +} + diff --git a/authz-core/src/main/java/com/att/authz/layer/FacadeImpl.java b/authz-core/src/main/java/com/att/authz/layer/FacadeImpl.java new file mode 100644 index 00000000..07394454 --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/layer/FacadeImpl.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.layer; + +import javax.servlet.http.HttpServletResponse; + +import com.att.inno.env.Data; +import com.att.inno.env.Data.TYPE; + + + +public abstract class FacadeImpl { + protected static final String IN = "in"; + + protected void setContentType(HttpServletResponse response, TYPE type) { + response.setContentType(type==Data.TYPE.JSON?"application/json":"text.xml"); + } +} diff --git a/authz-core/src/main/java/com/att/authz/layer/Result.java b/authz-core/src/main/java/com/att/authz/layer/Result.java new file mode 100644 index 00000000..1af9a26b --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/layer/Result.java @@ -0,0 +1,326 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.layer; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + + +/** + * It would be nice if Java Enums were extensible, but they're not. + * + * + */ +public class Result { + private static final String SUCCESS = "Success"; + public static final String[] EMPTY_VARS = new String[0]; + + public final static int OK=0, + ERR_Security = 1, + ERR_Denied = 2, + ERR_Policy = 3, + ERR_BadData = 4, + ERR_NotImplemented = 5, + ERR_NotFound = 6, + ERR_ConflictAlreadyExists = 7, + ERR_ActionNotCompleted = 8, + ERR_Backend = 9, + ERR_General = 20; + + public final RV value; + public final int status; + public final String details; + public final String[] variables; + + protected Result(RV value, int status, String details, String[] variables) { + this.value = value; + if(value==null) { + specialCondition|=EMPTY_LIST; + } + this.status = status; + this.details = details; + if(variables==null) { + this.variables = EMPTY_VARS; + } else { + this.variables=variables; + } + } + + /** + * Create a Result class with "OK" status and "Success" for details + * + * This is the easiest to use + * + * @param value + * @param status + * @return + */ + public static Result ok(R value) { + return new Result(value,OK,SUCCESS,null); + } + + /** + * Accept Arrays and mark as empty or not + * @param value + * @return + */ + public static Result ok(R value[]) { + return new Result(value,OK,SUCCESS,null).emptyList(value.length==0); + } + + /** + * Accept Sets and mark as empty or not + * @param value + * @return + */ + public static Result> ok(Set value) { + return new Result>(value,OK,SUCCESS,null).emptyList(value.size()==0); + } + + /** + * Accept Lists and mark as empty or not + * @param value + * @return + */ + public static Result> ok(List value) { + return new Result>(value,OK,SUCCESS,null).emptyList(value.size()==0); + } + + /** + * Accept Collections and mark as empty or not + * @param value + * @return + */ + public static Result> ok(Collection value) { + return new Result>(value,OK,SUCCESS,null).emptyList(value.size()==0); + } + + + /** + * Special Case for Void Type + * @return + */ + public static Result ok() { + return new Result(null,OK,SUCCESS,null); + } + + /** + * Create a Status (usually non OK, with a details statement + * @param value + * @param status + * @param details + * @return + */ +// public static Result err(int status, String details) { +// return new Result(null,status,details,null); +// } + + /** + * Create a Status (usually non OK, with a details statement and variables supported + * @param status + * @param details + * @param variables + * @return + */ + public static Result err(int status, String details, String ... variables) { + return new Result(null,status,details,variables); + } + + /** + * Create Error from status and Details of previous Result (and not data) + * @param pdr + * @return + */ + public static Result err(Result pdr) { + return new Result(null,pdr.status,pdr.details,pdr.variables); + } + + /** + * Create General Error from Exception + * @param e + * @return + */ + public static Result err(Exception e) { + return new Result(null,ERR_General,e.getMessage(),EMPTY_VARS); + } + + /** + * Create a Status (usually non OK, with a details statement + * @param value + * @param status + * @param details + * @return + */ + public static Result create(R value, int status, String details, String ... vars) { + return new Result(value,status,details,vars); + } + + /** + * Create a Status from a previous status' result/details + * @param value + * @param status + * @param details + * @return + */ + public static Result create(R value, Result result) { + return new Result(value,result.status,result.details,result.variables); + } + + private static final int PARTIAL_CONTENT = 0x001; + private static final int EMPTY_LIST = 0x002; + + /** + * AAF Specific problems, etc + * + * + */ + + /** + * specialCondition is a bit field to enable multiple conditions, e.g. PARTIAL_CONTENT + */ + private int specialCondition = 0; + + + /** + * Is result set only partial results, i.e. the DAO clipped the real result set to a smaller number. + * @return true iff result returned PARTIAL_CONTENT + */ + public boolean partialContent() { + return (specialCondition & PARTIAL_CONTENT) == PARTIAL_CONTENT; + } + + /** + * Set fact that result set only returned partial results, i.e. the DAO clipped the real result set to a smaller number. + * @param hasPartialContent set true iff result returned PARTIAL_CONTENT + * @return this Result object, so you can chain calls, in builder style + */ + public Result partialContent(boolean hasPartialContent) { + if (hasPartialContent) { + specialCondition |= PARTIAL_CONTENT; + } else { + specialCondition &= (~PARTIAL_CONTENT); + } + return this; + } + + /** + * When Result is a List, you can check here to see if it's empty instead of looping + * + * @return + */ + public boolean isEmpty() { + return (specialCondition & EMPTY_LIST) == EMPTY_LIST; + } + + /** + * A common occurrence is that data comes back, but list is empty. If set, you can skip looking + * at list at the outset. + * + * @param emptyList + * @return + */ + public Result emptyList(boolean emptyList) { + if (emptyList) { + specialCondition |= EMPTY_LIST; + } else { + specialCondition &= (~EMPTY_LIST); + } + return this; + } + + + /** + * Convenience function. Checks OK, and also if List is not Empty + * Not valid if Data is not a List + * @return + */ + public boolean isOK() { + return status == OK; + } + + /** + * Convenience function. Checks OK, and also if List is not Empty + * Not valid if Data is not a List + * @return + */ + public boolean notOK() { + return status != OK; + } + + /** + * Convenience function. Checks OK, and also if List is not Empty + * Not valid if Data is not a List + * @return + */ + public boolean isOKhasData() { + return status == OK && (specialCondition & EMPTY_LIST) != EMPTY_LIST; + } + + + /** + * Convenience function. Checks OK, and also if List is not Empty + * Not valid if Data is not a List + * @return + */ + public boolean notOKorIsEmpty() { + return status != OK || (specialCondition & EMPTY_LIST) == EMPTY_LIST; + } + + @Override + public String toString() { + if(status==0) { + return details; + } else { + StringBuilder sb = new StringBuilder(); + sb.append(status); + sb.append(':'); + sb.append(String.format(details,((Object[])variables))); + if(isEmpty()) { + sb.append("{empty}"); + } + sb.append('-'); + sb.append(value.toString()); + return sb.toString(); + } + } + + public String errorString() { + StringBuilder sb = new StringBuilder(); + switch(status) { + case 1: sb.append("Security"); break; + case 2: sb.append("Denied"); break; + case 3: sb.append("Policy"); break; + case 4: sb.append("BadData"); break; + case 5: sb.append("NotImplemented"); break; + case 6: sb.append("NotFound"); break; + case 7: sb.append("AlreadyExists"); break; + case 8: sb.append("ActionNotComplete"); break; + default: sb.append("Error"); + } + sb.append(" - "); + sb.append(String.format(details, (Object[])variables)); + return sb.toString(); + } +} diff --git a/authz-core/src/main/java/com/att/authz/local/AbsData.java b/authz-core/src/main/java/com/att/authz/local/AbsData.java new file mode 100644 index 00000000..cc00efff --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/local/AbsData.java @@ -0,0 +1,215 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.local; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.Iterator; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.local.DataFile.Token; +import com.att.authz.local.DataFile.Token.Field; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +public abstract class AbsData implements Iterable { + protected DataFile data; + protected TextIndex ti; + private File dataf,idxf,lockf; + private String name; + private char delim; + private int maxLineSize; + private int fieldOffset; + private int skipLines; + + public AbsData(File dataf,char sepChar, int maxLineSize, int fieldOffset) { + File dir = dataf.getParentFile(); + int dot = dataf.getName().lastIndexOf('.'); + if(dot>=0) { + name = dataf.getName().substring(0,dot); + } + + this.dataf=dataf; + this.delim = sepChar; + this.maxLineSize = maxLineSize; + this.fieldOffset = fieldOffset; + idxf = new File(dir,name.concat(".idx")); + lockf = new File(dir,name.concat(".lock")); + + + data = new DataFile(dataf,"r"); + ti = new TextIndex(idxf); + skipLines=0; + } + + public void skipLines(int lines) { + skipLines=lines; + } + + public String name() { + return name; + } + + public void open(AuthzTrans trans, long timeout) throws IOException { + TimeTaken tt = trans.start("Open Data File", Env.SUB); + boolean opened = false, first = true; + try { + if(!dataf.exists()) { + throw new FileNotFoundException("Data File Missing:" + dataf.getCanonicalPath()); + } + long begin = System.currentTimeMillis(); + long end = begin+timeout; + boolean exists; + while((exists=lockf.exists()) && beginidxf.lastModified()) { + trans.warn().log(idxf.getCanonicalPath(),"is missing, empty or out of date, creating"); + RandomAccessFile raf = new RandomAccessFile(lockf, "rw"); + try { + ti.create(trans, data, maxLineSize, delim, fieldOffset, skipLines); + if(!idxf.exists() || (idxf.length()==0 && dataf.length()!=0)) { + throw new IOException("Data Index File did not create correctly"); + } + } finally { + raf.close(); + lockf.delete(); + } + } + } + + public void close(AuthzTrans trans) throws IOException { + ti.close(); + data.close(); + } + + public class Reuse { + private Token tokenData; + private Field fieldData; + + private Reuse(int size,char delim) { + tokenData = data.new Token(size); + fieldData = getTokenData().new Field(delim); + } + + public void reset() { + getFieldData().reset(); + } + + public void pos(int rec) { + getFieldData().reset(); + getTokenData().pos(rec); + } + + public String next() { + return getFieldData().next(); + } + + public String at(int field) { + return getFieldData().at(field); + } + + public String atToEnd(int field) { + return getFieldData().atToEnd(field); + } + + public Field getFieldData() { + return fieldData; + } + + public Token getTokenData() { + return tokenData; + } + + } + + public Reuse reuse() { + return new Reuse(maxLineSize,delim); + } + + public Iter iterator() { + return new Iter(); + } + + public class Iter implements Iterator { + private Reuse reuse; + private com.att.authz.local.TextIndex.Iter tii; + + public Iter() { + reuse = reuse(); + tii = ti.new Iter(); + } + + @Override + public boolean hasNext() { + return tii.hasNext(); + } + + @Override + public String next() { + reuse.reset(); + int rec = tii.next(); + reuse.pos(rec); + return reuse.at(0); + } + + @Override + public void remove() { + // read only + } + } +} diff --git a/authz-core/src/main/java/com/att/authz/local/DataFile.java b/authz-core/src/main/java/com/att/authz/local/DataFile.java new file mode 100644 index 00000000..a54e8563 --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/local/DataFile.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.local; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileChannel.MapMode; + +public class DataFile { + private RandomAccessFile rafile; + private FileChannel channel; + public MappedByteBuffer mapBuff; + private final File file; + private final String access; + + public DataFile(File file, String access) { + this.file = file; + this.access = access; + } + public void open() throws IOException { + if(!file.exists()) throw new FileNotFoundException(); + rafile = new RandomAccessFile(file,access); + channel = rafile.getChannel(); + mapBuff = channel.map("r".equals(access)?MapMode.READ_ONLY:MapMode.READ_WRITE,0,channel.size()); + } + public void close() throws IOException { + if(channel!=null){channel.close();} + if(rafile!=null) {rafile.close();} + mapBuff = null; + } + + public long size() throws IOException { + return channel.size(); + } + + private synchronized int load(Token t) { + int len = Math.min(mapBuff.limit()-t.next,t.buff.length); + if(len>0) { + mapBuff.position(t.next); + mapBuff.get(t.buff,0,len); + } + return len<0?0:len; + } + + public class Token { + private byte[] buff; + int pos, next, end; + + public Token(int size) { + buff = new byte[size]; + pos = next = end = 0; + } + + public boolean pos(int to) { + pos = next = to; + return (end=load(this))>0; + } + + public boolean nextLine() { + end = load(this); + pos = next; + for(int i=0;i=end)return null; + int start = idx; + byte c=0; + int endStr = -1; + while(idx=end)?1:0))); + } + + } + + public int pos() { + return pos; + } + } + + public File file() { + return file; + } + +} diff --git a/authz-core/src/main/java/com/att/authz/local/TextIndex.java b/authz-core/src/main/java/com/att/authz/local/TextIndex.java new file mode 100644 index 00000000..a6899642 --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/local/TextIndex.java @@ -0,0 +1,253 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.local; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import com.att.authz.local.DataFile.Token; +import com.att.authz.local.DataFile.Token.Field; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; + +public class TextIndex { + private static final int REC_SIZE=8; + + private File file; + private DataFile dataFile=null; + + public TextIndex(File theFile) { + file = theFile; + } + + public void open() throws IOException { + dataFile = new DataFile(file,"r"); + dataFile.open(); + } + + public void close() throws IOException { + if(dataFile!=null) {dataFile.close();} + } + + public int find(Object key, AbsData.Reuse reuse, int offset) throws IOException { + return find(key,reuse.getTokenData(),reuse.getFieldData(),offset); + } + + public int find(Object key, DataFile.Token dtok, Field df, int offset) throws IOException { + if(dataFile==null) {throw new IOException("File not opened");} + long hash = hashToLong(key.hashCode()); + int min=0, max = (int)(dataFile.size()/REC_SIZE); + Token ttok = dataFile.new Token(REC_SIZE); + IntBuffer tib = ttok.getIntBuffer(); + long lhash; + int curr; + while((max-min)>100) { + ttok.pos((curr=(min+(max-min)/2))*REC_SIZE); + tib.rewind(); + lhash = hashToLong(tib.get()); + if(lhashhash) { + max=curr-1; + } else { + min=curr-40; + max=curr+40; + break; + } + } + + List entries = new ArrayList(); + for(int i=min;i<=max;++i) { + ttok.pos(i*REC_SIZE); + tib.rewind(); + lhash = hashToLong(tib.get()); + if(lhash==hash) { + entries.add(tib.get()); + } else if(lhash>hash) { + break; + } + } + + for(Integer i : entries) { + dtok.pos(i); + if(df.at(offset).equals(key)) { + return i; + } + } + return -1; + } + + + /* + * Have to change Bytes into a Long, to avoid the inevitable signs in the Hash + */ + private static long hashToLong(int hash) { + long rv; + if(hash<0) { + rv = 0xFFFFFFFFL & hash; + } else { + rv = hash; + } + return rv; + } + + public void create(final Trans trans,final DataFile data, int maxLine, char delim, int fieldOffset, int skipLines) throws IOException { + RandomAccessFile raf; + FileChannel fos; + + List list = new LinkedList(); // Some hashcodes will double... DO NOT make a set + TimeTaken tt2 = trans.start("Open Files", Env.SUB); + try { + raf = new RandomAccessFile(file,"rw"); + raf.setLength(0L); + fos = raf.getChannel(); + } finally { + tt2.done(); + } + + try { + + Token t = data.new Token(maxLine); + Field f = t.new Field(delim); + + int count = 0; + if(skipLines>0) { + trans.info().log("Skipping",skipLines,"line"+(skipLines==1?" in":"s in"),data.file().getName()); + } + for(int i=0;i { + public int hash, pos; + public Idx(Object obj, int pos) { + hash = obj.hashCode(); + this.pos = pos; + } + + @Override + public int compareTo(Idx ib) { + long a = hashToLong(hash); + long b = hashToLong(ib.hash); + return a>b?1:a 1, remove User from Owner + // if # of Owners = 1, changeOwner to X Remove Owner???? + boolean hasPermission(String user, String ns, String type, String instance, String action); + boolean inRole(String name); + + public String namespace() throws Exception; + public String id(); +} diff --git a/authz-core/src/main/java/com/att/authz/org/Organization.java b/authz-core/src/main/java/com/att/authz/org/Organization.java new file mode 100644 index 00000000..e8938cdc --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/org/Organization.java @@ -0,0 +1,491 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.org; + +import java.util.ArrayList; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.att.authz.env.AuthzTrans; + +/** + * Organization + * + * There is Organizational specific information required which we have extracted to a plugin + * + * It supports using Company Specific User Directory lookups, as well as supporting an + * Approval/Validation Process to simplify control of Roles and Permissions for large organizations + * in lieu of direct manipulation by a set of Admins. + * + * + */ +public interface Organization { + public static final String N_A = "n/a"; + + public interface Identity { + public String id(); + public String fullID(); // Fully Qualified ID (includes Domain of Organization) + public String type(); // Must be one of "IdentityTypes", see below + public String responsibleTo(); // Chain of Command, Comma Separated if required + public List delegate(); // Someone who has authority to act on behalf of Identity + public String email(); + public String fullName(); + public boolean isResponsible(); // Is id passed belong to a person suitable to be Responsible for content Management + public boolean isFound(); // Is Identity found in Identity stores + public Identity owner() throws OrganizationException; // Identity is directly responsible for App ID + public Organization org(); // Organization of Identity + } + + + /** + * Name of Organization, suitable for Logging + * @return + */ + public String getName(); + + /** + * Realm, for use in distinguishing IDs from different systems/Companies + * @return + */ + public String getRealm(); + + String getDomain(); + + /** + * Get Identity information based on userID + * + * @param id + * @return + */ + public Identity getIdentity(AuthzTrans trans, String id) throws OrganizationException; + + + /** + * Does the ID pass Organization Standards + * + * Return a Blank (empty) String if empty, otherwise, return a "\n" separated list of + * reasons why it fails + * + * @param id + * @return + */ + public String isValidID(String id); + + /** + * Return a Blank (empty) String if empty, otherwise, return a "\n" separated list of + * reasons why it fails + * + * Identity is passed in to allow policies regarding passwords that are the same as user ID + * + * any entries for "prev" imply a reset + * + * @param id + * @param password + * @return + */ + public String isValidPassword(String user, String password, String ... prev); + + + /** + * Does your Company distinguish essential permission structures by kind of Identity? + * i.e. Employee, Contractor, Vendor + * @return + */ + public Set getIdentityTypes(); + + public enum Notify { + Approval(1), + PasswordExpiration(2), + RoleExpiration(3); + + final int id; + Notify(int id) {this.id = id;} + public int getValue() {return id;} + public static Notify from(int type) { + for(Notify t : Notify.values()) { + if(t.id==type) { + return t; + } + } + return null; + } + } + + public enum Response{ + OK, + ERR_NotImplemented, + ERR_UserNotExist, + ERR_NotificationFailure, + }; + + public enum Expiration { + Password, + TempPassword, + Future, + UserInRole, + UserDelegate, + ExtendPassword + } + + public enum Policy { + CHANGE_JOB, + LEFT_COMPANY, + CREATE_MECHID, + CREATE_MECHID_BY_PERM_ONLY, + OWNS_MECHID, + AS_EMPLOYEE, + MAY_EXTEND_CRED_EXPIRES + } + + /** + * Notify a User of Action or Info + * + * @param type + * @param url + * @param users (separated by commas) + * @param ccs (separated by commas) + * @param summary + */ + + public Response notify(AuthzTrans trans, Notify type, String url, String ids[], String ccs[], String summary, Boolean urgent); + + /** + * (more) generic way to send an email + * + * @param toList + * @param ccList + * @param subject + * @param body + * @param urgent + */ + + public int sendEmail(AuthzTrans trans, List toList, List ccList, String subject, String body, Boolean urgent) throws OrganizationException; + + /** + * whenToValidate + * + * Authz support services will ask the Organization Object at startup when it should + * kickoff Validation processes given particular types. + * + * This allows the Organization to express Policy + * + * Turn off Validation behavior by returning "null" + * + */ + public Date whenToValidate(Notify type, Date lastValidated); + + + /** + * Expiration + * + * Given a Calendar item of Start (or now), set the Expiration Date based on the Policy + * based on type. + * + * For instance, "Passwords expire in 3 months" + * + * The Extra Parameter is used by certain Orgs. + * + * For Password, the extra is UserID, so it can check the Identity Type + * + * @param gc + * @param exp + * @return + */ + public GregorianCalendar expiration(GregorianCalendar gc, Expiration exp, String ... extra); + + /** + * Get Email Warning timing policies + * @return + */ + public EmailWarnings emailWarningPolicy(); + + /** + * + * @param trans + * @param user + * @return + */ + public List getApprovers(AuthzTrans trans, String user) throws OrganizationException ; + + /* + * + * @param user + * @param type + * @param users + * @return + public Response notifyRequest(AuthzTrans trans, String user, Approval type, List approvers); + */ + + /** + * + * @return + */ + public String getApproverType(); + + /* + * startOfDay - define for company what hour of day business starts (specifically for password and other expiration which + * were set by Date only.) + * + * @return + */ + public int startOfDay(); + + /** + * implement this method to support any IDs that can have multiple entries in the cred table + * NOTE: the combination of ID/expiration date/(encryption type when implemented) must be unique. + * Since expiration date is based on startOfDay for your company, you cannot create many + * creds for the same ID in the same day. + * @param id + * @return + */ + public boolean canHaveMultipleCreds(String id); + + /** + * + * @param id + * @return + */ + public boolean isValidCred(String id); + + /** + * If response is Null, then it is valid. Otherwise, the Organization specific reason is returned. + * + * @param trans + * @param policy + * @param executor + * @param vars + * @return + * @throws OrganizationException + */ + public String validate(AuthzTrans trans, Policy policy, Executor executor, String ... vars) throws OrganizationException; + + boolean isTestEnv(); + + public void setTestMode(boolean dryRun); + + public static final Organization NULL = new Organization() + { + private final GregorianCalendar gc = new GregorianCalendar(1900, 1, 1); + private final List nullList = new ArrayList(); + private final Set nullStringSet = new HashSet(); + private final Identity nullIdentity = new Identity() { + List nullIdentity = new ArrayList(); + @Override + public String type() { + return N_A; + } + @Override + public String responsibleTo() { + return N_A; + } + @Override + public boolean isResponsible() { + return false; + } + + @Override + public boolean isFound() { + return false; + } + + @Override + public String id() { + return N_A; + } + + @Override + public String fullID() { + return N_A; + } + + @Override + public String email() { + return N_A; + } + + @Override + public List delegate() { + return nullIdentity; + } + @Override + public String fullName() { + return N_A; + } + @Override + public Identity owner() { + return null; + } + @Override + public Organization org() { + return NULL; + } + }; + + @Override + public String getName() { + return N_A; + } + + @Override + public String getRealm() { + return N_A; + } + + @Override + public String getDomain() { + return N_A; + } + + @Override + public Identity getIdentity(AuthzTrans trans, String id) { + return nullIdentity; + } + + @Override + public String isValidID(String id) { + return N_A; + } + + @Override + public String isValidPassword(String user, String password,String... prev) { + return N_A; + } + + @Override + public Set getIdentityTypes() { + return nullStringSet; + } + + @Override + public Response notify(AuthzTrans trans, Notify type, String url, + String[] users, String[] ccs, String summary, Boolean urgent) { + return Response.ERR_NotImplemented; + } + + @Override + public int sendEmail(AuthzTrans trans, List toList, List ccList, + String subject, String body, Boolean urgent) throws OrganizationException { + return 0; + } + + @Override + public Date whenToValidate(Notify type, Date lastValidated) { + return gc.getTime(); + } + + @Override + public GregorianCalendar expiration(GregorianCalendar gc, + Expiration exp, String... extra) { + return gc==null?new GregorianCalendar():gc; + } + + @Override + public List getApprovers(AuthzTrans trans, String user) + throws OrganizationException { + return nullList; + } + + @Override + public String getApproverType() { + return ""; + } + + @Override + public int startOfDay() { + return 0; + } + + @Override + public boolean canHaveMultipleCreds(String id) { + return false; + } + + @Override + public boolean isValidCred(String id) { + return false; + } + + @Override + public String validate(AuthzTrans trans, Policy policy, Executor executor, String ... vars) + throws OrganizationException { + return "Null Organization rejects all Policies"; + } + + @Override + public boolean isTestEnv() { + return false; + } + + @Override + public void setTestMode(boolean dryRun) { + } + + @Override + public EmailWarnings emailWarningPolicy() { + return new EmailWarnings() { + + @Override + public long credEmailInterval() + { + return 604800000L; // 7 days in millis 1000 * 86400 * 7 + } + + @Override + public long roleEmailInterval() + { + return 604800000L; // 7 days in millis 1000 * 86400 * 7 + } + + @Override + public long apprEmailInterval() { + return 259200000L; // 3 days in millis 1000 * 86400 * 3 + } + + @Override + public long credExpirationWarning() + { + return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds + } + + @Override + public long roleExpirationWarning() + { + return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds + } + + @Override + public long emailUrgentWarning() + { + return( 1209600000L ); // Two weeks, in milliseconds 1000 * 86400 * 14 in milliseconds + } + + }; + } + }; +} + + diff --git a/authz-core/src/main/java/com/att/authz/org/OrganizationException.java b/authz-core/src/main/java/com/att/authz/org/OrganizationException.java new file mode 100644 index 00000000..a3928fb9 --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/org/OrganizationException.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.org; + +public class OrganizationException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public OrganizationException() { + super(); + } + + public OrganizationException(String message) { + super(message); + } + + public OrganizationException(Throwable cause) { + super(cause); + } + + public OrganizationException(String message, Throwable cause) { + super(message, cause); + } + + public OrganizationException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + +} diff --git a/authz-core/src/main/java/com/att/authz/org/OrganizationFactory.java b/authz-core/src/main/java/com/att/authz/org/OrganizationFactory.java new file mode 100644 index 00000000..c97111e9 --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/org/OrganizationFactory.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.org; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.inno.env.APIException; +import com.att.inno.env.Slot; + +/** + * Organization Plugin Mechanism + * + * Define a NameSpace for the company (i.e. com.att), and put in Properties as + * "Organization.[your NS" and assign the supporting Class. + * + * Example: + * Organization.com.att=com.att.authz.org.att.ATT + * + * + */ +public class OrganizationFactory { + public static final String ORG_SLOT = "ORG_SLOT"; + private static Organization defaultOrg = null; + private static Map orgs = new ConcurrentHashMap(); + private static Slot orgSlot; + + public static void setDefaultOrg(AuthzEnv env, String orgClass) throws APIException { + orgSlot = env.slot(ORG_SLOT); + try { + @SuppressWarnings("unchecked") + Class cls = (Class) Class.forName(orgClass); + Constructor cnst = cls.getConstructor(AuthzEnv.class); + defaultOrg = cnst.newInstance(env); + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | + InstantiationException | IllegalAccessException | IllegalArgumentException | + InvocationTargetException e) { + throw new APIException(e); + } + } + + public static Organization obtain(AuthzEnv env,String orgNS) throws OrganizationException { + int at = orgNS.indexOf('@'); + if(at<0) { + if(!orgNS.startsWith("com.")) { + int dot1; + if((dot1 = orgNS.lastIndexOf('.'))>-1) { + int dot2; + StringBuilder sb = new StringBuilder(); + if((dot2 = orgNS.lastIndexOf('.',dot1-1))>-1) { + sb.append(orgNS,dot1+1,orgNS.length()); + sb.append('.'); + sb.append(orgNS,dot2+1,dot1); + } else { + sb.append(orgNS,dot1+1,orgNS.length()); + sb.append('.'); + sb.append(orgNS,at+1,dot1); + } + orgNS=sb.toString(); + } + } + } else { + // Only use two places (Enterprise) of domain + int dot; + if((dot= orgNS.lastIndexOf('.'))>-1) { + StringBuilder sb = new StringBuilder(); + int dot2; + if((dot2 = orgNS.lastIndexOf('.',dot-1))>-1) { + sb.append(orgNS.substring(dot+1)); + sb.append(orgNS.subSequence(dot2, dot)); + orgNS = sb.toString(); + } else { + sb.append(orgNS.substring(dot+1)); + sb.append('.'); + sb.append(orgNS.subSequence(at+1, dot)); + orgNS = sb.toString(); + } + } + } + Organization org = orgs.get(orgNS); + if(org == null) { + String orgClass = env.getProperty("Organization."+orgNS); + if(orgClass == null) { + env.warn().log("There is no Organization." + orgNS + " property"); + } else { + for(Organization o : orgs.values()) { + if(orgClass.equals(o.getClass().getName())) { + org = o; + } + } + if(org==null) { + try { + @SuppressWarnings("unchecked") + Class cls = (Class) Class.forName(orgClass); + Constructor cnst = cls.getConstructor(AuthzEnv.class); + org = cnst.newInstance(env); + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | + InstantiationException | IllegalAccessException | IllegalArgumentException | + InvocationTargetException e) { + throw new OrganizationException(e); + } + } + orgs.put(orgNS, org); + } + if(org==null && defaultOrg!=null) { + org=defaultOrg; + orgs.put(orgNS, org); + } + } + + return org; + } + + public static void set(AuthzTrans trans, String orgNS) throws OrganizationException { + Organization org = obtain(trans.env(),orgNS); + trans.put(orgSlot, org); + } + + public static Organization get(AuthzTrans trans) { + return trans.get(orgSlot,defaultOrg); + } + +} diff --git a/authz-core/src/main/java/com/att/authz/server/AbsServer.java b/authz-core/src/main/java/com/att/authz/server/AbsServer.java new file mode 100644 index 00000000..aa935d09 --- /dev/null +++ b/authz-core/src/main/java/com/att/authz/server/AbsServer.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.server; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.net.URL; +import java.security.GeneralSecurityException; +import java.security.Principal; +import java.util.Properties; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; + +import com.att.authz.common.Define; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +//import com.att.cadi.PropAccess; +import com.att.cadi.aaf.v2_0.AAFConHttp; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cadi.config.Config; +import com.att.cadi.http.HTransferSS; +import com.att.cssa.rserv.RServlet; +import com.att.inno.env.APIException; + +public abstract class AbsServer extends RServlet { + private static final String AAF_API_VERSION = "2.0"; + public final String app; + public final AuthzEnv env; + public AAFConHttp aafCon; + + public AbsServer(final AuthzEnv env, final String app) throws CadiException, GeneralSecurityException, IOException { + this.env = env; + this.app = app; + if(env.getProperty(Config.AAF_URL)!=null) { + //aafCon = new AAFConHttp(env); + } + } + + // This is a method, so we can overload for AAFAPI + public String aaf_url() { + return env.getProperty(Config.AAF_URL); + } + + public abstract void startDME2(Properties props) throws Exception; + public static void setup(Class abss, String propFile) { + + try { + // Load Properties from authFramework.properties. Needed for DME2 and AuthzEnv + Properties props = new Properties(); + URL rsrc = ClassLoader.getSystemResource(propFile); + if(rsrc==null) { + System.err.println("Folder containing " + propFile + " must be on Classpath"); + System.exit(1); + } + + InputStream is = rsrc.openStream(); + try { + props.load(is); + } finally { + is.close(); + is=null; + } + + // Load Properties into AuthzEnv + AuthzEnv env = new AuthzEnv(props); + // Log where Config found + env.init().log("Configuring from",rsrc.getPath()); + rsrc = null; + + // Print Cipher Suites Available + if(env.debug().isLoggable()) { + SSLContext context = SSLContext.getDefault(); + SSLSocketFactory sf = context.getSocketFactory(); + StringBuilder sb = new StringBuilder("Available Cipher Suites: "); + boolean first = true; + int count=0; + for( String cs : sf.getSupportedCipherSuites()) { + if(first)first = false; + else sb.append(','); + sb.append(cs); + if(++count%4==0){sb.append('\n');} + } + env.debug().log(sb); + } + + // Set ROOT NS, etc + Define.set(env); + + // Convert CADI properties and Encrypted Passwords for these two properties (if exist) + // to DME2 Readable. Further, Discovery Props are loaded to System if missing. + // May be causing client errors + //Config.cadiToDME2(env,props); + env.init().log("DME2 ServiceName: " + env.getProperty("DMEServiceName","unknown")); + + // Construct with Env + Constructor cons = abss.getConstructor(new Class[] {AuthzEnv.class}); + // Start DME2 (DME2 needs Properties form of props) + AbsServer s = (AbsServer)cons.newInstance(env); + + // Schedule removal of Clear Text Passwords from System Props (DME2 Requirement) +// new Timer("PassRemove").schedule(tt, 120000); +// tt=null; + + s.startDME2(props); + } catch (Exception e) { + e.printStackTrace(System.err); + System.exit(1); + } + } + + public Rcli client() throws CadiException { + return aafCon.client(AAF_API_VERSION); + } + + public Rcli clientAsUser(Principal p) throws CadiException { + return aafCon.client(AAF_API_VERSION).forUser( + new HTransferSS(p,app, aafCon.securityInfo())); + } + + public RET clientAsUser(Principal p,Retryable retryable) throws APIException, LocatorException, CadiException { + return aafCon.hman().best(new HTransferSS(p,app, aafCon.securityInfo()), retryable); + } + +} diff --git a/authz-core/src/main/java/com/att/cache/Cache.java b/authz-core/src/main/java/com/att/cache/Cache.java new file mode 100644 index 00000000..2930e09c --- /dev/null +++ b/authz-core/src/main/java/com/att/cache/Cache.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cache; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; + +import com.att.inno.env.Env; +import com.att.inno.env.Trans; + +/** + * Create and maintain a Map of Maps used for Caching + * + * + * @param + * @param + */ +public class Cache { + private static Clean clean; + private static Timer cleanseTimer; + + public static final String CACHE_HIGH_COUNT = "CACHE_HIGH_COUNT"; + public static final String CACHE_CLEAN_INTERVAL = "CACHE_CLEAN_INTERVAL"; +// public static final String CACHE_MIN_REFRESH_INTERVAL = "CACHE_MIN_REFRESH_INTERVAL"; + + private static final Map> cacheMap; + + static { + cacheMap = new HashMap>(); + } + + /** + * Dated Class - store any Data with timestamp + * + * + */ + public final static class Dated { + public Date timestamp; + public List data; + + public Dated(List data) { + timestamp = new Date(); + this.data = data; + } + + public Dated(T t) { + timestamp = new Date(); + ArrayList al = new ArrayList(1); + al.add(t); + data = al; + } + + public void touch() { + timestamp = new Date(); + } + } + + public static Map obtain(String key) { + Map m = cacheMap.get(key); + if(m==null) { + m = new ConcurrentHashMap(); + synchronized(cacheMap) { + cacheMap.put(key, m); + } + } + return m; + } + + /** + * Clean will examine resources, and remove those that have expired. + * + * If "highs" have been exceeded, then we'll expire 10% more the next time. This will adjust after each run + * without checking contents more than once, making a good average "high" in the minimum speed. + * + * + */ + private final static class Clean extends TimerTask { + private final Env env; + private Set set; + + // The idea here is to not be too restrictive on a high, but to Expire more items by + // shortening the time to expire. This is done by judiciously incrementing "advance" + // when the "highs" are exceeded. This effectively reduces numbers of cached items quickly. + private final int high; + private long advance; + private final long timeInterval; + + public Clean(Env env, long cleanInterval, int highCount) { + this.env = env; + high = highCount; + timeInterval = cleanInterval; + advance = 0; + set = new HashSet(); + } + + public synchronized void add(String key) { + set.add(key); + } + + public void run() { + int count = 0; + int total = 0; + // look at now. If we need to expire more by increasing "now" by "advance" + Date now = new Date(System.currentTimeMillis() + advance); + + + for(String name : set) { + Map map = cacheMap.get(name); + if(map!=null) for(Map.Entry me : map.entrySet()) { + ++total; + if(me.getValue().timestamp.before(now)) { + map.remove(me.getKey()); + ++count; + } + } +// if(count>0) { +// env.info().log(Level.INFO, "Cache removed",count,"expired",name,"Elements"); +// } + } + + if(count>0) { + env.info().log(Level.INFO, "Cache removed",count,"expired Cached Elements out of", total); + } + + // If High (total) is reached during this period, increase the number of expired services removed for next time. + // There's no point doing it again here, as there should have been cleaned items. + if(total>high) { + // advance cleanup by 10%, without getting greater than timeInterval. + advance = Math.min(timeInterval, advance+(timeInterval/10)); + } else { + // reduce advance by 10%, without getting lower than 0. + advance = Math.max(0, advance-(timeInterval/10)); + } + } + } + + public static synchronized void startCleansing(Env env, String ... keys) { + if(cleanseTimer==null) { + cleanseTimer = new Timer("Cache Cleanup Timer"); + int cleanInterval = Integer.parseInt(env.getProperty(CACHE_CLEAN_INTERVAL,"60000")); // 1 minute clean cycles + int highCount = Integer.parseInt(env.getProperty(CACHE_HIGH_COUNT,"5000")); + cleanseTimer.schedule(clean = new Clean(env, cleanInterval, highCount), cleanInterval, cleanInterval); + } + + for(String key : keys) { + clean.add(key); + } + } + + public static void stopTimer() { + if(cleanseTimer!=null) { + cleanseTimer.cancel(); + cleanseTimer = null; + } + } + + public static void addShutdownHook() { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + Cache.stopTimer(); + } + }); + } + +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/Acceptor.java b/authz-core/src/main/java/com/att/cssa/rserv/Acceptor.java new file mode 100644 index 00000000..ea2850aa --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/Acceptor.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.att.inno.env.Trans; + +/** + * Find Acceptable Paths and place them where TypeCode can evaluate. + * + * If there are more than one, TypeCode will choose based on "q" value + * + * @param + */ +class Acceptor { + private List, List>>>> types; + List, List>>>> acceptable; + + public Acceptor(List, List>>>> types) { + this.types = types; + acceptable = new ArrayList, List>>>>(); + } + + private boolean eval(HttpCode code, String str, List props) { +// int plus = str.indexOf('+'); +// if(plus<0) { + boolean ok = false; + boolean any = false; + for(Pair, List>>> type : types) { + ok = true; + if(type.x.equals(str)) { + for(Iterator iter = props.iterator();ok && iter.hasNext();) { + ok = props(type,iter.next(),iter.next()); + } + if(ok) { + any = true; + acceptable.add(type); + } + } + } +// } else { // Handle Accepts with "+" as in application/xaml+xml +// int prev = str.indexOf('/')+1; +// String first = str.substring(0,prev); +// String nstr; +// while(prev!=0) { +// nstr = first + (plus<0?str.substring(prev):str.substring(prev,plus)); +// +// for(Pair, List>>> type : types) { +// if(type.x.equals(nstr)) { +// acceptable.add(type); +// return type; +// } +// } +// prev = plus+1; +// plus=str.indexOf('+', prev); +// }; +// } + return any; + } + + /** + * Evaluate Properties + * @param type + * @param tag + * @param value + * @return + */ + private boolean props(Pair, List>>> type, String tag, String value) { + boolean rv = false; + if(type.y!=null) { + for(Pair prop : type.y.y){ + if(tag.equals(prop.x)) { + if(tag.equals("charset")) { + return prop.x==null?false:prop.y.equals(value.toLowerCase()); // return True if Matched + } else if(tag.equals("version")) { + return prop.y.equals(new Version(value)); // Note: Version Class knows Minor Version encoding + } else if(tag.equals(Content.Q)) { // replace Q value + try { + type.y.y.get(0).y=Float.parseFloat(value); + } catch (NumberFormatException e) { + rv=false; // need to do something to make Sonar happy. But nothing to do. + } + return true; + } else { + return value.equals(prop.y); + } + } + } + } + return rv; + } + + /** + * parse + * + * Note: I'm processing by index to avoid lots of memory creation, which speeds things + * up for this time critical section of code. + * @param code + * @param cntnt + * @return + */ + protected boolean parse(HttpCode code, String cntnt) { + byte bytes[] = cntnt.getBytes(); + + int cis,cie=-1,cend; + int sis,sie,send; + String name; + ArrayList props = new ArrayList(); + do { + // Clear these in case more than one Semi + props.clear(); // on loop, do not want mixed properties + name=null; + + cis = cie+1; // find comma start + while(ciscis && Character.isSpaceChar(bytes[cend-1]))--cend; + // Start SEMIS + sie=cis-1; + do { + sis = sie+1; // semi start is one after previous end + while(siscend || sie<0?cend:sie; // if the Semicolon is after the comma, or non-existent, use comma end, else keep + while(send>sis && Character.isSpaceChar(bytes[send-1]))--send; + if(name==null) { // first entry in Comma set is the name, not a property + name = new String(bytes,sis,send-sis); + } else { // We've looped past the first Semi, now process as properties + // If there are additional elements (more entities within Semi Colons) + // apply Properties + int eq = cntnt.indexOf('=',sis); + if(eq>sis && eq=cis); // End SEMI processing + // Now evaluate Comma set and return if true + if(eval(code,name,props))return true; // else loop again to check next comma + } while(cie>=0); // loop to next comma + return false; // didn't get even one match + } + +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/CachingFileAccess.java b/authz-core/src/main/java/com/att/cssa/rserv/CachingFileAccess.java new file mode 100644 index 00000000..80de2692 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/CachingFileAccess.java @@ -0,0 +1,477 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NavigableMap; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; +import java.util.TreeMap; +import java.util.concurrent.ConcurrentSkipListMap; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.inno.env.Env; +import com.att.inno.env.EnvJAXB; +import com.att.inno.env.LogTarget; +import com.att.inno.env.Store; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +/* + * CachingFileAccess + * + * + */ +public class CachingFileAccess extends HttpCode { + public static void setEnv(Store store, String[] args) { + for(int i=0;i typeMap; + private final NavigableMap content; + private final Set attachOnly; + private final static String WEB_DIR_DEFAULT = "theme"; + public final static String CFA_WEB_DIR = "CFA_WebPath"; + // when to re-validate from file + // Re validating means comparing the Timestamp on the disk, and seeing it has changed. Cache is not marked + // dirty unless file has changed, but it still makes File IO, which for some kinds of cached data, i.e. + // deployed GUI elements is unnecessary, and wastes time. + // This parameter exists to cover the cases where data can be more volatile, so the user can choose how often the + // File IO will be accessed, based on probability of change. "0", of course, means, check every time. + private final static String CFA_CACHE_CHECK_INTERVAL = "CFA_CheckIntervalMS"; + private final static String CFA_MAX_SIZE = "CFA_MaxSize"; // Cache size limit + private final static String CFA_CLEAR_COMMAND = "CFA_ClearCommand"; + + // Note: can be null without a problem, but included + // to tie in with existing Logging. + public LogTarget logT = null; + public long checkInterval; // = 600000L; // only check if not hit in 10 mins by default + public int maxItemSize; // = 512000; // max file 500k + private Timer timer; + private String web_path; + // A command key is set in the Properties, preferably changed on deployment. + // it is compared at the beginning of the path, and if so, it is assumed to issue certain commands + // It's purpose is to protect, to some degree the command, even though it is HTTP, allowing + // local batch files to, for instance, clear caches on resetting of files. + private String clear_command; + + public CachingFileAccess(EnvJAXB env, String ... args) { + super(null,"Caching File Access"); + setEnv(env,args); + content = new ConcurrentSkipListMap(); // multi-thread changes possible + + attachOnly = new HashSet(); // short, unchanged + + typeMap = new TreeMap(); // Structure unchanged after Construction + typeMap.put("ico","image/icon"); + typeMap.put("html","text/html"); + typeMap.put("css","text/css"); + typeMap.put("js","text/javascript"); + typeMap.put("txt","text/plain"); + typeMap.put("xml","text/xml"); + typeMap.put("xsd","text/xml"); + attachOnly.add("xsd"); + typeMap.put("crl", "application/x-pkcs7-crl"); + typeMap.put("appcache","text/cache-manifest"); + + typeMap.put("json","text/json"); + typeMap.put("ogg", "audio/ogg"); + typeMap.put("jpg","image/jpeg"); + typeMap.put("gif","image/gif"); + typeMap.put("png","image/png"); + typeMap.put("svg","image/svg+xml"); + typeMap.put("jar","application/x-java-applet"); + typeMap.put("jnlp", "application/x-java-jnlp-file"); + typeMap.put("class", "application/java"); + + timer = new Timer("Caching Cleanup",true); + timer.schedule(new Cleanup(content,500),60000,60000); + + // Property params + web_path = env.getProperty(CFA_WEB_DIR,WEB_DIR_DEFAULT); + Object obj; + obj = env.get(env.staticSlot(CFA_CACHE_CHECK_INTERVAL),600000L); // Default is 10 mins + if(obj instanceof Long) {checkInterval=(Long)obj; + } else {checkInterval=Long.parseLong((String)obj);} + + obj = env.get(env.staticSlot(CFA_MAX_SIZE), 512000); // Default is max file 500k + if(obj instanceof Integer) {maxItemSize=(Integer)obj; + } else {maxItemSize =Integer.parseInt((String)obj);} + + clear_command = env.getProperty(CFA_CLEAR_COMMAND,null); + } + + + + @Override + public void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws IOException { + String key = pathParam(req, ":key"); + if(key.equals(clear_command)) { + String cmd = pathParam(req,":cmd"); + resp.setHeader("Content-type",typeMap.get("txt")); + if("clear".equals(cmd)) { + content.clear(); + resp.setStatus(HttpStatus.OK_200); + } else { + resp.setStatus(HttpStatus.BAD_REQUEST_400); + } + return; + } + Content c = load(logT , web_path,key, null, checkInterval); + if(c.attachmentOnly) { + resp.setHeader("Content-disposition", "attachment"); + } + c.write(resp.getOutputStream()); + c.setHeader(resp); + trans.checkpoint(req.getPathInfo()); + } + + + public String webPath() { + return web_path; + } + + /** + * Reset the Cleanup size and interval + * + * The size and interval when started are 500 items (memory size unknown) checked every minute in a background thread. + * + * @param size + * @param interval + */ + public void cleanupParams(int size, long interval) { + timer.cancel(); + timer.schedule(new Cleanup(content,size), interval, interval); + } + + + + /** + * Load a file, first checking cache + * + * + * @param logTarget - logTarget can be null (won't log) + * @param dataRoot - data root storage directory + * @param key - relative File Path + * @param mediaType - what kind of file is it. If null, will check via file extension + * @param timeCheck - "-1" will take system default - Otherwise, will compare "now" + timeCheck(Millis) before looking at File mod + * @return + * @throws IOException + */ + public Content load(LogTarget logTarget, String dataRoot, String key, String mediaType, long _timeCheck) throws IOException { + long timeCheck = _timeCheck; + if(timeCheck<0) { + timeCheck=checkInterval; // if time < 0, then use default + } + String fileName = dataRoot + '/' + key; + Content c = content.get(key); + long systime = System.currentTimeMillis(); + File f=null; + if(c!=null) { + // Don't check every hit... only after certain time value + if(c.date < systime + timeCheck) { + f = new File(fileName); + if(f.lastModified()>c.date) { + c=null; + } + } + } + if(c==null) { + if(logTarget!=null) { + logTarget.log("File Read: ",key); + } + + if(f==null){ + f = new File(fileName); + } + + boolean cacheMe; + if(f.exists()) { + if(f.length() > maxItemSize) { + c = new DirectFileContent(f); + cacheMe = false; + } else { + c = new CachedContent(f); + cacheMe = checkInterval>0; + } + + if(mediaType==null) { // determine from file Ending + int idx = key.lastIndexOf('.'); + String subkey = key.substring(++idx); + if((c.contentType = idx<0?null:typeMap.get(subkey))==null) { + // if nothing else, just set to default type... + c.contentType = "application/octet-stream"; + } + c.attachmentOnly = attachOnly.contains(subkey); + } else { + c.contentType=mediaType; + c.attachmentOnly = false; + } + + c.date = f.lastModified(); + + if(cacheMe) { + content.put(key, c); + } + } else { + c=NULL; + } + } else { + if(logTarget!=null)logTarget.log("Cache Read: ",key); + } + + // refresh hit time + c.access = systime; + return c; + } + + public Content loadOrDefault(Trans trans, String targetDir, String targetFileName, String sourcePath, String mediaType) throws IOException { + try { + return load(trans.info(),targetDir,targetFileName,mediaType,0); + } catch(FileNotFoundException e) { + String targetPath = targetDir + '/' + targetFileName; + TimeTaken tt = trans.start("File doesn't exist; copy " + sourcePath + " to " + targetPath, Env.SUB); + try { + FileInputStream sourceFIS = new FileInputStream(sourcePath); + FileChannel sourceFC = sourceFIS.getChannel(); + File targetFile = new File(targetPath); + targetFile.getParentFile().mkdirs(); // ensure directory exists + FileOutputStream targetFOS = new FileOutputStream(targetFile); + try { + ByteBuffer bb = ByteBuffer.allocate((int)sourceFC.size()); + sourceFC.read(bb); + bb.flip(); // ready for reading + targetFOS.getChannel().write(bb); + } finally { + sourceFIS.close(); + targetFOS.close(); + } + } finally { + tt.done(); + } + return load(trans.info(),targetDir,targetFileName,mediaType,0); + } + } + + public void invalidate(String key) { + content.remove(key); + } + + private static final Content NULL=new Content() { + + @Override + public void setHeader(HttpServletResponse resp) { + resp.setStatus(HttpStatus.NOT_FOUND_404); + resp.setHeader("Content-type","text/plain"); + } + + @Override + public void write(Writer writer) throws IOException { + } + + @Override + public void write(OutputStream os) throws IOException { + } + + }; + + private static abstract class Content { + private long date; // date of the actual artifact (i.e. File modified date) + private long access; // last accessed + + protected String contentType; + protected boolean attachmentOnly; + + public void setHeader(HttpServletResponse resp) { + resp.setStatus(HttpStatus.OK_200); + resp.setHeader("Content-type",contentType); + resp.setHeader("Cache-Control", MAX_AGE); + } + + public abstract void write(Writer writer) throws IOException; + public abstract void write(OutputStream os) throws IOException; + + } + + private static class DirectFileContent extends Content { + private File file; + public DirectFileContent(File f) { + file = f; + } + + public String toString() { + return file.getName(); + } + + public void write(Writer writer) throws IOException { + FileReader fr = new FileReader(file); + char[] buff = new char[1024]; + try { + int read; + while((read = fr.read(buff,0,1024))>=0) { + writer.write(buff,0,read); + } + } finally { + fr.close(); + } + } + + public void write(OutputStream os) throws IOException { + FileInputStream fis = new FileInputStream(file); + byte[] buff = new byte[1024]; + try { + int read; + while((read = fis.read(buff,0,1024))>=0) { + os.write(buff,0,read); + } + } finally { + fis.close(); + } + } + + } + private static class CachedContent extends Content { + private byte[] data; + private int end; + private char[] cdata; + + public CachedContent(File f) throws IOException { + // Read and Cache + ByteBuffer bb = ByteBuffer.allocate((int)f.length()); + FileInputStream fis = new FileInputStream(f); + try { + fis.getChannel().read(bb); + } finally { + fis.close(); + } + + data = bb.array(); + end = bb.position(); + cdata=null; + } + + public String toString() { + return data.toString(); + } + + public void write(Writer writer) throws IOException { + synchronized(this) { + // do the String Transformation once, and only if actually used + if(cdata==null) { + cdata = new char[end]; + new String(data).getChars(0, end, cdata, 0); + } + } + writer.write(cdata,0,end); + } + public void write(OutputStream os) throws IOException { + os.write(data,0,end); + } + + } + + public void setEnv(LogTarget env) { + logT = env; + } + + /** + * Cleanup thread to remove older items if max Cache is reached. + * + */ + private static class Cleanup extends TimerTask { + private int maxSize; + private NavigableMap content; + + public Cleanup(NavigableMap content, int size) { + maxSize = size; + this.content = content; + } + + private class Comp implements Comparable { + public Map.Entry entry; + + public Comp(Map.Entry en) { + entry = en; + } + + @Override + public int compareTo(Comp o) { + return (int)(entry.getValue().access-o.entry.getValue().access); + } + + } + @SuppressWarnings("unchecked") + @Override + public void run() { + int size = content.size(); + if(size>maxSize) { + ArrayList scont = new ArrayList(size); + Object[] entries = content.entrySet().toArray(); + for(int i=0;i)entries[i])); + } + Collections.sort(scont); + int end = size - ((maxSize/4)*3); // reduce to 3/4 of max size + System.out.println("------ Cleanup Cycle ------ " + new Date().toString() + " -------"); + for(int i=0;i entry = scont.get(i).entry; + content.remove(entry.getKey()); + System.out.println("removed Cache Item " + entry.getKey() + "/" + new Date(entry.getValue().access).toString()); + } + for(int i=end;i entry = scont.get(i).entry; + System.out.println("remaining Cache Item " + entry.getKey() + "/" + new Date(entry.getValue().access).toString()); + } + } + } + } +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/CodeSetter.java b/authz-core/src/main/java/com/att/cssa/rserv/CodeSetter.java new file mode 100644 index 00000000..01ecf38d --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/CodeSetter.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.inno.env.Trans; + +// Package on purpose. only want between RServlet and Routes +class CodeSetter { + private HttpCode code; + private TRANS trans; + private HttpServletRequest req; + private HttpServletResponse resp; + public CodeSetter(TRANS trans, HttpServletRequest req, HttpServletResponse resp) { + this.trans = trans; + this.req = req; + this.resp = resp; + + } + public boolean matches(Route route) throws IOException, ServletException { + // Find best Code in Route based on "Accepts (Get) or Content-Type" (if exists) + return (code = route.getCode(trans, req, resp))!=null; + } + + public HttpCode code() { + return code; + } +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/Content.java b/authz-core/src/main/java/com/att/cssa/rserv/Content.java new file mode 100644 index 00000000..fd6c8a58 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/Content.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.util.List; + +import com.att.inno.env.Trans; + + + +/** + * A Class to hold Service "ContentTypes", and to match incoming "Accept" types from HTTP. + * + * This is a multi-use class built to use the same Parser for ContentTypes and Accept. + * + * Thus, you would create and use "Content.Type" within your service, and use it to match + * Accept Strings. What is returned is an Integer (for faster processing), which can be + * used in a switch statement to act on match different Actions. The server should + * know which behaviors match. + * + * "bestMatch" returns an integer for the best match, or -1 if no matches. + * + * + */ +public abstract class Content { + public static final String Q = "q"; + protected abstract Pair,List>>> types(HttpCode code, String str); + protected abstract boolean props(Pair,List>>> type, String tag, String value); + + /** + * Parse a Content-Type/Accept. As found, call "types" and "props", which do different + * things depending on if it's a Content-Type or Accepts. + * + * For Content-Type, it builds a tree suitable for Comparison + * For Accepts, it compares against the tree, and builds an acceptable type list + * + * Since this parse code is used for every incoming HTTP transaction, I have removed the implementation + * that uses String.split, and replaced with integers evaluating the Byte array. This results + * in only the necessary strings created, resulting in 1/3 better speed, and less + * Garbage collection. + * + * @param trans + * @param code + * @param cntnt + * @return + */ + protected boolean parse(HttpCode code, String cntnt) { + byte bytes[] = cntnt.getBytes(); + boolean contType=false,contProp=true; + int cis,cie=-1,cend; + int sis,sie,send; + do { + cis = cie+1; + cie = cntnt.indexOf(',',cis); + cend = cie<0?bytes.length:cie; + // Start SEMIS + sie=cis-1; + Pair, List>>> me = null; + do { + sis = sie+1; + sie = cntnt.indexOf(';',sis); + send = sie>cend || sie<0?cend:sie; + if(me==null) { + String semi = new String(bytes,sis,send-sis); + // trans.checkpoint(semi); + // Look at first entity within comma group + // Is this an acceptable Type? + me=types(code, semi); + if(me==null) { + sie=-1; // skip the rest of the processing... not a type + } else { + contType=true; + } + } else { // We've looped past the first Semi, now process as properties + // If there are additional elements (more entities within Semi Colons) + // apply Propertys + int eq = cntnt.indexOf('=',sis); + if(eq>sis && eq + * @param + */ +public abstract class HttpCode { + protected CONTEXT context; + private String desc; + protected String [] roles; + private boolean all; + + // Package by design... Set by Route when linked + Match match; + + public HttpCode(CONTEXT context, String description, String ... roles) { + this.context = context; + desc = description; + + // Evaluate for "*" once... + all = false; + for(String srole : roles) { + if("*".equals(srole)) { + all = true; + break; + } + } + this.roles = all?null:roles; + } + + public abstract void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws Exception; + + public String desc() { + return desc; + } + + /** + * Get the variable element out of the Path Parameter, as set by initial Code + * + * @param req + * @param key + * @return + */ + public String pathParam(HttpServletRequest req, String key) { + return match.param(req.getPathInfo(), key); + } + + // Note: get Query Params from Request + + /** + * Check for Authorization when set. + * + * If no Roles set, then accepts all users + * + * @param req + * @return + */ + public boolean isAuthorized(HttpServletRequest req) { + if(all)return true; + if(roles!=null) { + for(String srole : roles) { + if(req.isUserInRole(srole)) return true; + } + } + return false; + } + + public boolean no_cache() { + return false; + } + + public String toString() { + return desc; + } +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/HttpMethods.java b/authz-core/src/main/java/com/att/cssa/rserv/HttpMethods.java new file mode 100644 index 00000000..c247aad0 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/HttpMethods.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +public enum HttpMethods { + POST, + GET, + PUT, + DELETE +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/Match.java b/authz-core/src/main/java/com/att/cssa/rserv/Match.java new file mode 100644 index 00000000..1f5a60f5 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/Match.java @@ -0,0 +1,212 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * This path matching algorithm avoids using split strings during the critical transactional run-time. By pre-analyzing the + * content at "set Param" time, and storing data in an array-index model which presumably is done once and at the beginning, + * we can match in much less time when it actually counts. + * + * + */ +public class Match { + private Map params; + private byte[] values[]; + private Integer vars[]; + private boolean wildcard; + + + /* + * These two methods are pairs of searching performance for variables Spark Style. + * setParams evaluates the target path, and sets a HashMap that will return an Integer. + * the Keys are both :key and key so that there will be no string operations during + * a transaction + * + * For the Integer, if the High Order is 0, then it is just one value. If High Order >0, then it is + * a multi-field option, i.e. ending with a wild-card. + */ + public Match(String path) { + // IF DEBUG: System.out.print("\n[" + path + "]"); + params = new HashMap(); + if(path!=null) { + String[] pa = path.split("/"); + values = new byte[pa.length][]; + vars = new Integer[pa.length]; + + int val = 0; + String key; + for(int i=0;i1) { + /* remove * from value */ + int newlength = values[i].length-1; + byte[] real = new byte[newlength]; + System.arraycopy(values[i],0,real,0,newlength); + values[i]=real; + } else { + vars[i]=0; // this is actually a variable, if it only contains a "*" + } + } + // vars[i]=null; + } + } + } + } + + /* + * This is the second of the param evaluation functions. First, we look up to see if there is + * any reference by key in the params Map created by the above. + * + * The resulting Integer, if not null, is split high/low order into start and end. + * We evaluate the string for '/', rather than splitting into String[] to avoid the time/mem needed + * We traverse to the proper field number for slash, evaluate the end (whether wild card or no), + * and return the substring. + * + * The result is something less than .003 milliseconds per evaluation + * + */ + public String param(String path,String key) { + Integer val = params.get(key); // :key or key + if(val!=null) { + int start = val & 0xFFFF; + int end = (val >> 16) & 0xFFFF; + int idx = -1; + int i; + for(i=0;i0?(pabytes[0]=='/'):false; + // IF DEBUG: System.out.println("\n -- " + path + " --"); + for(int i=0;rv && i=lastField) { // checking here allows there to be a non-functional ending / + rv = false; + break; + } + if(values[field]==null) { // it's a variable, just look for /s + if(wildcard && field==lastField-1) return true;// we've made it this far. We accept all remaining characters + Integer val = vars[field]; + int start = val & 0xFFFF; + int end = (val >> 16) & 0xFFFF; + if(end==0)end=start+1; + int k = i; + for(int j=start; ji)i=k-1; // if we've incremented, have to accommodate the outer for loop incrementing as well + fieldMatched = false; // reset + fieldIdx = 0; + } else { + // IF DEBUG: System.out.print((char)pabytes[i]); + if(pabytes[i]=='/') { // end of field, eval if Field is matched + // if double slash, check if supposed to be empty + if(fieldIdx==0 && values[field].length==0) { + fieldMatched = true; + } + rv = fieldMatched && ++field getParamNames() { + return params.keySet(); + } +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/Pair.java b/authz-core/src/main/java/com/att/cssa/rserv/Pair.java new file mode 100644 index 00000000..7d3b88c6 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/Pair.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +/** + * A pair of generic Objects. + * + * @param + * @param + */ +public class Pair { + public X x; + public Y y; + + public Pair(X x, Y y) { + this.x = x; + this.y = y; + } + + public String toString() { + return "X: " + x.toString() + "-->" + y.toString(); + } +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/RServlet.java b/authz-core/src/main/java/com/att/cssa/rserv/RServlet.java new file mode 100644 index 00000000..ed116e64 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/RServlet.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; + +public abstract class RServlet implements Servlet { + private Routes routes = new Routes(); + + private ServletConfig config; + + @Override + public void init(ServletConfig config) throws ServletException { + this.config = config; + } + + @Override + public ServletConfig getServletConfig() { + return config; + } + + public void route(Env env, HttpMethods meth, String path, HttpCode code, String ... moreTypes) { + Route r = routes.findOrCreate(meth,path); + r.add(code,moreTypes); + env.init().log(r.report(code),code); + } + + @Override + public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { + HttpServletRequest request = (HttpServletRequest)req; + HttpServletResponse response = (HttpServletResponse)res; + + @SuppressWarnings("unchecked") + TRANS trans = (TRANS)req.getAttribute(TransFilter.TRANS_TAG); + if(trans==null) { + response.setStatus(404); // Not Found, because it didn't go through TransFilter + return; + } + + Route route; + HttpCode code=null; + String ct = req.getContentType(); + TimeTaken tt = trans.start("Resolve to Code", Env.SUB); + try { + // routes have multiple code sets. This object picks the best code set + // based on Accept or Content-Type + CodeSetter codesetter = new CodeSetter(trans,request,response); + // Find declared route + route = routes.derive(request, codesetter); + if(route==null) { + String method = request.getMethod(); + trans.checkpoint("No Route matches "+ method + ' ' + request.getPathInfo()); + response.setStatus(404); // Not Found + } else { + // Find best Code in Route based on "Accepts (Get) or Content-Type" (if exists) + code = codesetter.code();// route.getCode(trans, request, response); + } + } finally { + tt.done(); + } + + if(route!=null && code!=null) { + StringBuilder sb = new StringBuilder(72); + sb.append(route.auditText); + sb.append(','); + sb.append(code.desc()); + if(ct!=null) { + sb.append(", ContentType: "); + sb.append(ct); + } + tt = trans.start(sb.toString(),Env.SUB); + try { + /*obj = */ + code.handle(trans, request, response); + response.flushBuffer(); + } catch (ServletException e) { + trans.error().log(e); + throw e; + } catch (Exception e) { + trans.error().log(e,request.getMethod(),request.getPathInfo()); + throw new ServletException(e); + } finally { + tt.done(); + } + } + } + + @Override + public String getServletInfo() { + return "RServlet for Jetty"; + } + + @Override + public void destroy() { + } + + public String applicationJSON(Class cls, String version) { + StringBuilder sb = new StringBuilder(); + sb.append("application/"); + sb.append(cls.getSimpleName()); + sb.append("+json"); + sb.append(";charset=utf-8"); + sb.append(";version="); + sb.append(version); + return sb.toString(); + } + + public String applicationXML(Class cls, String version) { + StringBuilder sb = new StringBuilder(); + sb.append("application/"); + sb.append(cls.getSimpleName()); + sb.append("+xml"); + sb.append(";charset=utf-8"); + sb.append(";version="); + sb.append(version); + return sb.toString(); + } + + public List routeReport() { + return routes.routeReport(); + } +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/Route.java b/authz-core/src/main/java/com/att/cssa/rserv/Route.java new file mode 100644 index 00000000..0a8cffe0 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/Route.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; + +public class Route { + public final String auditText; + public final HttpMethods meth; + public final String path; + + private Match match; + // package on purpose + private final TypedCode content; + private final boolean isGet; + + public Route(HttpMethods meth, String path) { + this.path = path; + auditText = meth.name() + ' ' + path; + this.meth = meth; // Note: Using Spark def for now. + isGet = meth.compareTo(HttpMethods.GET) == 0; + match = new Match(path); + content = new TypedCode(); + } + + public void add(HttpCode code, String ... others) { + code.match = match; + content.add(code, others); + } + +// public void add(HttpCode code, Class cls, String version, String ... others) { +// code.match = match; +// content.add(code, cls, version, others); +// } +// + public HttpCode getCode(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { + // Type is associated with Accept for GET (since it is what is being returned + // We associate the rest with ContentType. + // FYI, thought about this a long time before implementing this way. + String compare; +// String special[]; // todo, expose Charset (in special) to outside + if(isGet) { + compare = req.getHeader("Accept"); // Accept is used for read, as we want to agree on what caller is ready to handle + } else { + compare = req.getContentType(); // Content type used to declare what data is being created, updated or deleted (might be used for key) + } + + Pair, List>>> hl = content.prep(trans, compare); + if(hl==null) { + resp.setStatus(406); // NOT_ACCEPTABLE + } else { + if(isGet) { // Set Content Type to expected content + if("*".equals(hl.x) || "*/*".equals(hl.x)) {// if wild-card, then choose first kind of type + resp.setContentType(content.first()); + } else { + resp.setContentType(hl.x); + } + } + return hl.y.x; + } + return null; + } + + public Route matches(String method, String path) { + return meth.name().equalsIgnoreCase(method) && match.match(path)?this:null; + } + + public TimeTaken start(Trans trans, String auditText, HttpCode code, String type) { + StringBuilder sb = new StringBuilder(auditText); + sb.append(", "); + sb.append(code.desc()); + sb.append(", Content: "); + sb.append(type); + return trans.start(sb.toString(), Env.SUB); + } + + // Package on purpose.. for "find/Create" routes only + boolean resolvesTo(HttpMethods hm, String p) { + return(path.equals(p) && hm.equals(meth)); + } + + public String toString() { + return auditText + ' ' + content; + } + + public String report(HttpCode code) { + StringBuilder sb = new StringBuilder(); + sb.append(auditText); + sb.append(' '); + content.relatedTo(code, sb); + return sb.toString(); + } + + public RouteReport api() { + RouteReport tr = new RouteReport(); + tr.meth = meth; + tr.path = path; + content.api(tr); + return tr; + } + + + /** + * contentRelatedTo (For reporting) list routes that will end up at a specific Code + * @return + */ + public String contentRelatedTo(HttpCode code) { + StringBuilder sb = new StringBuilder(path); + sb.append(' '); + content.relatedTo(code, sb); + return sb.toString(); + } +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/RouteReport.java b/authz-core/src/main/java/com/att/cssa/rserv/RouteReport.java new file mode 100644 index 00000000..6dee8d32 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/RouteReport.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.util.ArrayList; +import java.util.List; + +public class RouteReport { + public HttpMethods meth; + public String path; + public String desc; + public final List contextTypes = new ArrayList(); + +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/Routes.java b/authz-core/src/main/java/com/att/cssa/rserv/Routes.java new file mode 100644 index 00000000..c2d7fb82 --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/Routes.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; + +import com.att.inno.env.Trans; + + +public class Routes { + // Since this must be very, very fast, and only needs one creation, we'll use just an array. + private Route[] routes; + private int end; + + + @SuppressWarnings("unchecked") + public Routes() { + routes = new Route[10]; + end = 0; + } + + // This method for setup of Routes only... + // Package on purpose + synchronized Route findOrCreate(HttpMethods meth, String path) { + Route rv = null; + for(int i=0;i=routes.length) { + @SuppressWarnings("unchecked") + Route[] temp = new Route[end+10]; + System.arraycopy(routes, 0, temp, 0, routes.length); + routes = temp; + } + + routes[end++]=rv=new Route(meth,path); + } + return rv; + } + + public Route derive(HttpServletRequest req, CodeSetter codeSetter) throws IOException, ServletException { + Route rv = null; + String path = req.getPathInfo(); + String meth = req.getMethod(); + //TODO a TREE would be better + for(int i=0;rv==null && i routeReport() { + ArrayList ltr = new ArrayList(); + for(int i=0;i implements Filter { + public static final String TRANS_TAG = "__TRANS__"; + + private CadiHTTPManip cadi; + + public TransFilter(Access access, Connector con, TrustChecker tc, Object ... additionalTafLurs) throws CadiException { + cadi = new CadiHTTPManip(access, con, tc, additionalTafLurs); + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } + + protected Lur getLur() { + return cadi.getLur(); + } + + protected abstract TRANS newTrans(); + protected abstract TimeTaken start(TRANS trans, ServletRequest request); + protected abstract void authenticated(TRANS trans, Principal p); + protected abstract void tallyHo(TRANS trans); + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + TRANS trans = newTrans(); + + TimeTaken overall = start(trans,request); + try { + request.setAttribute(TRANS_TAG, trans); + + HttpServletRequest req = (HttpServletRequest)request; + HttpServletResponse res = (HttpServletResponse)response; + + TimeTaken security = trans.start("CADI Security", Env.SUB); +// TimeTaken ttvalid; + TafResp resp; + RESP r; + CadiWrap cw = null; + try { + resp = cadi.validate(req,res); + switch(r=resp.isAuthenticated()) { + case IS_AUTHENTICATED: + cw = new CadiWrap(req,resp,cadi.getLur()); + authenticated(trans, cw.getUserPrincipal()); + break; + default: + break; + } + } finally { + security.done(); + } + + if(r==RESP.IS_AUTHENTICATED) { + trans.checkpoint(resp.desc()); + chain.doFilter(cw, response); + } else { + //TODO this is a good place to check if too many checks recently + // Would need Cached Counter objects that are cleaned up on + // use + trans.checkpoint(resp.desc(),Env.ALWAYS); + if(resp.isFailedAttempt()) + trans.audit().log(resp.desc()); + } + } catch(Exception e) { + trans.error().log(e); + trans.checkpoint("Error: " + e.getClass().getSimpleName() + ": " + e.getMessage()); + throw new ServletException(e); + } finally { + overall.done(); + tallyHo(trans); + } + } + + @Override + public void destroy() { + }; +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/TransOnlyFilter.java b/authz-core/src/main/java/com/att/cssa/rserv/TransOnlyFilter.java new file mode 100644 index 00000000..1ef5456a --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/TransOnlyFilter.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.io.IOException; +import java.security.Principal; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import com.att.inno.env.TimeTaken; +import com.att.inno.env.TransStore; + +/** + * Create a new Transaction Object for each and every incoming Transaction + * + * Attach to Request. User "FilterHolder" mechanism to retain single instance. + * + * TransFilter includes CADIFilter as part of the package, so that it can + * set User Data, etc, as necessary. + * + * + */ +public abstract class TransOnlyFilter implements Filter { + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } + + + + protected abstract TRANS newTrans(); + protected abstract TimeTaken start(TRANS trans, ServletRequest request); + protected abstract void authenticated(TRANS trans, Principal p); + protected abstract void tallyHo(TRANS trans); + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + TRANS trans = newTrans(); + + TimeTaken overall = start(trans,request); + try { + request.setAttribute(TransFilter.TRANS_TAG, trans); + chain.doFilter(request, response); + } finally { + overall.done(); + } + tallyHo(trans); + } + + @Override + public void destroy() { + }; +} diff --git a/authz-core/src/main/java/com/att/cssa/rserv/TypedCode.java b/authz-core/src/main/java/com/att/cssa/rserv/TypedCode.java new file mode 100644 index 00000000..6fd7049a --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/TypedCode.java @@ -0,0 +1,269 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import javax.servlet.ServletException; + +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; + + +/** + * TypedCode organizes implementation code based on the Type and Version of code it works with so that it can + * be located quickly at runtime based on the "Accept" HTTP Header. + * + * FYI: For those in the future wondering why I would create a specialized set of "Pair" for the data content: + * 1) TypeCode is used in Route, and this code is used for every transaction... it needs to be blazingly fast + * 2) The actual number of objects accessed is quite small and built at startup. Arrays are best + * 3) I needed a small, well defined tree where each level is a different Type. Using a "Pair" Generic definitions, + * I created type-safety at each level, which you can't get from a TreeSet, etc. + * 4) Chaining through the Network is simply object dereferencing, which is as fast as Java can go. + * 5) The drawback is that in your code is that all the variables are named "x" and "y", which can be a bit hard to + * read both in code, and in the debugger. However, TypeSafety allows your IDE (Eclipse) to help you make the + * choices. Also, make sure you have a good "toString()" method on each object so you can see what's happening + * in the IDE Debugger. + * + * Empirically, this method of obtaining routes proved to be much faster than the HashSet implementations available in otherwise + * competent Open Source. + * + * @param + */ +public class TypedCode extends Content { + private List,List>>>> types; + + public TypedCode() { + types = new ArrayList,List>>>>(); + } + + /** + * Construct Typed Code based on ContentType parameters passed in + * + * @param code + * @param others + * @return + */ + public TypedCode add(HttpCode code, String ... others) { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for(String str : others) { + if(first) { + first = false; + } else { + sb.append(','); + } + sb.append(str); + } + parse(code, sb.toString()); + + return this; + } + + @Override + protected Pair, List>>> types(HttpCode code, String str) { + Pair,List>>> type = null; + ArrayList> props = new ArrayList>(); + // Want Q percentage is to be first in the array everytime. If not listed, 1.0 is default + props.add(new Pair(Q,1f)); + Pair, List>> cl = new Pair, List>>(code, props); +// // breakup "plus" stuff, i.e. application/xaml+xml +// int plus = str.indexOf('+'); +// if(plus<0) { + type = new Pair,List>>>(str, cl); + types.add(type); + return type; +// } else { +// int prev = str.indexOf('/')+1; +// String first = str.substring(0,prev); +// String nstr; +// while(prev!=0) { +// nstr = first + (plus>-1?str.substring(prev,plus):str.substring(prev)); +// type = new Pair,List>>>(nstr, cl); +// types.add(type); +// prev = plus+1; +// plus = str.indexOf('+',prev); +// } +// return type; +// } + } + + @Override + protected boolean props(Pair, List>>> type, String tag, String value) { + if(tag.equals(Q)) { // reset the Q value (first in array) + boolean rv = true; + try { + type.y.y.get(0).y=Float.parseFloat(value); + return rv; + } catch (NumberFormatException e) { + rv=false; // Note: this awkward syntax forced by Sonar, which doesn't like doing nothing with Exception + // which is what should happen + } + } + return type.y.y.add(new Pair(tag,"version".equals(tag)?new Version(value):value)); + } + + public Pair, List>>> prep(TRANS trans, String compare) throws IOException, ServletException { + Pair, List>>> c,rv=null; + if(types.size()==1 && "".equals((c=types.get(0)).x)) { // if there are no checks for type, skip + rv = c; + } else { + if(compare==null || compare.length()==0) { + rv = types.get(0); // first code is used + } else { + Acceptor acc = new Acceptor(types); + boolean accepted; + TimeTaken tt = trans.start(compare, Env.SUB); + try { + accepted = acc.parse(null, compare); + } finally { + tt.done(); + } + if(accepted) { + switch(acc.acceptable.size()) { + case 0: +// // TODO best Status Code? +// resp.setStatus(HttpStatus.NOT_ACCEPTABLE_406); + break; + case 1: + rv = acc.acceptable.get(0); + break; + default: // compare Q values to get Best Match + float bestQ = -1.0f; + Pair, List>>> bestT = null; + for(Pair, List>>> type : acc.acceptable) { + Float f = (Float)type.y.y.get(0).y; // first property is always Q + if(f>bestQ) { + bestQ=f; + bestT = type; + } + } + if(bestT!=null) { + // When it is a GET, the matched type is what is returned, so set ContentType +// if(isGet)resp.setContentType(bestT.x); // set ContentType of Code +// rv = bestT.y.x; + rv = bestT; + } + } + } else { + trans.checkpoint("No Match found for Accept"); + } + } + } + return rv; + } + + /** + * Print on String Builder content related to specific Code + * + * This is for Reporting and Debugging purposes, so the content is not cached. + * + * If code is "null", then all content is matched + * + * @param code + * @return + */ + public StringBuilder relatedTo(HttpCode code, StringBuilder sb) { + boolean first = true; + for(Pair, List>>> pair : types) { + if(code==null || pair.y.x == code) { + if(first) { + first = false; + } else { + sb.append(','); + } + sb.append(pair.x); + for(Pair prop : pair.y.y) { + // Don't print "Q". it's there for internal use, but it is only meaningful for "Accepts" + if(!prop.x.equals(Q) || !prop.y.equals(1f) ) { + sb.append(';'); + sb.append(prop.x); + sb.append('='); + sb.append(prop.y); + } + } + } + } + return sb; + } + + public List> getContent(HttpCode code) { + for(Pair, List>>> pair : types) { + if(pair.y.x == code) { + return pair.y.y; + } + } + return null; + } + + public String toString() { + return relatedTo(null,new StringBuilder()).toString(); + } + + public void api(RouteReport tr) { + // Need to build up a map, because Prop entries can be in several places. + HashMap,StringBuilder> psb = new HashMap,StringBuilder>(); + StringBuilder temp; + tr.desc = null; + + // Read through Code/TypeCode trees for all accepted Typecodes + for(Pair, List>>> tc : types) { + // If new, then it's new Code set, create prefix content + if((temp=psb.get(tc.y.x))==null) { + psb.put(tc.y.x,temp=new StringBuilder()); + if(tr.desc==null) { + tr.desc = tc.y.x.desc(); + } + } else { + temp.append(','); + } + temp.append(tc.x); + + // add all properties + for(Pair props : tc.y.y) { + temp.append(';'); + temp.append(props.x); + temp.append('='); + temp.append(props.y); + } + } + // Gather all ContentType possibilities for the same code together + + for(StringBuilder sb : psb.values()) { + tr.contextTypes.add(sb.toString()); + } + } + + public String first() { + if(types.size()>0) { + return types.get(0).x; + } + return null; + } + + } diff --git a/authz-core/src/main/java/com/att/cssa/rserv/Version.java b/authz-core/src/main/java/com/att/cssa/rserv/Version.java new file mode 100644 index 00000000..e24c48eb --- /dev/null +++ b/authz-core/src/main/java/com/att/cssa/rserv/Version.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + + +/** + * Analyze and hold Version information for Code + * + * + */ +public class Version { + private Object[] parts; + + public Version(String v) { + String sparts[] = v.split("\\."); + parts = new Object[sparts.length]; + System.arraycopy(sparts, 0, parts, 0, sparts.length); + if(parts.length>1) { // has at least a minor + try { + parts[1]=Integer.decode(sparts[1]); // minor elements need to be converted to Integer for comparison + } catch (NumberFormatException e) { + // it's ok, leave it as a string + parts[1]=sparts[1]; // This useless piece of code forced by Sonar which calls empty Exceptions "Blockers". + } + } + } + + public boolean equals(Object obj) { + if(obj instanceof Version) { + Version ver = (Version)obj; + int length = Math.min(parts.length, ver.parts.length); + for(int i=0;i list = new ArrayList(); + try { + df.open(); + Token tok = df.new Token(1024000); + Field fld = tok.new Field('|'); + + while(tok.nextLine()) { + ++count; + fld.reset(); + list.add(fld.at(0)); + } +// Collections.sort(list); + for(String s: list) { + System.out.println(s); + + } + } finally { + System.out.printf("%15s:%12d\n","Total",count); + } + } + +} diff --git a/authz-core/src/test/java/com/att/authz/local/JU_TextIndex.java b/authz-core/src/test/java/com/att/authz/local/JU_TextIndex.java new file mode 100644 index 00000000..be0746bd --- /dev/null +++ b/authz-core/src/test/java/com/att/authz/local/JU_TextIndex.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.local; + +import static org.junit.Assert.*; + +import java.io.File; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class JU_TextIndex { + TextIndex textIndex; + @Mock + File file; + + @Before + public void setUp(){ + textIndex = new TextIndex(file); + } + + @Test + public void test() { + assertTrue(true); + } + +} diff --git a/authz-core/src/test/java/com/att/authz/org/JU_OrganizationException.java b/authz-core/src/test/java/com/att/authz/org/JU_OrganizationException.java new file mode 100644 index 00000000..91a54126 --- /dev/null +++ b/authz-core/src/test/java/com/att/authz/org/JU_OrganizationException.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.org; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class JU_OrganizationException { + + OrganizationException organizationException; + + @Before + public void setUp(){ + organizationException = new OrganizationException(); + } + + + @Test + public void test() { + assertTrue(true); + } + +} diff --git a/authz-core/src/test/java/com/att/authz/org/JU_OrganizationFactory.java b/authz-core/src/test/java/com/att/authz/org/JU_OrganizationFactory.java new file mode 100644 index 00000000..75f2a52a --- /dev/null +++ b/authz-core/src/test/java/com/att/authz/org/JU_OrganizationFactory.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.org; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.authz.env.AuthzEnv; +import com.att.inno.env.APIException; + +@RunWith(PowerMockRunner.class) +public class JU_OrganizationFactory { + private static final String ORG_SLOT = null; + OrganizationFactory organizationFactory; + @Mock + AuthzEnv authzEnvMock; + String orgClass="orgclass"; + String orgNS="orgns"; + @Before + public void setUp(){ + organizationFactory = new OrganizationFactory(); + } + + @SuppressWarnings("static-access") + @Test(expected = APIException.class) + public void testSetDefaultOrg() throws APIException { + //PowerMockito.when(authzEnvMock.slot(ORG_SLOT)).thenReturn("ORG_SLOT"); + organizationFactory.setDefaultOrg(authzEnvMock, orgClass); + } + + @SuppressWarnings("static-access") + @Test(expected = OrganizationException.class) + public void testObtain() throws OrganizationException{ + PowerMockito.when(authzEnvMock.getProperty("Organization."+orgNS)).thenReturn("notnull"); + organizationFactory.obtain(authzEnvMock, orgNS); + } +} diff --git a/authz-core/src/test/java/com/att/cssa/rserv/JU_CachingFileAccess.java b/authz-core/src/test/java/com/att/cssa/rserv/JU_CachingFileAccess.java new file mode 100644 index 00000000..3716b19d --- /dev/null +++ b/authz-core/src/test/java/com/att/cssa/rserv/JU_CachingFileAccess.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; + + +@RunWith(PowerMockRunner.class) +public class JU_CachingFileAccess { + CachingFileAccess cachingFileAccess; + + + @Before + public void setUp(){ + cachingFileAccess = new CachingFileAccess(null, null); + + } + + @Test + public void test() { + assertTrue(true); + } + +} diff --git a/authz-core/src/test/java/com/att/cssa/rserv/JU_CodeSetter.java b/authz-core/src/test/java/com/att/cssa/rserv/JU_CodeSetter.java new file mode 100644 index 00000000..d6405c2d --- /dev/null +++ b/authz-core/src/test/java/com/att/cssa/rserv/JU_CodeSetter.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.inno.env.Trans; + +@RunWith(PowerMockRunner.class) +public class JU_CodeSetter { + CodeSetter codeSetter; + @Mock + Trans transMock; + @Mock + HttpServletRequest reqMock; + @Mock + HttpServletResponse respMock; + + @Before + public void setUp(){ + codeSetter = new CodeSetter(transMock, reqMock, respMock); + } + + @SuppressWarnings("rawtypes") + @Mock + Route routeMock; + + @Test + public void testMatches() throws IOException, ServletException{ + boolean result = codeSetter.matches(routeMock); + System.out.println("value of res " + codeSetter.matches(routeMock)); + assertFalse(result); + } + +} diff --git a/authz-core/src/test/java/com/att/cssa/rserv/JU_Pair.java b/authz-core/src/test/java/com/att/cssa/rserv/JU_Pair.java new file mode 100644 index 00000000..5cc362f8 --- /dev/null +++ b/authz-core/src/test/java/com/att/cssa/rserv/JU_Pair.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class JU_Pair { + Pair pair; + Object x; + Object y; + + @Before + public void setUp(){ + pair = new Pair(x, y); + } + + @Test + public void test() { + assertTrue(true); + } + +} diff --git a/authz-core/src/test/java/com/att/cssa/rserv/JU_Routes.java b/authz-core/src/test/java/com/att/cssa/rserv/JU_Routes.java new file mode 100644 index 00000000..67328f6e --- /dev/null +++ b/authz-core/src/test/java/com/att/cssa/rserv/JU_Routes.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.inno.env.Trans; + +@RunWith(PowerMockRunner.class) +public class JU_Routes { + Routes routes; + @Mock + HttpServletRequest reqMock; + CodeSetter codeSetterMock; + Route routeObj; + + @Before + public void setUp(){ + routes = new Routes(); + } + + @Test + public void testRouteReport(){ + List listVal = routes.routeReport(); + System.out.println("value of Listval " +listVal); + assertNotNull(listVal); + + } + + @Test + public void testDerive() throws IOException, ServletException{ + routeObj = routes.derive(reqMock, codeSetterMock); + System.out.println("value of routeObj" +routeObj); + } + + +} diff --git a/authz-core/src/test/java/com/att/cssa/rserv/JU_TypedCode.java b/authz-core/src/test/java/com/att/cssa/rserv/JU_TypedCode.java new file mode 100644 index 00000000..76d5553e --- /dev/null +++ b/authz-core/src/test/java/com/att/cssa/rserv/JU_TypedCode.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class JU_TypedCode { + TypedCode typedCode; + @Mock + RouteReport routeReportMock; + + @Before + public void setUp(){ + typedCode = new TypedCode(); + } + + @Test + public void testFirst(){ + String returnVal = typedCode.first(); + assertNull(returnVal); + } + + +} diff --git a/authz-core/src/test/java/com/att/cssa/rserv/JU_Version.java b/authz-core/src/test/java/com/att/cssa/rserv/JU_Version.java new file mode 100644 index 00000000..47ea35be --- /dev/null +++ b/authz-core/src/test/java/com/att/cssa/rserv/JU_Version.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class JU_Version { + Version version; + + + @Before + public void setUp(){ + version = new Version("String"); + } + + @Test + public void testEquals(){ + boolean val = version.equals(version); + System.out.println("value of val " +val); + assertTrue(val); + } + + @Test + public void testToString(){ + String strVal = version.toString(); + System.out.println("value of strVal " +strVal); + assertNotNull(strVal); + } +} diff --git a/authz-core/src/test/java/com/att/cssa/rserv/test/JU_BetterMatch.java b/authz-core/src/test/java/com/att/cssa/rserv/test/JU_BetterMatch.java new file mode 100644 index 00000000..5a825917 --- /dev/null +++ b/authz-core/src/test/java/com/att/cssa/rserv/test/JU_BetterMatch.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv.test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; + +import org.junit.Test; + +import com.att.cssa.rserv.Match; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.inno.env.impl.EnvFactory; + + +public class JU_BetterMatch { + + @Test + public void test() { + Trans trans = EnvFactory.newTrans(); + // Bad Match + Match bm = new Match("/req/1.0.0/:var"); + + assertTrue(bm.match("/req/1.0.0/fred")); + assertTrue(bm.match("/req/1.0.0/wilma")); + assertTrue(bm.match("/req/1.0.0/wilma/")); + assertFalse(bm.match("/req/1.0.0/wilma/bambam")); + assertFalse(bm.match("/not/valid/234")); + assertFalse(bm.match("")); + + TimeTaken tt = trans.start("A", Env.SUB); + TimeTaken tt2; + int i = 0; + try { + bm = new Match(null); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match("")); + tt2.done(); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match(null)); + tt2.done(); + } finally { + tt.done(); + } + + + tt = trans.start("B", Env.SUB); + i = 0; + try { + bm = new Match("/req/1.0.0/:urn/:ref"); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345")); + tt2.done(); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertFalse(bm.match("/req/1.0.0/urn")); + tt2.done(); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/")); + tt2.done(); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/x")); + tt2.done(); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/xyx")); + } finally { + tt2.done(); + tt.done(); + } + + tt = trans.start("C", Env.SUB); + i = 0; + try { + String url = "/req/1.0.0/"; + bm = new Match(url+":urn*"); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + String value = "urn:fsdb,1.0,req,newreq/0x12345"; + + assertTrue(bm.match(url+value)); + assertEquals("urn:fsdb,1.0,req,newreq/0x12345",bm.param(url+value, ":urn")); + } finally { + tt2.done(); + tt.done(); + } + + tt = trans.start("D", Env.SUB); + i = 0; + try { + bm = new Match("/req/1.0.0/:urn/:ref*"); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345")); + tt2.done(); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/")); + } finally { + tt2.done(); + tt.done(); + } + + tt = trans.start("E", Env.SUB); + i = 0; + try { + bm = new Match("this*"); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match("this")); + tt2.done(); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match("thisandthat")); + tt2.done(); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match("this/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/")); + } finally { + tt2.done(); + tt.done(); + } + + tt = trans.start("F", Env.SUB); + i = 0; + try { + bm = new Match("*"); + tt2 = trans.start(Integer.toString(++i), Env.SUB); + assertTrue(bm.match("/this")); + } finally { + tt2.done(); + tt.done(); + } + + StringBuilder sb = new StringBuilder(); + trans.auditTrail(0, sb); + System.out.println(sb); + + } + + @Test + public void specialTest() { + Match match = new Match("/sample"); + assertTrue(match.match("/sample")); + + match = new Match("/lpeer//lpeer/:key/:item*"); + assertTrue(match.match("/lpeer//lpeer/x/y")); + assertFalse(match.match("/lpeer/x/lpeer/x/y")); + + } + +} diff --git a/authz-core/src/test/java/com/att/cssa/rserv/test/JU_Content.java b/authz-core/src/test/java/com/att/cssa/rserv/test/JU_Content.java new file mode 100644 index 00000000..dd2a33e1 --- /dev/null +++ b/authz-core/src/test/java/com/att/cssa/rserv/test/JU_Content.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.cssa.rserv.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Test; + +import com.att.cssa.rserv.HttpCode; +import com.att.cssa.rserv.TypedCode; +import com.att.inno.env.TransJAXB; +import com.att.inno.env.impl.EnvFactory; + + +/** + * Test the functioning of the "Content" class, which holds, and routes to the right code based on Accept values + */ +public class JU_Content { + + + @Test + public void test() throws Exception { + final String BOOL = "Boolean"; + final String XML = "XML"; + TransJAXB trans = EnvFactory.newTrans(); + try { + HttpCode cBool = new HttpCode(BOOL,"Standard String") { + @Override + public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) { + try { + resp.getOutputStream().write(context.getBytes()); + } catch (IOException e) { + } + } + }; + + HttpCode cXML = new HttpCode(XML, "Standard String") { + @Override + public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) { + try { + resp.getOutputStream().write(context.getBytes()); + } catch (IOException e) { + } + } + }; + + TypedCode ct = new TypedCode() + .add(cBool,"application/" + Boolean.class.getName()+"+xml;charset=utf8;version=1.1") + .add(cXML,"application/xml;q=.9"); + String expected = "application/java.lang.Boolean+xml;charset=utf8;version=1.1,application/xml;q=0.9"; + assertEquals(expected,ct.toString()); + + //BogusReq req = new BogusReq(); + //expected = (expected); + //HttpServletResponse resp = new BogusResp(); + + assertNotNull("Same Content String and Accept String",ct.prep(trans,expected)); + + //expects Null (not run) + // A Boolean xml that must have charset utf8 and match version 1.2 or greater + expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.2"); + assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected)); + + // Same with (too many) spaces + expected = (" application/java.lang.Boolean+xml ; charset = utf8 ; version = 1.2 "); + assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected)); + + //expects Null (not run) + expected = ("application/java.lang.Boolean+xml;charset=utf8;version=2.1"); + assertNull("Major Versions not the same",ct.prep(trans,expected)); + + expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.0"); + assertNotNull("Content Minor Version is greater than Accept Minor Version",ct.prep(trans,expected)); + + expected = "application/java.lang.Squid+xml;charset=utf8;version=1.0,application/xml;q=.9"; + assertNotNull("2nd one will have to do...",ct.prep(trans,expected)); + + expected = "application/java.lang.Boolean+xml;charset=UTF8;version=1.0"; + assertNotNull("Minor Charset in Caps acceptable",ct.prep(trans,expected)); + + // expects no run + expected="application/java.lang.Boolean+xml;charset=MyType;version=1.0"; + assertNull("Unknown Minor Charset",ct.prep(trans,expected)); + + expected=""; + assertNotNull("Blank Acceptance",ct.prep(trans,expected)); + + expected=null; + assertNotNull("Null Acceptance",ct.prep(trans,expected)); + + expected = ("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); + assertNotNull("Matches application/xml, and other content not known",ct.prep(trans,expected)); + + // No SemiColon + expected = ("i/am/bogus,application/xml"); + assertNotNull("Match second entry, with no Semis",ct.prep(trans,expected)); + + } finally { + StringBuilder sb = new StringBuilder(); + trans.auditTrail(0, sb); + System.out.println(sb); + } + } + +} diff --git a/authz-defOrg/.gitignore b/authz-defOrg/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-defOrg/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-defOrg/pom.xml b/authz-defOrg/pom.xml new file mode 100644 index 00000000..a61aa570 --- /dev/null +++ b/authz-defOrg/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-defOrg + Default Organization + Example Organization Module + jar + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + false + 0 + + + + + com.att.cadi + cadi-core + + + + com.att.authz + authz-core + + + + javax.mail + mail + + + + + + + + + diff --git a/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrg.java b/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrg.java new file mode 100644 index 00000000..5a3abc8c --- /dev/null +++ b/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrg.java @@ -0,0 +1,597 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.osaaf.defOrg; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.org.EmailWarnings; +import com.att.authz.org.Executor; +import com.att.authz.org.Organization; +import com.att.authz.org.OrganizationException; +import com.osaaf.defOrg.Identities.Data; + +public class DefaultOrg implements Organization { + private static final String PROPERTY_IS_REQUIRED = " property is Required"; + private static final String DOMAIN = "osaaf.com"; + private static final String REALM = "com.osaaf"; + private static final String NAME = "Default Organization"; + private static final String NO_PASS = NAME + " does not support Passwords. Use AAF"; + private final String mailHost,mailFromUserId,supportAddress; + private String SUFFIX; + // Possible ID Pattern + private static final String ID_PATTERN = "a-z[a-z0-9]{5-8}@.*"; + + public DefaultOrg(AuthzEnv env) throws OrganizationException { + String s; + mailHost = env.getProperty(s=(REALM + ".mailHost"), null); + if(mailHost==null) { + throw new OrganizationException(s + PROPERTY_IS_REQUIRED); + } + supportAddress = env.getProperty(s=(REALM + ".supportEmail"), null); + if(supportAddress==null) { + throw new OrganizationException(s + PROPERTY_IS_REQUIRED); + } + + String temp = env.getProperty(s=(REALM + ".mailFromUserId"), null); + mailFromUserId = temp==null?supportAddress:temp; + + System.getProperties().setProperty("mail.smtp.host",mailHost); + System.getProperties().setProperty("mail.user", mailFromUserId); + // Get the default Session object. + session = Session.getDefaultInstance(System.getProperties()); + + SUFFIX='.'+getDomain(); + + try { + String defFile; + temp=env.getProperty(defFile = (getClass().getName()+".file")); + File fIdentities=null; + if(temp==null) { + temp = env.getProperty("aaf_data_dir"); + if(temp!=null) { + env.warn().log(defFile, "is not defined. Using default: ",temp+"/identities.dat"); + File dir = new File(temp); + fIdentities=new File(dir,"identities.dat"); + if(!fIdentities.exists()) { + env.warn().log("No",fIdentities.getCanonicalPath(),"exists. Creating."); + if(!dir.exists()) { + dir.mkdirs(); + } + fIdentities.createNewFile(); + } + } + } else { + fIdentities = new File(temp); + if(!fIdentities.exists()) { + String dataDir = env.getProperty("aaf_data_dir"); + if(dataDir!=null) { + fIdentities = new File(dataDir,temp); + } + } + } + + if(fIdentities!=null && fIdentities.exists()) { + identities = new Identities(fIdentities); + } else { + throw new OrganizationException(fIdentities.getCanonicalPath() + " does not exist."); + } + } catch (IOException e) { + throw new OrganizationException(e); + } + } + + // Implement your own Delegation System + static final List NULL_DELEGATES = new ArrayList(); + + public Identities identities; + private boolean dryRun; + private Session session; + public enum Types {Employee, Contractor, Application, NotActive}; + private final static Set typeSet; + + static { + typeSet = new HashSet(); + for(Types t : Types.values()) { + typeSet.add(t.name()); + } + } + + private static final EmailWarnings emailWarnings = new DefaultOrgWarnings(); + + @Override + public String getName() { + return NAME; + } + + @Override + public String getRealm() { + return REALM; + } + + @Override + public String getDomain() { + return DOMAIN; + } + + @Override + public DefaultOrgIdentity getIdentity(AuthzTrans trans, String id) throws OrganizationException { + return new DefaultOrgIdentity(trans,id,this); + } + + // Note: Return a null if found; return a String Message explaining why not found. + @Override + public String isValidID(String id) { + Data data; + try { + data = identities.find(id, identities.reuse()); + } catch (IOException e) { + return getName() + " could not lookup " + id + ": " + e.getLocalizedMessage(); + } + return data==null?id + "is not an Identity in " + getName():null; + } + + @Override + public String isValidPassword(String user, String password, String... prev) { + // If you have an Organization user/Password scheme, use here, otherwise, just use AAF + return NO_PASS; + } + + @Override + public Set getIdentityTypes() { + return typeSet; + } + + @Override + public Response notify(AuthzTrans trans, Notify type, String url, String[] identities, String[] ccs, String summary, Boolean urgent) { + String system = trans.getProperty("CASS_ENV", ""); + + ArrayList toList = new ArrayList(); + Identity identity; + if (identities != null) { + for (String user : identities) { + try { + identity = getIdentity(trans, user); + if (identity == null) { + trans.error().log( + "Failure to obtain User " + user + " for " + + getName()); + } else { + toList.add(identity.email()); + } + } catch (Exception e) { + trans.error().log( + e, + "Failure to obtain User " + user + " for " + + getName()); + } + } + } + + if (toList.isEmpty()) { + trans.error().log("No Users listed to email"); + return Response.ERR_NotificationFailure; + } + + ArrayList ccList = new ArrayList(); + + // If we're sending an urgent email, CC the user's supervisor + // + if (urgent) { + trans.info().log("urgent msg for: " + identities[0]); + try { + List supervisors = getApprovers(trans, identities[0]); + for (Identity us : supervisors) { + trans.info().log("supervisor: " + us.email()); + ccList.add(us.email()); + } + } catch (Exception e) { + trans.error().log(e, + "Failed to find supervisor for " + identities[0]); + } + } + + if (ccs != null) { + for (String user : ccs) { + try { + identity = getIdentity(trans, user); + ccList.add(identity.email()); + } catch (Exception e) { + trans.error().log( + e, + "Failure to obtain User " + user + " for " + + getName()); + } + } + } + + if (summary == null) { + summary = ""; + } + + switch (type) { + case Approval: + try { + sendEmail(trans, toList, ccList, + "AAF Approval Notification " + + (system.length() == 0 ? "" : "(ENV: " + + system + ")"), + "AAF is the " + + NAME + + "System for Fine-Grained Authorizations. You are being asked to Approve" + + (system.length() == 0 ? "" : " in the " + + system + " environment") + + " before AAF Actions can be taken.\n\n" + + "Please follow this link: \n\n\t" + url + + "\n\n" + summary, urgent); + } catch (Exception e) { + trans.error().log(e, "Failure to send Email"); + return Response.ERR_NotificationFailure; + } + break; + case PasswordExpiration: + try { + sendEmail(trans, + toList, + ccList, + "AAF Password Expiration Warning " + + (system.length() == 0 ? "" : "(ENV: " + + system + ")"), + "AAF is the " + + NAME + + " System for Authorizations.\n\nOne or more passwords will expire soon or have expired" + + (system.length() == 0 ? "" : " in the " + + system + " environment") + + ".\n\nPasswords expired for more than 30 days without action are subject to deletion.\n\n" + + "Please follow each link to add a New Password with Expiration Date. Either are valid until expiration. " + + "Use this time to change the passwords on your system. If issues, reply to this email.\n\n" + + summary, urgent); + } catch (Exception e) { + trans.error().log(e, "Failure to send Email"); + return Response.ERR_NotificationFailure; + } + break; + + case RoleExpiration: + try { + sendEmail( + trans, + toList, + ccList, + "AAF Role Expiration Warning " + + (system.length() == 0 ? "" : "(ENV: " + + system + ")"), + "AAF is the " + + NAME + + " System for Authorizations. One or more roles will expire soon" + + (system.length() == 0 ? "" : " in the " + + system + " environment") + + ".\n\nRoles expired for more than 30 days are subject to deletion." + + "Please follow this link the GUI Command line, and either 'extend' or 'del' the user in the role.\n" + + "If issues, reply to this email.\n\n\t" + url + + "\n\n" + summary, urgent); + } catch (Exception e) { + trans.error().log(e, "Failure to send Email"); + return Response.ERR_NotificationFailure; + } + break; + default: + return Response.ERR_NotImplemented; + } + return Response.OK; + } + + @Override + public int sendEmail(AuthzTrans trans, List toList, List ccList, String subject, String body, + Boolean urgent) throws OrganizationException { + int status = 1; + + List to = new ArrayList(); + for(String em : toList) { + if(em.indexOf('@')<0) { + to.add(new DefaultOrgIdentity(trans, em, this).email()); + } else { + to.add(em); + } + } + + List cc = new ArrayList(); + if(ccList!=null && !ccList.isEmpty()) { + for(String em : ccList) { + if(em.indexOf('@')<0) { + cc.add(new DefaultOrgIdentity(trans, em, this).email()); + } else { + cc.add(em); + } + } + } + + + // for now, I want all emails so we can see what goes out. Remove later + if (!ccList.contains(supportAddress)) { + ccList.add(supportAddress); + } + + try { + // Create a default MimeMessage object. + MimeMessage message = new MimeMessage(session); + + // Set From: header field of the header. + message.setFrom(new InternetAddress(mailFromUserId)); + + if (!dryRun) { + // Set To: header field of the header. This is a required field + // and calling module should make sure that it is not null or + // blank + message.addRecipients(Message.RecipientType.TO, + getAddresses(to)); + + // Set CC: header field of the header. + if ((ccList != null) && (ccList.size() > 0)) { + message.addRecipients(Message.RecipientType.CC, + getAddresses(cc)); + } + + // Set Subject: header field + message.setSubject(subject); + + if (urgent) { + message.addHeader("X-Priority", "1"); + } + + // Now set the actual message + message.setText(body); + } else { + // override recipients + message.addRecipients(Message.RecipientType.TO, + InternetAddress.parse(supportAddress)); + + // Set Subject: header field + message.setSubject("[TESTMODE] " + subject); + + if (urgent) { + message.addHeader("X-Priority", "1"); + } + + ArrayList newBody = new ArrayList(); + + Address temp[] = getAddresses(to); + String headerString = "TO:\t" + InternetAddress.toString(temp) + + "\n"; + + temp = getAddresses(cc); + headerString += "CC:\t" + InternetAddress.toString(temp) + "\n"; + + newBody.add(headerString); + + newBody.add("Text: \n"); + + newBody.add(body); + String outString = ""; + for (String s : newBody) { + outString += s + "\n"; + } + + message.setText(outString); + } + // Send message + Transport.send(message); + status = 0; + + } catch (MessagingException mex) { + throw new OrganizationException("Exception send email message " + + mex.getMessage()); + } + + return status; + } + + /** + * Default Policy is to set to 6 Months for Notification Types. + * add others/change as required + */ + @Override + public Date whenToValidate(Notify type, Date lastValidated) { + switch(type) { + case Approval: + case PasswordExpiration: + return null; + default: + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(lastValidated); + gc.add(GregorianCalendar.MONTH, 6); // 6 month policy + return gc.getTime(); + } + } + + @Override + public GregorianCalendar expiration(GregorianCalendar gc, Expiration exp, String... extra) { + GregorianCalendar rv = gc==null?new GregorianCalendar():(GregorianCalendar)gc.clone(); + switch (exp) { + case ExtendPassword: + // Extending Password give 5 extra days + rv.add(GregorianCalendar.DATE, 5); + break; + case Future: + // Future Requests last 15 days before subject to deletion. + rv.add(GregorianCalendar.DATE, 15); + break; + case Password: + // Passwords expire in 90 days + rv.add(GregorianCalendar.DATE, 90); + break; + case TempPassword: + // Temporary Passwords last for 12 hours. + rv.add(GregorianCalendar.HOUR, 12); + break; + case UserDelegate: + // Delegations expire max in 2 months + rv.add(GregorianCalendar.MONTH, 2); + break; + case UserInRole: + // Roles expire in 6 months + rv.add(GregorianCalendar.MONTH, 6); + break; + default: + // Unless other wise set, 6 months is default + rv.add(GregorianCalendar.MONTH, 6); + break; + } + return rv; + } + + @Override + public EmailWarnings emailWarningPolicy() { + return emailWarnings; + } + + /** + * Assume the Supervisor is the Approver. + */ + @Override + public List getApprovers(AuthzTrans trans, String user) throws OrganizationException { + Identity orgIdentity = getIdentity(trans, user); + List orgIdentitys = new ArrayList(); + if(orgIdentity!=null) { + String supervisorID = orgIdentity.responsibleTo(); + if (supervisorID.indexOf('@') < 0) { + supervisorID += getDomain(); + } + Identity supervisor = getIdentity(trans, supervisorID); + orgIdentitys.add(supervisor); + } + return orgIdentitys; + } + + @Override + public String getApproverType() { + return "supervisor"; + } + + @Override + public int startOfDay() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public boolean canHaveMultipleCreds(String id) { + // External entities are likely mono-password... if you change it, it is a global change. + // This is great for people, but horrible for Applications. + // + // AAF's Password can have multiple Passwords, each with their own Expiration Date. + // For Default Org, we'll assume true for all, but when you add your external + // Identity stores, you need to return "false" if they cannot support multiple Passwords like AAF + return true; + } + + @Override + public boolean isValidCred(String id) { + if(id.endsWith(SUFFIX)) { + return true; + } + return id.matches(ID_PATTERN); + } + + @Override + public String validate(AuthzTrans trans, Policy policy, Executor executor, String... vars) throws OrganizationException { + switch(policy) { + case OWNS_MECHID: + case CREATE_MECHID: + if(vars.length>0) { + Identity requestor = getIdentity(trans, trans.user()); + if(requestor!=null) { + Identity mechid = getIdentity(trans, vars[0]); + if(requestor.equals(mechid.owner())) { + return null; + } + } + } + return trans.user() + " is not the Sponsor of MechID " + vars[0]; + + case CREATE_MECHID_BY_PERM_ONLY: + return getName() + " only allows sponsors to create MechIDs"; + + default: + return policy.name() + " is unsupported at " + getName(); + } + } + + @Override + public boolean isTestEnv() { + return false; + } + + @Override + public void setTestMode(boolean dryRun) { + this.dryRun = dryRun; + } + + /** + * Convert the delimiter String into Internet addresses with the default + * delimiter of ";" + * @param strAddress + * @return + */ + private Address[] getAddresses(List strAddress) throws OrganizationException { + return this.getAddresses(strAddress,";"); + } + /** + * Convert the delimiter String into Internet addresses with the + * delimiter of provided + * @param strAddress + * @param delimiter + * @return + */ + private Address[] getAddresses(List strAddresses, String delimiter) throws OrganizationException { + Address[] addressArray = new Address[strAddresses.size()]; + int count = 0; + for (String addr : strAddresses) + { + try{ + addressArray[count] = new InternetAddress(addr); + count++; + }catch(Exception e){ + throw new OrganizationException("Failed to parse the email address "+ addr +": "+e.getMessage()); + } + } + return addressArray; + } +} diff --git a/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrgIdentity.java b/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrgIdentity.java new file mode 100644 index 00000000..51787799 --- /dev/null +++ b/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrgIdentity.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.osaaf.defOrg; + +import java.io.IOException; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.local.AbsData.Reuse; +import com.att.authz.org.Organization; +import com.att.authz.org.Organization.Identity; +import com.att.authz.org.OrganizationException; +import com.att.cadi.config.Config; +import com.osaaf.defOrg.Identities.Data; + +/** + * Org Users are essential representations of Identities within the Org. Since this is a highly individual + * thing for most Orgs, i.e. some use LDAP, some need feed, some use something else, this object will allow + * the Organization to connect to their own Identity systems... + * + * + */ +public class DefaultOrgIdentity implements Identity { + private final static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF); + + private DefaultOrg org; + private Data identity; + private Identity owner; + + public DefaultOrgIdentity(AuthzTrans trans, String key, DefaultOrg dorg) throws OrganizationException { + org = dorg; + identity=null; + try { + org.identities.open(trans, TIMEOUT); + try { + Reuse r = org.identities.reuse(); + identity = org.identities.find(key, r); + if(identity==null) { + identity = Identities.NO_DATA; + } else { + if("a".equals(identity.status)) { + owner = new DefaultOrgIdentity(trans,identity.responsibleTo,org); + } else { + owner = null; + } + } + } finally { + org.identities.close(trans); + } + } catch (IOException e) { + throw new OrganizationException(e); + } + } + + @Override + public boolean equals(Object b) { + if(b instanceof DefaultOrgIdentity) { + return identity.id.equals(((DefaultOrgIdentity)b).identity.id); + } + return false; + } + + @Override + public String id() { + return identity.id; + } + + @Override + public String fullID() { + return identity.id+'@'+org.getDomain(); + } + + @Override + public String type() { + switch(identity.status) { + case "e": return DefaultOrg.Types.Employee.name(); + case "c": return DefaultOrg.Types.Contractor.name(); + case "a": return DefaultOrg.Types.Application.name(); + case "n": return DefaultOrg.Types.NotActive.name(); + default: + return "Unknown"; + } + } + + @Override + public String responsibleTo() { + return identity.responsibleTo; + } + + @Override + public List delegate() { + //NOTE: implement Delegate system, if desired + return DefaultOrg.NULL_DELEGATES; + } + + @Override + public String email() { + return identity.email; + } + + @Override + public String fullName() { + return identity.name; + } + + @Override + public boolean isResponsible() { + return "e".equals(identity.status); // Assume only Employees are responsible for Resources. + } + + @Override + public boolean isFound() { + return identity!=null; + } + + @Override + public Identity owner() throws OrganizationException { + return owner; + } + + @Override + public Organization org() { + return org; + } + +} diff --git a/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrgWarnings.java b/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrgWarnings.java new file mode 100644 index 00000000..cb184e3c --- /dev/null +++ b/authz-defOrg/src/main/java/com/osaaf/defOrg/DefaultOrgWarnings.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.osaaf.defOrg; + +import com.att.authz.org.EmailWarnings; + +public class DefaultOrgWarnings implements EmailWarnings { + + @Override + public long credEmailInterval() + { + return 604800000L; // 7 days in millis 1000 * 86400 * 7 + } + + @Override + public long roleEmailInterval() + { + return 604800000L; // 7 days in millis 1000 * 86400 * 7 + } + + @Override + public long apprEmailInterval() { + return 259200000L; // 3 days in millis 1000 * 86400 * 3 + } + + @Override + public long credExpirationWarning() + { + return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds + } + + @Override + public long roleExpirationWarning() + { + return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds + } + + @Override + public long emailUrgentWarning() + { + return( 1209600000L ); // Two weeks, in milliseconds 1000 * 86400 * 14 in milliseconds + } + +} diff --git a/authz-defOrg/src/main/java/com/osaaf/defOrg/Identities.java b/authz-defOrg/src/main/java/com/osaaf/defOrg/Identities.java new file mode 100644 index 00000000..73c579bc --- /dev/null +++ b/authz-defOrg/src/main/java/com/osaaf/defOrg/Identities.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.osaaf.defOrg; + +import java.io.File; +import java.io.IOException; + +import com.att.authz.local.AbsData; +import com.att.authz.local.DataFile.Token.Field; + +/* + * Example User Data file, which can be modified for many different kinds of Data Feeds. + * + * Note: This has shown to be extremely effective in AT&T, an acknowledged very large organizations, + * because there is no need to synchronize records. AAF simply receives a Data Feed in Organization + * defined intervals. (You might want to check for validity, such as size, etc), then is copied into + * Data Directory. You will want to do so first creating a "lock" file. Assuming the File name is "users.dat", + * the Lock File is "users.lock". + * + * After the movement of the Datafile into place, it is best to remove the Index File, then remove the lock file. + * + * Note, Any AAF Programs needing this data WILL wait on the Lock file, so you should get fresh Data files + * in a "stage" directory, from WEB, or wherever, and then, after it is correct, do the following as fast as feasible. + * + * a) lock + * b) copy from stage + * c) remove idx + * d) unlock + * + * If the Index File is either non-existent or out of date from the Data File, it will be reindexed, which + * has proven to be a very quick function, even with large numbers of entries. + * + * This Sample Feed is set for a file with delimiter of "|". 512 is maximum expected line length. The "0" is the + * field offset for the "key" to the record, which, for user, should be the unique Organization Identity. + * + */ +public class Identities extends AbsData { + public final static Data NO_DATA = new Data(); + + public Identities(File users) { + super(users,'|',512,0); + } + + /* + * Example Field Layout. note, in this example, Application IDs and People IDs are mixed. You may want to split + * out AppIDs, choose your own status indicators, or whatever you use. + * 0 - unique ID + * 1 - full name + * 2 - first name + * 3 - last name + * 4 - phone + * 5 - official email + * 6 - employment status e=employee, c=contractor, a=application, n=no longer with company + * 7 - responsible to (i.e Supervisor for People, or AppOwner, if it's an App ID) + */ + public static class Data { + public final String id; + public final String name; + public final String fname; + public final String lname; + public final String phone; + public final String email; + public final String status; + public final String responsibleTo; + + private Data(Field f) { + f.reset(); + id=f.next(); + name=f.next(); + fname=f.next(); + lname=f.next(); + phone=f.next(); + email=f.next(); + status=f.next(); + responsibleTo =f.next(); + } + + private Data() { + id = name = fname = lname = + phone = email = status = responsibleTo + = ""; + } + + public String toString() { + return id + '|' + + name + '|' + + lname + '|' + + fname + '|' + + phone + '|' + + email + '|' + + status + '|' + + responsibleTo; + } + + // Here, make up your own Methods which help you easily determine your Organization's structure + // in your Organization Object + public boolean hasStatus(String possible) { + return possible.contains(status); + } + + public boolean isEmployee() { + return "e".equals(status); + } + + public boolean isContractor() { + return "c".equals(status); + } + + public boolean isApplication() { + return "a".equals(status); + } + } + + public Data find(Object key,Reuse r) throws IOException { + r.getFieldData().reset(); + // These are new, to allow for Thread Safety + int rec = ti.find(key,r.getTokenData(),r.getFieldData(),0); + if(rec<0) { + return null; + } + r.getTokenData().pos(rec); + return new Data(r.getFieldData()); + } +} diff --git a/authz-defOrg/src/test/java/com/osaaf/defOrd/test/JU_Identities.java b/authz-defOrg/src/test/java/com/osaaf/defOrd/test/JU_Identities.java new file mode 100644 index 00000000..e8078e67 --- /dev/null +++ b/authz-defOrg/src/test/java/com/osaaf/defOrd/test/JU_Identities.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * + */ +package com.osaaf.defOrd.test; + +import java.io.File; +import java.io.IOException; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.local.AbsData.Reuse; +import com.osaaf.defOrg.Identities; +import com.osaaf.defOrg.Identities.Data; + +/** + * + */ +public class JU_Identities { + + private static final String DATA_IDENTITIES = "../opt/app/aaf/data/identities.dat"; + private static File fids; + private static Identities ids; + private static AuthzEnv env; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + env = new AuthzEnv(); + AuthzTrans trans = env.newTransNoAvg(); + // Note: utilize TimeTaken, from trans.start if you want to time. + fids = new File(DATA_IDENTITIES); + if(fids.exists()) { + ids = new Identities(fids); + ids.open(trans, 5000); + } else { + + throw new Exception("Data File for Tests, \"" + DATA_IDENTITIES + + "\" must exist before test can run. (Current dir is " + System.getProperty("user.dir") + ")"); + } + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + AuthzTrans trans = env.newTransNoAvg(); + if(ids!=null) { + ids.close(trans); + } + } + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + @Test + public void test() throws IOException { + Reuse reuse = ids.reuse(); // this object can be reused within the same thread. + Data id = ids.find("osaaf",reuse); + Assert.assertNotNull(id); + System.out.println(id); + + id = ids.find("mmanager",reuse); + Assert.assertNotNull(id); + System.out.println(id); + + //TODO Fill out JUnit with Tests of all Methods in "Data id" + } + +} diff --git a/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrg.java b/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrg.java new file mode 100644 index 00000000..a86ca4ea --- /dev/null +++ b/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrg.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.osaaf.defOrg; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; + +import javax.mail.Address; +import javax.mail.internet.InternetAddress; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.org.Executor; +import com.att.authz.org.OrganizationException; +import com.att.authz.org.Organization.Identity; +import com.att.authz.org.Organization.Policy; +import com.osaaf.defOrg.Identities.Data; + +@RunWith(PowerMockRunner.class) +public class JU_DefaultOrg { + +DefaultOrg defaultOrg; +//private DefaultOrg defaultOrgMock; +@Mock +AuthzEnv authzEnvMock; + +private static final String PROPERTY_IS_REQUIRED = " property is Required"; +private static final String DOMAIN = "osaaf.com"; +private static final String REALM = "com.osaaf"; +private static final String NAME = "Default Organization"; +private static final String NO_PASS = NAME + " does not support Passwords. Use AAF"; +String mailHost,mailFromUserId,supportAddress; +private String SUFFIX; +String s; +String defFile; +@Mock +File fIdentitiesMock; + +@Before +public void setUp() throws OrganizationException{ + MockitoAnnotations.initMocks(this); + PowerMockito.when(authzEnvMock.getProperty(s=(REALM + ".mailHost"), null)).thenReturn("hello"); + PowerMockito.when(authzEnvMock.getProperty(s=(REALM + ".supportEmail"), null)).thenReturn("notnull"); + PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn("C:/Users/sv8675/Desktop/AAF-Code-Sai/AAF-master/authz/authz-defOrg/src/main/java/test.txt"); + PowerMockito.when(fIdentitiesMock.exists()).thenReturn(true); + //PowerMockito.when((fIdentitiesMock!=null && fIdentitiesMock.exists())).thenReturn(true); + defaultOrg = new DefaultOrg(authzEnvMock); +} + +@Test //(expected=OrganizationException.class) +public void test() throws OrganizationException{ + //PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn(" "); + //defaultOrg = new DefaultOrg(authzEnvMock); + assertTrue(true); +} + +@Test +public void testIsValidID(){ + String Result = defaultOrg.isValidID(Matchers.anyString()); + System.out.println("value of res " +Result); + assertNotNull(Result); +} + +@Mock +AuthzTrans authzTransMock; + + +} diff --git a/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrgIdentity.java b/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrgIdentity.java new file mode 100644 index 00000000..97ae02e8 --- /dev/null +++ b/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrgIdentity.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.osaaf.defOrg; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.org.OrganizationException; +import com.att.authz.org.Organization.Identity; +import com.osaaf.defOrg.Identities.Data; + +@RunWith(PowerMockRunner.class) +public class JU_DefaultOrgIdentity { + + private DefaultOrgIdentity defaultOrgIdentity; + private DefaultOrgIdentity defaultOrgIdentityMock; + + @Mock + AuthzTrans authzTransMock; + + String key="key"; + + @Mock + private DefaultOrg defaultOrgMock; + @Mock + private Data dataMock; + @Mock + private Identity identityMock; + + @Before + public void setUp() throws OrganizationException{ + MockitoAnnotations.initMocks(this); + defaultOrgIdentityMock = PowerMockito.mock(DefaultOrgIdentity.class); + } + + @Test + public void testEquals(){ + Object b = null; + Boolean res = defaultOrgIdentityMock.equals(b); + System.out.println("value of res " +res); + } + +} diff --git a/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrgWarnings.java b/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrgWarnings.java new file mode 100644 index 00000000..d1c3107b --- /dev/null +++ b/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_DefaultOrgWarnings.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.osaaf.defOrg; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class JU_DefaultOrgWarnings { + + private DefaultOrgWarnings defaultOrgWarningsMock; + private DefaultOrgWarnings defaultOrgWarnings; + + + @Before + public void setUp(){ + MockitoAnnotations.initMocks(this); + + defaultOrgWarningsMock = PowerMockito.mock(DefaultOrgWarnings.class); + + defaultOrgWarnings = new DefaultOrgWarnings(); + } + + + @Test + public void testApprEmailInterval() { + + assertEquals(259200000, defaultOrgWarnings.apprEmailInterval() ); + } + + @Test + public void testCredEmailInterval() { + assertEquals(604800000, defaultOrgWarnings.credEmailInterval()); + + } + + @Test + public void testCredExpirationWarning() { + assertEquals(2592000000L, defaultOrgWarnings.credExpirationWarning()); + } + + @Test + public void testEmailUrgentWarning() { + assertEquals(1209600000L, defaultOrgWarnings.emailUrgentWarning()); + } + + @Test + public void testRoleEmailInterval() { + assertEquals(604800000L, defaultOrgWarnings.roleEmailInterval()); + } + + @Test + public void testRoleExpirationWarning() { + assertEquals(2592000000L, defaultOrgWarnings.roleExpirationWarning()); + } + +} diff --git a/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_Identities.java b/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_Identities.java new file mode 100644 index 00000000..65c6f1c3 --- /dev/null +++ b/authz-defOrg/src/test/java/com/osaaf/defOrg/JU_Identities.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * + */ +package com.osaaf.defOrg; + +import java.io.File; +import java.io.IOException; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.local.AbsData.Reuse; +import com.osaaf.defOrg.Identities; +import com.osaaf.defOrg.Identities.Data; + +/** + * + */ +public class JU_Identities { + + private static final String DATA_IDENTITIES = "../opt/app/aaf/data/identities.dat"; + private static File fids; + private static Identities ids; + private static AuthzEnv env; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + env = new AuthzEnv(); + AuthzTrans trans = env.newTransNoAvg(); + // Note: utilize TimeTaken, from trans.start if you want to time. + fids = new File(DATA_IDENTITIES); + if(fids.exists()) { + ids = new Identities(fids); + ids.open(trans, 5000); + } else { + + throw new Exception("Data File for Tests, \"" + DATA_IDENTITIES + + "\" must exist before test can run. (Current dir is " + System.getProperty("user.dir") + ")"); + } + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + AuthzTrans trans = env.newTransNoAvg(); + if(ids!=null) { + ids.close(trans); + } + } + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + @Test + public void test() throws IOException { + Reuse reuse = ids.reuse(); // this object can be reused within the same thread. + Data id = ids.find("osaaf",reuse); + Assert.assertNotNull(id); + System.out.println(id); + + id = ids.find("mmanager",reuse); + Assert.assertNotNull(id); + System.out.println(id); + + //TODO Fill out JUnit with Tests of all Methods in "Data id" + } + +} diff --git a/authz-fs/.gitignore b/authz-fs/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-fs/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-fs/pom.xml b/authz-fs/pom.xml new file mode 100644 index 00000000..aa896d6c --- /dev/null +++ b/authz-fs/pom.xml @@ -0,0 +1,163 @@ + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-fs + Authz File Server + Independent FileServer via HTTP (not S) for Public Files (i.e. CRLs) + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + true + 9 + + + + + + com.att.authz + authz-core + + + com.att.cadi + cadi-core + + + com.att.aft + dme2 + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + **/*.class + + + 2.3.1 + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + + + + + + + + ossrhdme + https://oss.sonatype.org/content/repositories/snapshots + + + ossrhdme + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + https://github.com/att/AAF.git + ${project.scm.connection} + http://github.com/att/AAF/tree/master + + diff --git a/authz-fs/src/main/config/FileServer.props b/authz-fs/src/main/config/FileServer.props new file mode 100644 index 00000000..ed1506e5 --- /dev/null +++ b/authz-fs/src/main/config/FileServer.props @@ -0,0 +1,20 @@ +## +## AUTHZ API (authz-service) Properties +## + +hostname=_HOSTNAME_ + +## DISCOVERY (DME2) Parameters on the Command Line +AFT_LATITUDE=_AFT_LATITUDE_ +AFT_LONGITUDE=_AFT_LONGITUDE_ +AFT_ENVIRONMENT=_AFT_ENVIRONMENT_ +DEPLOYED_VERSION=_ARTIFACT_VERSION_ + +DMEServiceName=service=com.att.authz.authz-fs/version=_MAJOR_VER_._MINOR_VER_._PATCH_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ +AFT_DME2_PORT_RANGE=_AUTHZ_FS_PORT_RANGE_ +AFT_DME2_SSL_ENABLE=false +AFT_DME2_DISABLE_PERSISTENT_CACHE=true + +CFA_WebPath=_ROOT_DIR_/data +CFA_ClearCommand=FmzYPpMY918MwE1hyacoiFSt +CFA_MaxSize=2000000 \ No newline at end of file diff --git a/authz-fs/src/main/config/log4j.properties b/authz-fs/src/main/config/log4j.properties new file mode 100644 index 00000000..38593d6a --- /dev/null +++ b/authz-fs/src/main/config/log4j.properties @@ -0,0 +1,91 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START==================================================== +# * org.onap.aai +# * =========================================================================== +# * Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# * Copyright © 2017 Amdocs +# * =========================================================================== +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END==================================================== +# * +# * ECOMP is a trademark and service mark of AT&T Intellectual Property. +# * +#------------------------------------------------------------------------------- +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +log4j.appender.INIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.INIT.File=_LOG_DIR_/${LOG4J_FILENAME_init} +log4j.appender.INIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.INIT.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.INIT.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.INIT.layout=org.apache.log4j.PatternLayout +log4j.appender.INIT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %m %n + + +log4j.appender.FS=org.apache.log4j.DailyRollingFileAppender +log4j.appender.FS.File=logs/${LOG4J_FILENAME_authz} +log4j.appender.FS.DatePattern='.'yyyy-MM-dd +#log4j.appender.FS.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.FS.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.FS.layout=org.apache.log4j.PatternLayout +log4j.appender.FS.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %p [%c] %m %n + +log4j.appender.AUDIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.AUDIT.File=_LOG_DIR_/${LOG4J_FILENAME_audit} +log4j.appender.AUDIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.AUDIT.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.AUDIT.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.AUDIT.layout=org.apache.log4j.PatternLayout +log4j.appender.AUDIT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %m %n + +log4j.appender.TRACE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.TRACE.File=logs/${LOG4J_FILENAME_trace} +log4j.appender.TRACE.DatePattern='.'yyyy-MM-dd +#log4j.appender.TRACE.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.TRACE.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.TRACE.layout=org.apache.log4j.PatternLayout +log4j.appender.TRACE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %m %n + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] %m %n + +# General Apache libraries +log4j.rootLogger=WARN +log4j.logger.org.apache=WARN,INIT +log4j.logger.dme2=WARN,INIT +log4j.logger.init=INFO,INIT +log4j.logger.authz=_LOG4J_LEVEL_,FS +log4j.logger.audit=INFO,AUDIT +log4j.logger.trace=TRACE,TRACE + + diff --git a/authz-fs/src/main/config/lrm-authz-fs.xml b/authz-fs/src/main/config/lrm-authz-fs.xml new file mode 100644 index 00000000..a51db07b --- /dev/null +++ b/authz-fs/src/main/config/lrm-authz-fs.xml @@ -0,0 +1,83 @@ + + + + + + com.att.authz._ARTIFACT_ID_ + + _MAJOR_VER_ + _MINOR_VER_ + _PATCH_VER_ + + _ROUTE_OFFER_ + + Java + com.att.authz.fs.FileServer + + process.workdir + _ROOT_DIR_ + + + jvm.version + 1.8 + + + jvm.args + -DAFT_LATITUDE=_AFT_LATITUDE_ -DAFT_LONGITUDE=_AFT_LONGITUDE_ -DAFT_ENVIRONMENT=_AFT_ENVIRONMENT_ -Dplatform=_SCLD_PLATFORM_ -Dcom.sun.jndi.ldap.connect.pool.maxsize=20 -Dcom.sun.jndi.ldap.connect.pool.prefsize=10 -Dcom.sun.jndi.ldap.connect.pool.timeout=3000 + + + jvm.classpath + _ROOT_DIR_/etc:_ROOT_DIR_/lib/*: + + + jvm.heap.min + 1024m + + + jvm.heap.max + 2048m + + + start.class + com.att.authz.fs.FileServer + + + stdout.redirect + _ROOT_DIR_/logs/SystemOut.log + + + stderr.redirect + _ROOT_DIR_/logs/SystemErr.log + + aft + AUTO + 2 + _RESOURCE_MIN_COUNT_ + _RESOURCE_MAX_COUNT_ + _RESOURCE_REGISTRATION_ + com.att.authz:_ARTIFACT_ID_ + _ARTIFACT_VERSION_ + + diff --git a/authz-fs/src/main/data/test.html b/authz-fs/src/main/data/test.html new file mode 100644 index 00000000..428a2742 --- /dev/null +++ b/authz-fs/src/main/data/test.html @@ -0,0 +1,43 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START==================================================== +# * org.onap.aai +# * =========================================================================== +# * Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# * Copyright © 2017 Amdocs +# * =========================================================================== +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END==================================================== +# * +# * ECOMP is a trademark and service mark of AT&T Intellectual Property. +# * +#------------------------------------------------------------------------------- + + + + AT&T Authentication/Authorization Tool + + + +
+

AT&T Auth Tool on _ENV_CONTEXT_

+

AAF Version: _ARTIFACT_VERSION_

+
+

Success for File Server Access

+ + diff --git a/authz-fs/src/main/java/com/att/authz/fs/FileServer.java b/authz-fs/src/main/java/com/att/authz/fs/FileServer.java new file mode 100644 index 00000000..d7d2995f --- /dev/null +++ b/authz-fs/src/main/java/com/att/authz/fs/FileServer.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.fs; + +import static com.att.cssa.rserv.HttpMethods.GET; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Properties; + +import com.att.aft.dme2.api.DME2Manager; +import com.att.aft.dme2.api.DME2Server; +import com.att.aft.dme2.api.DME2ServerProperties; +import com.att.aft.dme2.api.DME2ServiceHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder.RequestDispatcherType; +import com.att.aft.dme2.api.util.DME2ServletHolder; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.env.AuthzTransOnlyFilter; +import com.att.cssa.rserv.CachingFileAccess; +import com.att.cssa.rserv.RServlet; +import com.att.inno.env.APIException; + + +public class FileServer extends RServlet { + public FileServer(final AuthzEnv env) throws APIException, IOException { + try { + /////////////////////// + // File Server + /////////////////////// + + CachingFileAccess cfa = new CachingFileAccess(env); + route(env,GET,"/:key", cfa); + route(env,GET,"/:key/:cmd", cfa); + /////////////////////// + + + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + try { + // Load Properties from authFramework.properties. Needed for DME2 and AuthzEnv + Properties props = new Properties(); + URL rsrc = ClassLoader.getSystemResource("FileServer.props"); + if(rsrc==null) { + System.err.println("Folder containing FileServer.props must be on Classpath"); + System.exit(1); + } + InputStream is = rsrc.openStream(); + try { + props.load(is); + } finally { + is.close(); + } + + // Load Properties into AuthzEnv + AuthzEnv env = new AuthzEnv(props); + env.setLog4JNames("log4j.properties","authz","fs","audit","init",null); + + // AFT Discovery Libraries only read System Props + env.loadToSystemPropsStartsWith("AFT_","DME2_"); + env.init().log("DME2 using " + env.getProperty("DMEServiceName","unknown") + " URI"); + + // Start DME2 (DME2 needs Properties form of props) + DME2Manager dme2 = new DME2Manager("RServDME2Manager",props); + + DME2ServiceHolder svcHolder; + List slist = new ArrayList(); + svcHolder = new DME2ServiceHolder(); + String serviceName = env.getProperty("DMEServiceName",null); + if(serviceName!=null) { + svcHolder.setServiceURI(serviceName); + svcHolder.setManager(dme2); + svcHolder.setContext("/"); + + FileServer fs = new FileServer(env); + DME2ServletHolder srvHolder = new DME2ServletHolder(fs); + srvHolder.setContextPath("/*"); + slist.add(srvHolder); + + EnumSet edlist = EnumSet.of( + RequestDispatcherType.REQUEST, + RequestDispatcherType.FORWARD, + RequestDispatcherType.ASYNC + ); + + /////////////////////// + // Apply Filters + /////////////////////// + List flist = new ArrayList(); + + // Need TransFilter + flist.add(new DME2FilterHolder(new AuthzTransOnlyFilter(env),"/*",edlist)); + svcHolder.setFilters(flist); + svcHolder.setServletHolders(slist); + + DME2Server dme2svr = dme2.getServer(); + DME2ServerProperties dsprops = dme2svr.getServerProperties(); + dsprops.setGracefulShutdownTimeMs(1000); + + env.init().log("Starting AAF FileServer with Jetty/DME2 server..."); + dme2svr.start(); + try { +// if(env.getProperty("NO_REGISTER",null)!=null) + dme2.bindService(svcHolder); + env.init().log("DME2 is available as HTTP"+(dsprops.isSslEnable()?"/S":""),"on port:",dsprops.getPort()); + + while(true) { // Per DME2 Examples... + Thread.sleep(5000); + } + } catch(InterruptedException e) { + env.init().log("AAF Jetty Server interrupted!"); + } catch(Exception e) { // Error binding service doesn't seem to stop DME2 or Process + env.init().log(e,"DME2 Initialization Error"); + dme2svr.stop(); + System.exit(1); + } + } else { + env.init().log("Properties must contain DMEServiceName"); + } + + } catch (Exception e) { + e.printStackTrace(System.err); + System.exit(1); + } + } +} diff --git a/authz-fs/src/test/java/com/att/authz/fs/JU_FileServer.java b/authz-fs/src/test/java/com/att/authz/fs/JU_FileServer.java new file mode 100644 index 00000000..3ea025a9 --- /dev/null +++ b/authz-fs/src/test/java/com/att/authz/fs/JU_FileServer.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.fs; + +import static com.att.cssa.rserv.HttpMethods.GET; +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.cssa.rserv.CachingFileAccess; +import com.att.inno.env.APIException; +import com.att.authz.fs.*; + +@RunWith(MockitoJUnitRunner.class) +public class JU_FileServer { + @Mock + AuthzEnv authzEnvMock; + AuthzEnv authzEnv = new AuthzEnv(); + + @Before + public void setUp() throws APIException, IOException{ + + } + + @SuppressWarnings("static-access") + @Test + public void testMain() throws Exception{ + + String[] args = null; + Properties props = new Properties(); + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("FileServer.props").getFile()); + +//PowerMockito.whenNew(Something.class).withArguments(argument).thenReturn(mockSomething); + // env.setLog4JNames("log4j.properties","authz","fs","audit","init",null); + // PowerMockito.whenNew(AuthzEnv.class).withArguments(props).thenReturn(authzEnvMock); + // PowerMockito.doNothing().when(authzEnvMock.setLog4JNames(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString())); + // PowerMockito.when(new AuthzEnv(props)).thenReturn(authzEnvMock); + //PowerMockito.doNothing().when(authzEnv).setLog4JNames(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString()); + //PowerMockito.doNothing().when(authzEnvMock).setLog4JNames(" "," "," "," "," "," "); + + FileServer.main(args); + //assertTrue(true); + + } + +} diff --git a/authz-gui/.gitignore b/authz-gui/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-gui/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-gui/pom.xml b/authz-gui/pom.xml new file mode 100644 index 00000000..44faae59 --- /dev/null +++ b/authz-gui/pom.xml @@ -0,0 +1,232 @@ + + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-gui + Authz GUI (Mobile First) + GUI for Authz Management + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + + true + 28 + + + + + + com.att.authz + authz-core + + + javax.servlet + servlet-api + + + + + + com.att.authz + authz-client + + + + + + + com.att.authz + authz-cmd + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + + + + com.att.cadi + cadi-aaf + + + + com.att.cadi + cadi-tguard + + + + com.att.cadi + cadi-client + + + + gso + GLCookieDecryption + + + + com.att.inno + xgen + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + **/*.class + + + 2.3.1 + + + + maven-assembly-plugin + + + swm + package + + single + + + authz-gui-${project.version}.${project.swmVersion} + + + ../authz-service/src/main/assemble/swm.xml + + + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + + + + + + + + ossrhdme + https://oss.sonatype.org/content/repositories/snapshots + + + ossrhdme + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + https://github.com/att/AAF.git + ${project.scm.connection} + http://github.com/att/AAF/tree/master + + diff --git a/authz-gui/src/main/config/authGUI.props b/authz-gui/src/main/config/authGUI.props new file mode 100644 index 00000000..d90e4406 --- /dev/null +++ b/authz-gui/src/main/config/authGUI.props @@ -0,0 +1,34 @@ +## +## AUTHZ GUI (authz-gui) Properties +## + +hostname=_HOSTNAME_ + +## DISCOVERY (DME2) Parameters on the Command Line +AFT_LATITUDE=_AFT_LATITUDE_ +AFT_LONGITUDE=_AFT_LONGITUDE_ +AFT_ENVIRONMENT=_AFT_ENVIRONMENT_ +DEPLOYED_VERSION=_ARTIFACT_VERSION_ + +## Pull in common/security properties + +cadi_prop_files=_COMMON_DIR_/com.att.aaf.common.props;_COMMON_DIR_/com.att.aaf.props + +##DME2 related parameters +DMEServiceName=service=com.att.authz.authz-gui/version=_MAJOR_VER_._MINOR_VER_._PATCH_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ +AFT_DME2_PORT_RANGE=_AUTHZ_GUI_PORT_RANGE_ + +# Turn on both AAF TAF & LUR 2.0 +aaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=_MAJOR_VER_._MINOR_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ + +## URLs +aaf_url.gui_onboard=https://wiki.web.att.com/display/aaf/OnBoarding +aaf_url.aaf_help=http://wiki.web.att.com/display/aaf +aaf_url.cadi_help=http://wiki.web.att.com/display/cadi +aaf_tools=swm,scamper,dme2,soacloud +aaf_url.tool.swm=http://wiki.web.att.com/display/swm +aaf_url.tool.scamper=https://wiki.web.att.com/display/scamper/Home +aaf_url.tool.soacloud=https://wiki.web.att.com/display/soacloud/SOA+Cloud+Management+Platform +aaf_url.tool.dme2=https://wiki.web.att.com/display/soacloud/User+Guide+-+DME2 + + diff --git a/authz-gui/src/main/config/log4j.properties b/authz-gui/src/main/config/log4j.properties new file mode 100644 index 00000000..e1c9db74 --- /dev/null +++ b/authz-gui/src/main/config/log4j.properties @@ -0,0 +1,57 @@ +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +log4j.appender.INIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.INIT.File=_LOG_DIR_/${LOG4J_FILENAME_init} +log4j.appender.INIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.INIT.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.INIT.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.INIT.layout=org.apache.log4j.PatternLayout +log4j.appender.INIT.layout.ConversionPattern=%d %p [%c] %m %n + +log4j.appender.GUI=org.apache.log4j.DailyRollingFileAppender +log4j.appender.GUI.File=_LOG_DIR_/${LOG4J_FILENAME_gui} +log4j.appender.GUI.DatePattern='.'yyyy-MM-dd +#log4j.appender.GUI.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.GUI.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.GUI.layout=org.apache.log4j.PatternLayout +log4j.appender.GUI.layout.ConversionPattern=%d %p [%c] %m %n + +log4j.appender.AUDIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.AUDIT.File=_LOG_DIR_/${LOG4J_FILENAME_audit} +log4j.appender.AUDIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.GUI.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.GUI.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.AUDIT.layout=org.apache.log4j.PatternLayout +log4j.appender.AUDIT.layout.ConversionPattern=%d %p [%c] %m %n + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] %m %n + +# General Apache libraries +log4j.rootLogger=WARN +log4j.logger.org.apache=WARN,INIT +log4j.logger.dme2=WARN,INIT +log4j.logger.init=INFO,INIT +log4j.logger.gui=_LOG4J_LEVEL_,GUI +log4j.logger.audit=INFO,AUDIT + diff --git a/authz-gui/src/main/config/lrm-authz-gui.xml b/authz-gui/src/main/config/lrm-authz-gui.xml new file mode 100644 index 00000000..f9a45e94 --- /dev/null +++ b/authz-gui/src/main/config/lrm-authz-gui.xml @@ -0,0 +1,64 @@ + + + + + + + com.att.authz._ARTIFACT_ID_ + + _MAJOR_VER_ + _MINOR_VER_ + _PATCH_VER_ + + _ROUTE_OFFER_ + + Java + com.att.authz.gui.AuthGUI + + process.workdir + _ROOT_DIR_ + + + jvm.version + 1.8 + + + jvm.args + -DAFT_LATITUDE=_AFT_LATITUDE_ -DAFT_LONGITUDE=_AFT_LONGITUDE_ -DAFT_ENVIRONMENT=_AFT_ENVIRONMENT_ -Dplatform=_SCLD_PLATFORM_ -Dcom.sun.jndi.ldap.connect.pool.maxsize=20 -Dcom.sun.jndi.ldap.connect.pool.prefsize=10 -Dcom.sun.jndi.ldap.connect.pool.timeout=3000 + + + jvm.classpath + _ROOT_DIR_/etc:_ROOT_DIR_/lib/*: + + + jvm.heap.min + 512m + + + jvm.heap.max + 2048m + + + start.class + com.att.authz.gui.AuthGUI + + + stdout.redirect + _ROOT_DIR_/logs/SystemOut.log + + + stderr.redirect + _ROOT_DIR_/logs/SystemErr.log + + aft + AUTO + 3 + _RESOURCE_MIN_COUNT_ + _RESOURCE_MAX_COUNT_ + _RESOURCE_REGISTRATION_ + com.att.authz:_ARTIFACT_ID_ + _ARTIFACT_VERSION_ + + diff --git a/authz-gui/src/main/java/com/att/authz/cui/CUI.java b/authz-gui/src/main/java/com/att/authz/cui/CUI.java new file mode 100644 index 00000000..2f78ae24 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/cui/CUI.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.cui; + +import java.io.PrintWriter; +import java.security.Principal; + +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.cadi.config.Config; +import com.att.cadi.http.HTransferSS; +import com.att.cmd.AAFcli; +import com.att.cssa.rserv.HttpCode; + +public class CUI extends HttpCode { + private final AuthGUI gui; + public CUI(AuthGUI gui) { + super(null,"Command Line"); + this.gui = gui; + } + + @Override + public void handle(AuthzTrans trans, HttpServletRequest req,HttpServletResponse resp) throws Exception { + ServletInputStream isr = req.getInputStream(); + PrintWriter pw = resp.getWriter(); + int c; + StringBuilder cmd = new StringBuilder(); + + while((c=isr.read())>=0) { + cmd.append((char)c); + } + + Principal p = trans.getUserPrincipal(); + trans.env().setProperty(Config.AAF_DEFAULT_REALM, trans.env().getProperty(Config.AAF_DEFAULT_REALM,Config.getDefaultRealm())); + AAFcli aafcli = new AAFcli(trans.env(), pw, + gui.aafCon.hman(), + gui.aafCon.securityInfo(), new HTransferSS(p,AuthGUI.app, + gui.aafCon.securityInfo())); + + aafcli.verbose(false); + aafcli.gui(true); + String cmdStr = cmd.toString(); + if (!cmdStr.contains("--help")) { + cmdStr = cmdStr.replaceAll("help", "--help"); + } + if (!cmdStr.contains("--version")) { + cmdStr = cmdStr.replaceAll("version", "--version"); + } + try { + aafcli.eval(cmdStr); + pw.flush(); + } catch (Exception e) { + pw.flush(); + pw.println(e.getMessage()); + } finally { + aafcli.close(); + } + + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/AuthGUI.java b/authz-gui/src/main/java/com/att/authz/gui/AuthGUI.java new file mode 100644 index 00000000..3e28b83a --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/AuthGUI.java @@ -0,0 +1,319 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui; + +import static com.att.cssa.rserv.HttpMethods.GET; +import static com.att.cssa.rserv.HttpMethods.POST; +import static com.att.cssa.rserv.HttpMethods.PUT; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Properties; + +import com.att.aft.dme2.api.DME2Exception; +import com.att.aft.dme2.api.DME2Manager; +import com.att.aft.dme2.api.DME2Server; +import com.att.aft.dme2.api.DME2ServerProperties; +import com.att.aft.dme2.api.DME2ServiceHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder.RequestDispatcherType; +import com.att.aft.dme2.api.util.DME2ServletHolder; +import com.att.authz.common.Define; +import com.att.authz.cui.CUI; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.env.AuthzTransFilter; +import com.att.authz.env.AuthzTransOnlyFilter; +import com.att.authz.gui.pages.ApiDocs; +import com.att.authz.gui.pages.ApiExample; +import com.att.authz.gui.pages.ApprovalAction; +import com.att.authz.gui.pages.ApprovalForm; +import com.att.authz.gui.pages.Home; +import com.att.authz.gui.pages.LoginLanding; +import com.att.authz.gui.pages.LoginLandingAction; +import com.att.authz.gui.pages.NsDetail; +import com.att.authz.gui.pages.NsHistory; +import com.att.authz.gui.pages.NsInfoAction; +import com.att.authz.gui.pages.NsInfoForm; +import com.att.authz.gui.pages.NssShow; +import com.att.authz.gui.pages.PassChangeAction; +import com.att.authz.gui.pages.PassChangeForm; +import com.att.authz.gui.pages.PendingRequestsShow; +import com.att.authz.gui.pages.PermDetail; +import com.att.authz.gui.pages.PermGrantAction; +import com.att.authz.gui.pages.PermGrantForm; +import com.att.authz.gui.pages.PermHistory; +import com.att.authz.gui.pages.PermsShow; +import com.att.authz.gui.pages.RequestDetail; +import com.att.authz.gui.pages.RoleDetail; +import com.att.authz.gui.pages.RoleHistory; +import com.att.authz.gui.pages.RolesShow; +import com.att.authz.gui.pages.UserRoleExtend; +import com.att.authz.gui.pages.UserRoleRemove; +import com.att.authz.gui.pages.WebCommand; +import com.att.authz.org.OrganizationFactory; +import com.att.authz.server.AbsServer; +import com.att.cadi.CadiException; +import com.att.cadi.aaf.v2_0.AAFTrustChecker; +import com.att.cadi.client.Future; +import com.att.cadi.config.Config; +import com.att.cssa.rserv.CachingFileAccess; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.rosetta.env.RosettaDF; +import com.att.xgen.html.HTMLGen; +import com.att.xgen.html.State; + +import aaf.v2_0.Api; +import aaf.v2_0.Approvals; +import aaf.v2_0.CredRequest; +import aaf.v2_0.Error; +import aaf.v2_0.History; +import aaf.v2_0.Nss; +import aaf.v2_0.Perms; +import aaf.v2_0.RolePermRequest; +import aaf.v2_0.Roles; +import aaf.v2_0.UserRoles; +import aaf.v2_0.Users; + +public class AuthGUI extends AbsServer implements State{ + public static final int TIMEOUT = 60000; + public static final String app = "AAF GUI"; + + public RosettaDF permsDF; + public RosettaDF rolesDF; + public RosettaDF usersDF; + public RosettaDF userrolesDF; + public RosettaDF credReqDF; + public RosettaDF rolePermReqDF; + public RosettaDF approvalsDF; + public RosettaDF nssDF; + public RosettaDF apiDF; + public RosettaDF errDF; + public RosettaDF historyDF; + + public final AuthzEnv env; + public final Slot slot_httpServletRequest; + + public AuthGUI(final AuthzEnv env) throws CadiException, GeneralSecurityException, IOException, APIException { + super(env,app); + this.env = env; + + env.setLog4JNames("log4j.properties","authz","gui","audit","init","trace "); + OrganizationFactory.setDefaultOrg(env, "com.att.authz.org.att.ATT"); + + + slot_httpServletRequest = env.slot("HTTP_SERVLET_REQUEST"); + + permsDF = env.newDataFactory(Perms.class); + rolesDF = env.newDataFactory(Roles.class); +// credsDF = env.newDataFactory(Cred.class); + usersDF = env.newDataFactory(Users.class); + userrolesDF = env.newDataFactory(UserRoles.class); + credReqDF = env.newDataFactory(CredRequest.class); + rolePermReqDF = env.newDataFactory(RolePermRequest.class); + approvalsDF = env.newDataFactory(Approvals.class); + nssDF = env.newDataFactory(Nss.class); + apiDF = env.newDataFactory(Api.class); + errDF = env.newDataFactory(Error.class); + historyDF = env.newDataFactory(History.class); + + ///////////////////////// + // Screens + ///////////////////////// + // Start Screen + final Page start = new Display(this, GET, new Home(this)).page(); + + // MyPerms Screens + final Page myPerms = new Display(this, GET, new PermsShow(this, start)).page(); + Page permDetail = new Display(this, GET, new PermDetail(this, start, myPerms)).page(); + new Display(this, GET, new PermHistory(this,start,myPerms,permDetail)); + + // MyRoles Screens + final Page myRoles = new Display(this, GET, new RolesShow(this, start)).page(); + Page roleDetail = new Display(this, GET, new RoleDetail(this, start, myRoles)).page(); + new Display(this, GET, new RoleHistory(this,start,myRoles,roleDetail)); + + // MyNameSpace + final Page myNamespaces = new Display(this, GET, new NssShow(this, start)).page(); + Page nsDetail = new Display(this, GET, new NsDetail(this, start, myNamespaces)).page(); + new Display(this, GET, new NsHistory(this, start,myNamespaces,nsDetail)); + + // Password Change Screens + final Page pwc = new Display(this, GET, new PassChangeForm(this, start)).page(); + new Display(this, POST, new PassChangeAction(this, start, pwc)); + + // Validation Change Screens + final Page validate = new Display(this, GET, new ApprovalForm(this, start)).page(); + new Display(this, POST, new ApprovalAction(this, start, validate)); + + // Onboard, Detailed Edit Screens + final Page onb = new Display(this, GET, new NsInfoForm(this, start)).page(); + new Display(this, POST, new NsInfoAction(this, start, onb)); + + // Web Command Screens + /* final Page webCommand =*/ new Display(this, GET, new WebCommand(this, start)).page(); + + // API Docs + final Page apidocs = new Display(this, GET, new ApiDocs(this, start)).page(); + new Display(this, GET, new ApiExample(this,start, apidocs)).page(); + + // Permission Grant Page + final Page permGrant = new Display(this, GET, new PermGrantForm(this, start)).page(); + new Display(this, POST, new PermGrantAction(this, start, permGrant)).page(); + + // Login Landing if no credentials detected + final Page loginLanding = new Display(this, GET, new LoginLanding(this, start)).page(); + new Display(this, POST, new LoginLandingAction(this, start, loginLanding)); + + // User Role Request Extend and Remove + new Display(this, GET, new UserRoleExtend(this, start,myRoles)).page(); + new Display(this, GET, new UserRoleRemove(this, start,myRoles)).page(); + + // See my Pending Requests + final Page requestsShow = new Display(this, GET, new PendingRequestsShow(this, start)).page(); + new Display(this, GET, new RequestDetail(this, start, requestsShow)); + + // Command line Mechanism + route(env, PUT, "/gui/cui", new CUI(this),"text/plain;charset=utf-8","*/*"); + + /////////////////////// + // WebContent Handler + /////////////////////// + route(env,GET,"/theme/:key", new CachingFileAccess(env, + CachingFileAccess.CFA_WEB_DIR,"theme")); + /////////////////////// + } + + public static void main(String[] args) { + setup(AuthGUI.class, "authGUI.props"); + } + + /** + * Start up AuthzAPI as DME2 Service + * @param env + * @param props + * @throws DME2Exception + * @throws CadiException + */ + public void startDME2(Properties props) throws DME2Exception, CadiException { + + DME2Manager dme2 = new DME2Manager("AAF GUI DME2Manager", props); + DME2ServiceHolder svcHolder; + List slist = new ArrayList(); + svcHolder = new DME2ServiceHolder(); + String serviceName = env.getProperty("DMEServiceName",null); + if(serviceName!=null) { + svcHolder.setServiceURI(serviceName); + svcHolder.setManager(dme2); + svcHolder.setContext("/"); + + + DME2ServletHolder srvHolder = new DME2ServletHolder(this, new String[]{"/gui"}); + srvHolder.setContextPath("/*"); + slist.add(srvHolder); + + EnumSet edlist = EnumSet.of( + RequestDispatcherType.REQUEST, + RequestDispatcherType.FORWARD, + RequestDispatcherType.ASYNC + ); + + /////////////////////// + // Apply Filters + /////////////////////// + List flist = new ArrayList(); + + // Secure all GUI interactions with AuthzTransFilter + flist.add(new DME2FilterHolder(new AuthzTransFilter(env, aafCon, new AAFTrustChecker( + env.getProperty(Config.CADI_TRUST_PROP, Config.CADI_USER_CHAIN), + Define.ROOT_NS + ".mechid|"+Define.ROOT_COMPANY+"|trust" + )),"/gui/*", edlist)); + + // Don't need security for display Artifacts or login page + AuthzTransOnlyFilter atof; + flist.add(new DME2FilterHolder(atof =new AuthzTransOnlyFilter(env),"/theme/*", edlist)); + flist.add(new DME2FilterHolder(atof,"/js/*", edlist)); + flist.add(new DME2FilterHolder(atof,"/login/*", edlist)); + + svcHolder.setFilters(flist); + svcHolder.setServletHolders(slist); + + DME2Server dme2svr = dme2.getServer(); +// dme2svr.setGracefulShutdownTimeMs(1000); + + env.init().log("Starting AAF GUI with Jetty/DME2 server..."); + dme2svr.start(); + DME2ServerProperties dsprops = dme2svr.getServerProperties(); + try { +// if(env.getProperty("NO_REGISTER",null)!=null) + dme2.bindService(svcHolder); + env.init().log("DME2 is available as HTTP"+(dsprops.isSslEnable()?"/S":""),"on port:",dsprops.getPort()); + + while(true) { // Per DME2 Examples... + Thread.sleep(5000); + } + } catch(InterruptedException e) { + env.init().log("AAF Jetty Server interrupted!"); + } catch(Exception e) { // Error binding service doesn't seem to stop DME2 or Process + env.init().log(e,"DME2 Initialization Error"); + dme2svr.stop(); + System.exit(1); + } + } else { + env.init().log("Properties must contain DMEServiceName"); + } + } + + + public AuthzEnv env() { + return env; + } + + /** + * Derive API Error Class from AAF Response (future) + */ + public Error getError(AuthzTrans trans, Future fp) { +// try { + String text = fp.body(); + Error err = new Error(); + err.setMessageId(Integer.toString(fp.code())); + if(text==null || text.length()==0) { + err.setText("**No Message**"); + } else { + err.setText(fp.body()); + } + return err; +// } catch (APIException e) { +// Error err = new Error(); +// err.setMessageId(Integer.toString(fp.code())); +// err.setText("Could not obtain response from AAF Message: " + e.getMessage()); +// return err; +// } + } + + public void writeError(AuthzTrans trans, Future fp, HTMLGen hgen) { + Error err = getError(trans,fp); + + String messageBody = err.getText(); + List vars = err.getVariables(); + for (int varCounter=0;varCounter= 0) { + messageBody = messageBody.replace("%" + varCounter, var); + } + } + + String msg = "[" + err.getMessageId() + "] " + messageBody; + if(hgen!=null) { + hgen.text(msg); + } + trans.checkpoint("AAF Error: " + msg); + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/BreadCrumbs.java b/authz-gui/src/main/java/com/att/authz/gui/BreadCrumbs.java new file mode 100644 index 00000000..b18b563b --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/BreadCrumbs.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui; + +import static com.att.xgen.html.HTMLGen.A; +import static com.att.xgen.html.HTMLGen.LI; +import static com.att.xgen.html.HTMLGen.UL; + +import java.io.IOException; + +import com.att.inno.env.APIException; +import com.att.xgen.Cache; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + +public class BreadCrumbs extends NamedCode { + private Page[] breadcrumbs; + + public BreadCrumbs(Page ... pages) { + super(false,"breadcrumbs"); + breadcrumbs = pages; + } + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + // BreadCrumbs + Mark mark = new Mark(); + hgen.incr(mark, UL); + for(Page p : breadcrumbs) { + hgen.incr(LI,true) + .leaf(A,"href="+p.url()).text(p.name()) + .end(2); + } + hgen.end(mark); + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/Controls.java b/authz-gui/src/main/java/com/att/authz/gui/Controls.java new file mode 100644 index 00000000..c99c9ff2 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/Controls.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui; + +import java.io.IOException; + +import com.att.inno.env.APIException; +import com.att.xgen.Cache; +import com.att.xgen.html.HTMLGen; + +public class Controls extends NamedCode { + public Controls() { + super(false,"controls"); + } + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + hgen.incr("form","method=post") + .incr("input", true, "type=checkbox", "name=vehicle", "value=Bike").text("I have a bike").end() + .text("Password: ") + .incr("input", true, "type=password", "id=password1").end() + .tagOnly("input", "type=submit", "value=Submit") + .end(); + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/Display.java b/authz-gui/src/main/java/com/att/authz/gui/Display.java new file mode 100644 index 00000000..5ce77e95 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/Display.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui; + +import java.util.Enumeration; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.env.AuthzTrans; +import com.att.cssa.rserv.HttpCode; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.Slot; + +public class Display { + private final Page get; + public Display(final AuthGUI gui, final HttpMethods meth, final Page page) { + get = page; + final String[] fields = page.fields(); + final Slot slots[] = new Slot[fields.length]; + String prefix = page.name() + '.'; + for(int i=0;i(gui,page.name()) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + trans.put(gui.slot_httpServletRequest, req); + for(int i=0; i names = req.getParameterNames(); names.hasMoreElements();) { + String key = names.nextElement(); + if(key.subSequence(0, idx).equals(field)) { + try { + int x = Integer.parseInt(key.substring(field.length())); + if(x>=array.length) { + String[] temp = new String[x+10]; + System.arraycopy(temp, 0, temp, 0, array.length); + array = temp; + } + array[x]=req.getParameter(key); + } catch (NumberFormatException e) { + trans.debug().log(e); + } + } + } + trans.put(slots[i], array); + } + } + page.replay(context,trans,resp.getOutputStream(),"general"); + } + }, "application/x-www-form-urlencoded","*/*"); + + } else { + // Transfer whether Page shouldn't be cached to local Final var. + final boolean no_cache = page.no_cache; + + gui.route(gui.env, meth, page.url(), + new HttpCode(gui,page.name()) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + trans.put(gui.slot_httpServletRequest, req); + for(int i=0; i mm = req.getParameterNames();mm.hasMoreElements();) { + String key = mm.nextElement(); + if(key.startsWith(field)) { + try { + int x = Integer.parseInt(key.substring(field.length())); + if(x>=array.length) { + String[] temp = new String[x+10]; + System.arraycopy(temp, 0, temp, 0, array.length); + array = temp; + } + array[x]=req.getParameter(key); + } catch (NumberFormatException e) { + trans.debug().log(e); + } + } + } + trans.put(slots[i], array); + } + } + page.replay(context,trans,resp.getOutputStream(),"general"); + } + + @Override + public boolean no_cache() { + return no_cache; + } + }, "text/html","*/*"); + } + + } + + public Page page() { + return get; + } +} \ No newline at end of file diff --git a/authz-gui/src/main/java/com/att/authz/gui/Form.java b/authz-gui/src/main/java/com/att/authz/gui/Form.java new file mode 100644 index 00000000..3443c2c4 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/Form.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui; + +import java.io.IOException; + +import com.att.inno.env.APIException; +import com.att.xgen.Cache; +import com.att.xgen.html.HTMLGen; + +public class Form extends NamedCode { + private String preamble; + private NamedCode content; + + public Form(boolean no_cache, NamedCode content) { + super(no_cache,content.idattrs()); + this.content = content; + preamble=null; + idattrs = content.idattrs(); + } + + public Form preamble(String preamble) { + this.preamble = preamble; + return this; + } + + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + if(preamble!=null) { + hgen.incr("p","class=preamble").text(preamble).end(); + } + hgen.incr("form","method=post"); + + content.code(cache, hgen); + + hgen.tagOnly("input", "type=submit", "value=Submit") + .tagOnly("input", "type=reset", "value=Reset") + .end(); + } + + /* (non-Javadoc) + * @see com.att.authz.gui.NamedCode#idattrs() + */ + @Override + public String[] idattrs() { + return content.idattrs(); + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/NamedCode.java b/authz-gui/src/main/java/com/att/authz/gui/NamedCode.java new file mode 100644 index 00000000..90e11707 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/NamedCode.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui; + +import com.att.xgen.Code; +import com.att.xgen.html.HTMLGen; + + + +public abstract class NamedCode implements Code { + public final boolean no_cache; + protected String[] idattrs; + + /* + * Mark whether this code should not be cached, and any attributes + */ + public NamedCode(final boolean no_cache, String ... idattrs) { + this.idattrs = idattrs; + this.no_cache = no_cache; + } + + /** + * Return ID and Any Attributes needed to create a "div" section of this code + * @return + */ + public String[] idattrs() { + return idattrs; + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/Page.java b/authz-gui/src/main/java/com/att/authz/gui/Page.java new file mode 100644 index 00000000..8a97f0e0 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/Page.java @@ -0,0 +1,292 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui; + +import static com.att.xgen.html.HTMLGen.A; +import static com.att.xgen.html.HTMLGen.H1; +import static com.att.xgen.html.HTMLGen.LI; +import static com.att.xgen.html.HTMLGen.TITLE; +import static com.att.xgen.html.HTMLGen.UL; + +import java.io.IOException; +import java.security.Principal; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.cadi.config.Config; +import com.att.inno.env.APIException; +import com.att.inno.env.Slot; +import com.att.inno.env.util.Split; +import com.att.xgen.Cache; +import com.att.xgen.CacheGen; +import com.att.xgen.Code; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLCacheGen; +import com.att.xgen.html.HTMLGen; +import com.att.xgen.html.Imports; + +/** + * A Base "Mobile First" Page + * + * + */ +public class Page extends HTMLCacheGen { + public static enum BROWSER {iPhone,html5,ie,ieOld}; + + public static final int MAX_LINE=20; + + protected static final String[] NO_FIELDS = new String[0]; + + private static final String ENV_CONTEXT = "envContext"; + private static final String DME_SERVICE_NAME = "DMEServiceName"; + private static final String ROUTE_OFFER = "routeOffer"; + private static final String BROWSER_TYPE = "BROWSER_TYPE"; + + private final String bcName, bcUrl; + private final String[] fields; + + public final boolean no_cache; + + public String name() { + return bcName; + } + + public String url() { + return bcUrl; + } + + public String[] fields() { + return fields; + } + + public Page(AuthzEnv env, String name, String url, String [] fields, final NamedCode ... content) throws APIException,IOException { + this(env,name,url,1,fields,content); + } + + public Page(AuthzEnv env, String name, String url, int backdots, String [] fields, final NamedCode ... content) throws APIException,IOException { + super(CacheGen.PRETTY, new PageCode(env, backdots, content)); + bcName = name; + bcUrl = url; + this.fields = fields; + // Mark which fields must be "no_cache" + boolean no_cacheTemp=false; + for(NamedCode nc : content) { + if(nc.no_cache) { + no_cacheTemp=true; + break; + } + } + no_cache=no_cacheTemp; + } + + private static class PageCode implements Code { + private final NamedCode[] content; + private final Slot browserSlot; + private final int backdots; + protected AuthzEnv env; + + public PageCode(AuthzEnv env, int backdots, final NamedCode[] content) { + this.content = content; + this.backdots = backdots; + browserSlot = env.slot(BROWSER_TYPE); + this.env = env; + } + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + // Note: I found that App Storage saves everything about the page, or not. Thus, if you declare the page uncacheable, none of the + // Artifacts, like JPGs are stored, which makes this feature useless for Server driven elements + //hgen.html("manifest=../theme/aaf.appcache"); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI state, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + switch(browser(trans,browserSlot)) { + case ieOld: + case ie: + hgen.directive("!DOCTYPE html"); + hgen.directive("meta", "http-equiv=X-UA-Compatible","content=IE=11"); + default: + } + } + }); + hgen.html(); + Mark head = hgen.head(); + hgen.leaf(TITLE).text("AT&T Authentication/Authorization Tool").end(); + hgen.imports(new Imports(backdots).css("theme/aaf5.css") + .js("theme/comm.js") + .js("theme/console.js") + .js("theme/common.js")); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI state, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + switch(browser(trans,browserSlot)) { + case iPhone: + hgen.imports(new Imports(backdots).css("theme/aaf5iPhone.css")); + break; + case ie: + case ieOld: + hgen.js().text("document.createElement('header');") + .text("document.createElement('nav');") + .done(); + case html5: + hgen.imports(new Imports(backdots).css("theme/aaf5Desktop.css")); + break; + } + } + }); + hgen.end(head); + + Mark body = hgen.body(); + Mark header = hgen.header(); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI state, AuthzTrans trans,Cache cache, HTMLGen xgen) + throws APIException, IOException { + // Obtain Server Info, and print + String DMEServiceName = trans.getProperty(DME_SERVICE_NAME); + String env = DMEServiceName.substring( + DMEServiceName.indexOf(ENV_CONTEXT), + DMEServiceName.indexOf(ROUTE_OFFER) -1).split("=")[1]; + + xgen.leaf(H1).text("AT&T Auth Tool on " + env).end(); + xgen.leaf("p","id=version").text("AAF Version: " + trans.getProperty(Config.AAF_DEPLOYED_VERSION, "N/A")).end(); + + // Obtain User Info, and print + Principal p = trans.getUserPrincipal(); + String user; + if(p==null) { + user = "please choose a Login Authority"; + } else { + user = p.getName(); + } + xgen.leaf("p","id=welcome").text("Welcome, " + user).end(); + + switch(browser(trans,browserSlot)) { + case ieOld: + case ie: + xgen.incr("h5").text("This app is Mobile First HTML5. Internet Explorer " + + " does not support all HTML5 standards. Old, non TSS-Standard versions may not function correctly.").br() + .text(" For best results, use a highly compliant HTML5 browser like Firefox.") + .end(); + break; + default: + } + } + }); + + hgen.hr(); + + int cIdx; + NamedCode nc; + // If BreadCrumbs, put here + if(content.length>0 && content[0] instanceof BreadCrumbs) { + nc = content[0]; + Mark ctnt = hgen.divID(nc.idattrs()); + nc.code(cache, hgen); + hgen.end(ctnt); + cIdx = 1; + } else { + cIdx = 0; + } + + hgen.end(header); + + Mark inner = hgen.divID("inner"); + // Content + for(int i=cIdx;i=0 + * + * Use int found in "ieVersion" + * + * Official IE 7 + * Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; + * .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) + * Official IE 8 + * Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; + * .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; ATT) + * + * IE 11 Compatibility + * Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; + * .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; InfoPath.3; HVD; ATT) + * + * IE 11 (not Compatiblity) + * Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; + * .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; InfoPath.3; HVD; ATT) + * + * @param trans + * @return + */ + public static BROWSER browser(AuthzTrans trans, Slot slot) { + BROWSER br = trans.get(slot, null); + if(br==null) { + String agent = trans.agent(); + int msie; + if(agent.contains("iPhone") /* other phones? */) { + br=BROWSER.iPhone; + } else if ((msie = agent.indexOf("MSIE"))>=0) { + msie+=5; + int end = agent.indexOf(";",msie); + float ver; + try { + ver = Float.valueOf(agent.substring(msie,end)); + br = ver<8f?BROWSER.ieOld:BROWSER.ie; + } catch (Exception e) { + br = BROWSER.ie; + } + } else { + br = BROWSER.html5; + } + trans.put(slot,br); + } + return br; + } +} + diff --git a/authz-gui/src/main/java/com/att/authz/gui/Table.java b/authz-gui/src/main/java/com/att/authz/gui/Table.java new file mode 100644 index 00000000..2e20e532 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/Table.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui; + +import static com.att.xgen.html.HTMLGen.TABLE; +import static com.att.xgen.html.HTMLGen.TD; +import static com.att.xgen.html.HTMLGen.TR; + +import java.io.IOException; +import java.util.ArrayList; + +import com.att.authz.gui.table.AbsCell; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.Trans; +import com.att.inno.env.TransStore; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; +import com.att.xgen.html.State; + +public class Table, TRANS extends TransStore> extends NamedCode { + private final Slot ROW_MSG_SLOT, EMPTY_TABLE_SLOT; + private final String title; + private final String[] columns; + private final Rows rows; + + public Table(String title, TRANS trans, Data data, String ... attrs) { + super(true,attrs); + ROW_MSG_SLOT=trans.slot("TABLE_ROW_MSG"); + EMPTY_TABLE_SLOT=trans.slot("TABLE_EMPTY"); + this.columns = data.headers(); + boolean alt = false; + for(String s : attrs) { + if("class=std".equals(s) || "class=stdform".equals(s)) { + alt=true; + } + } + rows = new Rows(data,alt?1:0); + this.title = title; + + // Derive an ID from title (from no spaces, etc), and prepend to IDAttributes (Protected from NamedCode) + idattrs = new String[attrs.length+1]; + idattrs[0] = title.replaceAll("\\s",""); + System.arraycopy(attrs, 0, idattrs, 1, attrs.length); + } + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + Mark table = new Mark(); + Mark tr = new Mark(); + hgen.incr(table,TABLE) + .leaf("caption", "class=title").text(title).end() + .incr(tr,TR); + for(String column : columns) { + hgen.leaf("th").text(column).end(); + } + hgen.end(tr); + + // Load Rows Dynamically + cache.dynamic(hgen, rows); + // End Table + hgen.end(table); + + // Print Message from Row Gathering, if available + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(S state, TRANS trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + String msg; + if((msg = trans.get(EMPTY_TABLE_SLOT, null))!=null) { + hgen.incr("style").text("#inner tr,caption,input,p.preamble {display: none;}#inner p.notfound {margin: 0px 0px 0px 20px}").end(); + hgen.incr(HTMLGen.P,"class=notfound").text(msg).end().br(); + } else if((msg=trans.get(ROW_MSG_SLOT,null))!=null) { + hgen.p(msg).br(); + } + } + }); + } + + public static class Cells { + public static final Cells EMPTY = new Cells(); + private Cells() { + cells = new AbsCell[0][0]; + msg = "No Data Found"; + } + + public Cells(ArrayList arrayCells, String msg) { + cells = new AbsCell[arrayCells.size()][]; + arrayCells.toArray(cells); + this.msg = msg; + } + public AbsCell[][] cells; + public String msg; + } + + public interface Data, TRANS extends Trans> { + public Cells get(S state,TRANS trans); + public String[] headers(); + } + + private class Rows extends DynamicCode { + private Data data; + private int alt; + + public Rows(Data data, int alt) { + this.data = data; + this.alt = alt; + } + + @Override + public void code(S state, TRANS trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + Mark tr = new Mark(); + Mark td = new Mark(); + + int alt = this.alt; + Cells cells = data.get(state, trans); + if(cells.cells.length>0) { + for(AbsCell[] row : cells.cells) { + switch(alt) { + case 1: + alt=2; + case 0: + hgen.incr(tr,TR); + break; + default: + alt=1; + hgen.incr(tr,TR,"class=alt"); + } + for(AbsCell cell :row) { + hgen.leaf(td, TD,cell.attrs()); + cell.write(hgen); + hgen.end(td); + } + hgen.end(tr); + } + // Pass Msg back to Table code, in order to place after Table Complete + if(cells.msg!=null) { + trans.put(ROW_MSG_SLOT,cells.msg); + } + + } else { + trans.put(EMPTY_TABLE_SLOT,cells.msg); + } + } + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/ApiDocs.java b/authz-gui/src/main/java/com/att/authz/gui/pages/ApiDocs.java new file mode 100644 index 00000000..0e430009 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/ApiDocs.java @@ -0,0 +1,304 @@ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.Symm; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.Api; +import aaf.v2_0.Api.Route; + +public class ApiDocs extends Page { + // Package on purpose + private static final String HREF = "/gui/api"; + private static final String NAME = "AAF RESTful API"; + private static final String fields[] = {}; + private static final String ERROR_LINK = "
JSON " + + "XML "; + + + public ApiDocs(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, fields, + new BreadCrumbs(breadcrumbs), + new Preamble(), + new Table("AAF API Reference",gui.env.newTransNoAvg(),new Model(), "class=std") + ); + } + + private static class Preamble extends NamedCode { + + private static final String I = "i"; + + public Preamble() { + super(false, "preamble"); + } + + @Override + public void code(Cache cache, HTMLGen xgen) throws APIException, IOException { + xgen.leaf(HTMLGen.H1).text("AAF 2.0 RESTful interface").end() + .hr(); + xgen.leaf(HTMLGen.H2).text("Accessing RESTful").end(); + xgen.incr(HTMLGen.UL) + .leaf(HTMLGen.LI).text("AAF RESTful service is secured by the following:").end() + .incr(HTMLGen.UL) + .leaf(HTMLGen.LI).text("The Client must utilize HTTP/S. Non Secure HTTP is not acceptable").end() + .leaf(HTMLGen.LI).text("The Client MUST supply an Identity validated by one of the following mechanisms").end() + .incr(HTMLGen.UL) + .leaf(HTMLGen.LI).text("(Near Future) Application level Certificate").end() + .end() + .end() + .leaf(HTMLGen.LI).text("Responses").end() + .incr(HTMLGen.UL) + .leaf(HTMLGen.LI).text("Each API Entity listed shows what structure will be accepted by service (ContentType) " + + "or responded with by service (Accept). Therefore, use these in making your call. Critical for PUT/POST.").end() + .leaf(HTMLGen.LI).text("Each API call may respond with JSON or XML. Choose the ContentType/Accept that has " + + "+json after the type for JSON or +xml after the Type for XML").end() + .leaf(HTMLGen.LI).text("XSDs for Versions").end() + .incr(HTMLGen.UL) + .leaf(HTMLGen.LI).leaf(HTMLGen.A,"href=../theme/aaf_2_0.xsd").text("API 2.0").end().end() + .end() + .leaf(HTMLGen.LI).text("AAF can support multiple Versions of the API. Choose the ContentType/Accept that has " + + "the appropriate version=?.?").end() + .leaf(HTMLGen.LI).text("All Errors coming from AAF return AT&T Standard Error Message as a String: " + ERROR_LINK + + " (does not apply to errors from Container)").end() + .end() + .leaf(HTMLGen.LI).text("Character Restrictions").end() + .incr(HTMLGen.UL) + .leaf(HTMLGen.LI).text("Character Restrictions must depend on the Enforcement Point used").end() + .leaf(HTMLGen.LI).text("Most AAF usage will be AAF Enforcement Point Characters for Instance and Action are:") + .br().br().leaf(I).text("a-zA-Z0-9,.()_-=%").end() + .br().br().text("For Instance, you may declare a multi-dimensional key with : (colon) separator, example:").end() + .br().leaf(I).text(":myCluster:myKeyspace").end() + .br().br().text("The * (asterix) may be used as a wild-card by itself or within the multi-dimensional key, example:") + .br().leaf(I).text(":myCluster:*").end() + .br().br().text("The % (percent) character can be used as an Escape Character. Applications can use % followed by 2 hexadecimal " + + "digits to cover odd keys. It is their code, however, which must translate.") + .br().br().text("The = (equals) is allowed so that Applications can pass Base64 encodations of binary keys").end() + .leaf(HTMLGen.LI).text("Ask for a Consultation on how these are typically used, or, if your tool is the only Enforcement Point, if set may be expanded").end() + .end() + .end(); + /* + + The Content is defined in the AAF XSD - TODO Add aaf.xsd�; + Character Restrictions + + URLs impose restrictions on characters which have specific meanings. This means you cannot have these characters in the Field Content you send + “#� is a “Fragment URL�, or anchor. Content after this Character is not sent. AAF cannot do anything about this… don’t use it. + “?=&�. These are used to delineate Parameters. + “/“ is used to separate fields + */ + } + + }; + /** + * Implement the Table Content for Permissions by User + * + * + */ + private static class Model implements Table.Data { + public static final String[] HEADERS = new String[] {"Entity","Method","Path Info","Description"}; + private static final TextCell BLANK = new TextCell(""); + + @Override + public String[] headers() { + return HEADERS; + } + + @SuppressWarnings("unchecked") + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + ArrayList ns = new ArrayList(); + ArrayList perms = new ArrayList(); + ArrayList roles = new ArrayList(); + ArrayList user = new ArrayList(); + ArrayList aafOnly = new ArrayList(); + ArrayList rv = new ArrayList(); + + + TimeTaken tt = trans.start("AAF APIs",Env.REMOTE); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future fa = client.read("/api",gui.apiDF); + if(fa.get(5000)) { + tt.done(); + TimeTaken tt2 = trans.start("Load Data", Env.SUB); + try { + if(fa.value!=null)for(Route r : fa.value.getRoute()) { + String path = r.getPath(); + // Build info + StringBuilder desc = new StringBuilder(); + + desc.append("

"); + desc.append(r.getDesc()); + + if(r.getComments().size()>0) { + for(String ct : r.getComments()) { + desc.append("

"); + desc.append(ct); + } + } + + if(r.getParam().size()>0) { + desc.append("


Parameters

"); + + for(String params : r.getParam()) { + String param[] = params.split("\\s*\\|\\s*"); + desc.append("

"); + desc.append(param[0]); + desc.append(" : "); + desc.append(param[1]); + if("true".equalsIgnoreCase(param[2])) { + desc.append(" (Required)"); + } + } + } + + + if(r.getExpected()!=0) { + desc.append("

Expected HTTP Code

"); + desc.append(r.getExpected()); + } + + if(r.getExplicitErr().size()!=0) { + desc.append("

Explicit HTTP Error Codes

"); + boolean first = true; + for(int ee : r.getExplicitErr()) { + if(first) { + first = false; + } else { + desc.append(", "); + } + desc.append(ee); + } + } + + desc.append("

"); + desc.append("GET".equals(r.getMeth())?"Accept:":"ContentType:"); + Collections.sort(r.getContentType()); + if(r.getPath().startsWith("/authn/basicAuth")) { + desc.append("

text/plain"); + } + for(String ct : r.getContentType()) { + if(ct.contains("version=2")) { + desc.append("

"); + desc.append(ct); + desc.append(""); + } + } + desc.append("

"); + + + AbsCell[] sa = new AbsCell[] { + null, + new TextCell(r.getMeth(),"class=right"), + new TextCell(r.getPath()), + new TextCell(desc.toString()), + }; + + if(path.startsWith("/authz/perm")) { + sa[0] = perms.size()==0?new TextCell("PERMISSION"):BLANK; + perms.add(sa); + } else if(path.startsWith("/authz/role") || path.startsWith("/authz/userRole")) { + sa[0] = roles.size()==0?new TextCell("ROLE"):BLANK; + roles.add(sa); + } else if(path.startsWith("/authz/ns")) { + sa[0] = ns.size()==0?new TextCell("NAMESPACE"):BLANK; + ns.add(sa); + } else if(path.startsWith("/authn/basicAuth") + || path.startsWith("/authn/validate") + || path.startsWith("/authz/user")) { + sa[0] = user.size()==0?new TextCell("USER"):BLANK; + user.add(sa); + } else { + sa[0] = aafOnly.size()==0?new TextCell("AAF ONLY"):BLANK; + aafOnly.add(sa); + } + } + //TODO if(trans.fish(p)) + prepare(rv, perms,roles,ns,user); + } finally { + tt2.done(); + } + } else { + gui.writeError(trans, fa, null); + } + return null; + } + }); + } catch (Exception e) { + trans.error().log(e.getMessage()); + } finally { + tt.done(); + } + + return new Cells(rv,null); + } + + @SuppressWarnings("unchecked") + private void prepare(ArrayList rv, ArrayList ... all) { + AbsCell lead; + AbsCell[] row; + for(ArrayList al : all) { + if(al.size()>1) { + row = al.get(0); + lead = row[0]; + row[0]=BLANK; + al.get(0).clone()[0]=BLANK; + Collections.sort(al, new Comparator() { + @Override + public int compare(AbsCell[] ca1, AbsCell[] ca2) { + int meth = ((TextCell)ca1[2]).name.compareTo( + ((TextCell)ca2[2]).name); + if(meth == 0) { + return (HttpMethods.valueOf(((TextCell)ca1[1]).name).compareTo( + HttpMethods.valueOf(((TextCell)ca2[1]).name))); + } else { + return meth; + } + } + }); + // set new first row + al.get(0)[0]=lead; + + rv.addAll(al); + } + } + } + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/ApiExample.java b/authz-gui/src/main/java/com/att/authz/gui/pages/ApiExample.java new file mode 100644 index 00000000..d4f49d98 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/ApiExample.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.Symm; +import com.att.cadi.client.Future; +import com.att.inno.env.APIException; +import com.att.inno.env.Data.TYPE; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.Error; + +/** + * Detail Page for Permissions + * + * + */ +public class ApiExample extends Page { + public static final String HREF = "/gui/example/:tc"; + public static final String NAME = "APIExample"; + + public ApiExample(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, NAME, HREF, 2/*backdots*/, new String[] {"API Code Example"}, + new BreadCrumbs(breadcrumbs), + new Model() + ); + } + + private static class Model extends NamedCode { + private static final String WITH_OPTIONAL_PARAMETERS = "\n\n////////////\n Data with Optional Parameters \n////////////\n\n"; + + public Model() { + super(false); + } + + @Override + public void code(Cache cache, HTMLGen xgen) throws APIException, IOException { + Mark inner = xgen.divID("inner"); + xgen.divID("example","class=std"); + cache.dynamic(xgen, new DynamicCode() { + @Override + public void code(final AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen xgen) throws APIException, IOException { + TimeTaken tt = trans.start("Code Example",Env.REMOTE); + try { + final String typecode; + int prefix = trans.path().lastIndexOf('/')+1; + String encoded = trans.path().substring(prefix); + typecode = Symm.base64noSplit.decode(encoded); + Future fp = gui.client().read("/api/example/" + encoded, + "application/Void+json" + ); + Future fs2; + if(typecode.contains("Request+")) { + fs2 = gui.client().read("/api/example/" + typecode+"?optional=true", + "application/Void+json" + ); + } else { + fs2=null; + } + + + if(fp.get(5000)) { + xgen.incr(HTMLGen.H1).text("Sample Code").end() + .incr(HTMLGen.H5).text(typecode).end(); + xgen.incr("pre"); + if(typecode.contains("+xml")) { + xgen.xml(fp.body()); + if(fs2!=null && fs2.get(5000)) { + xgen.text(WITH_OPTIONAL_PARAMETERS); + xgen.xml(fs2.body()); + } + } else { + xgen.text(fp.body()); + if(fs2!=null && fs2.get(5000)) { + xgen.text(WITH_OPTIONAL_PARAMETERS); + xgen.text(fs2.body()); + } + } + xgen.end(); + } else { + Error err = gui.errDF.newData().in(TYPE.JSON).load(fp.body()).asObject(); + xgen.incr(HTMLGen.H3) + .textCR(2,"Error from AAF Service") + .end(); + + xgen.p("Error Code: ",err.getMessageId()) + .p(err.getText()) + .end(); + + } + + } catch (APIException e) { + throw e; + } catch (IOException e) { + throw e; + } catch (Exception e) { + throw new APIException(e); + }finally { + tt.done(); + } + } + + }); + xgen.end(inner); + } + } + +} + \ No newline at end of file diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/ApprovalAction.java b/authz-gui/src/main/java/com/att/authz/gui/pages/ApprovalAction.java new file mode 100644 index 00000000..34f6f4e2 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/ApprovalAction.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.Approval; +import aaf.v2_0.Approvals; + +public class ApprovalAction extends Page { + public ApprovalAction(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,"Approvals",ApprovalForm.HREF, ApprovalForm.FIELDS, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + final Slot sAppr = gui.env.slot(ApprovalForm.NAME+'.'+ApprovalForm.FIELDS[0]); + final Slot sUser = gui.env.slot(ApprovalForm.NAME+'.'+ApprovalForm.FIELDS[1]); + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(final AuthGUI gui, final AuthzTrans trans,Cache cache, HTMLGen hgen) throws APIException, IOException { + boolean fail = true; + String[] appr = trans.get(sAppr,null); + String user = trans.get(sUser,null); + String lastPage = ApprovalForm.HREF; + if (user != null) { + lastPage += "?user="+user; + } + + if(appr==null) { + hgen.p("No Approvals have been selected."); + } else { + Approval app; + final Approvals apps = new Approvals(); + int count = 0; + for(String a : appr) { + if(a!=null) { + int idx = a.indexOf('|'); + if(idx>=0) { + app = new Approval(); + app.setStatus(a.substring(0,idx)); + app.setTicket(a.substring(++idx)); + app.setApprover(trans.getUserPrincipal().getName()); + apps.getApprovals().add(app); + ++count; + } + } + } + if(apps.getApprovals().isEmpty()) { + hgen.p("No Approvals have been sent."); + } else { + TimeTaken tt = trans.start("AAF Update Approvals",Env.REMOTE); + try { + final int total = count; + fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Boolean code(Rcli client) throws APIException, CadiException { + boolean fail2 = true; + Future fa = client.update("/authz/approval",gui.approvalsDF,apps); + if(fa.get(AuthGUI.TIMEOUT)) { + // Do Remote Call + fail2 = false; + hgen.p(total + (total==1?" Approval has":" Approvals have") + " been Saved"); + } else { + gui.writeError(trans, fa, hgen); + } + return fail2; + } + }); + } catch (Exception e) { + e.printStackTrace(); + } finally { + tt.done(); + } + } + + hgen.br(); + if(fail) { + hgen.incr("a",true,"href="+lastPage).text("Try again").end(); + } else { + hgen.incr("a",true,"href="+Home.HREF).text("Home").end(); + } + } + } + }); + } + }); + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/ApprovalForm.java b/authz-gui/src/main/java/com/att/authz/gui/pages/ApprovalForm.java new file mode 100644 index 00000000..c880932b --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/ApprovalForm.java @@ -0,0 +1,262 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.Form; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.ButtonCell; +import com.att.authz.gui.table.RadioCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextAndRefCell; +import com.att.authz.gui.table.TextCell; +import com.att.authz.org.Organization; +import com.att.authz.org.Organization.Identity; +import com.att.authz.org.OrganizationFactory; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.Approval; + +public class ApprovalForm extends Page { + // Package on purpose + static final String NAME="Approvals"; + static final String HREF = "/gui/approve"; + static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id="; + static final String[] FIELDS = new String[] {"line[]","user"}; + + + public ApprovalForm(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, FIELDS, + + new BreadCrumbs(breadcrumbs), + new NamedCode(false, "filterByUser") { + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + String user = trans.get(trans.env().slot(NAME+".user"),""); + hgen.incr("p", "class=userFilter") + .text("Filter by User:") + .tagOnly("input", "type=text", "value="+user, "id=userTextBox") + .tagOnly("input", "type=button", "onclick=userFilter('"+HREF+"');", "value=Go!") + .end(); + } + }); + } + }, + new Form(true,new Table("Approval Requests", gui.env.newTransNoAvg(),new Model(gui.env()),"class=stdform")) + .preamble("The following requires your Approval to proceed in the AAF System.

Hover on Identity for Name; click for WebPhone"), + new NamedCode(false, "selectAlljs") { + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + Mark jsStart = new Mark(); + hgen.js(jsStart); + hgen.text("function selectAll(radioClass) {"); + hgen.text("var radios = document.querySelectorAll(\".\"+radioClass);"); + hgen.text("for (i = 0; i < radios.length; i++) {"); + hgen.text("radios[i].checked = true;"); + hgen.text("}"); + hgen.text("}"); + hgen.end(jsStart); + } + }); + + } + + /** + * Implement the Table Content for Approvals + * + * + */ + private static class Model implements Table.Data { + private static final String[] headers = new String[] {"Identity","Request","Approve","Deny"}; + private static final Object THE_DOMAIN = null; + private Slot sUser; + + public Model(AuthzEnv env) { + sUser = env.slot(NAME+".user"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + final String userParam = trans.get(sUser, null); + ArrayList rv = new ArrayList(); + String msg = null; + TimeTaken tt = trans.start("AAF Get Approvals for Approver",Env.REMOTE); + try { + final List pendingApprovals = new ArrayList(); + final List beginIndicesPerApprover = new ArrayList(); + int numLeft = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, ConnectException, APIException { + Future fa = client.read("/authz/approval/approver/"+trans.user(),gui.approvalsDF); + int numLeft = 0; + if(fa.get(AuthGUI.TIMEOUT)) { + + if(fa.value!=null) { + for (Approval appr : fa.value.getApprovals()) { + if (appr.getStatus().equals("pending")) { + if (userParam!=null) { + if (!appr.getUser().equalsIgnoreCase(userParam)) { + numLeft++; + continue; + } + } + pendingApprovals.add(appr); + } + } + } + + String prevApprover = null; + int overallIndex = 0; + + for (Approval appr : pendingApprovals) { + String currApprover = appr.getApprover(); + if (!currApprover.equals(prevApprover)) { + prevApprover = currApprover; + beginIndicesPerApprover.add(overallIndex); + } + overallIndex++; + } + } + return numLeft; + } + }); + + if (pendingApprovals.size() > 0) { + // Only add select all links if we have approvals + AbsCell[] selectAllRow = new AbsCell[] { + AbsCell.Null, + AbsCell.Null, + new ButtonCell("all", "onclick=selectAll('approve')", "class=selectAllButton"), + new ButtonCell("all", "onclick=selectAll('deny')", "class=selectAllButton") + }; + rv.add(selectAllRow); + } + + int line=-1; + + while (beginIndicesPerApprover.size() > 0) { + int beginIndex = beginIndicesPerApprover.remove(0); + int endIndex = (beginIndicesPerApprover.isEmpty()?pendingApprovals.size():beginIndicesPerApprover.get(0)); + List currApproverList = pendingApprovals.subList(beginIndex, endIndex); + + String currApproverFull = currApproverList.get(0).getApprover(); + String currApproverShort = currApproverFull.substring(0,currApproverFull.indexOf('@')); + String currApprover = (trans.user().indexOf('@')<0?currApproverShort:currApproverFull); + if (!currApprover.equals(trans.user())) { + AbsCell[] approverHeader; + if (currApproverFull.substring(currApproverFull.indexOf('@')).equals(THE_DOMAIN)) { + approverHeader = new AbsCell[] { + new TextAndRefCell("Approvals Delegated to Me by ", currApprover, + WEBPHONE + currApproverShort, + new String[] {"colspan=4", "class=head"}) + }; + } else { + approverHeader = new AbsCell[] { + new TextCell("Approvals Delegated to Me by " + currApprover, + new String[] {"colspan=4", "class=head"}) + }; + } + rv.add(approverHeader); + } + + // Sort by User Requesting + Collections.sort(currApproverList, new Comparator() { + @Override + public int compare(Approval a1, Approval a2) { + return a1.getUser().compareTo(a2.getUser()); + } + }); + + String prevUser = null; + for (Approval appr : currApproverList) { + if(++line0) { + msg = "After these, there will be " + numLeft + " approvals left to process"; + } + if(rv.size()==0) { + if (numLeft>0) { + msg = "No Approvals to process at this time for user " + userParam +". You have " + + numLeft + " other approvals to process."; + } else { + msg = "No Approvals to process at this time"; + } + } + } catch (Exception e) { + trans.error().log(e); + } finally { + tt.done(); + } + return new Cells(rv,msg); + } + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/Home.java b/authz-gui/src/main/java/com/att/authz/gui/pages/Home.java new file mode 100644 index 00000000..0eaa25ed --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/Home.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import static com.att.xgen.html.HTMLGen.A; +import static com.att.xgen.html.HTMLGen.H3; + +import java.io.IOException; + +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.inno.env.APIException; +import com.att.xgen.Cache; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + + +public class Home extends Page { + public static final String HREF = "/gui/home"; + public Home(final AuthGUI gui) throws APIException, IOException { + super(gui.env,"Home",HREF, NO_FIELDS, new NamedCode(false,"content") { + @Override + public void code(final Cache cache, final HTMLGen xgen) throws APIException, IOException { +// // TEMP +// JSGen jsg = xgen.js(); +// jsg.function("httpPost","sURL","sParam") +// .text("var oURL = new java.net.URL(sURL)") +// .text("var oConn = oURL.openConnection();") +// .text("oConn.setDoInput(true);") +// .text("oConn.setDoOutpu(true);") +// .text("oConn.setUseCaches(false);") +// .text("oConn.setRequestProperty(\"Content-Type\",\"application/x-www-form-urlencoded\");") +// .text(text) +// jsg.done(); + // TEMP + final Mark pages = xgen.divID("Pages"); + xgen.leaf(H3).text("Choose from the following:").end() + .leaf(A,"href=myperms").text("My Permissions").end() + .leaf(A,"href=myroles").text("My Roles").end() + // TODO: uncomment when on cassandra 2.1.2 for MyNamespace GUI page + .leaf(A,"href=mynamespaces").text("My Namespaces").end() + .leaf(A,"href=approve").text("My Approvals").end() + .leaf(A, "href=myrequests").text("My Pending Requests").end() + // Enable later +// .leaf(A, "href=onboard").text("Onboarding").end() + // Password Change. If logged in as CSP/GSO, go to their page + .leaf(A,"href=passwd").text("Password Management").end() + .leaf(A,"href=cui").text("Command Prompt").end() + .leaf(A,"href=api").text("AAF API").end() + ; + + xgen.end(pages); + } + }); + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/LoginLanding.java b/authz-gui/src/main/java/com/att/authz/gui/pages/LoginLanding.java new file mode 100644 index 00000000..1a42bfe5 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/LoginLanding.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.URLDecoder; + +import javax.servlet.http.HttpServletRequest; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.config.Config; +import com.att.inno.env.APIException; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + +public class LoginLanding extends Page { + public static final String HREF = "/login"; + static final String NAME = "Login"; + static final String fields[] = {"id","password","environment"}; + static final String envs[] = {"DEV","TEST","PROD"}; + + public LoginLanding(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, NAME,HREF, fields, new NamedCode(true, "content") { + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + hgen.leaf("p").text("No login credentials are found in your current session. " + + "Choose your preferred login option to continue.").end(); + + Mark loginPaths = hgen.divID("Pages"); + + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI authGUI, AuthzTrans trans, Cache cache, HTMLGen xgen) throws APIException, IOException { + HttpServletRequest req = trans.get(gui.slot_httpServletRequest, null); + if(req!=null) { + String query = req.getQueryString(); + if(query!=null) { + for(String qs : query.split("&")) { + int equals = qs.indexOf('='); + xgen.leaf(HTMLGen.A, "href="+URLDecoder.decode(qs.substring(equals+1),Config.UTF_8)).text(qs.substring(0,equals).replace('_', ' ')).end(); + } + } + } + xgen.leaf(HTMLGen.A, "href=gui/home?Authentication=BasicAuth").text("AAF Basic Auth").end(); + } + }); +// hgen.leaf("a", "href=#","onclick=divVisibility('cso');").text("Global Login").end() +// .incr("p", "id=cso","style=display:none").text("this will redirect to global login").end() +// .leaf("a", "href=#","onclick=divVisibility('tguard');").text("tGuard").end() +// .incr("p", "id=tguard","style=display:none").text("this will redirect to tGuard login").end() +// hgen.leaf("a", "href=#","onclick=divVisibility('basicauth');").text("AAF Basic Auth").end(); + hgen.end(loginPaths); + +// hgen.incr("form","method=post","style=display:none","id=basicauth","gui/home?Authentication=BasicAuth"); +// Mark table = new Mark(TABLE); +// hgen.incr(table); +// cache.dynamic(hgen, new DynamicCode() { +// @Override +// public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) +// throws APIException, IOException { +// hgen +// .input(fields[0],"Username",true) +// .input(fields[1],"Password",true, "type=password"); +// Mark selectRow = new Mark(); +// hgen +// .incr(selectRow, "tr") +// .incr("td") +// .incr("label", "for=envs", "required").text("Environment").end() +// .end() +// .incr("td") +// .incr("select", "name=envs", "id=envs", "required") +// .incr("option", "value=").text("Select Environment").end(); +// for (String env : envs) { +// hgen.incr("option", "value="+env).text(env).end(); +// } +// hgen +// .end(selectRow) + +// hgen.end(); +// } +// }); +// hgen.end(); +// hgen.tagOnly("input", "type=submit", "value=Submit") +// .tagOnly("input", "type=reset", "value=Reset") +// .end(); + + + } + }); + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/LoginLandingAction.java b/authz-gui/src/main/java/com/att/authz/gui/pages/LoginLandingAction.java new file mode 100644 index 00000000..35a2e328 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/LoginLandingAction.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.inno.env.APIException; +import com.att.inno.env.Slot; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +public class LoginLandingAction extends Page { + public LoginLandingAction(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,"Login",LoginLanding.HREF, LoginLanding.fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + final Slot sID = gui.env.slot(LoginLanding.NAME+'.'+LoginLanding.fields[0]); +// final Slot sPassword = gui.env.slot(LoginLanding.NAME+'.'+LoginLanding.fields[1]); + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(final AuthGUI gui, final AuthzTrans trans,Cache cache, HTMLGen hgen) throws APIException, IOException { + String username = trans.get(sID,null); +// String password = trans.get(sPassword,null); + + hgen.p("User: "+username); + hgen.p("Pass: ********"); + + // TODO: clarification from JG + // put in request header? + // then pass through authn/basicAuth call? + + } + }); + } + }); + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/NsDetail.java b/authz-gui/src/main/java/com/att/authz/gui/pages/NsDetail.java new file mode 100644 index 00000000..7ed241d4 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/NsDetail.java @@ -0,0 +1,223 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.List; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cmd.AAFcli; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Chrono; + +import aaf.v2_0.Nss; +import aaf.v2_0.Nss.Ns; +import aaf.v2_0.Perm; +import aaf.v2_0.Perms; +import aaf.v2_0.Role; +import aaf.v2_0.Roles; +import aaf.v2_0.Users; +import aaf.v2_0.Users.User; + +public class NsDetail extends Page { + + public static final String HREF = "/gui/nsdetail"; + public static final String NAME = "NsDetail"; + static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id="; + public static enum NS_FIELD { OWNERS, ADMINS, ROLES, PERMISSIONS, CREDS}; + private static final String BLANK = ""; + + public NsDetail(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, NAME, HREF, new String[] {"name"}, + new BreadCrumbs(breadcrumbs), + new Table("Namespace Details",gui.env.newTransNoAvg(),new Model(gui.env()),"class=detail") + ); + } + + /** + * Implement the table content for Namespace Detail + * + * + */ + private static class Model implements Table.Data { + private static final String[] headers = new String[0]; + private static final String CSP_ATT_COM = "@csp.att.com"; + private Slot name; + public Model(AuthzEnv env) { + name = env.slot(NAME+".name"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + final String nsName = trans.get(name, null); + if(nsName==null) { + return Cells.EMPTY; + } + ArrayList rv = new ArrayList(); + rv.add(new AbsCell[]{new TextCell("Name:"),new TextCell(nsName)}); + + final TimeTaken tt = trans.start("AAF Namespace Details",Env.REMOTE); + try { + gui.clientAsUser(trans.getUserPrincipal(),new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future fn = client.read("/authz/nss/"+nsName,gui.nssDF); + + if(fn.get(AuthGUI.TIMEOUT)) { + tt.done(); + try { +// TimeTaken tt = trans.start("Load Data", Env.SUB); + + for(Ns n : fn.value.getNs()) { + String desc = (n.getDescription()!=null?n.getDescription():BLANK); + rv.add(new AbsCell[]{new TextCell("Description:"),new TextCell(desc)}); + + addField(trans, rv, n.getAdmin(), NS_FIELD.ADMINS); + addField(trans, rv, n.getResponsible(), NS_FIELD.OWNERS); + + Future fu = client.read( + "/authn/creds/ns/"+nsName, + gui.usersDF + ); + List creds = new ArrayList(); + if(fu.get(AAFcli.timeout())) { + for (User u : fu.value.getUser()) { + StringBuilder sb = new StringBuilder(u.getId()); + switch(u.getType()) { + case 1: sb.append(" (U/Pass) "); break; + case 10: sb.append(" (Cert) "); break; + case 200: sb.append(" (x509) "); break; + default: + sb.append(" "); + } + sb.append(Chrono.niceDateStamp(u.getExpires())); + creds.add(sb.toString()); + } + } + addField(trans, rv, creds, NS_FIELD.CREDS); + + Future fr = client.read( + "/authz/roles/ns/"+nsName, + gui.rolesDF + ); + List roles = new ArrayList(); + if(fr.get(AAFcli.timeout())) { + for (Role r : fr.value.getRole()) { + roles.add(r.getName()); + } + } + addField(trans, rv, roles, NS_FIELD.ROLES); + + + Future fp = client.read( + "/authz/perms/ns/"+nsName, + gui.permsDF + ); + List perms = new ArrayList(); + + if(fp.get(AAFcli.timeout())) { + for (Perm p : fp.value.getPerm()) { + perms.add(p.getType() + "|" + p.getInstance() + "|" + p.getAction()); + } + } + addField(trans, rv, perms, NS_FIELD.PERMISSIONS); + } + String historyLink = NsHistory.HREF + + "?name=" + nsName; + rv.add(new AbsCell[] {new RefCell("See History",historyLink)}); + } finally { + tt.done(); + } + } else { + rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")}); + } + return null; + } + }); + } catch (Exception e) { + e.printStackTrace(); + } finally { + tt.done(); + } + return new Cells(rv,null); + } + + private void addField(AuthzTrans trans, ArrayList rv, List values, NS_FIELD field) { + if (!values.isEmpty()) { + switch(field) { + case OWNERS: + case ADMINS: + case CREDS: + for (int i=0; i< values.size(); i++) { + AbsCell label = (i==0?new TextCell(sentenceCase(field)+":"):AbsCell.Null); + String user = values.get(i); + AbsCell userCell = (user.endsWith(CSP_ATT_COM)? + new RefCell(user,WEBPHONE + user.substring(0,user.indexOf('@'))):new TextCell(user)); + rv.add(new AbsCell[] { + label, + userCell + }); + } + break; + case ROLES: + for (int i=0; i< values.size(); i++) { + AbsCell label = (i==0?new TextCell(sentenceCase(field)+":"):AbsCell.Null); + rv.add(new AbsCell[] { + label, + new TextCell(values.get(i)) + }); + } + break; + case PERMISSIONS: + for (int i=0; i< values.size(); i++) { + AbsCell label = (i==0?new TextCell(sentenceCase(field)+":"):AbsCell.Null); + String perm = values.get(i); + String[] fields = perm.split("\\|"); + String grantLink = PermGrantForm.HREF + + "?type=" + fields[0].trim() + + "&instance=" + fields[1].trim() + + "&action=" + fields[2].trim(); + + rv.add(new AbsCell[] { + label, + new TextCell(perm), + new RefCell("Grant This Perm", grantLink) + }); + } + break; + } + + } + } + + private String sentenceCase(NS_FIELD field) { + String sField = field.toString(); + return sField.substring(0, 1).toUpperCase() + sField.substring(1).toLowerCase(); + } + + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/NsHistory.java b/authz-gui/src/main/java/com/att/authz/gui/pages/NsHistory.java new file mode 100644 index 00000000..c9a599f2 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/NsHistory.java @@ -0,0 +1,210 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Comparator; +import java.util.List; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.History; +import aaf.v2_0.History.Item; + +public class NsHistory extends Page { + static final String NAME="NsHistory"; + static final String HREF = "/gui/nsHistory"; + static final String FIELDS[] = {"name","dates"}; + static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id="; + static enum Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, + AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER }; + + public NsHistory(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, FIELDS, + new BreadCrumbs(breadcrumbs), + new Table("History", gui.env.newTransNoAvg(),new Model(gui.env()),"class=std"), + new NamedCode(true, "content") { + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final Slot name = gui.env.slot(NAME+".name"); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + String obName = trans.get(name, null); + + // Use Javascript to make the table title more descriptive + hgen.js() + .text("var caption = document.querySelector(\".title\");") + .text("caption.innerHTML='History for Namespace [ " + obName + " ]';") + .done(); + + // Use Javascript to change Link Target to our last visited Detail page + String lastPage = NsDetail.HREF + "?name=" + obName; + hgen.js() + .text("alterLink('nsdetail', '"+lastPage + "');") + .done(); + + hgen.br(); + hgen.leaf("a","href=#advanced_search","onclick=divVisibility('advanced_search');").text("Advanced Search").end() + .divID("advanced_search", "style=display:none"); + hgen.incr("table"); + + addDateRow(hgen,"Start Date"); + addDateRow(hgen,"End Date"); + hgen.incr("tr").incr("td"); + hgen.tagOnly("input", "type=button","value=Get History", + "onclick=datesURL('"+HREF+"?name=" + obName+"');"); + hgen.end().end(); + hgen.end(); + hgen.end(); + + } + }); + } + } + + ); + } + + private static void addDateRow(HTMLGen hgen, String s) { + hgen + .incr("tr") + .incr("td") + .incr("label", "for=month", "required").text(s+"*").end() + .end() + .incr("td") + .incr("select", "name=month"+s.substring(0, s.indexOf(' ')), "id=month"+s.substring(0, s.indexOf(' ')), "required") + .incr("option", "value=").text("Month").end(); + for (Month m : Month.values()) { + if (Calendar.getInstance().get(Calendar.MONTH) == m.ordinal()) { + hgen.incr("option", "selected", "value="+(m.ordinal()+1)).text(m.name()).end(); + } else { + hgen.incr("option", "value="+(m.ordinal()+1)).text(m.name()).end(); + } + } + hgen.end() + .end() + .incr("td") + .tagOnly("input","type=number","id=year"+s.substring(0, s.indexOf(' ')),"required", + "value="+Calendar.getInstance().get(Calendar.YEAR), "min=1900", + "max="+Calendar.getInstance().get(Calendar.YEAR), + "placeholder=Year").end() + .end(); + } + + + + + /** + * Implement the Table Content for History + * + * + */ + private static class Model implements Table.Data { + private static final String CSP_ATT_COM = "@csp.att.com"; + private static final String[] headers = new String[] {"Date","User","Memo"}; + private Slot name; + private Slot dates; + + public Model(AuthzEnv env) { + name = env.slot(NAME+".name"); + dates = env.slot(NAME+".dates"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + final String oName = trans.get(name,null); + final String oDates = trans.get(dates,null); + + if(oName==null) { + return Cells.EMPTY; + } + + ArrayList rv = new ArrayList(); + String msg = null; + final TimeTaken tt = trans.start("AAF Get History for Namespace ["+oName+"]",Env.REMOTE); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + if (oDates != null) { + client.setQueryParams("yyyymm="+oDates); + } + Future fh = client.read("/authz/hist/ns/"+oName,gui.historyDF); + if (fh.get(AuthGUI.TIMEOUT)) { + tt.done(); + TimeTaken tt2 = trans.start("Load History Data", Env.SUB); + try { + List histItems = fh.value.getItem(); + + java.util.Collections.sort(histItems, new Comparator() { + @Override + public int compare(Item o1, Item o2) { + return o2.getTimestamp().compare(o1.getTimestamp()); + } + }); + + for (Item i : histItems) { + String user = i.getUser(); + AbsCell userCell = (user.endsWith(CSP_ATT_COM)? + new RefCell(user,WEBPHONE + user.substring(0,user.indexOf('@'))):new TextCell(user)); + + rv.add(new AbsCell[] { + new TextCell(i.getTimestamp().toGregorianCalendar().getTime().toString()), + userCell, + new TextCell(i.getMemo()) + }); + } + } finally { + tt2.done(); + } + } else { + if (fh.code()==403) { + rv.add(new AbsCell[] {new TextCell("You may not view History of Namespace [" + oName + "]", "colspan = 3", "class=center")}); + } else { + rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***", "colspan = 3", "class=center")}); + } + } + return null; + } + }); + } catch (Exception e) { + trans.error().log(e); + } finally { + tt.done(); + } + return new Cells(rv,msg); + } + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoAction.java b/authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoAction.java new file mode 100644 index 00000000..79492d2b --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoAction.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.text.ParseException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Chrono; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.CredRequest; + +public class NsInfoAction extends Page { + public NsInfoAction(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,"Onboard",PassChangeForm.HREF, PassChangeForm.fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + final Slot sID = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[0]); + final Slot sCurrPass = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[1]); + final Slot sPassword = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[2]); + final Slot sPassword2 = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[3]); + final Slot startDate = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[4]); + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(final AuthGUI gui, final AuthzTrans trans,Cache cache, HTMLGen hgen) throws APIException, IOException { + String id = trans.get(sID,null); + String currPass = trans.get(sCurrPass,null); + String password = trans.get(sPassword,null); + String password2 = trans.get(sPassword2,null); + + // Run Validations + boolean fail = true; + + if (id==null || id.indexOf('@')<=0) { + hgen.p("Data Entry Failure: Please enter a valid ID, including domain."); + } else if(password == null || password2 == null || currPass == null) { + hgen.p("Data Entry Failure: Both Password Fields need entries."); + } else if(!password.equals(password2)) { + hgen.p("Data Entry Failure: Passwords do not match."); + } else { // everything else is checked by Server + final CredRequest cred = new CredRequest(); + cred.setId(id); + cred.setPassword(currPass); + try { + fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Boolean code(Rcli client)throws CadiException, ConnectException, APIException { + TimeTaken tt = trans.start("Check Current Password",Env.REMOTE); + try { + Future fcr = client.create( // Note: Need "Post", because of hiding password in SSL Data + "/authn/validate", + gui.credReqDF, + cred + ); + boolean go; + boolean fail = true; + fcr.get(5000); + if(fcr.code() == 200) { + hgen.p("Current Password validated"); + go = true; + } else { + hgen.p(String.format("Invalid Current Password: %d %s",fcr.code(),fcr.body())); + go = false; + } + if(go) { + tt.done(); + tt = trans.start("AAF Change Password",Env.REMOTE); + try { + // Change over Cred to reset mode + cred.setPassword(password); + String start = trans.get(startDate, null); + if(start!=null) { + try { + cred.setStart(Chrono.timeStamp(Chrono.dateOnlyFmt.parse(start))); + } catch (ParseException e) { + throw new CadiException(e); + } + } + + fcr = client.create( + "/authn/cred", + gui.credReqDF, + cred + ); + + if(fcr.get(5000)) { + // Do Remote Call + hgen.p("New Password has been added."); + fail = false; + } else { + gui.writeError(trans, fcr, hgen); + } + } finally { + tt.done(); + } + } + return fail; + } finally { + tt.done(); + } + } + }); + + } catch (Exception e) { + hgen.p("Unknown Error"); + e.printStackTrace(); + } + } + hgen.br(); + if(fail) { + hgen.incr("a",true,"href="+PassChangeForm.HREF+"?id="+id).text("Try again").end(); + } else { + hgen.incr("a",true,"href="+Home.HREF).text("Home").end(); + } + } + }); + } + }); + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoForm.java b/authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoForm.java new file mode 100644 index 00000000..32b3c4c4 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoForm.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import static com.att.xgen.html.HTMLGen.A; +import static com.att.xgen.html.HTMLGen.TABLE; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.Nss; +import aaf.v2_0.Nss.Ns; +import aaf.v2_0.Nss.Ns.Attrib; + +public class NsInfoForm extends Page { + // Package on purpose + static final String HREF = "/gui/onboard"; + static final String NAME = "Onboarding"; + static final String fields[] = {"ns","description","mots","owners","admins"}; + + public NsInfoForm(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + + private final Slot sID = gui.env.slot(NsInfoForm.NAME+'.'+NsInfoForm.fields[0]); + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + // p tags not closing right using .p() - causes issues in IE8 password form - so using leaf for the moment + hgen.leaf(HTMLGen.H2).text("Namespace Info").end() + .leaf("p").text("Hover over Fields for Tool Tips, or click ") + .leaf(A,"href="+gui.env.getProperty("aaf_url.gui_onboard","")).text("Here").end() + .text(" for more information") + .end() + .incr("form","method=post"); + Mark table = new Mark(TABLE); + hgen.incr(table); + cache.dynamic(hgen, new DynamicCode() { + @SuppressWarnings("unchecked") + @Override + public void code(final AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + final String incomingID= trans.get(sID, ""); + final String[] info = new String[fields.length]; + final Object own_adm[] = new Object[2]; + for(int i=0;i0) { + TimeTaken tt = trans.start("AAF Namespace Info",Env.REMOTE); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future fn = client.read("/authz/nss/"+incomingID,gui.nssDF); + if(fn.get(AuthGUI.TIMEOUT)) { + for(Ns ns : fn.value.getNs()) { + info[0]=ns.getName(); + info[1]=ns.getDescription(); + for(Attrib attr: ns.getAttrib()) { + switch(attr.getKey()) { + case "mots": + info[2]=attr.getValue(); + default: + } + } + own_adm[0]=ns.getResponsible(); + own_adm[1]=ns.getAdmin(); + } + } else { + trans.error().log(fn.body()); + } + return null; + } + }); + } catch (Exception e) { + trans.error().log("Unable to access AAF for NS Info",incomingID); + e.printStackTrace(); + } finally { + tt.done(); + } + } + hgen.input(fields[0],"Namespace",false,"value="+info[0],"title=AAF Namespace") + .input(fields[1],"Description*",true,"value="+info[1],"title=Full Application Name, Tool Name or Group") + .input(fields[2],"MOTS ID",false,"value="+info[2],"title=MOTS ID if this is an Application, and has MOTS"); + Mark endTD = new Mark(),endTR=new Mark(); + // Owners + hgen.incr(endTR,HTMLGen.TR) + .incr(endTD,HTMLGen.TD) + .leaf("label","for="+fields[3]).text("Responsible Party") + .end(endTD) + .incr(endTD,HTMLGen.TD) + .tagOnly("input","id="+fields[3],"title=Owner of App, must be an Non-Bargained Employee"); + if(own_adm[0]!=null) { + for(String s : (List)own_adm[0]) { + hgen.incr("label",true).text(s).end(); + } + } + hgen.end(endTR); + + // Admins + hgen.incr(endTR,HTMLGen.TR) + .incr(endTD,HTMLGen.TD) + .leaf("label","for="+fields[4]).text("Administrators") + .end(endTD) + .incr(endTD,HTMLGen.TD) + .tagOnly("input","id="+fields[4],"title=Admins may be employees, contractors or mechIDs"); + if(own_adm[1]!=null) { + for(String s : (List)own_adm[1]) { + hgen.incr(HTMLGen.P,true).text(s).end(); + } + } + hgen.end(endTR) + .end(); + } + }); + hgen.end(); + hgen.tagOnly("input", "type=submit", "value=Submit") + .end(); + + } + }); + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/NssShow.java b/authz-gui/src/main/java/com/att/authz/gui/pages/NssShow.java new file mode 100644 index 00000000..0333d92c --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/NssShow.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; + +import aaf.v2_0.Nss; +import aaf.v2_0.Nss.Ns; + +public class NssShow extends Page { + public static final String HREF = "/gui/mynamespaces"; + + public NssShow(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, "MyNamespaces",HREF, NO_FIELDS, + new BreadCrumbs(breadcrumbs), + new Table("Namespaces I administer",gui.env.newTransNoAvg(),new Model("admin",gui.env), + "class=std", "style=display: inline-block; width: 45%; margin: 10px;"), + new Table("Namespaces I own",gui.env.newTransNoAvg(),new Model("responsible",gui.env), + "class=std", "style=display: inline-block; width: 45%; margin: 10px;")); + } + + private static class Model implements Table.Data { + private String[] headers; + private String privilege = null; + public final Slot sNssByUser; + private boolean isAdmin; + + public Model(String privilege,AuthzEnv env) { + super(); + headers = new String[] {privilege}; + this.privilege = privilege; + isAdmin = "admin".equals(privilege); + sNssByUser = env.slot("NSS_SHOW_MODEL_DATA"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + ArrayList rv = new ArrayList(); + List nss = trans.get(sNssByUser, null); + if(nss==null) { + TimeTaken tt = trans.start("AAF Nss by User for " + privilege,Env.REMOTE); + try { + nss = gui.clientAsUser(trans.getUserPrincipal(), new Retryable>() { + @Override + public List code(Rcli client) throws CadiException, ConnectException, APIException { + List nss = null; + Future fp = client.read("/authz/nss/either/" + trans.user(),gui.nssDF); + if(fp.get(AuthGUI.TIMEOUT)) { + TimeTaken tt = trans.start("Load Data for " + privilege, Env.SUB); + try { + if(fp.value!=null) { + nss = fp.value.getNs(); + Collections.sort(nss, new Comparator() { + public int compare(Ns ns1, Ns ns2) { + return ns1.getName().compareToIgnoreCase(ns2.getName()); + } + }); + trans.put(sNssByUser,nss); + } + } finally { + tt.done(); + } + }else { + gui.writeError(trans, fp, null); + } + return nss; + } + }); + } catch (Exception e) { + trans.error().log(e); + } finally { + tt.done(); + } + } + + if(nss!=null) { + for(Ns n : nss) { + if((isAdmin && !n.getAdmin().isEmpty()) + || (!isAdmin && !n.getResponsible().isEmpty())) { + AbsCell[] sa = new AbsCell[] { + new RefCell(n.getName(),NsDetail.HREF + +"?name="+n.getName()), + }; + rv.add(sa); + } + } + } + + return new Cells(rv,null); + } + } + + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/PassChangeAction.java b/authz-gui/src/main/java/com/att/authz/gui/pages/PassChangeAction.java new file mode 100644 index 00000000..eeb2b0ec --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/PassChangeAction.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.text.ParseException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Chrono; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.CredRequest; + +public class PassChangeAction extends Page { + public PassChangeAction(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,"PassChange",PassChangeForm.HREF, PassChangeForm.fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + final Slot sID = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[0]); + final Slot sCurrPass = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[1]); + final Slot sPassword = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[2]); + final Slot sPassword2 = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[3]); + final Slot startDate = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[4]); + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(final AuthGUI gui, final AuthzTrans trans,Cache cache, HTMLGen hgen) throws APIException, IOException { + String id = trans.get(sID,null); + String currPass = trans.get(sCurrPass,null); + String password = trans.get(sPassword,null); + String password2 = trans.get(sPassword2,null); + + // Run Validations + boolean fail = true; + + if (id==null || id.indexOf('@')<=0) { + hgen.p("Data Entry Failure: Please enter a valid ID, including domain."); + } else if(password == null || password2 == null || currPass == null) { + hgen.p("Data Entry Failure: Both Password Fields need entries."); + } else if(!password.equals(password2)) { + hgen.p("Data Entry Failure: Passwords do not match."); + } else { // everything else is checked by Server + final CredRequest cred = new CredRequest(); + cred.setId(id); + cred.setPassword(currPass); + try { + fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Boolean code(Rcli client)throws CadiException, ConnectException, APIException { + boolean fail = true; + boolean go = false; + TimeTaken tt = trans.start("Check Current Password",Env.REMOTE); + try { + Future fcr = client.create( // Note: Need "Post", because of hiding password in SSL Data + "/authn/validate",gui.credReqDF,cred); + + fcr.get(5000); + if(fcr.code() == 200) { + hgen.p("Current Password validated"); + go = true; + } else { + hgen.p(String.format("Invalid Current Password: %d %s",fcr.code(),fcr.body())); + go = false; + } + } finally { + tt.done(); + } + if(go) { + tt = trans.start("AAF Change Password",Env.REMOTE); + try { + // Change over Cred to reset mode + cred.setPassword(password); + String start = trans.get(startDate, null); + if(start!=null) { + try { + cred.setStart(Chrono.timeStamp(Chrono.dateOnlyFmt.parse(start))); + } catch (ParseException e) { + throw new CadiException(e); + } + } + + Future fcr = client.create( + "/authn/cred", + gui.credReqDF, + cred + ); + + if(fcr.get(5000)) { + // Do Remote Call + hgen.p("New Password has been added."); + fail = false; + } else { + gui.writeError(trans, fcr, hgen); + } + } finally { + tt.done(); + } + } + return fail; + } + + }); + } catch (Exception e) { + hgen.p("Unknown Error"); + e.printStackTrace(); + } + + } + hgen.br(); + if(fail) { + hgen.incr("a",true,"href="+PassChangeForm.HREF+"?id="+id).text("Try again").end(); + } else { + hgen.incr("a",true,"href="+Home.HREF).text("Home").end(); + } + } + }); + } + }); + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/PassChangeForm.java b/authz-gui/src/main/java/com/att/authz/gui/pages/PassChangeForm.java new file mode 100644 index 00000000..4172235a --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/PassChangeForm.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import static com.att.xgen.html.HTMLGen.TABLE; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.inno.env.APIException; +import com.att.inno.env.Slot; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + +public class PassChangeForm extends Page { + // Package on purpose + static final String HREF = "/gui/passwd"; + static final String NAME = "PassChange"; + static final String fields[] = {"id","current","password","password2","startDate"}; + + public PassChangeForm(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + private final Slot sID = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[0]); + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + // p tags not closing right using .p() - causes issues in IE8 password form - so using leaf for the moment + hgen.leaf("p").text("You are requesting a new Mechanical Password in the AAF System. " + + "So that you can perform clean migrations, you will be able to use both this " + + "new password and the old one until their respective expiration dates.").end() + .leaf("p").text("Note: You must be a Namespace Admin where the MechID resides.").end() + .incr("form","method=post"); + Mark table = new Mark(TABLE); + hgen.incr(table); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { +// GregorianCalendar gc = new GregorianCalendar(); +// System.out.println(gc.toString()); + String incomingID= trans.get(sID, ""); + hgen + .input(fields[0],"ID*",true,"value="+incomingID) + .input(fields[1],"Current Password*",true,"type=password") + .input(fields[2],"New Password*",true, "type=password") + .input(fields[3], "Reenter New Password*",true, "type=password") +// .input(fields[3],"Start Date",false,"type=date", "value="+ +// Chrono.dateOnlyFmt.format(new Date(System.currentTimeMillis())) +// ) + .end(); + } + }); + hgen.end(); + hgen.tagOnly("input", "type=submit", "value=Submit") + .end(); + + } + }); + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/PendingRequestsShow.java b/authz-gui/src/main/java/com/att/authz/gui/pages/PendingRequestsShow.java new file mode 100644 index 00000000..c0dd3f7f --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/PendingRequestsShow.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.UUID; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.Approval; +import aaf.v2_0.Approvals; + +public class PendingRequestsShow extends Page { + public static final String HREF = "/gui/myrequests"; + public static final String NAME = "MyRequests"; + static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id="; + private static final String DATE_TIME_FORMAT = "yyyy-MM-dd"; + + public PendingRequestsShow(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, NAME,HREF, NO_FIELDS, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"expedite") { + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + hgen + .leaf("p", "class=expedite_request").text("These are your submitted Requests that are awaiting Approval. ") + .br() + .text("To Expedite a Request: ") + .leaf("a","href=#expedite_directions","onclick=divVisibility('expedite_directions');") + .text("Click Here").end() + .divID("expedite_directions", "style=display:none"); + hgen + .incr(HTMLGen.OL) + .incr(HTMLGen.LI) + .leaf("a","href="+ApprovalForm.HREF+"?user="+trans.user(), "id=userApprove") + .text("Copy This Link") + .end() + .end() + .incr(HTMLGen.LI) + .text("Send it to the Approver Listed") + .end() + .end() + .text("NOTE: Using this link, the Approver will only see your requests. You only need to send this link once!") + .end() + .end(); + } + }); + } + }, + new Table("Pending Requests",gui.env.newTransNoAvg(),new Model(), "class=std") + ); + + + } + + /** + * Implement the Table Content for Requests by User + * + * + */ + private static class Model implements Table.Data { + private static final String CSP_ATT_COM = "@csp.att.com"; + final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L; + private static final String[] headers = new String[] {"Request Date","Status","Memo","Approver"}; + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + DateFormat createdDF = new SimpleDateFormat(DATE_TIME_FORMAT); + ArrayList rv = new ArrayList(); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client)throws CadiException, ConnectException, APIException { + TimeTaken tt = trans.start("AAF Get Approvals by User",Env.REMOTE); + try { + Future fa = client.read("/authz/approval/user/"+trans.user(),gui.approvalsDF); + if(fa.get(5000)) { + tt.done(); + tt = trans.start("Load Data", Env.SUB); + if(fa.value!=null) { + List approvals = fa.value.getApprovals(); + Collections.sort(approvals, new Comparator() { + @Override + public int compare(Approval a1, Approval a2) { + UUID id1 = UUID.fromString(a1.getId()); + UUID id2 = UUID.fromString(a2.getId()); + return id1.timestamp()<=id2.timestamp()?1:-1; + } + }); + + String prevTicket = null; + for(Approval a : approvals) { + String approver = a.getApprover(); + String approverShort = approver.substring(0,approver.indexOf('@')); + + AbsCell tsCell = null; + String ticket = a.getTicket(); + if (ticket.equals(prevTicket)) { + tsCell = AbsCell.Null; + } else { + UUID id = UUID.fromString(a.getId()); + tsCell = new RefCell(createdDF.format((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000), + RequestDetail.HREF + "?ticket=" + a.getTicket()); + prevTicket = ticket; + } + + AbsCell approverCell = null; + if (approver.endsWith(CSP_ATT_COM)) { + approverCell = new RefCell(approver, WEBPHONE + approverShort); + } else { + approverCell = new TextCell(approver); + } + AbsCell[] sa = new AbsCell[] { + tsCell, + new TextCell(a.getStatus()), + new TextCell(a.getMemo()), + approverCell + }; + rv.add(sa); + } + } + } else { + gui.writeError(trans, fa, null); + } + } finally { + tt.done(); + } + + + return null; + } + }); + } catch (Exception e) { + trans.error().log(e); + } + return new Cells(rv,null); + } + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/PermDetail.java b/authz-gui/src/main/java/com/att/authz/gui/pages/PermDetail.java new file mode 100644 index 00000000..784642cd --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/PermDetail.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.List; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; + +import aaf.v2_0.Perm; +import aaf.v2_0.Perms; + +/** + * Detail Page for Permissions + * + */ +public class PermDetail extends Page { + public static final String HREF = "/gui/permdetail"; + public static final String NAME = "PermDetail"; + private static final String BLANK = ""; + + public PermDetail(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, NAME, HREF, new String[] {"type","instance","action"}, + new BreadCrumbs(breadcrumbs), + new Table("Permission Details",gui.env.newTransNoAvg(),new Model(gui.env()),"class=detail") + ); + } + + /** + * Implement the table content for Permissions Detail + * + * + */ + private static class Model implements Table.Data { + private static final String[] headers = new String[0]; + private Slot type, instance, action; + public Model(AuthzEnv env) { + type = env.slot(NAME+".type"); + instance = env.slot(NAME+".instance"); + action = env.slot(NAME+".action"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + final String pType = trans.get(type, null); + final String pInstance = trans.get(instance, null); + final String pAction = trans.get(action, null); + if(pType==null || pInstance==null || pAction==null) { + return Cells.EMPTY; + } + ArrayList rv = new ArrayList(); + rv.add(new AbsCell[]{new TextCell("Type:"),new TextCell(pType)}); + rv.add(new AbsCell[]{new TextCell("Instance:"),new TextCell(pInstance)}); + rv.add(new AbsCell[]{new TextCell("Action:"),new TextCell(pAction)}); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client)throws CadiException, ConnectException, APIException { + TimeTaken tt = trans.start("AAF Perm Details",Env.REMOTE); + try { + Future fp= client.read("/authz/perms/"+pType + '/' + pInstance + '/' + pAction,gui.permsDF); + + if(fp.get(AuthGUI.TIMEOUT)) { + tt.done(); + tt = trans.start("Load Data", Env.SUB); + List ps = fp.value.getPerm(); + if(!ps.isEmpty()) { + Perm perm = fp.value.getPerm().get(0); + String desc = (perm.getDescription()!=null?perm.getDescription():BLANK); + rv.add(new AbsCell[]{new TextCell("Description:"),new TextCell(desc)}); + boolean first=true; + for(String r : perm.getRoles()) { + if(first){ + first=false; + rv.add(new AbsCell[] { + new TextCell("Associated Roles:"), + new TextCell(r) + }); + } else { + rv.add(new AbsCell[] { + AbsCell.Null, + new TextCell(r) + }); + } + } + } + String historyLink = PermHistory.HREF + + "?type=" + pType + "&instance=" + pInstance + "&action=" + pAction; + + rv.add(new AbsCell[] {new RefCell("See History",historyLink)}); + } else { + rv.add(new AbsCell[] {new TextCell( + fp.code()==HttpStatus.NOT_FOUND_404? + "*** Implicit Permission ***": + "*** Data Unavailable ***" + )}); + } + } finally { + tt.done(); + } + + return null; + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + return new Cells(rv,null); + } + } +} + \ No newline at end of file diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/PermGrantAction.java b/authz-gui/src/main/java/com/att/authz/gui/pages/PermGrantAction.java new file mode 100644 index 00000000..a7aacc20 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/PermGrantAction.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.Pkey; +import aaf.v2_0.RolePermRequest; + +public class PermGrantAction extends Page { + + + public PermGrantAction(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,PermGrantForm.NAME, PermGrantForm.HREF, PermGrantForm.fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + final Slot sType = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[0]); + final Slot sInstance = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[1]); + final Slot sAction = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[2]); + final Slot sRole = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[3]); + + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(final AuthGUI gui, final AuthzTrans trans,Cache cache, HTMLGen hgen) throws APIException, IOException { + + String type = trans.get(sType,null); + String instance = trans.get(sInstance,null); + String action = trans.get(sAction,null); + String role = trans.get(sRole,null); + + String lastPage = PermGrantForm.HREF + + "?type=" + type + "&instance=" + instance + "&action=" + action; + + // Run Validations + boolean fail = true; + + TimeTaken tt = trans.start("AAF Grant Permission to Role",Env.REMOTE); + try { + + final RolePermRequest grantReq = new RolePermRequest(); + Pkey pkey = new Pkey(); + pkey.setType(type); + pkey.setInstance(instance); + pkey.setAction(action); + grantReq.setPerm(pkey); + grantReq.setRole(role); + + fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Boolean code(Rcli client) throws CadiException, ConnectException, APIException { + boolean fail = true; + Future fgrant = client.create( + "/authz/role/perm", + gui.rolePermReqDF, + grantReq + ); + + if(fgrant.get(5000)) { + hgen.p("Permission has been granted to role."); + fail = false; + } else { + if (202==fgrant.code()) { + hgen.p("Permission Grant Request sent, but must be Approved before actualizing"); + fail = false; + } else { + gui.writeError(trans, fgrant, hgen); + } + } + return fail; + } + }); + } catch (Exception e) { + hgen.p("Unknown Error"); + e.printStackTrace(); + } finally { + tt.done(); + } + + hgen.br(); + hgen.incr("a",true,"href="+lastPage); + if (fail) { + hgen.text("Try again"); + } else { + hgen.text("Grant this Permission to Another Role"); + } + hgen.end(); + hgen.js() + .text("alterLink('permgrant', '"+lastPage + "');") + .done(); + + } + }); + } + }); + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/PermGrantForm.java b/authz-gui/src/main/java/com/att/authz/gui/pages/PermGrantForm.java new file mode 100644 index 00000000..bd3884f1 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/PermGrantForm.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import static com.att.xgen.html.HTMLGen.TABLE; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.List; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.Role; +import aaf.v2_0.Roles; + +public class PermGrantForm extends Page { + static final String HREF = "/gui/permgrant"; + static final String NAME = "Permission Grant"; + static final String fields[] = {"type","instance","action","role"}; + + public PermGrantForm(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final Slot type = gui.env.slot(NAME+".type"); + final Slot instance = gui.env.slot(NAME+".instance"); + final Slot action = gui.env.slot(NAME+".action"); + final Slot role = gui.env.slot(NAME+".role"); + // p tags not closing right using .p() - causes issues in IE8 password form - so using leaf for the moment + hgen.leaf("p").text("Choose a role to grant to this permission").end() + .incr("form","method=post"); + Mark table = new Mark(TABLE); + hgen.incr(table); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + + Mark copyRoleJS = new Mark(); + hgen.js(copyRoleJS); + hgen.text("function copyRole(role) {"); + hgen.text("var txtRole = document.querySelector(\"#role\");"); +// hgen.text("if (role==;"); + hgen.text("txtRole.value=role;"); + hgen.text("}"); + hgen.end(copyRoleJS); + + String typeValue = trans.get(type, ""); + String instanceValue = trans.get(instance, ""); + String actionValue = trans.get(action, ""); + String roleValue = trans.get(role,null); + List myRoles = getMyRoles(gui, trans); + hgen + .input(fields[0],"Perm Type",true,"value="+typeValue,"disabled") + .input(fields[1],"Perm Instance",true,"value="+instanceValue,"disabled") + .input(fields[2],"Perm Action",true,"value="+actionValue,"disabled"); + + // select & options are not an input type, so we must create table row & cell tags + Mark selectRow = new Mark(); + hgen + .incr(selectRow, "tr") + .incr("td") + .incr("label", "for=myroles", "required").text("My Roles").end() + .end() + .incr("td") + .incr("select", "name=myroles", "id=myroles", "onchange=copyRole(this.value)") + .incr("option", "value=").text("Select one of my roles").end(); + for (String role : myRoles) { + hgen.incr("option", "value="+role).text(role).end(); + } + hgen + .incr("option", "value=").text("Other").end() + .end(selectRow); + if(roleValue==null) { + hgen.input(fields[3],"Role", true, "placeholder=or type a role here"); + } else { + hgen.input(fields[3],"Role",true, "value="+roleValue); + } + hgen.end(); + } + }); + hgen.end(); + hgen.tagOnly("input", "type=submit", "value=Submit") + .end(); + + } + }); + } + + private static List getMyRoles(final AuthGUI gui, final AuthzTrans trans) { + List myRoles = new ArrayList(); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + TimeTaken tt = trans.start("AAF get my roles",Env.REMOTE); + try { + Future fr = client.read("/authz/roles/user/"+trans.user(),gui.rolesDF); + if(fr.get(5000)) { + tt.done(); + tt = trans.start("Load Data", Env.SUB); + if (fr.value != null) for (Role r : fr.value.getRole()) { + myRoles.add(r.getName()); + } + } else { + gui.writeError(trans, fr, null); + } + } finally { + tt.done(); + } + return null; + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + + return myRoles; + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/PermHistory.java b/authz-gui/src/main/java/com/att/authz/gui/pages/PermHistory.java new file mode 100644 index 00000000..0a204051 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/PermHistory.java @@ -0,0 +1,223 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Comparator; +import java.util.List; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.History; +import aaf.v2_0.History.Item; + + +public class PermHistory extends Page { + static final String NAME="PermHistory"; + static final String HREF = "/gui/permHistory"; + static final String FIELDS[] = {"type","instance","action","dates"}; + static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id="; + static enum Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, + AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER }; + + public PermHistory(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, FIELDS, + new BreadCrumbs(breadcrumbs), + new Table("History", gui.env.newTransNoAvg(),new Model(gui.env()),"class=std"), + new NamedCode(true, "content") { + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final Slot sType = gui.env.slot(NAME+".type"); + final Slot sInstance = gui.env.slot(NAME+".instance"); + final Slot sAction = gui.env.slot(NAME+".action"); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + String type = trans.get(sType, null); + String instance = trans.get(sInstance,null); + String action = trans.get(sAction,null); + + // Use Javascript to make the table title more descriptive + hgen.js() + .text("var caption = document.querySelector(\".title\");") + .text("caption.innerHTML='History for Permission [ " + type + " ]';") + .done(); + + // Use Javascript to change Link Target to our last visited Detail page + String lastPage = PermDetail.HREF + "?type=" + type + + "&instance=" + instance + + "&action=" + action; + hgen.js() + .text("alterLink('permdetail', '"+lastPage + "');") + .done(); + + hgen.br(); + hgen.leaf("a", "href=#advanced_search", "onclick=divVisibility('advanced_search');").text("Advanced Search").end() + .divID("advanced_search", "style=display:none"); + hgen.incr("table"); + + addDateRow(hgen,"Start Date"); + addDateRow(hgen,"End Date"); + hgen.incr("tr").incr("td"); + hgen.tagOnly("input", "type=button","value=Get History", + "onclick=datesURL('"+HREF+"?type=" + type + + "&instance=" + instance + + "&action=" + action+"');"); + hgen.end().end(); + hgen.end(); + hgen.end(); + } + }); + } + } + + ); + + } + + private static void addDateRow(HTMLGen hgen, String s) { + hgen + .incr("tr") + .incr("td") + .incr("label", "for=month", "required").text(s+"*").end() + .end() + .incr("td") + .incr("select", "name=month"+s.substring(0, s.indexOf(' ')), "id=month"+s.substring(0, s.indexOf(' ')), "required") + .incr("option", "value=").text("Month").end(); + for (Month m : Month.values()) { + if (Calendar.getInstance().get(Calendar.MONTH) == m.ordinal()) { + hgen.incr("option", "selected", "value="+(m.ordinal()+1)).text(m.name()).end(); + } else { + hgen.incr("option", "value="+(m.ordinal()+1)).text(m.name()).end(); + } + } + hgen.end() + .end() + .incr("td") + .tagOnly("input","type=number","id=year"+s.substring(0, s.indexOf(' ')),"required", + "value="+Calendar.getInstance().get(Calendar.YEAR), "min=1900", + "max="+Calendar.getInstance().get(Calendar.YEAR), + "placeholder=Year").end() + .end(); + } + + /** + * Implement the Table Content for History + * + * + */ + private static class Model implements Table.Data { + private static final String CSP_ATT_COM = "@csp.att.com"; + private static final String[] headers = new String[] {"Date","User","Memo"}; + private Slot sType; + private Slot sDates; + + public Model(AuthzEnv env) { + sType = env.slot(NAME+".type"); + sDates = env.slot(NAME+".dates"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + final String oName = trans.get(sType,null); + final String oDates = trans.get(sDates,null); + + if(oName==null) { + return Cells.EMPTY; + } + + ArrayList rv = new ArrayList(); + String msg = null; + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + TimeTaken tt = trans.start("AAF Get History for Permission ["+oName+"]",Env.REMOTE); + try { + if (oDates != null) { + client.setQueryParams("yyyymm="+oDates); + } + Future fh = client.read( + "/authz/hist/perm/"+oName, + gui.historyDF + ); + + + if (fh.get(AuthGUI.TIMEOUT)) { + tt.done(); + tt = trans.start("Load History Data", Env.SUB); + List histItems = fh.value.getItem(); + + java.util.Collections.sort(histItems, new Comparator() { + @Override + public int compare(Item o1, Item o2) { + return o2.getTimestamp().compare(o1.getTimestamp()); + } + }); + + for (Item i : histItems) { + String user = i.getUser(); + AbsCell userCell = (user.endsWith(CSP_ATT_COM)? + new RefCell(user,WEBPHONE + user.substring(0,user.indexOf('@'))):new TextCell(user)); + + rv.add(new AbsCell[] { + new TextCell(i.getTimestamp().toGregorianCalendar().getTime().toString()), + userCell, + new TextCell(i.getMemo()) + }); + } + + } else { + if (fh.code()==403) { + rv.add(new AbsCell[] {new TextCell("You may not view History of Permission [" + oName + "]", "colspan = 3", "class=center")}); + } else { + rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***", "colspan = 3", "class=center")}); + } + } + } finally { + tt.done(); + } + + return null; + } + }); + + } catch (Exception e) { + trans.error().log(e); + } + return new Cells(rv,msg); + } + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/PermsShow.java b/authz-gui/src/main/java/com/att/authz/gui/pages/PermsShow.java new file mode 100644 index 00000000..9af71ef7 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/PermsShow.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +import aaf.v2_0.Perm; +import aaf.v2_0.Perms; + +/** + * Page content for My Permissions + * + * + */ +public class PermsShow extends Page { + public static final String HREF = "/gui/myperms"; + + public PermsShow(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, "MyPerms",HREF, NO_FIELDS, + new BreadCrumbs(breadcrumbs), + new Table("Permissions",gui.env.newTransNoAvg(),new Model(), "class=std")); + } + + /** + * Implement the Table Content for Permissions by User + * + * + */ + private static class Model implements Table.Data { + private static final String[] headers = new String[] {"Type","Instance","Action"}; + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + ArrayList rv = new ArrayList(); + TimeTaken tt = trans.start("AAF Perms by User",Env.REMOTE); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future fp = client.read("/authz/perms/user/"+trans.user(), gui.permsDF); + if(fp.get(5000)) { + TimeTaken ttld = trans.start("Load Data", Env.SUB); + try { + if(fp.value!=null) { + for(Perm p : fp.value.getPerm()) { + AbsCell[] sa = new AbsCell[] { + new RefCell(p.getType(),PermDetail.HREF + +"?type="+p.getType() + +"&instance="+p.getInstance() + +"&action="+p.getAction()), + new TextCell(p.getInstance()), + new TextCell(p.getAction()) + }; + rv.add(sa); + } + } else { + gui.writeError(trans, fp, null); + } + } finally { + ttld.done(); + } + } + return null; + } + }); + } catch (Exception e) { + trans.error().log(e); + } finally { + tt.done(); + } + return new Cells(rv,null); + } + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/RequestDetail.java b/authz-gui/src/main/java/com/att/authz/gui/pages/RequestDetail.java new file mode 100644 index 00000000..a2d06cdf --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/RequestDetail.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.UUID; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; + +import aaf.v2_0.Approval; +import aaf.v2_0.Approvals; + +public class RequestDetail extends Page { + public static final String HREF = "/gui/requestdetail"; + public static final String NAME = "RequestDetail"; + private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final String[] FIELDS = {"ticket"}; + + public RequestDetail(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, NAME, HREF, FIELDS, + new BreadCrumbs(breadcrumbs), + new Table("Request Details",gui.env.newTransNoAvg(),new Model(gui.env()),"class=detail") + ); + } + + /** + * Implement the table content for Request Detail + * + * + */ + private static class Model implements Table.Data { + static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id="; + private static final String CSP_ATT_COM = "@csp.att.com"; + final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L; + private static final String[] headers = new String[0]; + private Slot sTicket; + public Model(AuthzEnv env) { + sTicket = env.slot(NAME+".ticket"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + Cells rv=Cells.EMPTY; + final String ticket = trans.get(sTicket, null); + if(ticket!=null) { + try { + rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Cells code(Rcli client) throws CadiException, ConnectException, APIException { + TimeTaken tt = trans.start("AAF Approval Details",Env.REMOTE); + ArrayList rv = new ArrayList(); + try { + Future fa = client.read( + "/authz/approval/ticket/"+ticket, + gui.approvalsDF + ); + + if(fa.get(AuthGUI.TIMEOUT)) { + if (!trans.user().equals(fa.value.getApprovals().get(0).getUser())) { + return Cells.EMPTY; + } + tt.done(); + tt = trans.start("Load Data", Env.SUB); + boolean first = true; + for ( Approval approval : fa.value.getApprovals()) { + AbsCell[] approverLine = new AbsCell[4]; + // only print common elements once + if (first) { + DateFormat createdDF = new SimpleDateFormat(DATE_TIME_FORMAT); + UUID id = UUID.fromString(approval.getId()); + + rv.add(new AbsCell[]{new TextCell("Ticket ID:"),new TextCell(approval.getTicket(),"colspan=3")}); + rv.add(new AbsCell[]{new TextCell("Memo:"),new TextCell(approval.getMemo(),"colspan=3")}); + rv.add(new AbsCell[]{new TextCell("Requested On:"), + new TextCell(createdDF.format((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000),"colspan=3") + }); + rv.add(new AbsCell[]{new TextCell("Operation:"),new TextCell(decodeOp(approval.getOperation()),"colspan=3")}); + String user = approval.getUser(); + if (user.endsWith(CSP_ATT_COM)) { + rv.add(new AbsCell[]{new TextCell("User:"), + new RefCell(user,WEBPHONE + user.substring(0, user.indexOf("@")),"colspan=3")}); + } else { + rv.add(new AbsCell[]{new TextCell("User:"),new TextCell(user,"colspan=3")}); + } + + // headers for listing each approver + rv.add(new AbsCell[]{new TextCell(" ","colspan=4","class=blank_line")}); + rv.add(new AbsCell[]{AbsCell.Null, + new TextCell("Approver","class=bold"), + new TextCell("Type","class=bold"), + new TextCell("Status","class=bold")}); + approverLine[0] = new TextCell("Approvals:"); + + first = false; + } else { + approverLine[0] = AbsCell.Null; + } + + String approver = approval.getApprover(); + String approverShort = approver.substring(0,approver.indexOf('@')); + + if (approver.endsWith(CSP_ATT_COM)) { + approverLine[1] = new RefCell(approver, WEBPHONE + approverShort); + } else { + approverLine[1] = new TextCell(approval.getApprover()); + } + + String type = approval.getType(); + if ("owner".equalsIgnoreCase(type)) { + type = "resource owner"; + } + + approverLine[2] = new TextCell(type); + approverLine[3] = new TextCell(approval.getStatus()); + rv.add(approverLine); + + } + } else { + rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")}); + } + } finally { + tt.done(); + } + return new Cells(rv,null); + } + }); + } catch (Exception e) { + trans.error().log(e); + } + } + return rv; + } + + private String decodeOp(String operation) { + if ("C".equalsIgnoreCase(operation)) { + return "Create"; + } else if ("D".equalsIgnoreCase(operation)) { + return "Delete"; + } else if ("U".equalsIgnoreCase(operation)) { + return "Update"; + } else if ("G".equalsIgnoreCase(operation)) { + return "Grant"; + } else if ("UG".equalsIgnoreCase(operation)) { + return "Un-Grant"; + } + return operation; + } + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/RoleDetail.java b/authz-gui/src/main/java/com/att/authz/gui/pages/RoleDetail.java new file mode 100644 index 00000000..426928b8 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/RoleDetail.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; + +import aaf.v2_0.Pkey; +import aaf.v2_0.Role; +import aaf.v2_0.Roles; + +/** + * Detail Page for Permissions + * + * + */ +public class RoleDetail extends Page { + public static final String HREF = "/gui/roledetail"; + public static final String NAME = "RoleDetail"; + private static final String BLANK = ""; + + public RoleDetail(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, NAME, HREF, new String[] {"role"}, + new BreadCrumbs(breadcrumbs), + new Table("Role Details",gui.env.newTransNoAvg(),new Model(gui.env()),"class=detail") + ); + } + + /** + * Implement the table content for Permissions Detail + * + * + */ + private static class Model implements Table.Data { + private static final String[] headers = new String[0]; + private Slot role; + public Model(AuthzEnv env) { + role = env.slot(NAME+".role"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + final String pRole = trans.get(role, null); + Cells rv = Cells.EMPTY; + if(pRole!=null) { + try { + rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Cells code(Rcli client) throws CadiException, ConnectException, APIException { + ArrayList rv = new ArrayList(); + rv.add(new AbsCell[]{new TextCell("Role:"),new TextCell(pRole)}); + + TimeTaken tt = trans.start("AAF Role Details",Env.REMOTE); + try { + + Future fr = client.read("/authz/roles/"+pRole,gui.rolesDF); + if(fr.get(AuthGUI.TIMEOUT)) { + tt.done(); + tt = trans.start("Load Data", Env.SUB); + Role role = fr.value.getRole().get(0); + String desc = (role.getDescription()!=null?role.getDescription():BLANK); + rv.add(new AbsCell[]{new TextCell("Description:"),new TextCell(desc)}); + boolean first=true; + for(Pkey r : role.getPerms()) { + if(first){ + first=false; + rv.add(new AbsCell[] { + new TextCell("Associated Permissions:"), + new TextCell(r.getType() + + " | " + r.getInstance() + + " | " + r.getAction() + ) + }); + } else { + rv.add(new AbsCell[] { + AbsCell.Null, + new TextCell(r.getType() + + " | " + r.getInstance() + + " | " + r.getAction() + ) + }); + } + } + String historyLink = RoleHistory.HREF + + "?role=" + pRole; + rv.add(new AbsCell[] {new RefCell("See History",historyLink)}); + } else { + rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")}); + } + } finally { + tt.done(); + } + return new Cells(rv,null); + } + }); + } catch (Exception e) { + trans.error().log(e); + } + } + return rv; + } + } +} + \ No newline at end of file diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/RoleHistory.java b/authz-gui/src/main/java/com/att/authz/gui/pages/RoleHistory.java new file mode 100644 index 00000000..80f1bc51 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/RoleHistory.java @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + + +import java.io.IOException; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Comparator; +import java.util.List; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +import aaf.v2_0.History; +import aaf.v2_0.History.Item; + + +public class RoleHistory extends Page { + static final String NAME="RoleHistory"; + static final String HREF = "/gui/roleHistory"; + static final String FIELDS[] = {"role","dates"}; + static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id="; + static enum Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, + AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER }; + + public RoleHistory(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, FIELDS, + new BreadCrumbs(breadcrumbs), + new Table("History", gui.env.newTransNoAvg(),new Model(gui.env()),"class=std"), + new NamedCode(true, "content") { + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final Slot role = gui.env.slot(NAME+".role"); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + String obRole = trans.get(role, null); + + // Use Javascript to make the table title more descriptive + hgen.js() + .text("var caption = document.querySelector(\".title\");") + .text("caption.innerHTML='History for Role [ " + obRole + " ]';") + .done(); + + // Use Javascript to change Link Target to our last visited Detail page + String lastPage = RoleDetail.HREF + "?role=" + obRole; + hgen.js() + .text("alterLink('roledetail', '"+lastPage + "');") + .done(); + + hgen.br(); + hgen.leaf("a", "href=#advanced_search","onclick=divVisibility('advanced_search');").text("Advanced Search").end() + .divID("advanced_search", "style=display:none"); + hgen.incr("table"); + + addDateRow(hgen,"Start Date"); + addDateRow(hgen,"End Date"); + hgen.incr("tr").incr("td"); + hgen.tagOnly("input", "type=button","value=Get History", + "onclick=datesURL('"+HREF+"?role=" + obRole+"');"); + hgen.end().end(); + hgen.end(); + hgen.end(); + } + }); + } + } + + ); + + } + + private static void addDateRow(HTMLGen hgen, String s) { + hgen + .incr("tr") + .incr("td") + .incr("label", "for=month", "required").text(s+"*").end() + .end() + .incr("td") + .incr("select", "name=month"+s.substring(0, s.indexOf(' ')), "id=month"+s.substring(0, s.indexOf(' ')), "required") + .incr("option", "value=").text("Month").end(); + for (Month m : Month.values()) { + if (Calendar.getInstance().get(Calendar.MONTH) == m.ordinal()) { + hgen.incr("option", "selected", "value="+(m.ordinal()+1)).text(m.name()).end(); + } else { + hgen.incr("option", "value="+(m.ordinal()+1)).text(m.name()).end(); + } + } + hgen.end() + .end() + .incr("td") + .tagOnly("input","type=number","id=year"+s.substring(0, s.indexOf(' ')),"required", + "value="+Calendar.getInstance().get(Calendar.YEAR), "min=1900", + "max="+Calendar.getInstance().get(Calendar.YEAR), + "placeholder=Year").end() + .end(); + } + + + /** + * Implement the Table Content for History + * + * + */ + private static class Model implements Table.Data { + private static final String CSP_ATT_COM = "@csp.att.com"; + private static final String[] headers = new String[] {"Date","User","Memo"}; + private Slot role; + private Slot dates; + + public Model(AuthzEnv env) { + role = env.slot(NAME+".role"); + dates = env.slot(NAME+".dates"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + final String oName = trans.get(role,null); + final String oDates = trans.get(dates,null); + + Cells rv = Cells.EMPTY; + if(oName!=null) { + + try { + rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Cells code(Rcli client) throws CadiException, ConnectException, APIException { + ArrayList rv = new ArrayList(); + TimeTaken tt = trans.start("AAF Get History for Namespace ["+oName+"]",Env.REMOTE); + String msg = null; + try { + if (oDates != null) { + client.setQueryParams("yyyymm="+oDates); + } + Future fh = client.read("/authz/hist/role/"+oName,gui.historyDF); + if (fh.get(AuthGUI.TIMEOUT)) { + tt.done(); + tt = trans.start("Load History Data", Env.SUB); + List histItems = fh.value.getItem(); + + java.util.Collections.sort(histItems, new Comparator() { + @Override + public int compare(Item o1, Item o2) { + return o2.getTimestamp().compare(o1.getTimestamp()); + } + }); + + for (Item i : histItems) { + String user = i.getUser(); + AbsCell userCell = (user.endsWith(CSP_ATT_COM)? + new RefCell(user,WEBPHONE + user.substring(0,user.indexOf('@'))):new TextCell(user)); + + rv.add(new AbsCell[] { + new TextCell(i.getTimestamp().toGregorianCalendar().getTime().toString()), + userCell, + new TextCell(i.getMemo()) + }); + } + } else { + if (fh.code()==403) { + rv.add(new AbsCell[] {new TextCell("You may not view History of Permission [" + oName + "]", "colspan = 3", "class=center")}); + } else { + rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***", "colspan = 3", "class=center")}); + } + } + } finally { + tt.done(); + } + return new Cells(rv,msg); + } + }); + } catch (Exception e) { + trans.error().log(e); + } + } + return rv; + } + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/RolesShow.java b/authz-gui/src/main/java/com/att/authz/gui/pages/RolesShow.java new file mode 100644 index 00000000..e1d93eeb --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/RolesShow.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.Page; +import com.att.authz.gui.Table; +import com.att.authz.gui.Table.Cells; +import com.att.authz.gui.table.AbsCell; +import com.att.authz.gui.table.RefCell; +import com.att.authz.gui.table.TextCell; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Chrono; + +import aaf.v2_0.UserRole; +import aaf.v2_0.UserRoles; + + +/** + * Page content for My Roles + * + * + */ +public class RolesShow extends Page { + public static final String HREF = "/gui/myroles"; + private static final String DATE_TIME_FORMAT = "yyyy-MM-dd"; + private static SimpleDateFormat expiresDF; + + static { + expiresDF = new SimpleDateFormat(DATE_TIME_FORMAT); + } + + public RolesShow(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, "MyRoles",HREF, NO_FIELDS, + new BreadCrumbs(breadcrumbs), + new Table("Roles",gui.env.newTransNoAvg(),new Model(), "class=std")); + } + + /** + * Implement the Table Content for Permissions by User + * + * + */ + private static class Model implements Table.Data { + private static final String[] headers = new String[] {"Role","Expires","Remediation","Actions"}; + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthGUI gui, final AuthzTrans trans) { + Cells rv = Cells.EMPTY; + + try { + rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Cells code(Rcli client) throws CadiException, ConnectException, APIException { + ArrayList rv = new ArrayList(); + TimeTaken tt = trans.start("AAF Roles by User",Env.REMOTE); + try { + Future fur = client.read("/authz/userRoles/user/"+trans.user(),gui.userrolesDF); + if (fur.get(5000)) { + if(fur.value != null) for (UserRole u : fur.value.getUserRole()) { + if(u.getExpires().compare(Chrono.timeStamp()) < 0) { + AbsCell[] sa = new AbsCell[] { + new TextCell(u.getRole() + "*", "class=expired"), + new TextCell(expiresDF.format(u.getExpires().toGregorianCalendar().getTime()),"class=expired"), + new RefCell("Extend", + UserRoleExtend.HREF + "?user="+trans.user()+"&role="+u.getRole(), + new String[]{"class=expired"}), + new RefCell("Remove", + UserRoleRemove.HREF + "?user="+trans.user()+"&role="+u.getRole(), + new String[]{"class=expired"}) + + }; + rv.add(sa); + } else { + AbsCell[] sa = new AbsCell[] { + new RefCell(u.getRole(), + RoleDetail.HREF+"?role="+u.getRole()), + new TextCell(expiresDF.format(u.getExpires().toGregorianCalendar().getTime())), + AbsCell.Null, + new RefCell("Remove", + UserRoleRemove.HREF + "?user="+trans.user()+"&role="+u.getRole()) + }; + rv.add(sa); + } + } + } + + } finally { + tt.done(); + } + return new Cells(rv,null); + } + }); + } catch (Exception e) { + trans.error().log(e); + } + return rv; + } + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleExtend.java b/authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleExtend.java new file mode 100644 index 00000000..1dc057da --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleExtend.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +public class UserRoleExtend extends Page { + public static final String HREF = "/gui/urExtend"; + static final String NAME = "Extend User Role"; + static final String fields[] = {"user","role"}; + + public UserRoleExtend(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME, HREF, fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true, "content") { + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final Slot sUser = gui.env.slot(NAME+".user"); + final Slot sRole = gui.env.slot(NAME+".role"); + + + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + final String user = trans.get(sUser, ""); + final String role = trans.get(sRole, ""); + + TimeTaken tt = trans.start("Request to extend user role",Env.REMOTE); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client)throws CadiException, ConnectException, APIException { + Future fv = client.setQueryParams("request=true").update("/authz/userRole/extend/"+user+"/"+role); + if(fv.get(5000)) { + // not sure if we'll ever hit this + hgen.p("Extended User ["+ user+"] in Role [" +role+"]"); + } else { + if (fv.code() == 202 ) { + hgen.p("User ["+ user+"] in Role [" +role+"] Extension sent for Approval"); + } else { + gui.writeError(trans, fv, hgen); + } + } + return null; + } + }); + } catch (Exception e) { + trans.error().log(e); + e.printStackTrace(); + } finally { + tt.done(); + } + + + } + }); + } + + }); + } +} + diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleRemove.java b/authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleRemove.java new file mode 100644 index 00000000..0140a7f6 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleRemove.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; +import java.net.ConnectException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.Slot; +import com.att.inno.env.TimeTaken; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.html.HTMLGen; + +public class UserRoleRemove extends Page { + public static final String HREF = "/gui/urRemove"; + static final String NAME = "Remove User Role"; + static final String fields[] = {"user","role"}; + + public UserRoleRemove(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME, HREF, fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true, "content") { + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final Slot sUser = gui.env.slot(NAME+".user"); + final Slot sRole = gui.env.slot(NAME+".role"); + + + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI gui, AuthzTrans trans, Cache cache, HTMLGen hgen) throws APIException, IOException { + final String user = trans.get(sUser, ""); + final String role = trans.get(sRole, ""); + + TimeTaken tt = trans.start("Request a user role delete",Env.REMOTE); + try { + gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future fv = client.setQueryParams("request=true").delete( + "/authz/userRole/"+user+"/"+role,Void.class); + + if(fv.get(5000)) { + // not sure if we'll ever hit this + hgen.p("User ["+ user+"] Removed from Role [" +role+"]"); + } else { + if (fv.code() == 202 ) { + hgen.p("User ["+ user+"] Removal from Role [" +role+"] sent for Approval"); + } else { + gui.writeError(trans, fv, hgen); + } + } + return null; + } + }); + } catch (Exception e) { + e.printStackTrace(); + } finally { + tt.done(); + } + } + }); + } + + }); + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/pages/WebCommand.java b/authz-gui/src/main/java/com/att/authz/gui/pages/WebCommand.java new file mode 100644 index 00000000..a13beb58 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/pages/WebCommand.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.pages; + +import java.io.IOException; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gui.AuthGUI; +import com.att.authz.gui.BreadCrumbs; +import com.att.authz.gui.NamedCode; +import com.att.authz.gui.Page; +import com.att.inno.env.APIException; +import com.att.xgen.Cache; +import com.att.xgen.DynamicCode; +import com.att.xgen.Mark; +import com.att.xgen.html.HTMLGen; + +public class WebCommand extends Page { + public static final String HREF = "/gui/cui"; + + public WebCommand(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env, "Web Command Client",HREF, NO_FIELDS, + new BreadCrumbs(breadcrumbs), + new NamedCode(true, "content") { + @Override + public void code(Cache cache, HTMLGen hgen) throws APIException, IOException { + hgen.leaf("p","id=help_msg") + .text("Questions about this page? ") + .leaf("a", "href=http://wiki.web.att.com/display/aaf/Web+CUI+Usage", "target=_blank") + .text("Click here") + .end() + .text(". Type 'help' below for a list of AAF commands") + .end() + + .divID("console_and_options"); + hgen.divID("console_area"); + hgen.end(); //console_area + + hgen.divID("options_link", "class=closed"); + hgen.img("src=../../theme/options_down.png", "onclick=handleDivHiding('options',this);", + "id=options_img", "alt=Options", "title=Options") + .end(); //options_link + + hgen.divID("options"); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AuthGUI state, AuthzTrans trans, Cache cache, HTMLGen xgen) + throws APIException, IOException { + switch(browser(trans,trans.env().slot(getBrowserType()))) { + case ie: + case ieOld: + // IE doesn't support file save + break; + default: + xgen.img("src=../../theme/AAFdownload.png", "onclick=saveToFile();", + "alt=Save log to file", "title=Save log to file"); + } +// xgen.img("src=../../theme/AAFemail.png", "onclick=emailLog();", +// "alt=Email log to me", "title=Email log to me"); + xgen.img("src=../../theme/AAF_font_size.png", "onclick=handleDivHiding('text_slider',this);", + "id=fontsize_img", "alt=Change text size", "title=Change text size"); + xgen.img("src=../../theme/AAF_details.png", "onclick=selectOption(this,0);", + "id=details_img", "alt=Turn on/off details mode", "title=Turn on/off details mode"); + xgen.img("src=../../theme/AAF_maximize.png", "onclick=maximizeConsole(this);", + "id=maximize_img", "alt=Maximize Console Window", "title=Maximize Console Window"); + } + }); + + hgen.divID("text_slider"); + hgen.tagOnly("input", "type=button", "class=change_font", "onclick=buttonChangeFontSize('dec')", "value=-") + .tagOnly("input", "id=text_size_slider", "type=range", "min=75", "max=200", "value=100", + "oninput=changeFontSize(this.value)", "onchange=changeFontSize(this.value)", "title=Change Text Size") + .tagOnly("input", "type=button", "class=change_font", "onclick=buttonChangeFontSize('inc')", "value=+") + .end(); //text_slider + + hgen.end(); //options + hgen.end(); //console_and_options + + hgen.divID("input_area"); + hgen.tagOnly("input", "type=text", "id=command_field", + "autocomplete=off", "autocorrect=off", "autocapitalize=off", "spellcheck=false", + "onkeypress=keyPressed()", "placeholder=Type your AAFCLI commands here", "autofocus") + .tagOnly("input", "id=submit", "type=button", "value=Submit", + "onclick=http('put','../../gui/cui',getCommand(),callCUI);") + .end(); + + Mark callCUI = new Mark(); + hgen.js(callCUI); + hgen.text("function callCUI(resp) {") + .text("moveCommandToDiv();") + .text("printResponse(resp);") + .text("}"); + hgen.end(callCUI); + + } + }); + + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/table/AbsCell.java b/authz-gui/src/main/java/com/att/authz/gui/table/AbsCell.java new file mode 100644 index 00000000..eb91c22a --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/table/AbsCell.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.table; + +import com.att.xgen.html.HTMLGen; + +public abstract class AbsCell { + private static final String[] NONE = new String[0]; + protected static final String[] CENTER = new String[]{"class=center"}; + + /** + * Write Cell Data with HTMLGen generator + * @param hgen + */ + public abstract void write(HTMLGen hgen); + + public final static AbsCell Null = new AbsCell() { + @Override + public void write(final HTMLGen hgen) { + } + }; + + public String[] attrs() { + return NONE; + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/table/ButtonCell.java b/authz-gui/src/main/java/com/att/authz/gui/table/ButtonCell.java new file mode 100644 index 00000000..4c270cfc --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/table/ButtonCell.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.table; + +import com.att.xgen.html.HTMLGen; + +public class ButtonCell extends AbsCell { + private String[] attrs; + + public ButtonCell(String value, String ... attributes) { + attrs = new String[2+attributes.length]; + attrs[0]="type=button"; + attrs[1]="value="+value; + System.arraycopy(attributes, 0, attrs, 2, attributes.length); + } + @Override + public void write(HTMLGen hgen) { + hgen.incr("input",true,attrs).end(); + + } + + @Override + public String[] attrs() { + return AbsCell.CENTER; + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/table/RadioCell.java b/authz-gui/src/main/java/com/att/authz/gui/table/RadioCell.java new file mode 100644 index 00000000..b4fa6440 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/table/RadioCell.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.table; + +import com.att.xgen.html.HTMLGen; + +public class RadioCell extends AbsCell { + private String[] attrs; + + public RadioCell(String name, String radioClass, String value, String ... attributes) { + attrs = new String[4+attributes.length]; + attrs[0]="type=radio"; + attrs[1]="name="+name; + attrs[2]="class="+radioClass; + attrs[3]="value="+value; + System.arraycopy(attributes, 0, attrs, 4, attributes.length); + } + + @Override + public void write(HTMLGen hgen) { + hgen.incr("input",true,attrs).end(); + } + + @Override + public String[] attrs() { + return AbsCell.CENTER; + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/table/RefCell.java b/authz-gui/src/main/java/com/att/authz/gui/table/RefCell.java new file mode 100644 index 00000000..49719837 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/table/RefCell.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.table; + +import static com.att.xgen.html.HTMLGen.A; + +import com.att.xgen.html.HTMLGen; + +/** + * Write a Reference Link into a Cell + * + */ +public class RefCell extends AbsCell { + public final String name; + public final String href; + private String[] attrs; + + public RefCell(String name, String href, String... attributes) { + attrs = new String[attributes.length]; + System.arraycopy(attributes, 0, attrs, 0, attributes.length); + this.name = name; + this.href = href; + } + + @Override + public void write(HTMLGen hgen) { + hgen.leaf(A,"href="+href).text(name); + } + + @Override + public String[] attrs() { + return attrs; + } +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/table/TextAndRefCell.java b/authz-gui/src/main/java/com/att/authz/gui/table/TextAndRefCell.java new file mode 100644 index 00000000..1c25361b --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/table/TextAndRefCell.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.table; + +import static com.att.xgen.html.HTMLGen.A; + +import com.att.xgen.html.HTMLGen; + +public class TextAndRefCell extends RefCell { + + private String text; + + public TextAndRefCell(String text, String name, String href, String[] attributes) { + super(name, href, attributes); + this.text = text; + } + + @Override + public void write(HTMLGen hgen) { + hgen.text(text); + hgen.leaf(A,"href="+href).text(name); + } + +} diff --git a/authz-gui/src/main/java/com/att/authz/gui/table/TextCell.java b/authz-gui/src/main/java/com/att/authz/gui/table/TextCell.java new file mode 100644 index 00000000..d0987920 --- /dev/null +++ b/authz-gui/src/main/java/com/att/authz/gui/table/TextCell.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +package com.att.authz.gui.table; + +import com.att.xgen.html.HTMLGen; + +/** + * Write Simple Text into a Cell + * + */ +public class TextCell extends AbsCell { + public final String name; + private String[] attrs; + + public TextCell(String name, String... attributes) { + attrs = new String[attributes.length]; + System.arraycopy(attributes, 0, attrs, 0, attributes.length); + this.name = name; + } + + @Override + public void write(HTMLGen hgen) { + hgen.text(name); + } + + @Override + public String[] attrs() { + return attrs; + } +} diff --git a/authz-gui/theme/AAF_details.png b/authz-gui/theme/AAF_details.png new file mode 100644 index 0000000000000000000000000000000000000000..5c187459255b22df00373dda3f2b8ae0b2059575 GIT binary patch literal 650 zcmV;50(Jd~P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0v}04K~zXf<(Azm z!%-N=CodP0T!@lf;Kq%6S4#Na!PokWb#e?M?0 z8UGK^e{7`^wR%xM`baDBMPtyHD3VA3V=ctsGiF2jhyf7y>qk%J)B%**tie<1E!wJ? zL+H-=5{|(I5cdn4GqY_WyIlwMZd}Zs+;puOF#_dw=&VnkkPMN4l98R9cAe?L1(E!C zeSWM7%4pS=jT@o@cwT++b*la?lf~hNm;%U`&XODF{x-nw_9BzhN7qd3RBIi^M# z)e7)%mVB{daz7}bbaXGjdnH;x`NTfL?AbVnkPx#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&1eHldK~z{r-B(>q z990zlc6N8@!U_nKp9K_!B4|rODG$~*txaiDkyI;b)x`KvQxl)8Hq}-P^{1L>qA{jE z_+sS6#8ew2rqncTjWPOw6$3^aTjL)Tq=_x%Z)ay`{mz};%L2>NNV6s$GVGn1bMHC# zJKs6?j3-7Zefb1N$1V801~MUb)WPzgiQ$f|@RYpN6B`)|!}NPIVO!g#CO{Kj2pm{4hMG9eH?lIif5$>14?cVA{r$ z>u%LH9%Aeh^8BV+z;U2ZT0oZMfH2*g(Y|oEiEO6jBf8+AX);fTCJo8dwkP-oFDuRvGMc7zVLNO^cA@9FhN14DYseT@~c7a-$&1g31fx~*PM-n*Uzv!e4MB>DDl zm`T0PljnelgUAGPpAL7N;C)=)Y`YzpjHC>~tV$@PlFAi6+=`?9Lx>XkT@B^%Jar7d zEI*8RRTDiw$J5kP@DktdpN3(0JV?~NN$$9PRY)5xJN!9@ud?r$bNbFgz~Q8AwZ&@E zk*|M6SMQ%{+}?E4EC@yK-g;M0gm%$ZU#hC$J@G5qxahpNtCEl4&%R>1Z`bYp^YCuHv)$ZNGjvXIpG9D_+Ibt+JSd> zG{6bZ98d}Y@w6b@k4hGmfsrxcqE0z^7w{XXWlbMtj!!XEq1|Bh?=lMT4nCN={3q?!-0000Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0p>|WK~z{r#h1HI z!!Q(vkJH;i*h;I;6+27Es7O>Gb>IQIbtghXER+p8m4Vk_r&4(hB;J9`1}wb>pWJZV zIJPS{JyRl``2WuD6DNmwH0t*+@bx=`V!?tuVzFF7b*~KXx2HgAcN6d9dkW=JArI|X zV>VwxZNCE6C#^hhail;^)V4~gwiC_`{@#pPs4duZk5h>5*Fjnx2i`jN#zdN3$AdLs z(6*u3K7@XVK#-A7%fM3r5U$}x zF{3gVCo-`iu_w|(p$QdLGt!7a93R;tfDNO|E=-3GJk-Q=TLg$iZE)QHWK>@V$pL@? zxu77uMuH-<3HfG9Gcv7tgXeGy9B`|_Qk3qvVa?i|$a100000NkvXXu0mjfZv*?B literal 0 HcmV?d00001 diff --git a/authz-gui/theme/AAFdownload.png b/authz-gui/theme/AAFdownload.png new file mode 100644 index 0000000000000000000000000000000000000000..cebd95223478bf7168c05b5b2162d926ae31d98e GIT binary patch literal 1834 zcmV+_2i5qAP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&2ER!}K~z{rwO4D1 zRaF%J_IcgMTpgX!e9f4Taq?A>rYWhQR7Cp2#0VsbAR>B685mLIk6uP3YCn2F)DNj2 zfuKeBt1u`S1yg!6=37V8nYlUldCoq&Z|!p@9i6MFxi9;kbI;j(t+m(s*0 zK792{6{k-W5yFAO|2>QqDBqr|(AMf>`Rp7f4@*PsIax5Te%^(S?+ehef#dw&%0=G! zBSl&xm-et^X%-t+v_h@ldCYA3=q$26?Q>mw{>0uJGsKj#4w1(GmJWl**!>ndKGLP(m`xF^WZs^fcE9l&)-q=R4355w~*V z5wrj2B78qd6R5$HkkLUkGMLkr#>0ym(Z_qo)Ycjo4LOb1KRttdq(NVz|J8+1mep1V zzbZWV>ZK#0R=j)C{N9I;-x0Lg-ZQ!FM+F%gN5WPVNUz$qbE%9(zSINiqY;sWU((R$Q%@#SOq5(a zT_(DY9mK})THgS^<{D-I*UFv&a^$ytCVF^fD6IEmEivOmKgr#M#l%v^lZ(aWxr~c> zZCT75pFwL=V!*(BNq)^3m&T0oDa@IYvN0ATtUU3Y;KKs622_fX1W*fKJYrIf0b+vD zScFHmda+7V3F|`aqR(i2@^mAnjmagdW3J^=B^20iO{{G(ld=7W65jaw6ozssGSQ1LH zPG>nAhWNl=Bf)1urq# zGeV^lq3@hVp%9V6`MVk-)Gk&o9!&$DJ!p=1hqYLY{o<&p2AY>G^xW4KkGG&G#pugyDk!RVKl`u3|zGzeu zmRew}Adeq8S+S^)r^UT_7N9Vs)egc61v6_FuI)s}p9PBn*|T}uX*{!~3qGnSmmHg3 zVHxNtRM1y&D2pT}*kS18Q`2bg>48J^K(9ru#IQ;*j>tK9@5u=$R;z5E(pdfW9~Q+- z9-b_Osk-Q{g!pOmG;|y|hsWPJj+>fgzY@67y)kCC=J4_(BT*_CdH`6x;Q)r_SjKCi zE3+0nxQHQ`%@7+>9XWite!_n;)O~v~wpsijIpCsP)eHe!GSPZI=ZR7Zy|^o!IW~=U=6735 z8k1TwXdjnF`^_0lY4I>)at`f$KBYB-$$U4tC5v0e11;7gG9)`h2b&pUK&Ehk?Vuzo zchUo=y9<_LB`rcy^O)f-cE2wk&`cR_w!k4au5xICRN7pLeXwjV#?iCl0XcQK3Oq2M z5NjQ-aEF z041XP*3mhrdtW+iA{HBAv{?H@tyDu9S8gn?J}`28s~){Y4|h-CpVO`1^_evvpTw-` z85SPaXO`a^IRs(76@_1ai?Qp?W+AZ9e6zcZFLo7CWeP}3bt4CB8JaU5o>-Q`?UQo& Y7c^3lExr!}S^xk507*qoM6N<$g5c0h;s5{u literal 0 HcmV?d00001 diff --git a/authz-gui/theme/AAFemail.png b/authz-gui/theme/AAFemail.png new file mode 100644 index 0000000000000000000000000000000000000000..6d48776998fe16cdbbfdaade33e9be89b8663901 GIT binary patch literal 2277 zcmVv00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&2zp6GK~z{rtypc0 zTvZu<&dkp4%r&)$!@ z_uS_^@B2RQdyeyLy@PjRyfh7D+5out&pCKr>6{mcFT%CXQ|!sT@Y8|^jS+=+^^o4v zJv-+G|8(gi{SaTHRzsmXi{j4?!1ccW4qq(I0G(O5G(ond;8H|j-4KRj7~Jl?!RCqB z8!UnssJQzE??(-w!RvYreyW1Lo*WTuKIGArhwEsE%cR-c;8Q%drDLFCF#)FYgv}-u z%K$7e36qH#3|K@KdDMBm4qqqGYR$T*g`L}ayGLgZ$Yqgg&%hI8N@hS8B4&5MS;_?(J*kHz?^{2RN*V^d06y`#g< z!E-yd^m- zKGo9+m(OxQ0pY{^sN;hI?PzNAQL$*&ZZ$bAQf;8n*^Uovd=vIoxgqw zPyY2RUOqR8_8dX92AMG#Gb%rHX66PW28)x4)u(3=vAfb#01F1qPM|b##PM8}CN_}Mh{{z1 zNd&Q9*sLt-)I)q2d!f&PQRnR2IhnZt|8jP6){~EYY!lXATtHR9(At_-Nh~CClfV+D z_&QcQIjcaLP)JV#EF);mt$8z!ZN^+V^)|1_v4Enx!U~m2hX2r{4S&7`OkE5-F@+S8&3y}m8VY*0P zWCS9j>^Mmedo;xiSRBPQyY|D~blm&e$SM5v8}|S!R={;L(j^g+3(0~aUAk#N>B7uP z9DW|iXHJb_c&f^Tbv`3mc4MTcd2jo-evgbMtf-brldNI@712Q#rHu?0jEvwtd-fu; zat++zcf4QSPa?a4`@eh?(<7t6%8QWh>V#)tq@-s8O8xR}8Kej{A{%x2*s=3W-tns! zap2p3018YD!bxe8Ip6X2OK|dqv&c{d%;01(B706Im0Jm15bmf<_J&81BU!iXzZD}T z;MHOBvTo;Xw@JpNq1$(C#=x4j`17+TY-UzuG_wTtQXHxnkj3aj6=Hes`c-D~Etjpp zws)?^Q~xOksbv zIBx#v4JZ}?CL5GlRv450^y@<2+!0+}B!KVV{`n)8s@%%Hm`!B{3cayPvqkjL2H6}x zx&uABzewBiwWsj(-^nJ;-efQ2=7=c#$e7X|4u0iJv=lH-ysRxSE@CI*f@@Zr;g5VC zM~)rDyS8nC|JP|WCZ?D}r)}1#Xy#;@*#Ts~K*{;dKWUQ%+I_!$2~R)&3euF7*sOei zn#>VJW4r|a@+n+(?PeUlj{x~yeSdD7$E0E;1TpfRz_~Le96NH%rsMj0;c^VBX0FX3 z;>gi70h7(W*T2mQ8A))KL3Y;@e=;9TXZSKpFGf)eR3M9_h}U}$?Zd#uU6^95sMe6? zSNLcvlM8}OW}{r6rz_ll?{WP5#7STvNL4Vua=aqnz}A!|LgN=x)JAEabXTbkGc`o? zKSjfuD>vd(dv~E+HWjiae}7#d^|Asb%b-2+%nNw*!AF4Z98y85Or}hlXnXldQn4#z zktt(PfnwT6M5E*Q&?k1|%1u{bhCbJtgmkV~IF}1BSpZlFK{Y^P?hCn?iX^GX(80S= zo}jrTRb

7*wq26F+hMnlgz|B!Ke6(IWEQ-8eAxSsR*3ZeD8zSt8*RA#h@I3nWdN zCy2#BCaf|!;m1!rho2vR%x0JB=ZrpJ-Mn`6|*NSvO zknbbNfn|V92F(%IE6mpqe*Gboi(_y-%m!9}vUs*in*hgHOBTAZ=aaYK(lveNe~Yzw zAo=_-$S$`RZ?%jv} zf&UG#`MnE(aAMNTtz{0)%}i)Zo8`3b9^fA@4&%v3e~414#30LKaOVx!u<;U1(sh^G zWB?^31aKe=c?4xuM6bdcbj92MU5!a2X@6KH%9Q2-N1hVbXU`AAlV`O00000NkvXXu0mjf0s392 literal 0 HcmV?d00001 diff --git a/authz-gui/theme/aaf5.css b/authz-gui/theme/aaf5.css new file mode 100644 index 00000000..920bdab7 --- /dev/null +++ b/authz-gui/theme/aaf5.css @@ -0,0 +1,524 @@ +/* + Standard CSS for AAF +*/ + +html { + height: 100%; +} + +body { + background-image:url('t_bubbles.jpg'); + background-color: #FFFFFF; + background-repeat:no-repeat; + background-position: right top; + background-size:15em 4.3em; + color:#606060; + font-family: Verdana,Arial,Helvetica,sans-serif; + overflow: scroll; + } + +header h1,p { + margin: 4px auto; +} + +header h1 { + display: inline; +} + +header { + display: block; + color: #F13099; +} + +p#version { + margin:0; + display:inline; + font-size: 0.75em; + float:right; + color: orange; + padding-right:4.2em; +} + +header hr { + margin: 0; +} + +hr { + border: 1px solid #C0C0C0; +} + +#breadcrumbs { + padding: 5px 0 12px 0; +} + + +#breadcrumbs ul { + color: #DFEFFC; + margin: 0; + list-style-type:none; + padding: 0; +} + +#breadcrumbs li { + border-width:2px; + margin: 3px 1px; + padding: 2px 9px; + border-style:solid; + border-top-left-radius: .8em; + border-bottom-left-radius: .8em; + background-color:#80C337; + display:inline; +} + +#breadcrumbs a { + text-decoration:none; + color: white; +} + +caption { + color:#FF7241; + text-align: center; + font-size:1.3em; + font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +} + +#Pages { + padding: 3px 2px 10px 4px; + background: linear-gradient(to right, #147AB3,#FFFFFF); +} + +#Pages h3, +#Pages h4, +h5{ + color: #909090; +} + +form { + padding: 10px; + margin: 4px; +} + + +form input[id],select#myroles { + margin: 4px 0; + width: 150%; +} + +form label { + margin: 4px 0; +} + +form label[required] { + color: red; +} + +form input[type=submit], form input[type=reset] { + font-size: 1.0em; + margin: 12px 0 0px 0; + color: #F13099; +} + +p.preamble, p.notfound,.expedite_request { + display: block; + margin: 30px 0px 10px 0px; + font: italic bold 20px/30px Georgia, serif; + font-size: 110%; + color: #0079B8; +} +.expedite_request { + margin-top: 0; + color: #FF7241; +} + +.subtext { + margin-left: 10px; + font-size: 75%; + font-style: italic; +} + +#Pages a { + display:block; + font-weight:bold; + color:#FFFFFF; + background-color:#80C337; + text-decoration:none; + border-top-right-radius: .8em; + border-bottom-right-radius: .8em; + border-top-left-radius: .2em; + border-bottom-left-radius: .2em; + padding: 3px 40px 3px 10px; + margin: 4px; + width: 50%; +} + +#footer { + background-color: #FF7200; + color: #FFFFFF; + text-align:right; + font-size: 60%; + padding: 5px; + position:fixed; + bottom: 0px; + left: 0px; + right: 0px; +} + +/* + Standard Table, with Alternating Colors +*/ +div.std { + vertical-align: top; +} + +div.std table, div.stdform table { + position: relative; + border-collapse:collapse; + table-layout:auto; + left: 1.3%; + width: 98%; + margin-top: 5px; + bottom: 4px; + border-radius: 4px; +} + +div.std td, div.stdform td { + font-size:.9em; +} + +.center { + text-align: center; +} + +.right { + text-align: right; + padding-right: 4px; +} + +p.double { + line-height: 2em; +} + +p.api_comment { + font-size: .9em; + text-indent: 6px; +} + +p.api_contentType { + font-size: .8em; + text-indent: 6px; +} + +p.api_label { + font-size: .9em; + font-style: italic; +} + +div.std h1, div.std h2, div.std h3, div.std h4, div.std h5 { + text-indent: 7px; +} + +div.std td { + border:1px solid #A6C9E2; +} + +div.std th, div.stdform th { + background-color:#6FA7D1; + color:#FFFFFF; + } + +div.std tr.alt, div.stdform tr.alt { + background-color:#DFEFFC; +} + +div.std a, div.stdform a { + /*color: #606060;*/ + color: #147AB3; +} + +td.head { + font-weight:bold; + text-align: center; +} + +td.head a { + color:blue; +} + +/* + A Table representing 1 or more columns of text, i.e. Detail lists +*/ +div.detail table { + width: 100%; +} + +div.detail caption { + border-bottom: solid 1px #C0C0C0; +} + +/* + Approval Form select all + +*/ +.selectAllButton { + background: transparent; + border:none; + color:blue; + text-decoration:underline; + font-weight:bold; + cursor:pointer; +} + + +/* + Begin Web Command Styling +*/ +#console_and_options { + position:relative; +} + +.maximized { + position:absolute; + top:0px; + bottom:50px; + left:0px; + right:0px; + z-index:1000; + background-color:white; +} + +#console_area { + -webkit-border-radius: 15px; + -moz-border-radius: 15px; + border-radius: 15px; + background-color: black; + color: white; + font-family: "Lucida Console", Monaco, monospace; + overflow-y: scroll; + height: 300px; + min-width: 600px; + padding: 5px; + resize: vertical; +} + +.command,.bold { + font-weight: bold; +} + +.command:before { + content: "> "; +} + +.response{ + font-style: italic; + font-size: 150%; +} + +#input_area { + margin-top: 10px; + clear: both; +} + +#command_field, #submit { + font-size: 125%; + background-color: #333333; + color: white; + font-family: "Lucida Console", Monaco, monospace; + -webkit-border-radius: 1em; + -moz-border-radius: 1em; + border-radius: 1em; +} + +#command_field { + width: 75%; + padding-left: 1em; +} + +#submit { + background-color: #80C337; + padding: 0 5%; + float: right; +} + +/* + Options Menu Styling for Web Command +*/ +#options_link { + -webkit-border-radius: 0 0 20% 20%; + -moz-border-radius: 0 0 20% 20%; + border-radius: 0 0 20% 20%; + -webkit-transition: opacity 0.5s ease-in-out; + -moz-transition: opacity 0.5s ease-in-out; + -ms-transition: opacity 0.5s ease-in-out; + -o-transition: opacity 0.5s ease-in-out; + transition: opacity 0.5s ease-in-out; +} + +.closed { + opacity: 0.5; + filter: alpha(opacity=50); +} + +#options_link:hover, .open { + opacity: 1.0; + filter: alpha(opacity=100); +} + +#options_link, #options { + background: white; + position:absolute; + top:0; + right:2em; + padding:0.1em; +} + +#options > img { + cursor: pointer; + float: right; + padding: 0.2em; +} + +.selected { + border: 3px solid orange; +} + +#options, #text_slider { + display:none; + padding:0.5em; + -webkit-border-radius: 0 0 0 10px; + -moz-border-radius: 0 0 0 10px; + border-radius: 0 0 0 10px; +} +#text_slider { + clear:both; +} + +/* + Button styling for changing text size +*/ +.change_font { + border-top: 1px solid #96d1f8; + background: #65a9d7; + background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7)); + background: -webkit-linear-gradient(top, #3e779d, #65a9d7); + background: -moz-linear-gradient(top, #3e779d, #65a9d7); + background: -ms-linear-gradient(top, #3e779d, #65a9d7); + background: -o-linear-gradient(top, #3e779d, #65a9d7); + padding: 0 2px; + -webkit-border-radius: 50%; + -moz-border-radius: 50%; + border-radius: 50%; + -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0; + -moz-box-shadow: rgba(0,0,0,1) 0 1px 0; + box-shadow: rgba(0,0,0,1) 0 1px 0; + text-shadow: rgba(0,0,0,.4) 0 1px 0; + color: white; + font-size: 14px; + font-family: monospace; + text-decoration: none; + vertical-align: middle; +} +.change_font:hover { + border-top-color: #28597a; + background: #28597a; + color: #ccc; +} + +/* + Text Size Slider styling +*/ + +input[type=range] { + -webkit-appearance: none; + width: 60%; + margin: 0; +} +input[type=range]:focus { + outline: none; +} +input[type=range]::-webkit-slider-runnable-track { + width: 100%; + height: 4px; + cursor: pointer; + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + background: #3071a9; + border-radius: 0.6px; + border: 0.5px solid #010101; +} +input[type=range]::-webkit-slider-thumb { + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + border: 1px solid #000000; + height: 16px; + width: 16px; + border-radius: 30px; + background: #efffff; + cursor: pointer; + -webkit-appearance: none; + margin-top: -7.15px; +} +input[type=range]:focus::-webkit-slider-runnable-track { + background: #367ebd; +} +input[type=range]::-moz-range-track { + width: 100%; + height: 2.7px; + cursor: pointer; + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + background: #3071a9; + border-radius: 0.6px; + border: 0.5px solid #010101; +} +input[type=range]::-moz-range-thumb { + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + border: 1px solid #000000; + height: 16px; + width: 16px; + border-radius: 30px; + background: #efffff; + cursor: pointer; +} +input[type=range]::-ms-track { + width: 100%; + height: 2.7px; + cursor: pointer; + background: transparent; + border-color: transparent; + color: transparent; +} +input[type=range]::-ms-fill-lower { + background: #2a6495; + border: 0.5px solid #010101; + border-radius: 1.2px; + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; +} +input[type=range]::-ms-fill-upper { + background: #3071a9; + border: 0.5px solid #010101; + border-radius: 1.2px; + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; +} +input[type=range]::-ms-thumb { + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + border: 1px solid #000000; + height: 16px; + width: 16px; + border-radius: 30px; + background: #efffff; + cursor: pointer; + height: 2.7px; +} +input[type=range]:focus::-ms-fill-lower { + background: #3071a9; +} +input[type=range]:focus::-ms-fill-upper { + background: #367ebd; +} +.expired { + color: red; + background-color: pink; +} +.blank_line { + padding: 10px; +} +#filterByUser input { + display: inline; +} diff --git a/authz-gui/theme/aaf5Desktop.css b/authz-gui/theme/aaf5Desktop.css new file mode 100644 index 00000000..b4aa02f8 --- /dev/null +++ b/authz-gui/theme/aaf5Desktop.css @@ -0,0 +1,92 @@ +/* + Modifications for Desktop +*/ +body { + background-size:23em 4.7em; +} + + +#breadcrumbs a:visited, #breadcrumbs a:link { + transition: padding .5s; +} + +#breadcrumbs a:hover { + padding: 2px 2px 2px 30px; + transition: padding .5s; +} + +#breadcrumbs, #inner { + margin: 3px; + width: 77%; + float: left; + min-width:500px; + background-color: #FFFFFF; + +} + +#breadcrumbs li { + box-shadow: 3px 3px 2px #888888; +} + +#Pages { + margin: 20px; + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#147AB3', endColorstr='#ffffff',GradientType=1 ); /*linear gradient for IE 6-9*/ +} + +#Pages a:visited, #Pages a:link { + padding: 3px 40px 3px 10px; + transition: padding .5s; + margin: 6px; + box-shadow: 3px 3px 2px #888888; +} + +#Pages a:hover { + padding: 4px 80px 4px 15px; + transition: box-shadow padding .5s; + box-shadow: 4px 4px 3px #888888; +} + + +#inner { + padding: 7px; + background: #FFFFFF; + overflow: hidden; +} + +div.std, form { + border: solid 2px #D0D0D0; + border-radius: 5px; + box-shadow: 10px 10px 5px #888888; +} + +div.detail { + border: solid 2px #C0C0C0; + border-radius: 14px; + box-shadow: 10px 10px 5px #888888; +} + +#nav { + display: inline-block; + position: absolute; + right: 2%; + left: 81%; +} + +#nav h2 { + color: #FF7200; + font-size: 1.2em; + font-family: Verdana,Arial,Helvetica,sans-serif; + font-style: italic; + font-weight: normal; + +} + +#nav ul { + font-style:italic; + font-size: .8em; + font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; + color: #067ab4; + list-style-type: square; + margin: 0; + padding: 0; +} diff --git a/authz-gui/theme/aaf5iPhone.css b/authz-gui/theme/aaf5iPhone.css new file mode 100644 index 00000000..c356983b --- /dev/null +++ b/authz-gui/theme/aaf5iPhone.css @@ -0,0 +1,38 @@ +/* + Modifications for iPhone +*/ +body { + zoom: 210%; +} + +#breadcrumbs { + font-size: .9em; +} + + +div.std table { + margin: 0 0 20px 0; + zoom: 130% +} + + +div.stdform th { + font-size: 9px; +} + +#content input { + font-size: 1.3em; +} + + +#Pages a { + font-size: 1.3em; + width: 75%; + height:35px; +} + +#nav { + display: none; +} + + diff --git a/authz-gui/theme/aafOldIE.css b/authz-gui/theme/aafOldIE.css new file mode 100644 index 00000000..5910c5cf --- /dev/null +++ b/authz-gui/theme/aafOldIE.css @@ -0,0 +1,162 @@ +/* + Modifications for non-html5 IE +*/ +body { + background-size:23em 4.7em; +} + + +body h1 { + margin: 4px auto; + color: #F13099; +} + +#footer { + background-color: #FF7200; + color: #FFFFFF; + text-align:right; + font-size: 60%; + padding: 5px; + position:fixed; + bottom: 0px; + left: 0px; + right: 0px; +} + +#breadcrumbs a:visited, #breadcrumbs a:link { + transition: padding .5s; +} + +#breadcrumbs a:hover { + padding: 2px 2px 2px 30px; + transition: padding .5s; +} + +#breadcrumbs, #content { + margin: 3px; +} + +#breadcrumbs, #inner { + margin: 3px; + width: 77%; + float: left; + min-width:500px; + background-color: #FFFFFF; +} + + +#breadcrumbs li { + box-shadow: 3px 3px 2px #888888; +} + +#inner { + padding: 10px; + overflow: hidden; +} + +#inner form { + border: solid 2px #D0D0D0; +} + +#inner form input[id] { + margin: 4px 0; +} + +#inner form label { + margin: 4px 0; +} + +#inner form label[required] { + color: red; +} + +#inner form input[type=submit] { + font-size: 1.0em; + margin: 12px 0 0px 0; + color: #F13099; +} + +p.preamble, p.notfound { + display: block; + margin: 30px 0px 10px 0px; + font: italic bold 20px/30px Georgia, serif; + font-size: 110%; + color: #0079B8; +} + + +#Pages { + margin: 20px; + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#147AB3', endColorstr='#ffffff',GradientType=1 ); /*linear gradient for IE 6-9*/ +} + +#Pages a:visited, #Pages a:link { + display: block; + padding: 3px 40px 3px 10px; + transition: padding .5s; + margin: 6px; + box-shadow: 3px 3px 2px #888888; + background-color: #98bf21; + text-decoration: none; + color: white; + font-weight: bold; +} + +#Pages a:hover { + padding: 4px 80px 4px 20px; + transition: box-shadow padding 1s; + box-shadow: 4px 4px 3px #888888; +} + +tr { + font-size: .9em; +} + +tr.alt { + background-color: #EEF0F0; +} + +#nav { + + display: block; + position: absolute; + top: 175px; + right: 2%; + left: 81%; + z-index=1; + clear: both; +} + + +#nav h2 { + color: #FF7200; + font-size: 1.2em; + font-family: Verdana,Arial,Helvetica,sans-serif; + font-style: italic; + font-weight: normal; + +} + +#nav ul { + font-style:italic; + font-size: .8em; + font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; + color: #067ab4; + list-style-type: square; + margin: 0; + padding: 0; +} + +div.std { + border: solid 2px #D0D0D0; + border-radius: 5px; + box-shadow: 10px 10px 5px #888888; +} + + +div.detail { + border: solid 2px #C0C0C0; + border-radius: 14px; + box-shadow: 10px 10px 5px #888888; +} + diff --git a/authz-gui/theme/aaf_1_0.xsd b/authz-gui/theme/aaf_1_0.xsd new file mode 100644 index 00000000..a71e2ea1 --- /dev/null +++ b/authz-gui/theme/aaf_1_0.xsd @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/authz-gui/theme/aaf_2_0.xsd b/authz-gui/theme/aaf_2_0.xsd new file mode 100644 index 00000000..95c8ff9e --- /dev/null +++ b/authz-gui/theme/aaf_2_0.xsd @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/authz-gui/theme/comm.js b/authz-gui/theme/comm.js new file mode 100644 index 00000000..5a1ac4d8 --- /dev/null +++ b/authz-gui/theme/comm.js @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +function http(meth, sURL, sInput, func) { + if (sInput != "") { + var http; + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + http=new XMLHttpRequest(); + } else {// code for IE6, IE5 + http=new ActiveXObject('Microsoft.XMLHTTP'); + } + + http.onreadystatechange=function() { + if(http.readyState==4 && http.status == 200) { + func(http.responseText) + } + // Probably want Exception code too. + } + + http.open(meth,sURL,false); + http.setRequestHeader('Content-Type','text/plain;charset=UTF-8'); + http.send(sInput); + } +} \ No newline at end of file diff --git a/authz-gui/theme/common.js b/authz-gui/theme/common.js new file mode 100644 index 00000000..e9af8fef --- /dev/null +++ b/authz-gui/theme/common.js @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +Object.defineProperty(Element.prototype, 'outerHeight', { + 'get': function(){ + var height = this.clientHeight; + height += getStyle(this,'marginTop'); + height += getStyle(this,'marginBottom'); + height += getStyle(this,'borderTopWidth'); + height += getStyle(this,'borderBottomWidth'); + return height; + } +}); + +if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', function () { + var height = document.querySelector("#footer").outerHeight; + document.querySelector("#inner").setAttribute("style", + "margin-bottom:" + height.toString()+ "px"); + }); +} else { + window.attachEvent("onload", function () { + var height = document.querySelector("#footer").outerHeight; + document.querySelector("#inner").setAttribute("style", + "margin-bottom:" + height.toString()+ "px"); + }); +} + + + +function getStyle(el, prop) { + var result = el.currentStyle ? el.currentStyle[prop] : + document.defaultView.getComputedStyle(el,"")[prop]; + if (parseInt(result,10)) + return parseInt(result,10); + else + return 0; +} + +function divVisibility(divID) { + var element = document.querySelector("#"+divID); + if (element.style.display=="block") + element.style.display="none"; + else + element.style.display="block"; +} + +function datesURL(histPage) { + var validated=true; + var yearStart = document.querySelector('#yearStart').value; + var yearEnd = document.querySelector('#yearEnd').value; + var monthStart = document.querySelector('#monthStart').value; + var monthEnd = document.querySelector('#monthEnd').value; + if (monthStart.length == 1) monthStart = 0 + monthStart; + if (monthEnd.length == 1) monthEnd = 0 + monthEnd; + + validated &= validateYear(yearStart); + validated &= validateYear(yearEnd); + validated &= validateMonth(monthStart); + validated &= validateMonth(monthEnd); + + if (validated) window.location=histPage+"&dates="+yearStart+monthStart+"-"+yearEnd+monthEnd; + else alert("Please correct your date selections"); +} + +function userFilter(approvalPage) { + var user = document.querySelector('#userTextBox').value; + if (user != "") + window.location=approvalPage+"?user="+user; + else + window.location=approvalPage; +} + +function validateYear(year) { + var today = new Date(); + if (year >= 1900 && year <= today.getFullYear()) return true; + else return false; +} + +function validateMonth(month) { + if (month) return true; + else return false; +} + +function alterLink(breadcrumbToFind, newTarget) { + var breadcrumbs = document.querySelector("#breadcrumbs").getElementsByTagName("A"); + for (var i=0; i< breadcrumbs.length;i++) { + var breadcrumbHref = breadcrumbs[i].getAttribute('href'); + if (breadcrumbHref.indexOf(breadcrumbToFind)>-1) + breadcrumbs[i].setAttribute('href', newTarget); + } +} + +// clipBoardData object not cross-browser supported. Only IE it seems +function copyToClipboard(controlId) { + var control = document.getElementById(controlId); + if (control == null) { + alert("ERROR - control not found - " + controlId); + } else { + var controlValue = control.href; + window.clipboardData.setData("text/plain", controlValue); + alert("Copied text to clipboard : " + controlValue); + } +} diff --git a/authz-gui/theme/console.js b/authz-gui/theme/console.js new file mode 100644 index 00000000..e35becff --- /dev/null +++ b/authz-gui/theme/console.js @@ -0,0 +1,275 @@ +/******************************************************************************* + * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. + *******************************************************************************/ +function getCommand() { + if(typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + }; + } + + var cmds = []; + cmds = document.querySelector("#command_field").value.split(" "); + var cleanCmd = ""; + if (document.querySelector("#details_img").getAttribute("class") == "selected") + cleanCmd += "set details=true "; + for (var i = 0; i < cmds.length;i++) { + var trimmed = cmds[i].trim(); + if (trimmed != "") + cleanCmd += trimmed + " "; + } + + return cleanCmd.trim(); +} + +function moveCommandToDiv() { + + var textInput = document.querySelector("#command_field"); + var content = document.createTextNode(textInput.value); + var parContent = document.createElement("p"); + var consoleDiv = document.querySelector("#console_area"); + var commandCount = consoleDiv.querySelectorAll(".command").length; + parContent.setAttribute("class", "command"); + parContent.appendChild(content); + consoleDiv.appendChild(parContent); + + textInput.value = ""; +} + +function printResponse(response) { + var parContent = document.createElement("p"); + parContent.setAttribute("class", "response"); + var preTag = document.createElement("pre"); + parContent.appendChild(preTag); + var content = document.createTextNode(response); + preTag.appendChild(content); + var consoleDiv = document.querySelector("#console_area"); + consoleDiv.appendChild(parContent); + + consoleDiv.scrollTop = consoleDiv.scrollHeight; +} + +function clearHistory() { + var consoleDiv = document.querySelector("#console_area"); + var curr; + while (curr=consoleDiv.firstChild) { + consoleDiv.removeChild(curr); + } + document.querySelector("#command_field").value = ""; + currentCmd = 0; +} + +function buttonChangeFontSize(direction) { + var slider = document.querySelector("#text_size_slider"); + var currentSize = parseInt(slider.value); + var newSize; + if (direction == "inc") { + newSize = currentSize + 10; + } else { + newSize = currentSize - 10; + } + if (newSize > slider.max) newSize = parseInt(slider.max); + if (newSize < slider.min) newSize = parseInt(slider.min); + slider.value = newSize; + changeFontSize(newSize); +} + +function changeFontSize(size) { + var consoleDiv = document.querySelector("#console_area"); + consoleDiv.style.fontSize = size + "%"; +} + +function handleDivHiding(id, img) { + var options_link = document.querySelector("#options_link"); + var divHeight = toggleVisibility(document.querySelector("#"+id)); + + if (id == 'options') { + if (options_link.getAttribute("class") == "open") { + changeImg(document.querySelector("#options_img"), "../../theme/options_down.png"); + options_link.setAttribute("class", "closed"); + } else { + changeImg(document.querySelector("#options_img"), "../../theme/options_up.png"); + options_link.setAttribute("class", "open"); + } + moveToggleImg(options_link, divHeight); + } else { //id=text_slider + selectOption(img,divHeight); + } + +} + +function selectOption(img, divHeight) { + var options_link = document.querySelector("#options_link"); + var anySelected; + if (img.getAttribute("class") != "selected") { + anySelected = document.querySelectorAll(".selected").length>0; + if (anySelected == false) + divHeight += 4; + img.setAttribute("class", "selected"); + } else { + img.setAttribute("class", ""); + anySelected = document.querySelectorAll(".selected").length>0; + if (anySelected == false) + divHeight -= 4; + + } + + moveToggleImg(options_link, divHeight); +} + +function toggleVisibility(element) { + var divHeight; + if(element.style.display == 'block') { + divHeight = 0 - element.clientHeight; + element.style.display = 'none'; + } else { + element.style.display = 'block'; + divHeight = element.clientHeight; + } + return divHeight; +} + +function moveToggleImg(element, height) { + var curTop = (element.style.top == "" ? 0 : parseInt(element.style.top)); + element.style.top = curTop + height; +} + +function changeImg(img, loc) { + img.src = loc; +} + +var currentCmd = 0; +function keyPressed() { + document.querySelector("#command_field").onkeyup=function(e) { + if (!e) e = window.event; + var keyCode = e.which || e.keyCode; + if (keyCode == 38 || keyCode == 40 || keyCode == 13 || keyCode == 27) { + var cmdHistoryList = document.querySelectorAll(".command"); + switch (keyCode) { + case 13: + // press enter + + if (getCommand().toLowerCase()=="clear") { + clearHistory(); + } else { + currentCmd = cmdHistoryList.length + 1; + document.querySelector("#submit").click(); + } + break; + + case 27: + //press escape + currentCmd = cmdHistoryList.length; + document.querySelector("#command_field").value = ""; + break; + + case 38: + // press arrow up + if (currentCmd != 0) + currentCmd -= 1; + if (cmdHistoryList.length != 0) + document.querySelector("#command_field").value = cmdHistoryList[currentCmd].innerHTML; + break; + case 40: + // press arrow down + var cmdText = ""; + currentCmd = (currentCmd == cmdHistoryList.length) ? currentCmd : currentCmd + 1; + if (currentCmd < cmdHistoryList.length) + cmdText = cmdHistoryList[currentCmd].innerHTML; + + document.querySelector("#command_field").value = cmdText; + break; + } + } + } +} + +function saveToFile() { + var commands = document.querySelectorAll(".command"); + var responses = document.querySelectorAll(".response"); + var textToWrite = ""; + for (var i = 0; i < commands.length; i++) { + textToWrite += "> " + commands[i].innerHTML + "\r\n"; + textToWrite += prettyResponse(responses[i].firstChild.innerHTML); + } + + var ie = navigator.userAgent.match(/MSIE\s([\d.]+)/); + var ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/); + var ieVer=(ie ? ie[1] : (ie11 ? 11 : -1)); + +// if (ie && ieVer<10) { +// console.log("No blobs on IE ver<10"); +// return; +// } + + var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'}); + var fileName = "AAFcommands.log"; + + if (ieVer >= 10) { +// window.navigator.msSaveBlob(textFileAsBlob, fileName); + window.navigator.msSaveOrOpenBlob(textFileAsBlob, fileName); + } else { + var downloadLink = document.createElement("a"); + downloadLink.download = fileName; + downloadLink.innerHTML = "Download File"; + if (window.webkitURL != null) { + // Chrome allows the link to be clicked + // without actually adding it to the DOM. + downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob); + } else { + // Firefox requires the link to be added to the DOM + // before it can be clicked. + downloadLink.href = window.URL.createObjectURL(textFileAsBlob); + downloadLink.onclick = destroyClickedElement; + downloadLink.style.display = "none"; + document.body.appendChild(downloadLink); + } + + downloadLink.click(); + } +} + +function prettyResponse(response) { + var lines = response.split('\n'); + var cleanResponse = ""; + for (var i=0; i < lines.length; i++) { + cleanResponse += lines[i] + "\r\n"; + } + cleanResponse = cleanResponse.replace(/(<)/g,"<").replace(/(>)/g,">"); + return cleanResponse; +} + +function destroyClickedElement(event){ + document.body.removeChild(event.target); +} + +function fakePlaceholder() { + document.querySelector("#command_field").setAttribute("value", "Type your AAFCLI commands here"); +} + +function maximizeConsole(img) { + var footer = document.querySelector("#footer"); + var console_area = document.querySelector("#console_area"); + var content = document.querySelector("#content"); + var input_area = document.querySelector("#input_area"); + var help_msg = document.querySelector("#help_msg"); + var console_space = document.documentElement.clientHeight; + console_space -= input_area.outerHeight; + console_space -= help_msg.outerHeight; + var height = getStyle(console_area,'paddingTop') + getStyle(console_area,'paddingBottom'); + console_space -= height; + + + if (content.getAttribute("class") != "maximized") { + content.setAttribute("class", "maximized"); + footer.style.display="none"; + console_area.style.resize="none"; + console_area.style.height=console_space.toString()+"px"; + } else { + content.removeAttribute("class"); + footer.style.display=""; + console_area.style.resize="vertical"; + console_area.style.height="300px"; + } + selectOption(img,0); +} diff --git a/authz-gui/theme/favicon.ico b/authz-gui/theme/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..3aea27221ca7732bc043a84f0cd2fcbfa3c80894 GIT binary patch literal 3638 zcmeHJXFycP7XB^~LWogf6kEiuV2nmIq-cVeL`~EXi6x3%5wRsgP_Y0mf?|QCH>Juh z9Tt{d$^r|7vXrH)TwFTRn>6X|&4Ru>U-BzI-mmxV-kmw;n|o%?+}ZP8fPx&9l`(-c z^1uqxTeN7>4paneiBFA~vLP}z1>z*wOieU@`57M{M~a;W5_y5}G6Y(xGQe^+f`n@d zS5qxiXL}<{lnasH9@Nygfp0zoQ2`I&X{`r`3(L{h-2ib02L>N?(b(DvIy(w+x94GWq#qS!MewvaiOMWjNd91>P7)43 z`|}Ws#mE+h!~eqDC@&H~9BGV#M0aGT^3X`fz}tE+vL5RoUla#{%TDC64nWBI9bGS) z5P4Mr{X@fGJLn_DYac4IS>RZ$L!CGXFIwx+(Oizkx@rvcw4%C7ih?i$6lH`Wnr#me z`vhp-O_ZiQ#LK=BbocZk>Ha!Y7e=D-Sv-bE$52(A3=!WMU2Qdx2t8nbQ5{i?Wf<;l z#`D^G)X}k|ts(ghBbG56gM$M|uv$QJEkh3b5X9jZQIP77#xfzECEZ15R}bo{i%}u+ zL04BZvV49dd$=FjDI7dYU|?u?2)zR@$v&<|h^HCCj3|tdGt>LB7abklsBLIPRY5pe zGZTC>W$-O#Vt8Z(T+3zXY%NDkO$}-#k>IlJAWrna*w`3E-a6>->nHcWKusmtgYYvb zO>@8)i90?%hGEhUkB(!A#2FnK!qCtVI!V6GWl1Cs6OtIyzntU$JO05AP%^M@G0!}i z=z;RKy?j#P!8Fh1JADEdQ=rcOq`m*ci{E^&ap$cgF2vrfx?tw)U*`Vsie-6HmP znm>PVRzBpO&95epmQpx8eb(+}d*8bzr{m~$dqxnBDXuoUxn<3{P><7}uJFAAGv$SI z-nsj>#kcQMl=((2d=<9j;XEhjt6zVi=1(z4Af5DPjjuzbkE3ad%%o_0VIP zEkp1pK6VqGzf?dAvSt7DB1d$h&MqP`Hk0dhowb-kjK6`b&L)xnP*7+%%=gKoQ5uIL z&aZH>HbnR(fO(13h`I(ylHHM+DMFmP9-^MyMVQT2#8}LM^C=2e#}+^sAA#=XLX?)| zqmR^(j7QtRGGBvYQ6$_fb|c*V65KD&Lv8yAa#?zi3K$6Rb%%}7cc{+sK}sYOX>23- zKhT5ALsQh&l%T6`6tT8n!1tmOlB2zmAP^wVc?X_~lTj?KM8GMaUJ{13_6`JHo(Z1y za#$Umj%ZUQBn6ryI?NAgUOywkT9ed`5G45;5FJT}-xX4qhI(OVFb6#^svyoU0G;6v ze@A0d`)?uLc_YFc4bTUn2DPQRlw)RqEu*$BuiC-|7;QzLS-(oh(E4R%JG;BK}R(Vm8QnxBQx z%hOOKDS?OaQe+c7EEh+hDE=;-FMkHF+q#Id-GRh=%Tbc)fk!q+ksNvlqQLXW3Nt|* z%Y@Y8VWJy5k;y&`@|e=tx|+DR-qu}31TB%iRONQ zhRPgtb+;qp`uiv;p>hBG8sy|;BZ+AD^8yxxX_-iH+=2vGU9jD*puV{UoU8KS+~15+ zNjloQM-gW^7hG>+m>rl7ze_WSmPJD<3Id-K1Q!EE)R(0r>CQ(;@;r!CH*KWFu~8{4 z0Q<&rjE)T=;@VtD)4kEx--o`g=XlXxJ5k@uE1#peJQ;2ejNx`i9|OIeU>uo)5Mz1N zmk|9-iy)eEfYfahIGJukRYM2bYqF3S`hdJ6aFF7l2|iOBS;9!7=Vvf5JV>;?8-9iq zcn&%c@}3~r&jFdywurJ+M`^wQzW4S_=wW9Q4c3);C@U{VX6$34rzgM%moB;{Z>XhIcczAjy>Kfb8($azu)7hZQN>M>) zBkImtq^11!DkpZv3p#RM?@?xj1)*)E!Zmjg* zyk4%_+Rx)}nwl=Zdw2eKg@G=ElObN;umAYa;u*j1-M;k5#*L*1`u+Fqs#cSYV37Gq zOPxq_F1EWgOM09?=&Potu~OLmXg`+_lRUj<@!KEmx)qx5-K5@pIQ7PfA>ReP)3UWl z945MLyi{gdIVv-XFVt@3Q>^9*@@< z%)a0e%I3SDqiMoZLo1$~{nG50lX)sC0tQX%(-cKJB=1@F%SbLI;Kfet-VJ^oJFWii&>qegwN4QSPyQ5o;^^Oq5v-I);um~6u-8Y;;j1O7s+L`dI#%5h^3WX=$Wbv0{UqtK9YL z_4QRuCbLbIMN|6aMJj~%d8^e%cY~&)qGtWp*(o~}a>`V?dsHkXdZLQd*5T`{RyX~n-o*L4* z|DmDbdV|@j3aJXJme)0{6bSY&0FW^bd&IwyC;tk>A^d!Ni&SYyBTsJvwGo?6zh)=f$KyKV)yI|2 zkw4HmzLT+3@Fy(`NH&`9Qd2WN)rG+LxPxrtW#2cTrzCZ9lJd*{ocRsP000yS1^@s6cz2e)00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0@g`HK~zXfy;SW> zQ(+YU-Mj62o6hAd6-mR2G6KuYRu~0=R6>N%8$vHwU+POy{Re%k4}ItbN<>h^3WFd9 zSy9L=Vx`k;6H&4kU-B(-W3t^{?>f(&_pag88QA%B@AI5p3`06Z;(}T;896k%yQr;(lcjPM72*4K^7F zp|YVJ&QC*tfk$qR1Z0S1mk6p6@CCA`gy>L*?Bj`|h_I`zm67qwb23#zZID6p+g zL+P58F%Z#c!2S)H>VY=V3{;Y5aQT@R0cn1Xt~fksBn?cn04#?hN04t_5f8#Hu9p`g z+bSZgMCot@Vj@N_yN7YUxho-?7HUsJ`wwu`3FfZ?uy_*TM#X08zA?sxeepbpx}#eG zUroBrbl=GS(k2#vZCf3ed#OzBoo= z>7)OurVcf@XVi~3-Z2=(C;;=5NViNX=GNgYu!yGkBIkR%4%EKK3(p8l6u{cX5{0M3 zIBCy^duR&1;{gb?Q|ftGLBXn2Vz3=M@-pV=r!Qk7WlL{6@$t)qKALJvq#0T^(rQ)* z#=u6pInM6HuC=yAX%>FFTF%+Am$inkok{R}xMgHJJ_C?_56OZyf~ zu3s|YleJfUW0A6ZZIPR;eaVKXen~UYcYz*HHdRZpC4(#_x#s%^)39)n%^;gG00000 LNkvXXu0mjfMrm;Y literal 0 HcmV?d00001 diff --git a/authz-gui/theme/options_up.png b/authz-gui/theme/options_up.png new file mode 100644 index 0000000000000000000000000000000000000000..7414dab5d20a7451b47cd840a7a6fcbe06f4a99d GIT binary patch literal 826 zcmV-A1I7G_P)P000yS1^@s6cz2e)00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0?$cAK~zXfy_N4v zQ&AYlzq{Rgw;B$r*-*1G1aT&&=3bN%2w^aSAS+E23hYhvqBp(kKd`7b^&*p^up*%# zT9Fj=Q%glN3Jbx0kZCu>BeVa zHQg;p3)1p*7}XcM@Mw5EEs$ZU?J7O@1cPJKP=g9YlZf+sx1iavX-Tk@kb&=B>~4Dn z_oN@9QG{SHAgo59`hwV+Z$;O!N|?kINnuIbGLWm(jMFoh0XiO_g1b4Gw|o2}?MUbQGFVI{p^CvoUT zKLHpdDH@Q46%<&_s4L3>`xQjo`O-=Wy(1H-xzxRM$TQl&&tT-Ij{pJ;)FPE%C8pwb zV+F3)m%~|-gAh|R5MP(b2oK+mqVmFX1VYMRumzRO1VT7*_Z=o?qAlV9xWcm`RNL2~ z(3YW%+w03s<19)D;FD%a#MwP|$aEQ%*gG3P$H&7H zx(RfM=ZB9jS+slH`;PofTs>I2C?LLIw^`7(uLP>cuT`Xpa^+Be%xPNG+Ttu^XIa3e z17P%gR8f0eM;yAlQjr?U*5k_2?J$Z0*i3-;pL4Kgl^kWpA4o6Rw_|V=`I%6xI@^2i$6zC~R8uG7O8G!8i}uH+wEic{1^ySvZd*oCE|UBOp;E4oHq7!3aoHkeo!aBoPTBK{5z}WCY0| zNs#OiX67GsKmGRpd-v|MHP6%Mopb7R*IQNHU0s+-%sfD*rLL(CfIuMN3ibzJ7KzL> zRaI^D4fWJDuc~1e0D$PqRfM|-m<#~i+{~sZ8J5O(4008M@wMFe6eC)9JAr{{X z@bx^O-@#(4o37^=3_Zu*SOc+`_8dF?!k2#P{K87-*xt?E9;dsmXP2V5x~0txBT11-&+43oX7T;#=gPNn1N{e|IGc_ z`)AJM1pr7LVtw=E&)m&40H}Ke0JKwo=GdPD0O>;js2%(pADZ)garX7~lo1pR2nY~B zIM@lCJM_2wp9;S<|99}W>j|7+@3-$*E;~5d`rYznId`g^$1M*(Zx$ad5r~> z`DlR3MgSliqyivY{Q#7b5P(=_V^=`G<8~F_1USF*OyR4)@*az^>pzeGbO6U=|AKuG zPAuoss)oiac7ERe=NNlWoF8xi0)P~t0_Xr{fDPaV_yG|>5|9Oy05w1h&;yKt>wq<2 z2RH+6fHx2T1OxYga3C6Z0we+HKn{=(lmHdLYoHEj1X_VEpbz*2i~-ZYJg@?60z1GF zaEg79!9c_yN)R0g4&ngufkZ%3AO(;b=qkt%bRBd98ZJ7+a15Jk(Lu;WO&=KeYbO(yYA;w|E;lq)^(Zn&s zal#3}3CBssDa5J4>BJesS;0BN#l@w;<-(Q3y@Gok*9G?uZVYY~ZYAz}+#%d0+(Q@) zMhD}A$;0$uwlH5*c*A(Bc&GSe z_#F5$_N;@CWf%@J|WI3AhO435*F`2<{Q25>ya$5_}=pCnO}iNGMHc zK!_l`OPEUdim-=pf$*4!f{2$$mB^CFk0_3)i0D1hXQF*#Vq#8WC1P`8U*b6865@8^ zSz;s!C5ZruCW$>s7)b_6Ey*y+HYq+S2dOftHE9rOGHEsGAn7+Ud@@clRWe($P_hiN zw`3D!hvbyx!sL47ZsalKFUfn!*C=2VoD^yl_7o2(@+jIVmM9^VY?P{$c9ah&^C>$i zSEz8QxTrL#T&SX{%BcpZcBm<+#i&iF1F18po2ch$AT*pbnl!g);%Q#fjMJQ4V7j1u z!QsN=3l$fJFZ`fopjD!EppBxfq#dI@p<|&_qjRNuN>@iWLl33rr8l4tpwFi7r2oc1 z#URUI#}LKvnqi6&%*e}V$ase_kFlTekcpW|gUORAjj5gK8#4{F60-~QGv;RIbvPwl z0giw_gSWspSg2W)S#GhUvUITQurjh~QU${YdPlQ**P9#HQRFqg$ zT{KLzUUXNCPs~9qTWnICQd~zoLcC2JB_S!{Em0w{F3B!=Lo!oxLW)XCUn)kbM;b?3 zMLJBnQTkX$LdI9-waj-}epy%9m$GYeTyhR_`EpD07v*i`bLHn1SQKt3JXe@kWL30P ze4)6g#HM7gRH(G7%%kk0T&BFOBBbK2Qls)iRYo;L_5EeYWsS>Gmj~1+)UK(etIeuk zRCiJ@Ro~GN*SMqc{tC_&?JG~OOlUG`+G&<(?r2GBg=lqX6KNZ1r)w`><-O{CwLu50 zqotFm^F^0K*IlEO-f9Dm|iwbFr7COGz&57yH0-{alPIgW^Q6$Xnts+W|3sEVkvGJ zZaHqnWff@EYfW!`%eu*i)W+7P`UcJo(;F{uoZ0HxzOX&Ksd+Q==8m1JU5eeNy^{Si z`*jC-hXjXJM|sBt$2BK;r$nc9XGP~^=WhsAL^@*E<%&y=%MVvQ*CJQUEz?_-Zg_4t z+}^rVxVyS{crbeedJK8;d4_w=d&zhudF^;>dl&kEe5`!xeW|d;RKFj$-y^>Te+B;x ze`J73Ky@H_pnG8dZQk3DZ?6Wa2Nm3b-m$yW7R(xaFL)tDIV3j}6nZnXEsQPfVc5!D zjl0G72=2Mw`*>gIe!~5O2c{1i9x^?=`*7)z#-q}3l5p?vi3r(#J@1Mw2^*-vnvxIYVWmSvyHFPGO>@K@wk(o{yj0$%yO+NiowHU3)rbz8Mmb;TQwH<>k*HBq&o z+S|1|bUL1|0*P+MPXJ>Rs*K%H1tJ@;!~cGQDphhCHkGPYYQv!&cF~*O_wfm6F3{4^b8vET^YDs^OGrvd%cx#fQ`fknsbyq* z&BPR2_SxAxI665aTzq`}`~w1S2R(TBC_Ezaaa2O$v!vvd)U@;$dHDr}Ma3mAUsu1W zsjaJj+tAkD(b?7A)B9m~WOQtNV)FCU!s62M%GcGk^^M)V{e#1!AIRgAb6(i^{G#=n z+5g~$bpi+sg+idPb6y~Dz&UYpC=RPIE`_oI%+`zYqR2fwDwU_XRjv4JqJ}%vH@$}l zXxPOTICjse{bcr^5xf6iG5byI53ebJ2m-#)Zx*la@v*+2?kik$C_kQi2+_LRnD9V zVSuL&dMBrXsEe>JFW6~ESX+xkK+=iy0uHud*9R&6y8%AR5vBki`?u;s&r*ta7;YKr1ZnOIw&tBoJlc)EkYu}2 z@n$in%=A(V)qsl3@yO)UTqafNd>7R*7rKvZCcFb0?1OMr-Zp0ql4I$yt#{mzSx1K* z2gfLXp4Z^ZD(ZtXN*uYx`(d+TzU&x47M>lLW~je#rmbh89GrE93kgr;L&;1Wu%12a z;~RcTlo@uozaDo$Coe8P_rA7ku6^e%gU*-NS2dPig+|+aYGztsB6>k_XY^SCa<8(D z8yT}#B*9V9D>!i|OK_Ul{X5M6i1xo26pOXc!HO^cmJ)X4*&#B+HxOqrD@LHXSWn6P2jO;0JVo{S#nA7obM=X>2AS_>vdu@4f;D_R0ee?4$LXjP7OD z!xFh0e4Gw!=06=thbq7(LO5~`z0h*vT~k>+AAiiKj{)jh4j#iZk+~Rv{fG;_fC1Jg z;m-)iTb|FZ?(t2&YT_aL$geP9rLs3WKzdk5LatXBRD}V2?NOpuX`#4d{#b<=@=)iKVJm10M_Zn=1N(;cti812tivTy;jQxO5Jl0!&Aup_yFr|vUDbW6G3 zi07HI++unu&s&8mj|EphxAL!Vq>VQeEqxao7`Ax=WKfiyv#dkRqP8!!svdkS%kRTy z&afyNy>S{f-!ac^id@?NjKTn4{T4(st;x~bc?Ut2?+#5A;&=2qwBZy~RgK0YHNnBJ zwozZ|H&-YJLgE#Y_UPgajEKK$n4ztUW>y$Awc*Y>+@os^+9PL?p>mTI1v>%V z${iUK7tc@1yN!#jJq3Bm5y;T)M7!R2aGL`g^&e^8vLU>it3)u1erqZBzW>+ z^fT|WrxD+rEqd7n5<0dRt3(>Td0I_iEb+Nz`H4E>zWv6T_W4=q)1%|NdXMF6_%n8f{|a75aYuvyTv0uvoA0sa6T z^X^rvw9#!#LLc_jg$$thB=LRaRHgw^%}JeLudc{wxKUEnxlVXy)dx>+O5sLzYwO^JFzgJz9~_%PZ{vm)~NOKXTDiBMwH*`ULSoK1lXRD&&pFMKU= zo`>sIXih3z3suRpRMsNoLYeY9W1WwE&OyHURC4l|QQg!eu5>m&83TxxYz|gxonGFq zxLw8*`By0aP4v;Ze8)TJ;@@cyg`nX;Fx}60xjuOWDLLb{AH6oGENQnF&@nZNW}7(7 z3R{MePJaYClJ zEk1p_aI^N2lCvSb)rsA=$LNa!;_MmCMN%`aWgSYQnz2kK5sMi!JjryaGm{5GRedbm z`q??Et(9*U21Gkn5{x$_4dcz4EKLJj1ZM7(4@xp5w>30azFuG52tsA8G@%*;OkU&L zK5;PfWA5;SO-^i261BxCL{+M5>8IEX9fe*!)*3C+(iQzuV^#QnKE6RH71R9%ls*;6 zWMgCY1D$)tYTWqL4B?;`A2gQA&(ZEKQ1)`{5%=4VQ+)n2309LCnpQa?$cdxG;e*xm z?$%^g^LiEIjXH~jQTP#=?ea-NUVTqxe|05=^Cx#&sr{C($xn{?8JiCpHg1nq^@jjsNZ%EHoEOZiJA_PZ|;hc2R*PONAD_{pKUU9(N*v_2kk{|5vm2#egARqzVIf#wPq`_6{2sA9F(BjwJ2BE)-n84_JWBXPlClfkc+AY-sNqE16DpCG z%X~RXcBi-;IkCye5Pek7ti6dl(fbZvcKmHP>*c<0P>urQYIZ%7>!$T;I)^rp4^v*) z@^_>7CZYYgU#TJDSm*~c)_C)iIGRP7xAJ#3*0q=7(O()T+)H&odf9nuQxduf#2?7F z@#JN5uRiK{s+F7Pw`LqCY%}D`*Vag_-sf6`kyt0GtocI;g zGk69%b)=YIojPoZIF!vIAv!)8HK~?=;Wn@}@`zjbzRb8Fxu*8hUaqNiMGJY|$OTs| z5*PkXziQX-=5W){9t=>Oowb{HeJogQ@#qN>-Zr8^+?7Kp=2l`YlX9w<`j9I20x_#0 z?Y4ft{nPzmo$NlrhlpXD#^k}!YjXpq0x4fkW=R){za}P`PaJv8@JnZ`&#;%xSzU`C zQ%B`A!)h~7$)OZT({EjZ?0u-DTLS(k(a*E}zaQ1D&bCOSr@Qxk?jYvE9#5e&g5$?+ zNLDK3;z@Pq7ECd~`)0ng?NAf+SWdNN7=Expo=qUd_z?zZvlc?6=#Egyf9y>9BIQ&^ zye}5{VLFe0-}8N9OwLffheF_nVXWh`1=prTtHaIaDR|FjZ-#PX!$_k)OEs?Y|FfVjDy&vtJrg=dG~rJLS;o*gmJ@+Rj|T=jga z_;g_14AOdO;K`#ea}GJ=ALQ?{GM@5>gyGsX#qke&XhrMo@|$inJ7uLAel6;+vq>?U z=iEexxE|WA`ZH+WH3X4XE{Ao!WRsVCpZ?ZM;HjuP`2+DZ#hJnW2m3vh6LOLR(}wSj z@7(!>0jBddnmJZ{R;wF%(Y(jmPY)}{8*&tj|CE=%KZ%0iZ90USyNaFgh-RjVNEwNm zMJAa+qu7ia33Tq{=JKDH0%gOPrKwxf#t1SP+aT#)-Z~7x!WMz2!BCkuPr68J4Yc444-u_#$SM|57`S3MAm+(w~@O-qjoIWuI z*DC3$Bs#Gj1u@+HOeBK0tPgwUq6kqScKI{r=v8 zU*9cd+*~Xx)e+ofmbZK$Sjr`>|G>k4F{qspUU2){5ot6AaBgAlysP%+9+xh3mI>CIVT z1#=x-uSeaMYa1S}5;MNM7O@=oqm_xzh1x;OE0ZbHYNA9`vvbZZ{(}cKGU$6-Hru$I z?43k~MDLyB2(-DzkG#bDfxfIQ^r#U?Oq{?&J`Dul*-2$$gMwBKmzFze?x3lWD1j2y zrwhK*<0FTJ+MO66FM25`!Q9MVy*J4hYh@OoB7eoCRYa+LDXD!9LN_!{B^)6fC$ zD+d#!B-byPg z@6%ns4fTTtlq58Sv=Az+D8Cu8KucP{?GbZz9^I~RQqJ(bHS&6yM=KW5 zhG>)0)|azy`IZkWWDOQ9DA1Nmm$g$%^E4UiCA~TMxORxXR#1K?r{Hm>&*p41F}#Sh z@Vuemw9)X8UN@`QCB@PLF+MzF2|r?0**bw(A{#Gz9u%0|Q4!D^=KYq|mn1oPRy5|v zkY#7oGUmY$GG5@t@v%LqvCI-(*z(NFEN#(Mw_Gnur}w1E=4UZOXGM>M;)=A}E%nj9KFYo2H{ZwNWb@jj9C{tx345<-Qh==9 zu{(-NoX=_fPJ&c-)lM2Os}%H|j+VMvJ95c41L0n=#hT)E>2*G*;PCEgw3R1e%zuizAtBIF!Di|IE=q# zhcoY3G>2+S>+0Evd(GJpDzs>@ikl;HhMVjI!1LnD`rVOFC}*zcQ~9hBd$@>1oQd-0k9bwssI20 literal 0 HcmV?d00001 diff --git a/authz-gw/.gitignore b/authz-gw/.gitignore new file mode 100644 index 00000000..f99ab6a2 --- /dev/null +++ b/authz-gw/.gitignore @@ -0,0 +1,5 @@ +.metadata +.settings +.classpath +.project +target diff --git a/authz-gw/pom.xml b/authz-gw/pom.xml new file mode 100644 index 00000000..c4399f3c --- /dev/null +++ b/authz-gw/pom.xml @@ -0,0 +1,176 @@ + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-gw + Authz Gate/Wall + GW API + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + true + 30 + + + + + com.att.authz + authz-core + + + + javax.servlet + servlet-api + + + + + + com.att.cadi + cadi-aaf + + + + + + + + + + + org.codehaus.mojo + jaxb2-maven-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + **/*.class + + + 2.3.1 + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + + + + + + + ossrhdme + https://oss.sonatype.org/content/repositories/snapshots + + + ossrhdme + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + https://github.com/att/AAF.git + ${project.scm.connection} + http://github.com/att/AAF/tree/master + + diff --git a/authz-gw/src/main/config/authGW.props b/authz-gw/src/main/config/authGW.props new file mode 100644 index 00000000..294db359 --- /dev/null +++ b/authz-gw/src/main/config/authGW.props @@ -0,0 +1,33 @@ +## +## AUTHZ GateWall (authz-gw) Properties +## + +hostname=_HOSTNAME_ + +## DISCOVERY (DME2) Parameters on the Command Line +AFT_LATITUDE=_AFT_LATITUDE_ +AFT_LONGITUDE=_AFT_LONGITUDE_ +AFT_ENVIRONMENT=_AFT_ENVIRONMENT_ +AFT_ENV_CONTEXT=_ENV_CONTEXT_ + +DEPLOYED_VERSION=_ARTIFACT_VERSION_ + +## Pull in common/security properties + +cadi_prop_files=_COMMON_DIR_/com.att.aaf.common.props;_COMMON_DIR_/com.att.aaf.props + + +##DME2 related parameters +DMEServiceName=service=com.att.authz.authz-gw/version=_MAJOR_VER_._MINOR_VER_._PATCH_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ +AFT_DME2_PORT_RANGE=_AUTHZ_GW_PORT_RANGE_ + +# Turn on both AAF TAF & LUR 2.0 +aaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=_MAJOR_VER_._MINOR_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ + +# CSP +csp_domain=PROD + +# GUI Login Page +cadi_loginpage_url=https://DME2RESOLVE/service=com.att.authz.authz-gui/version=_MAJOR_VER_._MINOR_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_/login + + diff --git a/authz-gw/src/main/config/log4j.properties b/authz-gw/src/main/config/log4j.properties new file mode 100644 index 00000000..963c6f08 --- /dev/null +++ b/authz-gw/src/main/config/log4j.properties @@ -0,0 +1,80 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START==================================================== +# * org.onap.aai +# * =========================================================================== +# * Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# * Copyright © 2017 Amdocs +# * =========================================================================== +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END==================================================== +# * +# * ECOMP is a trademark and service mark of AT&T Intellectual Property. +# * +#------------------------------------------------------------------------------- +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +log4j.appender.INIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.INIT.File=_LOG_DIR_/${LOG4J_FILENAME_init} +log4j.appender.INIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.INIT.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.INIT.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.INIT.layout=org.apache.log4j.PatternLayout +log4j.appender.INIT.layout.ConversionPattern=%d %p [%c] %m %n + +log4j.appender.GW=org.apache.log4j.DailyRollingFileAppender +log4j.appender.GW.File=_LOG_DIR_/${LOG4J_FILENAME_gw} +log4j.appender.GW.DatePattern='.'yyyy-MM-dd +#log4j.appender.GW.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.GW.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.GW.layout=org.apache.log4j.PatternLayout +log4j.appender.GW.layout.ConversionPattern=%d %p [%c] %m %n + +log4j.appender.AUDIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.AUDIT.File=_LOG_DIR_/${LOG4J_FILENAME_audit} +log4j.appender.AUDIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.GW.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.GW.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.AUDIT.layout=org.apache.log4j.PatternLayout +log4j.appender.AUDIT.layout.ConversionPattern=%d %p [%c] %m %n + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] %m %n + +# General Apache libraries +log4j.rootLogger=WARN +log4j.logger.org.apache=WARN,INIT +log4j.logger.dme2=WARN,INIT +log4j.logger.init=INFO,INIT +log4j.logger.gw=_LOG4J_LEVEL_,GW +log4j.logger.audit=INFO,AUDIT + diff --git a/authz-gw/src/main/config/lrm-authz-gw.xml b/authz-gw/src/main/config/lrm-authz-gw.xml new file mode 100644 index 00000000..7e6c4272 --- /dev/null +++ b/authz-gw/src/main/config/lrm-authz-gw.xml @@ -0,0 +1,83 @@ + + + + + + com.att.authz._ARTIFACT_ID_ + + _MAJOR_VER_ + _MINOR_VER_ + _PATCH_VER_ + + _ROUTE_OFFER_ + + Java + com.att.authz.gw.GwAPI + + process.workdir + _ROOT_DIR_ + + + jvm.version + 1.8 + + + jvm.args + -DAFT_LATITUDE=_AFT_LATITUDE_ -DAFT_LONGITUDE=_AFT_LONGITUDE_ -DAFT_ENVIRONMENT=_AFT_ENVIRONMENT_ -Dplatform=_SCLD_PLATFORM_ -Dcom.sun.jndi.ldap.connect.pool.maxsize=20 -Dcom.sun.jndi.ldap.connect.pool.prefsize=10 -Dcom.sun.jndi.ldap.connect.pool.timeout=3000 + + + jvm.classpath + _ROOT_DIR_/etc:_ROOT_DIR_/lib/*: + + + jvm.heap.min + 512m + + + jvm.heap.max + 2048m + + + start.class + com.att.authz.gw.GwAPI + + + stdout.redirect + _ROOT_DIR_/logs/SystemOut.log + + + stderr.redirect + _ROOT_DIR_/logs/SystemErr.log + + aft + AUTO + 4 + _RESOURCE_MIN_COUNT_ + _RESOURCE_MAX_COUNT_ + _RESOURCE_REGISTRATION_ + com.att.authz:_ARTIFACT_ID_ + _ARTIFACT_VERSION_ + + diff --git a/authz-gw/src/main/java/com/att/authz/gw/GwAPI.java b/authz-gw/src/main/java/com/att/authz/gw/GwAPI.java new file mode 100644 index 00000000..9411bcd1 --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/GwAPI.java @@ -0,0 +1,248 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw; + +import java.net.HttpURLConnection; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import com.att.aft.dme2.api.DME2Exception; + +import com.att.aft.dme2.api.DME2Manager; +import com.att.aft.dme2.api.DME2Server; +import com.att.aft.dme2.api.DME2ServerProperties; +import com.att.aft.dme2.api.DME2ServiceHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder.RequestDispatcherType; +import com.att.aft.dme2.api.util.DME2ServletHolder; +import com.att.authz.env.AuthzEnv; +import com.att.authz.gw.api.API_AAFAccess; +import com.att.authz.gw.api.API_Api; +import com.att.authz.gw.api.API_Find; +import com.att.authz.gw.api.API_Proxy; +import com.att.authz.gw.api.API_TGuard; +import com.att.authz.gw.facade.GwFacade_1_0; +import com.att.authz.gw.mapper.Mapper.API; +import com.att.authz.server.AbsServer; +import com.att.cache.Cache; +import com.att.cache.Cache.Dated; +import com.att.cadi.CadiException; +//import com.att.cadi.PropAccess; +import com.att.cadi.aaf.v2_0.AAFAuthn; +import com.att.cadi.aaf.v2_0.AAFLurPerm; +import com.att.cadi.config.Config; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; + +public class GwAPI extends AbsServer { + private static final String USER_PERMS = "userPerms"; + private GwFacade_1_0 facade; // this is the default Facade + private GwFacade_1_0 facade_1_0_XML; + public Map cacheUser; + public final String aafurl; + public final AAFAuthn aafAuthn; + public final AAFLurPerm aafLurPerm; + public DME2Manager dme2Man; + + + /** + * Construct AuthzAPI with all the Context Supporting Routes that Authz needs + * + * @param env + * @param si + * @param dm + * @param decryptor + * @throws APIException + */ + public GwAPI(AuthzEnv env) throws Exception { + super(env,"AAF GW"); + aafurl = env.getProperty(Config.AAF_URL); + + // Setup Logging + //env.setLog4JNames("log4j.properties","authz","gw","audit","init","trace"); + + aafLurPerm = aafCon.newLur(); + // Note: If you need both Authn and Authz construct the following: + aafAuthn = aafCon.newAuthn(aafLurPerm); + + // Initialize Facade for all uses + //AuthzTrans trans = env.newTrans(); + + // facade = GwFacadeFactory.v1_0(env,trans,Data.TYPE.JSON); // Default Facade + // facade_1_0_XML = GwFacadeFactory.v1_0(env,trans,Data.TYPE.XML); + + synchronized(env) { + if(cacheUser == null) { + cacheUser = Cache.obtain(USER_PERMS); + //Cache.startCleansing(env, USER_PERMS); + Cache.addShutdownHook(); // Setup Shutdown Hook to close cache + } + } + + //////////////////////////////////////////////////////////////////////////// + // Time Critical + // These will always be evaluated first + //////////////////////////////////////////////////////////////////////// + API_AAFAccess.init(this,facade); + API_Find.init(this, facade); + API_TGuard.init(this, facade); + API_Proxy.init(this, facade); + + //////////////////////////////////////////////////////////////////////// + // Management APIs + //////////////////////////////////////////////////////////////////////// + // There are several APIs around each concept, and it gets a bit too + // long in this class to create. The initialization of these Management + // APIs have therefore been pushed to StandAlone Classes with static + // init functions + API_Api.init(this, facade); + + //////////////////////////////////////////////////////////////////////// + // Default Function + //////////////////////////////////////////////////////////////////////// + API_AAFAccess.initDefault(this,facade); + + } + + /** + * Setup XML and JSON implementations for each supported Version type + * + * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties + * to do Versions and Content switches + * + */ + public void route(HttpMethods meth, String path, API api, GwCode code) throws Exception { + String version = "1.0"; + // Get Correct API Class from Mapper + Class respCls = facade.mapper().getClass(api); + if(respCls==null) throw new Exception("Unknown class associated with " + api.getClass().getName() + ' ' + api.name()); + // setup Application API HTML ContentTypes for JSON and Route + String application = applicationJSON(respCls, version); + //route(env,meth,path,code,application,"application/json;version="+version,"*/*"); + + // setup Application API HTML ContentTypes for XML and Route + application = applicationXML(respCls, version); + //route(env,meth,path,code.clone(facade_1_0_XML,false),application,"text/xml;version="+version); + + // Add other Supported APIs here as created + } + + public void routeAll(HttpMethods meth, String path, API api, GwCode code) throws Exception { + //route(env,meth,path,code,""); // this will always match + } + + + /** + * Start up AuthzAPI as DME2 Service + * @param env + * @param props + * @throws DME2Exception + * @throws CadiException + */ + public void startDME2(Properties props) throws DME2Exception, CadiException { + + dme2Man = new DME2Manager("GatewayDME2Manager",props); + + DME2ServiceHolder svcHolder; + List slist = new ArrayList(); + svcHolder = new DME2ServiceHolder(); + String serviceName = env.getProperty("DMEServiceName",null); + if(serviceName!=null) { + svcHolder.setServiceURI(serviceName); + svcHolder.setManager(dme2Man); + svcHolder.setContext("/"); + + + + DME2ServletHolder srvHolder = new DME2ServletHolder(this, new String[] {"/dme2","/api"}); + srvHolder.setContextPath("/*"); + slist.add(srvHolder); + + EnumSet edlist = EnumSet.of( + RequestDispatcherType.REQUEST, + RequestDispatcherType.FORWARD, + RequestDispatcherType.ASYNC + ); + + /////////////////////// + // Apply Filters + /////////////////////// + List flist = new ArrayList(); + + // Leave Login page un secured + // AuthzTransOnlyFilter atof = new AuthzTransOnlyFilter(env); + // flist.add(new DME2FilterHolder(atof,"/login", edlist)); + + // Secure all other interactions with AuthzTransFilter +// flist.add(new DME2FilterHolder( +// new AuthzTransFilter(env, aafCon, new AAFTrustChecker( +// env.getProperty(Config.CADI_TRUST_PROP, Config.CADI_USER_CHAIN), +// Define.ROOT_NS + ".mechid|"+Define.ROOT_COMPANY+"|trust" +// )), +// "/*", edlist)); +// + + svcHolder.setFilters(flist); + svcHolder.setServletHolders(slist); + + DME2Server dme2svr = dme2Man.getServer(); +// dme2svr.setGracefulShutdownTimeMs(1000); + + // env.init().log("Starting GW Jetty/DME2 server..."); + dme2svr.start(); + DME2ServerProperties dsprops = dme2svr.getServerProperties(); + try { +// if(env.getProperty("NO_REGISTER",null)!=null) + dme2Man.bindService(svcHolder); +// env.init().log("DME2 is available as HTTP"+(dsprops.isSslEnable()?"/S":""),"on port:",dsprops.getPort()); + + while(true) { // Per DME2 Examples... + Thread.sleep(5000); + } + } catch(InterruptedException e) { + // env.init().log("AAF Jetty Server interrupted!"); + } catch(Exception e) { // Error binding service doesn't seem to stop DME2 or Process + // env.init().log(e,"DME2 Initialization Error"); + dme2svr.stop(); + System.exit(1); + } + } else { + //env.init().log("Properties must contain DMEServiceName"); + } + } + + public static void main(String[] args) { + setup(GwAPI.class,"authGW.props"); + } + +// public void route(PropAccess env, HttpMethods get, String string, GwCode gwCode, String string2, String string3, +// String string4) { +// // TODO Auto-generated method stub +// +// } + +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/GwCode.java b/authz-gw/src/main/java/com/att/authz/gw/GwCode.java new file mode 100644 index 00000000..07717db3 --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/GwCode.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.facade.GwFacade; +import com.att.cssa.rserv.HttpCode; + +public abstract class GwCode extends HttpCode implements Cloneable { + public boolean useJSON; + + public GwCode(GwFacade facade, String description, boolean useJSON, String ... roles) { + super(facade, description, roles); + this.useJSON = useJSON; + } + + public D clone(GwFacade facade, boolean useJSON) throws Exception { + @SuppressWarnings("unchecked") + D d = (D)clone(); + d.useJSON = useJSON; + d.context = facade; + return d; + } + +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/api/API_AAFAccess.java b/authz-gw/src/main/java/com/att/authz/gw/api/API_AAFAccess.java new file mode 100644 index 00000000..ffe42e1c --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/api/API_AAFAccess.java @@ -0,0 +1,363 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.api; + +import java.io.IOException; +import java.net.ConnectException; +import java.net.MalformedURLException; +import java.net.URI; +import java.security.Principal; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.GwAPI; +import com.att.authz.gw.GwCode; +import com.att.authz.gw.facade.GwFacade; +import com.att.authz.gw.mapper.Mapper.API; +import com.att.authz.layer.Result; +import com.att.cache.Cache.Dated; +import com.att.cadi.CadiException; +import com.att.cadi.Locator; +import com.att.cadi.Locator.Item; +import com.att.cadi.LocatorException; +import com.att.cadi.aaf.AAFPermission; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cadi.dme2.DME2Locator; +import com.att.cadi.principal.BasicPrincipal; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +public class API_AAFAccess { + private static final String AUTHZ_DME2_GUI = "com.att.authz.authz-gui"; + static final String AFT_ENVIRONMENT="AFT_ENVIRONMENT"; + static final String AFT_ENV_CONTEXT="AFT_ENV_CONTEXT"; + static final String AFTUAT="AFTUAT"; + + private static final String PROD = "PROD"; + private static final String IST = "IST"; // main NONPROD system + private static final String PERF = "PERF"; + private static final String TEST = "TEST"; + private static final String DEV = "DEV"; + +// private static String service, version, envContext; + private static String routeOffer; + + private static final String GET_PERMS_BY_USER = "Get Perms by User"; + private static final String USER_HAS_PERM ="User Has Perm"; +// private static final String USER_IN_ROLE ="User Has Role"; + private static final String BASIC_AUTH ="AAF Basic Auth"; + + /** + * Normal Init level APIs + * + * @param gwAPI + * @param facade + * @throws Exception + */ + public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception { + String aftenv = gwAPI.env.getProperty(AFT_ENVIRONMENT); + if(aftenv==null) throw new Exception(AFT_ENVIRONMENT + " must be set"); + + int equals, count=0; + for(int slash = gwAPI.aafurl.indexOf('/');slash>0;++count) { + equals = gwAPI.aafurl.indexOf('=',slash)+1; + slash = gwAPI.aafurl.indexOf('/',slash+1); + switch(count) { + case 2: +// service = gwAPI.aafurl.substring(equals, slash); + break; + case 3: +// version = gwAPI.aafurl.substring(equals, slash); + break; + case 4: +// envContext = gwAPI.aafurl.substring(equals, slash); + break; + case 5: + routeOffer = gwAPI.aafurl.substring(equals); + break; + } + } + if(count<6) throw new MalformedURLException(gwAPI.aafurl); + + gwAPI.route(HttpMethods.GET,"/authz/perms/user/:user",API.VOID,new GwCode(facade,GET_PERMS_BY_USER, true) { + @Override + public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception { + TimeTaken tt = trans.start(GET_PERMS_BY_USER, Env.SUB); + try { + final String accept = req.getHeader("ACCEPT"); + final String user = pathParam(req,":user"); + if(!user.contains("@")) { + context.error(trans,resp,Result.ERR_BadData,"User [%s] must be fully qualified with domain",user); + return; + } + String key = trans.user() + user + (accept!=null&&accept.contains("xml")?"-xml":"-json"); + TimeTaken tt2 = trans.start("Cache Lookup",Env.SUB); + Dated d; + try { + d = gwAPI.cacheUser.get(key); + } finally { + tt2.done(); + } + + if(d==null || d.data.isEmpty()) { + tt2 = trans.start("AAF Service Call",Env.REMOTE); + try { + gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future fp = client.read("/authz/perms/user/"+user,accept); + if(fp.get(5000)) { + gwAPI.cacheUser.put(key, new Dated(new User(fp.code(),fp.body()))); + resp.setStatus(HttpStatus.OK_200); + ServletOutputStream sos; + try { + sos = resp.getOutputStream(); + sos.print(fp.value); + } catch (IOException e) { + throw new CadiException(e); + } + } else { + gwAPI.cacheUser.put(key, new Dated(new User(fp.code(),fp.body()))); + context.error(trans,resp,fp.code(),fp.body()); + } + return null; + } + }); + } finally { + tt2.done(); + } + } else { + User u = (User)d.data.get(0); + resp.setStatus(u.code); + ServletOutputStream sos = resp.getOutputStream(); + sos.print(u.resp); + } + } finally { + tt.done(); + } + } + }); + + gwAPI.route(gwAPI.env,HttpMethods.GET,"/authn/basicAuth",new GwCode(facade,BASIC_AUTH, true) { + @Override + public void handle(final AuthzTrans trans, final HttpServletRequest req, HttpServletResponse resp) throws Exception { + Principal p = trans.getUserPrincipal(); + if(p == null) { + trans.error().log("Transaction not Authenticated... no Principal"); + resp.setStatus(HttpStatus.FORBIDDEN_403); + } else if (p instanceof BasicPrincipal) { + // the idea is that if call is made with this credential, and it's a BasicPrincipal, it's ok + // otherwise, it wouldn't have gotten here. + resp.setStatus(HttpStatus.OK_200); + } else { + trans.checkpoint("Basic Auth Check Failed: This wasn't a Basic Auth Trans"); + // For Auth Security questions, we don't give any info to client on why failed + resp.setStatus(HttpStatus.FORBIDDEN_403); + } + } + },"text/plain","*/*","*"); + + /** + * Query User Has Perm + */ + gwAPI.route(HttpMethods.GET,"/ask/:user/has/:type/:instance/:action",API.VOID,new GwCode(facade,USER_HAS_PERM, true) { + @Override + public void handle(final AuthzTrans trans, final HttpServletRequest req, HttpServletResponse resp) throws Exception { + try { + resp.getOutputStream().print( + gwAPI.aafLurPerm.fish(pathParam(req,":user"), new AAFPermission( + pathParam(req,":type"), + pathParam(req,":instance"), + pathParam(req,":action")))); + resp.setStatus(HttpStatus.OK_200); + } catch(Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); + + if(AFTUAT.equals(aftenv)) { + gwAPI.route(HttpMethods.GET,"/ist/aaf/:version/:path*",API.VOID ,new GwCode(facade,"Access UAT GUI for AAF", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + try{ + redirect(trans, req, resp, context, + new DME2Locator(gwAPI.env, gwAPI.dme2Man, AUTHZ_DME2_GUI, pathParam(req,":version"), IST, routeOffer), + pathParam(req,":path")); + } catch (LocatorException e) { + context.error(trans, resp, Result.ERR_BadData, e.getMessage()); + } catch (Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); + + gwAPI.route(HttpMethods.GET,"/test/aaf/:version/:path*",API.VOID ,new GwCode(facade,"Access TEST GUI for AAF", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + try{ + redirect(trans, req, resp, context, + new DME2Locator(gwAPI.env, gwAPI.dme2Man, AUTHZ_DME2_GUI, pathParam(req,":version"), TEST, routeOffer), + pathParam(req,":path")); + } catch (LocatorException e) { + context.error(trans, resp, Result.ERR_BadData, e.getMessage()); + } catch (Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); + + gwAPI.route(HttpMethods.GET,"/perf/aaf/:version/:path*",API.VOID ,new GwCode(facade,"Access PERF GUI for AAF", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + try{ + redirect(trans, req, resp, context, + new DME2Locator(gwAPI.env, gwAPI.dme2Man, AUTHZ_DME2_GUI, pathParam(req,":version"), PERF, routeOffer), + pathParam(req,":path")); + } catch (LocatorException e) { + context.error(trans, resp, Result.ERR_BadData, e.getMessage()); + } catch (Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); + + gwAPI.route(HttpMethods.GET,"/dev/aaf/:version/:path*",API.VOID,new GwCode(facade,"Access DEV GUI for AAF", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + try { + redirect(trans, req, resp, context, + new DME2Locator(gwAPI.env, gwAPI.dme2Man, AUTHZ_DME2_GUI, pathParam(req,":version"), DEV, routeOffer), + pathParam(req,":path")); + } catch (LocatorException e) { + context.error(trans, resp, Result.ERR_BadData, e.getMessage()); + } catch (Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); + } else { + gwAPI.route(HttpMethods.GET,"/aaf/:version/:path*",API.VOID,new GwCode(facade,"Access PROD GUI for AAF", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + try { + redirect(trans, req, resp, context, + new DME2Locator(gwAPI.env, gwAPI.dme2Man, AUTHZ_DME2_GUI, pathParam(req,":version"), PROD, routeOffer), + pathParam(req,":path")); + } catch (LocatorException e) { + context.error(trans, resp, Result.ERR_BadData, e.getMessage()); + } catch (Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); + } + + } + + public static void initDefault(final GwAPI gwAPI, GwFacade facade) throws Exception { + String aftenv = gwAPI.env.getProperty(AFT_ENVIRONMENT); + if(aftenv==null) throw new Exception(AFT_ENVIRONMENT + " must be set"); + + String aftctx = gwAPI.env.getProperty(AFT_ENV_CONTEXT); + if(aftctx==null) throw new Exception(AFT_ENV_CONTEXT + " must be set"); + + /** + * "login" url + */ + gwAPI.route(HttpMethods.GET,"/login",API.VOID,new GwCode(facade,"Access " + aftctx + " GUI for AAF", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + try { + redirect(trans, req, resp, context, + new DME2Locator(gwAPI.env, gwAPI.dme2Man, AUTHZ_DME2_GUI, "2.0", aftctx, routeOffer), + "login"); + } catch (LocatorException e) { + context.error(trans, resp, Result.ERR_BadData, e.getMessage()); + } catch (Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); + + /** + * Default URL + */ + gwAPI.route(HttpMethods.GET,"/",API.VOID,new GwCode(facade,"Access " + aftctx + " GUI for AAF", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + try { + redirect(trans, req, resp, context, + new DME2Locator(gwAPI.env, gwAPI.dme2Man, AUTHZ_DME2_GUI, "2.0", aftctx, routeOffer), + "gui/home"); + } catch (LocatorException e) { + context.error(trans, resp, Result.ERR_BadData, e.getMessage()); + } catch (Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); + } + + private static void redirect(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, GwFacade context, Locator loc, String path) throws IOException { + try { + if(loc.hasItems()) { + Item item = loc.best(); + URI uri = (URI) loc.get(item); + StringBuilder redirectURL = new StringBuilder(uri.toString()); + redirectURL.append('/'); + redirectURL.append(path); + String str = req.getQueryString(); + if(str!=null) { + redirectURL.append('?'); + redirectURL.append(str); + } + trans.info().log("Redirect to",redirectURL); + resp.sendRedirect(redirectURL.toString()); + } else { + context.error(trans, resp, Result.err(Result.ERR_NotFound,"%s is not valid",req.getPathInfo())); + } + } catch (LocatorException e) { + context.error(trans, resp, Result.err(Result.ERR_NotFound,"No DME2 Endpoints found for %s",req.getPathInfo())); + } + } + + private static class User { + public final int code; + public final String resp; + + public User(int code, String resp) { + this.code = code; + this.resp = resp; + } + } +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/api/API_Api.java b/authz-gw/src/main/java/com/att/authz/gw/api/API_Api.java new file mode 100644 index 00000000..a752e67b --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/api/API_Api.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.api; + +import static com.att.authz.layer.Result.OK; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.GwAPI; +import com.att.authz.gw.GwCode; +import com.att.authz.gw.facade.GwFacade; +import com.att.authz.gw.mapper.Mapper.API; +import com.att.authz.layer.Result; +import com.att.cadi.Symm; +import com.att.cssa.rserv.HttpMethods; + +/** + * API Apis + * + */ +public class API_Api { + /** + * Normal Init level APIs + * + * @param gwAPI + * @param facade + * @throws Exception + */ + public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception { + //////// + // Overall APIs + /////// + gwAPI.route(HttpMethods.GET,"/api",API.VOID,new GwCode(facade,"Document API", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + Result r = context.getAPI(trans,resp,gwAPI); + switch(r.status) { + case OK: + resp.setStatus(HttpStatus.OK_200); + break; + default: + context.error(trans,resp,r); + } + + } + }); + + //////// + // Overall Examples + /////// + gwAPI.route(HttpMethods.GET,"/api/example/*",API.VOID,new GwCode(facade,"Document API", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + String pathInfo = req.getPathInfo(); + int question = pathInfo.lastIndexOf('?'); + + pathInfo = pathInfo.substring(13, question<0?pathInfo.length():question);// IMPORTANT, this is size of "/api/example/" + String nameOrContextType=Symm.base64noSplit.decode(pathInfo); +// String param = req.getParameter("optional"); + Result r = context.getAPIExample(trans,resp,nameOrContextType, + question>=0 && "optional=true".equalsIgnoreCase(req.getPathInfo().substring(question+1)) + ); + switch(r.status) { + case OK: + resp.setStatus(HttpStatus.OK_200); + break; + default: + context.error(trans,resp,r); + } + + } + }); + + } +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/api/API_Find.java b/authz-gw/src/main/java/com/att/authz/gw/api/API_Find.java new file mode 100644 index 00000000..7705c4a4 --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/api/API_Find.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.api; + +import java.net.URI; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.GwAPI; +import com.att.authz.gw.GwCode; +import com.att.authz.gw.facade.GwFacade; +import com.att.authz.gw.mapper.Mapper.API; +import com.att.authz.layer.Result; +import com.att.cadi.Locator; +import com.att.cadi.Locator.Item; +import com.att.cadi.LocatorException; +import com.att.cadi.dme2.DME2Locator; +import com.att.cssa.rserv.HttpMethods; + +/** + * API Apis.. using Redirect for mechanism + * + * + */ +public class API_Find { + /** + * Normal Init level APIs + * + * @param gwAPI + * @param facade + * @throws Exception + */ + public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception { + //////// + // Overall APIs + /////// + gwAPI.route(HttpMethods.GET,"/dme2/:service/:version/:envContext/:routeOffer/:path*",API.VOID,new GwCode(facade,"Document API", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + //TODO cache this... + try { + Locator loc = new DME2Locator(gwAPI.env, gwAPI.dme2Man, + pathParam(req,":service"), + pathParam(req,":version"), + pathParam(req,":envContext"), + pathParam(req,":routeOffer") + ); + if(loc.hasItems()) { + Item item = loc.best(); + URI uri = (URI) loc.get(item); + String redirectURL = uri.toString() + '/' + pathParam(req,":path"); + trans.warn().log("Redirect to",redirectURL); + resp.sendRedirect(redirectURL); + } else { + context.error(trans, resp, Result.err(Result.ERR_NotFound,"%s is not valid",req.getPathInfo())); + } + } catch (LocatorException e) { + context.error(trans, resp, Result.err(Result.ERR_NotFound,"No DME2 Endpoints found for %s",req.getPathInfo())); + } + } + }); + + } +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/api/API_Proxy.java b/authz-gw/src/main/java/com/att/authz/gw/api/API_Proxy.java new file mode 100644 index 00000000..14d8c41f --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/api/API_Proxy.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.api; + +import java.net.ConnectException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.GwAPI; +import com.att.authz.gw.GwCode; +import com.att.authz.gw.facade.GwFacade; +import com.att.authz.gw.mapper.Mapper.API; +import com.att.cadi.CadiException; +import com.att.cadi.client.Future; +import com.att.cadi.client.Rcli; +import com.att.cadi.client.Retryable; +import com.att.cadi.config.Config; +import com.att.cssa.rserv.HttpMethods; +import com.att.inno.env.APIException; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; + +/** + * API Apis.. using Redirect for mechanism + * + * + */ +public class API_Proxy { + + /** + * Normal Init level APIs + * + * @param gwAPI + * @param facade + * @throws Exception + */ + public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception { + + String aafurl = gwAPI.env.getProperty(Config.AAF_URL); + if(aafurl==null) { + } else { + + //////// + // Transferring APIs + /////// + gwAPI.routeAll(HttpMethods.GET,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy GET", true) { + @Override + public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception { + TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE); + try { + gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200); + ft.get(10000); // Covers return codes and err messages + return null; + } + }); + + } catch (CadiException | APIException e) { + trans.error().log(e); + } finally { + tt.done(); + } + } + }); + + gwAPI.routeAll(HttpMethods.POST,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy POST", true) { + @Override + public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception { + TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE); + try { + gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.CREATED_201); + ft.get(10000); // Covers return codes and err messages + return null; + } + }); + } catch (CadiException | APIException e) { + trans.error().log(e); + } finally { + tt.done(); + } + } + }); + + gwAPI.routeAll(HttpMethods.PUT,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy PUT", true) { + @Override + public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception { + TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE); + try { + gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200); + ft.get(10000); // Covers return codes and err messages + return null; + } + }); + } catch (CadiException | APIException e) { + trans.error().log(e); + } finally { + tt.done(); + } + } + }); + + gwAPI.routeAll(HttpMethods.DELETE,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy DELETE", true) { + @Override + public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception { + TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE); + try { + gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200); + ft.get(10000); // Covers return codes and err messages + return null; + } + }); + } catch (CadiException | APIException e) { + trans.error().log(e); + } finally { + tt.done(); + } + } + }); + } + } +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/api/API_TGuard.java b/authz-gw/src/main/java/com/att/authz/gw/api/API_TGuard.java new file mode 100644 index 00000000..52dae40b --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/api/API_TGuard.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.api; + +import static com.att.authz.layer.Result.OK; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.aft.dme2.internal.jetty.http.HttpStatus; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.GwAPI; +import com.att.authz.gw.GwCode; +import com.att.authz.gw.facade.GwFacade; +import com.att.authz.gw.mapper.Mapper.API; +import com.att.authz.layer.Result; +import com.att.cssa.rserv.HttpMethods; + +/** + * API Apis + * + */ +public class API_TGuard { + /** + * Normal Init level APIs + * + * @param gwAPI + * @param facade + * @throws Exception + */ + public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception { + String aftenv = gwAPI.env.getProperty(API_AAFAccess.AFT_ENVIRONMENT); + if(aftenv==null) throw new Exception(API_AAFAccess.AFT_ENVIRONMENT + " must be set"); + + //////// + // Do not deploy these to PROD + /////// + if(API_AAFAccess.AFTUAT.equals(aftenv)) { + gwAPI.route(HttpMethods.GET,"/tguard/:path*",API.VOID,new GwCode(facade,"TGuard Test", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + Result r = context.getAPI(trans,resp,gwAPI); + switch(r.status) { + case OK: + resp.setStatus(HttpStatus.OK_200); + break; + default: + context.error(trans,resp,r); + } + } + }); + } + } +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacade.java b/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacade.java new file mode 100644 index 00000000..e4eb6352 --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacade.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.facade; + +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cssa.rserv.RServlet; + + +/** + * + * + */ +public interface GwFacade { + +///////////////////// STANDARD ELEMENTS ////////////////// + /** + * @param trans + * @param response + * @param result + */ + void error(AuthzTrans trans, HttpServletResponse response, Result result); + + /** + * + * @param trans + * @param response + * @param status + */ + void error(AuthzTrans trans, HttpServletResponse response, int status, String msg, String ... detail); + + + /** + * + * @param trans + * @param resp + * @param rservlet + * @return + */ + public Result getAPI(AuthzTrans trans, HttpServletResponse resp, RServlet rservlet); + + /** + * + * @param trans + * @param resp + * @param typeCode + * @param optional + * @return + */ + public abstract Result getAPIExample(AuthzTrans trans, HttpServletResponse resp, String typeCode, boolean optional); + +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacadeFactory.java b/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacadeFactory.java new file mode 100644 index 00000000..4b79b07e --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacadeFactory.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.facade; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.mapper.Mapper_1_0; +import com.att.authz.gw.service.GwServiceImpl; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; + +import gw.v1_0.Error; +import gw.v1_0.InRequest; +import gw.v1_0.Out; + + +public class GwFacadeFactory { + public static GwFacade_1_0 v1_0(AuthzEnv env, AuthzTrans trans, Data.TYPE type) throws APIException { + return new GwFacade_1_0(env, + new GwServiceImpl< + InRequest, + Out, + Error>(trans,new Mapper_1_0()), + type); + } + +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacadeImpl.java b/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacadeImpl.java new file mode 100644 index 00000000..9f1c3f1a --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/facade/GwFacadeImpl.java @@ -0,0 +1,258 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.facade; + + +import static com.att.authz.layer.Result.ERR_ActionNotCompleted; +import static com.att.authz.layer.Result.ERR_BadData; +import static com.att.authz.layer.Result.ERR_ConflictAlreadyExists; +import static com.att.authz.layer.Result.ERR_Denied; +import static com.att.authz.layer.Result.ERR_NotFound; +import static com.att.authz.layer.Result.ERR_NotImplemented; +import static com.att.authz.layer.Result.ERR_Policy; +import static com.att.authz.layer.Result.ERR_Security; + +import java.lang.reflect.Method; + +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.mapper.Mapper; +import com.att.authz.gw.mapper.Mapper.API; +import com.att.authz.gw.service.GwService; +import com.att.authz.gw.service.GwServiceImpl; +import com.att.authz.layer.FacadeImpl; +import com.att.authz.layer.Result; +import com.att.cadi.aaf.client.Examples; +import com.att.cssa.rserv.RServlet; +import com.att.cssa.rserv.RouteReport; +import com.att.cssa.rserv.doc.ApiDoc; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; +import com.att.inno.env.Data.TYPE; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.rosetta.env.RosettaDF; + +import gw.v1_0.Api; + +/** + * AuthzFacade + * + * This Service Facade encapsulates the essence of the API Service can do, and provides + * a single created object for elements such as RosettaDF. + * + * The Responsibilities of this class are to: + * 1) Interact with the Service Implementation (which might be supported by various kinds of Backend Storage) + * 2) Validate incoming data (if applicable) + * 3) Convert the Service response into the right Format, and mark the Content Type + * a) In the future, we may support multiple Response Formats, aka JSON or XML, based on User Request. + * 4) Log Service info, warnings and exceptions as necessary + * 5) When asked by the API layer, this will create and write Error content to the OutputStream + * + * Note: This Class does NOT set the HTTP Status Code. That is up to the API layer, so that it can be + * clearly coordinated with the API Documentation + * + * + */ +public abstract class GwFacadeImpl extends FacadeImpl implements GwFacade + { + private GwService service; + + private final RosettaDF errDF; + private final RosettaDF apiDF; + + public GwFacadeImpl(AuthzEnv env, GwService service, Data.TYPE dataType) throws APIException { + this.service = service; + (errDF = env.newDataFactory(mapper().getClass(API.ERROR))).in(dataType).out(dataType); + (apiDF = env.newDataFactory(Api.class)).in(dataType).out(dataType); + } + + public Mapper mapper() { + return service.mapper(); + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#error(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, int) + * + * Note: Conforms to AT&T TSS RESTful Error Structure + */ + @Override + public void error(AuthzTrans trans, HttpServletResponse response, Result result) { + String msg = result.details==null?"":result.details.trim(); + String[] detail; + if(result.variables==null) { + detail = new String[1]; + } else { + int l = result.variables.length; + detail=new String[l+1]; + System.arraycopy(result.variables, 0, detail, 1, l); + } + error(trans, response, result.status,msg,detail); + } + + @Override + public void error(AuthzTrans trans, HttpServletResponse response, int status, String msg, String ... _detail) { + String[] detail = _detail; + if(detail.length==0) { + detail=new String[1]; + } + String msgId; + switch(status) { + case 202: + case ERR_ActionNotCompleted: + msgId = "SVC1202"; + detail[0] = "Accepted, Action not complete"; + response.setStatus(/*httpstatus=*/202); + break; + + case 403: + case ERR_Policy: + case ERR_Security: + case ERR_Denied: + msgId = "SVC1403"; + detail[0] = "Forbidden"; + response.setStatus(/*httpstatus=*/403); + break; + + case 404: + case ERR_NotFound: + msgId = "SVC1404"; + detail[0] = "Not Found"; + response.setStatus(/*httpstatus=*/404); + break; + + case 406: + case ERR_BadData: + msgId="SVC1406"; + detail[0] = "Not Acceptable"; + response.setStatus(/*httpstatus=*/406); + break; + + case 409: + case ERR_ConflictAlreadyExists: + msgId = "SVC1409"; + detail[0] = "Conflict Already Exists"; + response.setStatus(/*httpstatus=*/409); + break; + + case 501: + case ERR_NotImplemented: + msgId = "SVC1501"; + detail[0] = "Not Implemented"; + response.setStatus(/*httpstatus=*/501); + break; + + + default: + msgId = "SVC1500"; + detail[0] = "General Service Error"; + response.setStatus(/*httpstatus=*/500); + break; + } + + try { + StringBuilder holder = new StringBuilder(); + errDF.newData(trans).load( + mapper().errorFromMessage(holder,msgId,msg,detail)).to(response.getOutputStream()); + trans.checkpoint( + "ErrResp [" + + msgId + + "] " + + holder.toString(), + Env.ALWAYS); + } catch (Exception e) { + trans.error().log(e,"unable to send response for",msg); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getAPI(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse) + */ + public final static String API_REPORT = "apiReport"; + @Override + public Result getAPI(AuthzTrans trans, HttpServletResponse resp, RServlet rservlet) { + TimeTaken tt = trans.start(API_REPORT, Env.SUB); + try { + Api api = new Api(); + Api.Route ar; + Method[] meths = GwServiceImpl.class.getDeclaredMethods(); + for(RouteReport rr : rservlet.routeReport()) { + api.getRoute().add(ar = new Api.Route()); + ar.setMeth(rr.meth.name()); + ar.setPath(rr.path); + ar.setDesc(rr.desc); + ar.getContentType().addAll(rr.contextTypes); + for(Method m : meths) { + ApiDoc ad; + if((ad = m.getAnnotation(ApiDoc.class))!=null && + rr.meth.equals(ad.method()) && + rr.path.equals(ad.path())) { + for(String param : ad.params()) { + ar.getParam().add(param); + } + for(String text : ad.text()) { + ar.getComments().add(text); + } + ar.setExpected(ad.expectedCode()); + for(int ec : ad.errorCodes()) { + ar.getExplicitErr().add(ec); + } + } + } + } + apiDF.newData(trans).load(api).to(resp.getOutputStream()); + setContentType(resp,apiDF.getOutType()); + return Result.ok(); + + } catch (Exception e) { + trans.error().log(e,IN,API_REPORT); + return Result.err(e); + } finally { + tt.done(); + } + } + + public final static String API_EXAMPLE = "apiExample"; + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getAPIExample(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getAPIExample(AuthzTrans trans, HttpServletResponse resp, String nameOrContentType, boolean optional) { + TimeTaken tt = trans.start(API_EXAMPLE, Env.SUB); + try { + String content =Examples.print(apiDF.getEnv(), nameOrContentType, optional); + resp.getOutputStream().print(content); + setContentType(resp,content.contains(" +{ + public GwFacade_1_0(AuthzEnv env, GwService service, Data.TYPE type) throws APIException { + super(env, service, type); + } +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/mapper/Mapper.java b/authz-gw/src/main/java/com/att/authz/gw/mapper/Mapper.java new file mode 100644 index 00000000..c2f30498 --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/mapper/Mapper.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.mapper; + +public interface Mapper +{ + public enum API{IN_REQ,OUT,ERROR,VOID}; + public Class getClass(API api); + public A newInstance(API api); + + public ERROR errorFromMessage(StringBuilder holder, String msgID, String text, String... detail); + +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/mapper/Mapper_1_0.java b/authz-gw/src/main/java/com/att/authz/gw/mapper/Mapper_1_0.java new file mode 100644 index 00000000..49f2f846 --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/mapper/Mapper_1_0.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.mapper; + +import com.att.cadi.util.Vars; + +import gw.v1_0.Error; +import gw.v1_0.InRequest; +import gw.v1_0.Out; + +public class Mapper_1_0 implements Mapper { + + @Override + public Class getClass(API api) { + switch(api) { + case IN_REQ: return InRequest.class; + case OUT: return Out.class; + case ERROR: return Error.class; + case VOID: return Void.class; + } + return null; + } + + @SuppressWarnings("unchecked") + @Override + public A newInstance(API api) { + switch(api) { + case IN_REQ: return (A) new InRequest(); + case OUT: return (A) new Out(); + case ERROR: return (A)new Error(); + case VOID: return null; + } + return null; + } + + ////////////// Mapping Functions ///////////// + @Override + public gw.v1_0.Error errorFromMessage(StringBuilder holder, String msgID, String text,String... var) { + Error err = new Error(); + err.setMessageId(msgID); + // AT&T Restful Error Format requires numbers "%" placements + err.setText(Vars.convert(holder, text, var)); + for(String s : var) { + err.getVariables().add(s); + } + return err; + } + +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/service/GwService.java b/authz-gw/src/main/java/com/att/authz/gw/service/GwService.java new file mode 100644 index 00000000..aaa5489a --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/service/GwService.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.service; + +import com.att.authz.gw.mapper.Mapper; + +public interface GwService { + public Mapper mapper(); +} diff --git a/authz-gw/src/main/java/com/att/authz/gw/service/GwServiceImpl.java b/authz-gw/src/main/java/com/att/authz/gw/service/GwServiceImpl.java new file mode 100644 index 00000000..3113d9de --- /dev/null +++ b/authz-gw/src/main/java/com/att/authz/gw/service/GwServiceImpl.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw.service; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.gw.mapper.Mapper; + +public class GwServiceImpl + implements GwService { + + private Mapper mapper; + + public GwServiceImpl(AuthzTrans trans, Mapper mapper) { + this.mapper = mapper; + } + + public Mapper mapper() {return mapper;} + +//////////////// APIs /////////////////// +}; diff --git a/authz-gw/src/main/xsd/gw_1_0.xsd b/authz-gw/src/main/xsd/gw_1_0.xsd new file mode 100644 index 00000000..d5716dd9 --- /dev/null +++ b/authz-gw/src/main/xsd/gw_1_0.xsd @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/authz-gw/src/test/java/com/att/authz/gw/JU_GwAPI.java b/authz-gw/src/test/java/com/att/authz/gw/JU_GwAPI.java new file mode 100644 index 00000000..2a53c31e --- /dev/null +++ b/authz-gw/src/test/java/com/att/authz/gw/JU_GwAPI.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.gw; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class JU_GwAPI { + + @Test + public void test() { + fail("Not yet implemented"); + } + + @Test + public void testRoute() { + fail("Not yet implemented"); + } + + @Test + public void testRouteAll() { + fail("Not yet implemented"); + } + + @Test + public void testStartDME2() { + fail("Not yet implemented"); + } + +} diff --git a/authz-service/.gitignore b/authz-service/.gitignore new file mode 100644 index 00000000..b85845b7 --- /dev/null +++ b/authz-service/.gitignore @@ -0,0 +1,7 @@ +.metadata +.settings +.classpath +.project +target +/dme2reg/ +/logs/ diff --git a/authz-service/pom.xml b/authz-service/pom.xml new file mode 100644 index 00000000..85b9d5d6 --- /dev/null +++ b/authz-service/pom.xml @@ -0,0 +1,246 @@ + + + + 4.0.0 + + com.att.authz + parent + 2.0.15 + ../pom.xml + + + authz-service + Authz Service + API for Authorization and Authentication + https://github.com/att/AAF + + + BSD License + + + + + + Jonathan Gathman + + ATT + + + + + + true + 1 + + + + + + com.att.authz + authz-client + + + + com.att.authz + authz-core + + + javax.servlet + servlet-api + + + + + + com.att.authz + authz-cass + + + + com.att.authz + authz-defOrg + ${project.version} + + + + + + + + com.att.inno + env + + + + + com.att.cadi + cadi-core + + + + com.att.aft + dme2 + + + + com.att.inno + rosetta + + + com.att.cadi + cadi-aaf + + + + + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.5.0 + + java + + -DAFT_LATITUDE=33 + -DAFT_LONGITUDE=-84 + -DAFT_ENVIRONMENT=AFTUAT + + -XX:NewRatio=3 + -XX:+PrintGCTimeStamps + -XX:+PrintGCDetails + -Xloggc:gc.log + -classpath + + + + + com.att.authz.service.AuthAPI + + service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=Dev + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + *.properties + + + 2.3.1 + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + + + attach-javadocs + + jar + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrhdme + https://oss.sonatype.org/ + true + + + + + + + + + + + + + ossrhdme + https://oss.sonatype.org/content/repositories/snapshots + + + ossrhdme + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + https://github.com/att/AAF.git + ${project.scm.connection} + http://github.com/att/AAF/tree/master + + diff --git a/authz-service/src/main/assemble/swm.xml b/authz-service/src/main/assemble/swm.xml new file mode 100644 index 00000000..20f5adef --- /dev/null +++ b/authz-service/src/main/assemble/swm.xml @@ -0,0 +1,36 @@ + + + swm + + zip + + + ${artifactId} + + + target/swm + + + diff --git a/authz-service/src/main/config/authAPI.props b/authz-service/src/main/config/authAPI.props new file mode 100644 index 00000000..6bc78699 --- /dev/null +++ b/authz-service/src/main/config/authAPI.props @@ -0,0 +1,24 @@ +## +## AUTHZ API (authz-service) Properties +## + +hostname=_HOSTNAME_ + +## DISCOVERY (DME2) Parameters on the Command Line +AFT_LATITUDE=_AFT_LATITUDE_ +AFT_LONGITUDE=_AFT_LONGITUDE_ +AFT_ENVIRONMENT=_AFT_ENVIRONMENT_ +DEPLOYED_VERSION=_ARTIFACT_VERSION_ + +## Pull in common/security properties + +cadi_prop_files=_COMMON_DIR_/com.att.aaf.common.props;_COMMON_DIR_/com.att.aaf.props + +##DME2 related parameters + +DMEServiceName=service=com.att.authz.AuthorizationService/version=_MAJOR_VER_._MINOR_VER_._PATCH_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ +AFT_DME2_PORT_RANGE=_AUTHZ_SERVICE_PORT_RANGE_ + + +CACHE_HIGH_COUNT=20000 +CACHE_CLEAN_INTERVAL=60000 \ No newline at end of file diff --git a/authz-service/src/main/config/log4j.properties b/authz-service/src/main/config/log4j.properties new file mode 100644 index 00000000..1b55ee89 --- /dev/null +++ b/authz-service/src/main/config/log4j.properties @@ -0,0 +1,91 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START==================================================== +# * org.onap.aai +# * =========================================================================== +# * Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# * Copyright © 2017 Amdocs +# * =========================================================================== +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END==================================================== +# * +# * ECOMP is a trademark and service mark of AT&T Intellectual Property. +# * +#------------------------------------------------------------------------------- +############################################################################### +# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved. +############################################################################### +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +log4j.appender.INIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.INIT.File=_LOG_DIR_/${LOG4J_FILENAME_init} +log4j.appender.INIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.INIT.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.INIT.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.INIT.layout=org.apache.log4j.PatternLayout +log4j.appender.INIT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %m %n + + +log4j.appender.SRVR=org.apache.log4j.DailyRollingFileAppender +log4j.appender.SRVR.File=logs/${LOG4J_FILENAME_authz} +log4j.appender.SRVR.DatePattern='.'yyyy-MM-dd +#log4j.appender.SRVR.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.SRVR.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.SRVR.layout=org.apache.log4j.PatternLayout +log4j.appender.SRVR.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %p [%c] %m %n + +log4j.appender.AUDIT=org.apache.log4j.DailyRollingFileAppender +log4j.appender.AUDIT.File=_LOG_DIR_/${LOG4J_FILENAME_audit} +log4j.appender.AUDIT.DatePattern='.'yyyy-MM-dd +#log4j.appender.AUDIT.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.AUDIT.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.AUDIT.layout=org.apache.log4j.PatternLayout +log4j.appender.AUDIT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %m %n + +log4j.appender.TRACE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.TRACE.File=logs/${LOG4J_FILENAME_trace} +log4j.appender.TRACE.DatePattern='.'yyyy-MM-dd +#log4j.appender.TRACE.MaxFileSize=_MAX_LOG_FILE_SIZE_ +#log4j.appender.TRACE.MaxBackupIndex=_MAX_LOG_FILE_BACKUP_COUNT_ +log4j.appender.TRACE.layout=org.apache.log4j.PatternLayout +log4j.appender.TRACE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSSZ} %m %n + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] %m %n + +# General Apache libraries +log4j.rootLogger=WARN +log4j.logger.org.apache=WARN,INIT +log4j.logger.dme2=WARN,INIT +log4j.logger.init=INFO,INIT +log4j.logger.authz=_LOG4J_LEVEL_,SRVR +log4j.logger.audit=INFO,AUDIT +log4j.logger.trace=TRACE,TRACE + + diff --git a/authz-service/src/main/config/lrm-authz-service.xml b/authz-service/src/main/config/lrm-authz-service.xml new file mode 100644 index 00000000..d7824cf7 --- /dev/null +++ b/authz-service/src/main/config/lrm-authz-service.xml @@ -0,0 +1,83 @@ + + + + + + com.att.authz._ARTIFACT_ID_ + + _MAJOR_VER_ + _MINOR_VER_ + _PATCH_VER_ + + _ROUTE_OFFER_ + + Java + com.att.authz.service.AuthzAPI + + process.workdir + _ROOT_DIR_ + + + jvm.version + 1.8 + + + jvm.args + -DAFT_LATITUDE=_AFT_LATITUDE_ -DAFT_LONGITUDE=_AFT_LONGITUDE_ -DAFT_ENVIRONMENT=_AFT_ENVIRONMENT_ -Dplatform=_SCLD_PLATFORM_ -Dcom.sun.jndi.ldap.connect.pool.maxsize=20 -Dcom.sun.jndi.ldap.connect.pool.prefsize=10 -Dcom.sun.jndi.ldap.connect.pool.timeout=3000 + + + jvm.classpath + _ROOT_DIR_/etc:_ROOT_DIR_/lib/*: + + + jvm.heap.min + 1024m + + + jvm.heap.max + 2048m + + + start.class + com.att.authz.service.AuthAPI + + + stdout.redirect + _ROOT_DIR_/logs/SystemOut.log + + + stderr.redirect + _ROOT_DIR_/logs/SystemErr.log + + aft + AUTO + 2 + _RESOURCE_MIN_COUNT_ + _RESOURCE_MAX_COUNT_ + _RESOURCE_REGISTRATION_ + com.att.authz:_ARTIFACT_ID_ + _ARTIFACT_VERSION_ + + diff --git a/authz-service/src/main/java/com/att/authz/cadi/DirectAAFLur.java b/authz-service/src/main/java/com/att/authz/cadi/DirectAAFLur.java new file mode 100644 index 00000000..9c7234dd --- /dev/null +++ b/authz-service/src/main/java/com/att/authz/cadi/DirectAAFLur.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cadi; + +import static com.att.authz.layer.Result.OK; + +import java.security.Principal; +import java.util.List; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cadi.Lur; +import com.att.cadi.Permission; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.PermDAO.Data; +import com.att.dao.aaf.hl.Question; + +public class DirectAAFLur implements Lur { + private final AuthzEnv env; + private final Question question; + + public DirectAAFLur(AuthzEnv env, Question question) { + this.env = env; + this.question = question; + } + + @Override + public boolean fish(Principal bait, Permission pond) { + return fish(env.newTransNoAvg(),bait,pond); + } + + public boolean fish(AuthzTrans trans, Principal bait, Permission pond) { + Result> pdr = question.getPermsByUser(trans, bait.getName(),false); + switch(pdr.status) { + case OK: + for(PermDAO.Data d : pdr.value) { + if(new PermPermission(d).match(pond)) return true; + } + break; + default: + trans.error().log("Can't access Cassandra to fulfill Permission Query: ",pdr.status,"-",pdr.details); + } + return false; + } + + @Override + public void fishAll(Principal bait, List permissions) { + Result> pdr = question.getPermsByUser(env.newTrans(), bait.getName(),false); + switch(pdr.status) { + case OK: + for(PermDAO.Data d : pdr.value) { + permissions.add(new PermPermission(d)); + } + break; + default: + env.error().log("Can't access Cassandra to fulfill Permission Query: ",pdr.status,"-", pdr.details); + } + } + + @Override + public void destroy() { + } + + @Override + public boolean handlesExclusively(Permission pond) { + return false; + } + + /** + * Small Class implementing CADI's Permission with Cassandra Data + * + */ + public static class PermPermission implements Permission { + private PermDAO.Data data; + + public PermPermission(PermDAO.Data d) { + data = d; + } + + public PermPermission(AuthzTrans trans, Question q, String p) { + data = PermDAO.Data.create(trans, q, p); + } + + public PermPermission(String ns, String type, String instance, String action) { + data = new PermDAO.Data(); + data.ns = ns; + data.type = type; + data.instance = instance; + data.action = action; + } + + @Override + public String getKey() { + return data.type; + } + + @Override + public boolean match(Permission p) { + if(p==null)return false; + PermDAO.Data pd; + if(p instanceof DirectAAFLur.PermPermission) { + pd = ((DirectAAFLur.PermPermission)p).data; + if(data.ns.equals(pd.ns)) + if(data.type.equals(pd.type)) + if(data.instance!=null && (data.instance.equals(pd.instance) || "*".equals(data.instance))) + if(data.action!=null && (data.action.equals(pd.action) || "*".equals(data.action))) + return true; + } else{ + String[] lp = p.getKey().split("\\|"); + if(lp.length<3)return false; + if(data.fullType().equals(lp[0])) + if(data.instance!=null && (data.instance.equals(lp[1]) || "*".equals(data.instance))) + if(data.action!=null && (data.action.equals(lp[2]) || "*".equals(data.action))) + return true; + } + return false; + } + + @Override + public String permType() { + return "AAFLUR"; + } + + } + + public String toString() { + return "DirectAAFLur is enabled"; + + } + + @Override + public boolean supports(String userName) { + //TODO + return true; + } + + @Override + public Permission createPerm(String p) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void clear(Principal p, StringBuilder report) { + // TODO Auto-generated method stub + + } +} diff --git a/authz-service/src/main/java/com/att/authz/cadi/DirectAAFUserPass.java b/authz-service/src/main/java/com/att/authz/cadi/DirectAAFUserPass.java new file mode 100644 index 00000000..78b2922e --- /dev/null +++ b/authz-service/src/main/java/com/att/authz/cadi/DirectAAFUserPass.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cadi; + +import static com.att.authz.layer.Result.OK; + +import java.util.Date; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cadi.CredVal; +import com.att.dao.DAOException; +import com.att.dao.aaf.hl.Question; + +/** + * DirectAAFUserPass is intended to provide password Validation directly from Cassandra Database, and is only + * intended for use in AAF itself. The normal "AAF Taf" objects are, of course, clients. + * + * + */ +public class DirectAAFUserPass implements CredVal { + private final AuthzEnv env; + private final Question question; + + public DirectAAFUserPass(AuthzEnv env, Question question, String appPass) { + this.env = env; + this.question = question; + } + + @Override + public boolean validate(String user, Type type, byte[] pass) { + try { + AuthzTrans trans = env.newTransNoAvg(); + Result result = question.doesUserCredMatch(trans, user, pass); + trans.logAuditTrail(env.info()); + switch(result.status) { + case OK: + return true; + default: + + env.warn().log(user, "failed Password Validation:",result.errorString()); + } + } catch (DAOException e) { + System.out.println(" exception in DirectAAFUserPass class "); + e.printStackTrace(); + env.error().log(e,"Cannot validate User/Pass from Cassandra"); + } + return false; + } + + +} diff --git a/authz-service/src/main/java/com/att/authz/cadi/DirectCertIdentity.java b/authz-service/src/main/java/com/att/authz/cadi/DirectCertIdentity.java new file mode 100644 index 00000000..70676467 --- /dev/null +++ b/authz-service/src/main/java/com/att/authz/cadi/DirectCertIdentity.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.cadi; + +import java.nio.ByteBuffer; +import java.security.Principal; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cadi.principal.X509Principal; +import com.att.cadi.taf.cert.CertIdentity; +import com.att.cadi.taf.cert.X509Taf; +import com.att.cssa.rserv.TransFilter; +import com.att.dao.aaf.cached.CachedCertDAO; +import com.att.dao.aaf.cass.CertDAO.Data; + +/** + * Direct view of CertIdentities + * + * Warning: this class is difficult to instantiate. The only service that can use it is AAF itself, and is thus + * entered in the "init" after the CachedCertDAO is created. + * + * + */ +public class DirectCertIdentity implements CertIdentity { + private static CachedCertDAO certDAO; + + @Override + public Principal identity(HttpServletRequest req, X509Certificate cert, byte[] _certBytes) throws CertificateException { + byte[] certBytes = _certBytes; + if(cert==null && certBytes==null) { + return null; + } + if(certBytes==null) { + certBytes = cert.getEncoded(); + } + byte[] fingerprint = X509Taf.getFingerPrint(certBytes); + + AuthzTrans trans = (AuthzTrans) req.getAttribute(TransFilter.TRANS_TAG); + + Result> cresp = certDAO.read(trans, ByteBuffer.wrap(fingerprint)); + if(cresp.isOKhasData()) { + Data cdata = cresp.value.get(0); + return new X509Principal(cdata.id,cert,certBytes); + } + return null; + } + + public static void set(CachedCertDAO ccd) { + certDAO = ccd; + } + +} diff --git a/authz-service/src/main/java/com/att/authz/facade/AuthzFacade.java b/authz-service/src/main/java/com/att/authz/facade/AuthzFacade.java new file mode 100644 index 00000000..f562d627 --- /dev/null +++ b/authz-service/src/main/java/com/att/authz/facade/AuthzFacade.java @@ -0,0 +1,264 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.facade; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.cssa.rserv.RServlet; +import com.att.dao.aaf.cass.NsType; + +/** + * AuthzFacade + * This layer is responsible for covering the Incoming Messages, be they XML, JSON or just entries on the URL, + * and converting them to data that can be called on the Service Layer. + * + * Upon response, this layer, because it knew the incoming Data Formats (i.e. XML/JSON), the HTTP call types + * are set on "ContentType" on Response. + * + * Finally, we wrap the call in Time Stamps with explanation of what is happing for Audit trails. + * + * + */ +public interface AuthzFacade { + public static final int PERM_DEPEND_424 = -1000; + public static final int ROLE_DEPEND_424 = -1001; + + /* + * Namespaces + */ + public abstract Result requestNS(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, NsType type); + + public abstract Result getNSsByName(AuthzTrans trans, HttpServletResponse resp, String ns); + + public abstract Result getNSsByAdmin(AuthzTrans trans, HttpServletResponse resp, String user, boolean full); + + public abstract Result getNSsByResponsible(AuthzTrans trans, HttpServletResponse resp, String user, boolean full); + + public abstract Result getNSsByEither(AuthzTrans trans, HttpServletResponse resp, String user, boolean full); + + public abstract Result getNSsChildren(AuthzTrans trans, HttpServletResponse resp, String pathParam); + + public abstract Result addAdminToNS(AuthzTrans trans, HttpServletResponse resp, String ns, String id); + + public abstract Result delAdminFromNS(AuthzTrans trans, HttpServletResponse resp, String ns, String id); + + public abstract Result addResponsibilityForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String id); + + public abstract Result delResponsibilityForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String id); + + public abstract Result updateNsDescription(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result deleteNS(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, String ns); + + // NS Attribs + public abstract Result createAttribForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String key, String value); + + public abstract Result readNsByAttrib(AuthzTrans trans, HttpServletResponse resp, String key); + + public abstract Result updAttribForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String key, String value); + + public abstract Result delAttribForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String key); + + /* + * Permissions + */ + public abstract Result createPerm(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result getPermsByName(AuthzTrans trans, HttpServletResponse resp, + String type, String instance, String action); + + public abstract Result getPermsByUser(AuthzTrans trans, HttpServletResponse response, String user); + + public abstract Result getPermsByUserWithAAFQuery(AuthzTrans trans, HttpServletRequest request, HttpServletResponse response, String user); + + public abstract Result getPermsByType(AuthzTrans trans, HttpServletResponse resp, String type); + + public abstract Result getPermsForRole(AuthzTrans trans, HttpServletResponse response, String roleName); + + public abstract Result getPermsByNS(AuthzTrans trans, HttpServletResponse response, String ns); + + public abstract Result renamePerm(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, + String type, String instance, String action); + + public abstract Result updatePermDescription(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result resetPermRoles(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result deletePerm(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result deletePerm(AuthzTrans trans, HttpServletResponse resp, + String perm, String type, String action); + + /* + * Roles + */ + public abstract Result createRole(AuthzTrans trans, HttpServletRequest req, HttpServletResponse response); + + public abstract Result getRolesByName(AuthzTrans trans,HttpServletResponse resp, String name); + + public abstract Result getRolesByNS(AuthzTrans trans, HttpServletResponse resp, String ns); + + public abstract Result getRolesByNameOnly(AuthzTrans trans, HttpServletResponse resp, String nameOnly); + + public abstract Result getRolesByUser(AuthzTrans trans, HttpServletResponse resp, String user); + + public abstract Result getRolesByPerm(AuthzTrans trans, HttpServletResponse resp, String type, String instance, String action); + + public abstract Result updateRoleDescription(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result addPermToRole(AuthzTrans trans,HttpServletRequest req, HttpServletResponse resp); + + public abstract Result delPermFromRole(AuthzTrans trans,HttpServletRequest req, HttpServletResponse resp); + + public abstract Result deleteRole(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result deleteRole(AuthzTrans trans, HttpServletResponse resp, String role); + + /* + * Users + */ + + public abstract Result getUsersByRole(AuthzTrans trans, HttpServletResponse resp, String role); + + public abstract Result getUsersByPermission(AuthzTrans trans, HttpServletResponse resp, + String type, String instance, String action); + + + + /* + * Delegates + */ + public abstract Result createDelegate(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result updateDelegate(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result deleteDelegate(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result deleteDelegate(AuthzTrans trans, String user); + + public abstract Result getDelegatesByUser(AuthzTrans trans, String userName, HttpServletResponse resp); + + public abstract Result getDelegatesByDelegate(AuthzTrans trans, String userName, HttpServletResponse resp); + + /* + * Credentials + */ + public abstract Result createUserCred(AuthzTrans trans, HttpServletRequest req); + + public abstract Result changeUserCred(AuthzTrans trans, HttpServletRequest req); + + public abstract Result extendUserCred(AuthzTrans trans, HttpServletRequest req, String days); + + public abstract Result getCredsByNS(AuthzTrans trans, HttpServletResponse resp, String ns); + + public abstract Result getCredsByID(AuthzTrans trans, HttpServletResponse resp, String id); + + public abstract Result deleteUserCred(AuthzTrans trans, HttpServletRequest req); + + public abstract Result validBasicAuth(AuthzTrans trans, HttpServletResponse resp, String basicAuth); + + public abstract Result doesCredentialMatch(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + /* + * Miscellaneous + */ + /** + * Place Standard Messages based on HTTP Code onto Error Data Structure, and write to OutputStream + * Log message + */ + public abstract void error(AuthzTrans trans, HttpServletResponse response, Result result); + + /* + * UserRole + */ + public abstract Result requestUserRole(AuthzTrans trans,HttpServletRequest req, HttpServletResponse resp); + + public abstract Result getUserInRole(AuthzTrans trans, HttpServletResponse resp, String user, String role); + + public abstract Result getUserRolesByRole(AuthzTrans trans, HttpServletResponse resp, String role); + + public abstract Result getUserRolesByUser(AuthzTrans trans, HttpServletResponse resp, String user); + + public abstract Result deleteUserRole(AuthzTrans trans, HttpServletResponse resp, String user, String role); + + public abstract Result resetUsersForRole(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req); + + public abstract Result resetRolesForUser(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req); + + public abstract Result extendUserRoleExpiration(AuthzTrans trans, HttpServletResponse resp, String user, + String role); + + /* + * Approval + */ + public abstract Result updateApproval(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + + public abstract Result getApprovalsByUser(AuthzTrans trans, HttpServletResponse resp, String user); + + public abstract Result getApprovalsByTicket(AuthzTrans trans, HttpServletResponse resp, String ticket); + + public abstract Result getApprovalsByApprover(AuthzTrans trans, HttpServletResponse resp, String approver); + + + /* + * History + */ + public abstract Result getHistoryByUser(AuthzTrans trans, HttpServletResponse resp, String user, int[] yyyymm, final int sort); + + public abstract Result getHistoryByRole(AuthzTrans trans, HttpServletResponse resp, String subject, int[] yyyymm, final int sort); + + public abstract Result getHistoryByPerm(AuthzTrans trans, HttpServletResponse resp, String subject, int[] yyyymm, final int sort); + + public abstract Result getHistoryByNS(AuthzTrans trans, HttpServletResponse resp, String subject, int[] yyyymm, final int sort); + + /* + * Cache + */ + public abstract Result cacheClear(AuthzTrans trans, String pathParam); + + public abstract Result cacheClear(AuthzTrans trans, String string,String segments); + + public abstract void dbReset(AuthzTrans trans); + + + + /* + * API + */ + public Result getAPI(AuthzTrans trans, HttpServletResponse resp, RServlet rservlet); + + public abstract Result getAPIExample(AuthzTrans trans, HttpServletResponse resp, String typeCode, boolean optional); + + public abstract Result getCertInfoByID(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, String id); + + + + + +} diff --git a/authz-service/src/main/java/com/att/authz/facade/AuthzFacadeFactory.java b/authz-service/src/main/java/com/att/authz/facade/AuthzFacadeFactory.java new file mode 100644 index 00000000..98e09bbc --- /dev/null +++ b/authz-service/src/main/java/com/att/authz/facade/AuthzFacadeFactory.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.facade; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.service.AuthzCassServiceImpl; +import com.att.authz.service.mapper.Mapper_2_0; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; + + +public class AuthzFacadeFactory { + public static AuthzFacade_2_0 v2_0(AuthzEnv env, AuthzTrans trans, Data.TYPE type, Question question) throws APIException { + return new AuthzFacade_2_0(env, + new AuthzCassServiceImpl< + aaf.v2_0.Nss, + aaf.v2_0.Perms, + aaf.v2_0.Pkey, + aaf.v2_0.Roles, + aaf.v2_0.Users, + aaf.v2_0.UserRoles, + aaf.v2_0.Delgs, + aaf.v2_0.Certs, + aaf.v2_0.Keys, + aaf.v2_0.Request, + aaf.v2_0.History, + aaf.v2_0.Error, + aaf.v2_0.Approvals> + (trans,new Mapper_2_0(question),question), + type); + } + + +} diff --git a/authz-service/src/main/java/com/att/authz/facade/AuthzFacadeImpl.java b/authz-service/src/main/java/com/att/authz/facade/AuthzFacadeImpl.java new file mode 100644 index 00000000..3ba557f7 --- /dev/null +++ b/authz-service/src/main/java/com/att/authz/facade/AuthzFacadeImpl.java @@ -0,0 +1,2565 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.facade; + +import static com.att.authz.layer.Result.ERR_ActionNotCompleted; +import static com.att.authz.layer.Result.ERR_Backend; +import static com.att.authz.layer.Result.ERR_BadData; +import static com.att.authz.layer.Result.ERR_ConflictAlreadyExists; +import static com.att.authz.layer.Result.ERR_Denied; +import static com.att.authz.layer.Result.ERR_NotFound; +import static com.att.authz.layer.Result.ERR_NotImplemented; +import static com.att.authz.layer.Result.ERR_Policy; +import static com.att.authz.layer.Result.ERR_Security; +import static com.att.authz.layer.Result.OK; +import static com.att.dao.aaf.cass.Status.ERR_ChoiceNeeded; +import static com.att.dao.aaf.cass.Status.ERR_DelegateNotFound; +import static com.att.dao.aaf.cass.Status.ERR_DependencyExists; +import static com.att.dao.aaf.cass.Status.ERR_FutureNotRequested; +import static com.att.dao.aaf.cass.Status.ERR_InvalidDelegate; +import static com.att.dao.aaf.cass.Status.ERR_NsNotFound; +import static com.att.dao.aaf.cass.Status.ERR_PermissionNotFound; +import static com.att.dao.aaf.cass.Status.ERR_RoleNotFound; +import static com.att.dao.aaf.cass.Status.ERR_UserNotFound; +import static com.att.dao.aaf.cass.Status.ERR_UserRoleNotFound; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.FacadeImpl; +import com.att.authz.layer.Result; +import com.att.authz.service.AuthzCassServiceImpl; +import com.att.authz.service.AuthzService; +import com.att.authz.service.mapper.Mapper; +import com.att.authz.service.mapper.Mapper.API; +import com.att.cadi.aaf.client.Examples; +import com.att.cssa.rserv.RServlet; +import com.att.cssa.rserv.RouteReport; +import com.att.cssa.rserv.doc.ApiDoc; +import com.att.dao.aaf.cass.NsType; +import com.att.dao.aaf.cass.Status; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; +import com.att.inno.env.Data.TYPE; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Chrono; +import com.att.rosetta.Marshal; +import com.att.rosetta.env.RosettaDF; +import com.att.rosetta.env.RosettaData; + +import aaf.v2_0.Api; + +/** + * AuthzFacade + * + * This Service Facade encapsulates the essence of the API Service can do, and provides + * a single created object for elements such as RosettaDF. + * + * The Responsibilities of this class are to: + * 1) Interact with the Service Implementation (which might be supported by various kinds of Backend Storage) + * 2) Validate incoming data (if applicable) + * 3) Convert the Service response into the right Format, and mark the Content Type + * a) In the future, we may support multiple Response Formats, aka JSON or XML, based on User Request. + * 4) Log Service info, warnings and exceptions as necessary + * 5) When asked by the API layer, this will create and write Error content to the OutputStream + * + * Note: This Class does NOT set the HTTP Status Code. That is up to the API layer, so that it can be + * clearly coordinated with the API Documentation + * + * + */ +public abstract class AuthzFacadeImpl extends FacadeImpl implements AuthzFacade + { + private static final String FORBIDDEN = "Forbidden"; + private static final String NOT_FOUND = "Not Found"; + private static final String NOT_ACCEPTABLE = "Not Acceptable"; + private static final String GENERAL_SERVICE_ERROR = "General Service Error"; + private static final String NO_DATA = "***No Data***"; + private AuthzService service = null; + private final RosettaDF nssDF; + private final RosettaDF permsDF; + private final RosettaDF roleDF; + private final RosettaDF usersDF; + private final RosettaDF userrolesDF; + private final RosettaDF certsDF; + private final RosettaDF delgDF; + private final RosettaDF permRequestDF; + private final RosettaDF roleRequestDF; + private final RosettaDF userRoleRequestDF; + private final RosettaDF rolePermRequestDF; + private final RosettaDF nsRequestDF; + private final RosettaDF credRequestDF; + private final RosettaDF delgRequestDF; + private final RosettaDF historyDF; + private final RosettaDF keysDF; + + private final RosettaDF errDF; + private final RosettaDF approvalDF; + // Note: Api is not different per Version + private final RosettaDF apiDF; + + + @SuppressWarnings("unchecked") + public AuthzFacadeImpl(AuthzEnv env, AuthzService service, Data.TYPE dataType) throws APIException { + this.service = service; + (nssDF = env.newDataFactory(service.mapper().getClass(API.NSS))).in(dataType).out(dataType); + (permRequestDF = env.newDataFactory(service.mapper().getClass(API.PERM_REQ))).in(dataType).out(dataType); + (permsDF = env.newDataFactory(service.mapper().getClass(API.PERMS))).in(dataType).out(dataType); +// (permKeyDF = env.newDataFactory(service.mapper().getClass(API.PERM_KEY))).in(dataType).out(dataType); + (roleDF = env.newDataFactory(service.mapper().getClass(API.ROLES))).in(dataType).out(dataType); + (roleRequestDF = env.newDataFactory(service.mapper().getClass(API.ROLE_REQ))).in(dataType).out(dataType); + (usersDF = env.newDataFactory(service.mapper().getClass(API.USERS))).in(dataType).out(dataType); + (userrolesDF = env.newDataFactory(service.mapper().getClass(API.USER_ROLES))).in(dataType).out(dataType); + (certsDF = env.newDataFactory(service.mapper().getClass(API.CERTS))).in(dataType).out(dataType) + .rootMarshal((Marshal) service.mapper().getMarshal(API.CERTS)); + ; + (userRoleRequestDF = env.newDataFactory(service.mapper().getClass(API.USER_ROLE_REQ))).in(dataType).out(dataType); + (rolePermRequestDF = env.newDataFactory(service.mapper().getClass(API.ROLE_PERM_REQ))).in(dataType).out(dataType); + (nsRequestDF = env.newDataFactory(service.mapper().getClass(API.NS_REQ))).in(dataType).out(dataType); + (credRequestDF = env.newDataFactory(service.mapper().getClass(API.CRED_REQ))).in(dataType).out(dataType); + (delgRequestDF = env.newDataFactory(service.mapper().getClass(API.DELG_REQ))).in(dataType).out(dataType); + (historyDF = env.newDataFactory(service.mapper().getClass(API.HISTORY))).in(dataType).out(dataType); + ( keysDF = env.newDataFactory(service.mapper().getClass(API.KEYS))).in(dataType).out(dataType); + (delgDF = env.newDataFactory(service.mapper().getClass(API.DELGS))).in(dataType).out(dataType); + (approvalDF = env.newDataFactory(service.mapper().getClass(API.APPROVALS))).in(dataType).out(dataType); + (errDF = env.newDataFactory(service.mapper().getClass(API.ERROR))).in(dataType).out(dataType); + (apiDF = env.newDataFactory(Api.class)).in(dataType).out(dataType); + } + + public Mapper mapper() { + return service.mapper(); + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#error(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, int) + * + * Note: Conforms to AT&T TSS RESTful Error Structure + */ + @Override + public void error(AuthzTrans trans, HttpServletResponse response, Result result) { + String msg = result.details==null?"%s":"%s - " + result.details.trim(); + String msgId; + String[] detail; + if(result.variables==null) { + detail = new String[1]; + } else { + int l = result.variables.length; + detail=new String[l+1]; + System.arraycopy(result.variables, 0, detail, 1, l); + } + //int httpstatus; + + switch(result.status) { + case ERR_ActionNotCompleted: + msgId = "SVC1202"; + detail[0] = "Accepted, Action not complete"; + response.setStatus(/*httpstatus=*/202); + break; + + case ERR_Policy: + msgId = "SVC3403"; + detail[0] = FORBIDDEN; + response.setStatus(/*httpstatus=*/403); + break; + case ERR_Security: + msgId = "SVC2403"; + detail[0] = FORBIDDEN; + response.setStatus(/*httpstatus=*/403); + break; + case ERR_Denied: + msgId = "SVC1403"; + detail[0] = FORBIDDEN; + response.setStatus(/*httpstatus=*/403); + break; + // This is still forbidden to directly impact, but can be Requested when passed + // with "request=true" query Param + case ERR_FutureNotRequested: + msgId = "SVC2403"; + detail[0] = msg; + response.setStatus(/*httpstatus=*/403); + break; + + case ERR_NsNotFound: + msgId = "SVC2404"; + detail[0] = NOT_FOUND; + response.setStatus(/*httpstatus=*/404); + break; + case ERR_RoleNotFound: + msgId = "SVC3404"; + detail[0] = NOT_FOUND; + response.setStatus(/*httpstatus=*/404); + break; + case ERR_PermissionNotFound: + msgId = "SVC4404"; + detail[0] = NOT_FOUND; + response.setStatus(/*httpstatus=*/404); + break; + case ERR_UserNotFound: + msgId = "SVC5404"; + detail[0] = NOT_FOUND; + response.setStatus(/*httpstatus=*/404); + break; + case ERR_UserRoleNotFound: + msgId = "SVC6404"; + detail[0] = NOT_FOUND; + response.setStatus(/*httpstatus=*/404); + break; + case ERR_DelegateNotFound: + msgId = "SVC7404"; + detail[0] = NOT_FOUND; + response.setStatus(/*httpstatus=*/404); + break; + case ERR_NotFound: + msgId = "SVC1404"; + detail[0] = NOT_FOUND; + response.setStatus(/*httpstatus=*/404); + break; + + case ERR_InvalidDelegate: + msgId="SVC2406"; + detail[0] = NOT_ACCEPTABLE; + response.setStatus(/*httpstatus=*/406); + break; + case ERR_BadData: + msgId="SVC1406"; + detail[0] = NOT_ACCEPTABLE; + response.setStatus(/*httpstatus=*/406); + break; + + case ERR_ConflictAlreadyExists: + msgId = "SVC1409"; + detail[0] = "Conflict Already Exists"; + response.setStatus(/*httpstatus=*/409); + break; + + case ERR_DependencyExists: + msgId = "SVC1424"; + detail[0] = "Failed Dependency"; + response.setStatus(/*httpstatus=*/424); + break; + + case ERR_NotImplemented: + msgId = "SVC1501"; + detail[0] = "Not Implemented"; + response.setStatus(/*httpstatus=*/501); + break; + + case Status.ACC_Future: + msgId = "SVC1202"; + detail[0] = "Accepted for Future, pending Approvals"; + response.setStatus(/*httpstatus=*/202); + break; + case ERR_ChoiceNeeded: + msgId = "SVC1300"; + detail = result.variables; + response.setStatus(/*httpstatus=*/300); + break; + case ERR_Backend: + msgId = "SVC2500"; + detail[0] = GENERAL_SERVICE_ERROR; + response.setStatus(/*httpstatus=*/500); + break; + + default: + msgId = "SVC1500"; + detail[0] = GENERAL_SERVICE_ERROR; + response.setStatus(/*httpstatus=*/500); + break; + } + + try { + StringBuilder holder = new StringBuilder(); + errDF.newData(trans).load( + service.mapper() + .errorFromMessage(holder,msgId,msg,detail)) + .to(response.getOutputStream()); + trans.checkpoint( + holder.toString(), +// String.format("ErrResp [" + msgId + "] " + msg,(Object[])detail), + Env.ALWAYS); + } catch (Exception e) { + trans.error().log(e,"unable to send response for",msg); + } + } + + /////////////////////////// + // Namespace + /////////////////////////// + public static final String CREATE_NS = "createNamespace"; + public static final String ADD_NS_ADMIN = "addNamespaceAdmin"; + public static final String DELETE_NS_ADMIN = "delNamespaceAdmin"; + public static final String ADD_NS_RESPONSIBLE = "addNamespaceResponsible"; + public static final String DELETE_NS_RESPONSIBLE = "delNamespaceResponsible"; + public static final String GET_NS_BY_NAME = "getNamespaceByName"; + public static final String GET_NS_BY_ADMIN = "getNamespaceByAdmin"; + public static final String GET_NS_BY_RESPONSIBLE = "getNamespaceByResponsible"; + public static final String GET_NS_BY_EITHER = "getNamespaceByEither"; + public static final String GET_NS_CHILDREN = "getNamespaceChildren"; + public static final String UPDATE_NS_DESC = "updateNamespaceDescription"; + public static final String DELETE_NS = "deleteNamespace"; + + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#createNS(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public Result requestNS(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, NsType type) { + TimeTaken tt = trans.start(CREATE_NS, Env.SUB|Env.ALWAYS); + try { + REQUEST request; + try { + Data rd = nsRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,rd.asString()); + } + request = rd.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,CREATE_NS); + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.createNS(trans,request,type); + switch(rp.status) { + case OK: + setContentType(resp,nsRequestDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,CREATE_NS); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#addAdminToNS(com.att.authz.env.AuthzTrans, java.lang.String, java.lang.String) + */ + @Override + public Result addAdminToNS(AuthzTrans trans, HttpServletResponse resp, String ns, String id) { + TimeTaken tt = trans.start(ADD_NS_ADMIN + ' ' + ns + ' ' + id, Env.SUB|Env.ALWAYS); + try { + Result rp = service.addAdminNS(trans,ns,id); + switch(rp.status) { + case OK: + //TODO Perms?? + setContentType(resp,nsRequestDF.getOutType()); + resp.getOutputStream().println(); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,ADD_NS_ADMIN); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#delAdminFromNS(com.att.authz.env.AuthzTrans, java.lang.String, java.lang.String) + */ + @Override + public Result delAdminFromNS(AuthzTrans trans, HttpServletResponse resp, String ns, String id) { + TimeTaken tt = trans.start(DELETE_NS_ADMIN + ' ' + ns + ' ' + id, Env.SUB|Env.ALWAYS); + try { + Result rp = service.delAdminNS(trans, ns, id); + switch(rp.status) { + case OK: + setContentType(resp,nsRequestDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_NS_ADMIN); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#addAdminToNS(com.att.authz.env.AuthzTrans, java.lang.String, java.lang.String) + */ + @Override + public Result addResponsibilityForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String id) { + TimeTaken tt = trans.start(ADD_NS_RESPONSIBLE + ' ' + ns + ' ' + id, Env.SUB|Env.ALWAYS); + try { + Result rp = service.addResponsibleNS(trans,ns,id); + switch(rp.status) { + case OK: + setContentType(resp,nsRequestDF.getOutType()); + resp.getOutputStream().println(); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,ADD_NS_RESPONSIBLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#delAdminFromNS(com.att.authz.env.AuthzTrans, java.lang.String, java.lang.String) + */ + @Override + public Result delResponsibilityForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String id) { + TimeTaken tt = trans.start(DELETE_NS_RESPONSIBLE + ' ' + ns + ' ' + id, Env.SUB|Env.ALWAYS); + try { + Result rp = service.delResponsibleNS(trans, ns, id); + switch(rp.status) { + case OK: + setContentType(resp,nsRequestDF.getOutType()); + resp.getOutputStream().println(); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_NS_RESPONSIBLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getNSsByName(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getNSsByName(AuthzTrans trans, HttpServletResponse resp, String ns) { + TimeTaken tt = trans.start(GET_NS_BY_NAME + ' ' + ns, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getNSbyName(trans, ns); + switch(rp.status) { + case OK: + RosettaData data = nssDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,nssDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_NS_BY_NAME); + return Result.err(e); + } finally { + tt.done(); + } + } + +// TODO: uncomment when on cassandra 2.1.2 for MyNamespace GUI page + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getNSsByAdmin(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getNSsByAdmin(AuthzTrans trans, HttpServletResponse resp, String user, boolean full){ + TimeTaken tt = trans.start(GET_NS_BY_ADMIN + ' ' + user, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getNSbyAdmin(trans, user, full); + switch(rp.status) { + case OK: + RosettaData data = nssDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,nssDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_NS_BY_ADMIN); + return Result.err(e); + } finally { + tt.done(); + } + } + +// TODO: uncomment when on cassandra 2.1.2 for MyNamespace GUI page + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getNSsByResponsible(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getNSsByResponsible(AuthzTrans trans, HttpServletResponse resp, String user, boolean full){ + TimeTaken tt = trans.start(GET_NS_BY_RESPONSIBLE + ' ' + user, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getNSbyResponsible(trans, user, full); + switch(rp.status) { + case OK: + RosettaData data = nssDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + + setContentType(resp,nssDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_NS_BY_RESPONSIBLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getNSsByResponsible(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getNSsByEither(AuthzTrans trans, HttpServletResponse resp, String user, boolean full){ + TimeTaken tt = trans.start(GET_NS_BY_EITHER + ' ' + user, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getNSbyEither(trans, user, full); + + switch(rp.status) { + case OK: + RosettaData data = nssDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + + setContentType(resp,nssDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_NS_BY_EITHER); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getNSsByResponsible(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getNSsChildren(AuthzTrans trans, HttpServletResponse resp, String parent){ + TimeTaken tt = trans.start(GET_NS_CHILDREN + ' ' + parent, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getNSsChildren(trans, parent); + switch(rp.status) { + case OK: + RosettaData data = nssDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,nssDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_NS_CHILDREN); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result updateNsDescription(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(UPDATE_NS_DESC, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = nsRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,UPDATE_NS_DESC); + return Result.err(Status.ERR_BadData,"Invalid Input"); + + } + Result rp = service.updateNsDescription(trans, rreq); + switch(rp.status) { + case OK: + setContentType(resp,nsRequestDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,UPDATE_NS_DESC); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* + * (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#requestNS(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public Result deleteNS(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, String ns) { + TimeTaken tt = trans.start(DELETE_NS + ' ' + ns, Env.SUB|Env.ALWAYS); + try { + Result rp = service.deleteNS(trans,ns); + switch(rp.status) { + case OK: + setContentType(resp,nsRequestDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_NS); + return Result.err(e); + } finally { + tt.done(); + } + } + + private final static String NS_CREATE_ATTRIB = "nsCreateAttrib"; + private final static String NS_UPDATE_ATTRIB = "nsUpdateAttrib"; + private final static String READ_NS_BY_ATTRIB = "readNsByAttrib"; + private final static String NS_DELETE_ATTRIB = "nsDeleteAttrib"; + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#createAttribForNS(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public Result createAttribForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String key, String value) { + TimeTaken tt = trans.start(NS_CREATE_ATTRIB + ' ' + ns + ':'+key+':'+value, Env.SUB|Env.ALWAYS); + try { + Result rp = service.createNsAttrib(trans,ns,key,value); + switch(rp.status) { + case OK: + setContentType(resp, keysDF.getOutType()); + resp.getOutputStream().println(); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,NS_CREATE_ATTRIB); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#readAttribForNS(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result readNsByAttrib(AuthzTrans trans, HttpServletResponse resp, String key) { + TimeTaken tt = trans.start(READ_NS_BY_ATTRIB + ' ' + key, Env.SUB|Env.ALWAYS); + try { + Result rp = service.readNsByAttrib(trans, key); + switch(rp.status) { + case OK: + RosettaData data = keysDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,keysDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,READ_NS_BY_ATTRIB); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#updAttribForNS(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public Result updAttribForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String key, String value) { + TimeTaken tt = trans.start(NS_UPDATE_ATTRIB + ' ' + ns + ':'+key+':'+value, Env.SUB|Env.ALWAYS); + try { + Result rp = service.updateNsAttrib(trans,ns,key,value); + switch(rp.status) { + case OK: + setContentType(resp, keysDF.getOutType()); + resp.getOutputStream().println(); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,NS_UPDATE_ATTRIB); + return Result.err(e); + } finally { + tt.done(); + } + + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#delAttribForNS(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String) + */ + @Override + public Result delAttribForNS(AuthzTrans trans, HttpServletResponse resp, String ns, String key) { + TimeTaken tt = trans.start(NS_DELETE_ATTRIB + ' ' + ns + ':'+key, Env.SUB|Env.ALWAYS); + try { + Result rp = service.deleteNsAttrib(trans,ns,key); + switch(rp.status) { + case OK: + setContentType(resp, keysDF.getOutType()); + resp.getOutputStream().println(); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,NS_DELETE_ATTRIB); + return Result.err(e); + } finally { + tt.done(); + } + } + +// +// PERMISSION +// + public static final String CREATE_PERMISSION = "createPermission"; + public static final String GET_PERMS_BY_TYPE = "getPermsByType"; + public static final String GET_PERMS_BY_NAME = "getPermsByName"; + public static final String GET_PERMISSIONS_BY_USER = "getPermissionsByUser"; + public static final String GET_PERMISSIONS_BY_USER_WITH_QUERY = "getPermissionsByUserWithQuery"; + public static final String GET_PERMISSIONS_BY_ROLE = "getPermissionsByRole"; + public static final String GET_PERMISSIONS_BY_NS = "getPermissionsByNS"; + public static final String UPDATE_PERMISSION = "updatePermission"; + public static final String UPDATE_PERM_DESC = "updatePermissionDescription"; + public static final String SET_PERMISSION_ROLES_TO = "setPermissionRolesTo"; + public static final String DELETE_PERMISSION = "deletePermission"; + + /* + * (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#createOrUpdatePerm(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, boolean, java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public Result createPerm(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start( CREATE_PERMISSION, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = permRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,CREATE_PERMISSION); + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.createPerm(trans,rreq); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,CREATE_PERMISSION); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getChildPerms(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getPermsByType(AuthzTrans trans, HttpServletResponse resp, String perm) { + TimeTaken tt = trans.start(GET_PERMS_BY_TYPE + ' ' + perm, Env.SUB|Env.ALWAYS); + try { + + Result rp = service.getPermsByType(trans, perm); + switch(rp.status) { + case OK: + RosettaData data = permsDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_PERMS_BY_TYPE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getPermsByName(AuthzTrans trans, HttpServletResponse resp, + String type, String instance, String action) { + + TimeTaken tt = trans.start(GET_PERMS_BY_NAME + ' ' + type + + '|' + instance + '|' + action, Env.SUB|Env.ALWAYS); + try { + + Result rp = service.getPermsByName(trans, type, instance, action); + switch(rp.status) { + case OK: + RosettaData data = permsDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_PERMS_BY_TYPE); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getPermissionByUser(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getPermsByUser(AuthzTrans trans, HttpServletResponse resp, String user) { + TimeTaken tt = trans.start(GET_PERMISSIONS_BY_USER + ' ' + user, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getPermsByUser(trans, user); + switch(rp.status) { + case OK: + RosettaData data = permsDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_PERMISSIONS_BY_USER, user); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getPermissionByUser(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getPermsByUserWithAAFQuery(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, String user) { + TimeTaken tt = trans.start(GET_PERMISSIONS_BY_USER_WITH_QUERY + ' ' + user, Env.SUB|Env.ALWAYS); + try { + PERMS perms; + try { + RosettaData data = permsDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + perms = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,CREATE_PERMISSION); + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.getPermsByUser(trans, perms, user); + switch(rp.status) { + case OK: + RosettaData data = permsDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_PERMISSIONS_BY_USER_WITH_QUERY , user); + return Result.err(e); + } finally { + tt.done(); + } + } + + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getPermissionsForRole(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getPermsForRole(AuthzTrans trans, HttpServletResponse resp, String roleName) { + TimeTaken tt = trans.start(GET_PERMISSIONS_BY_ROLE + ' ' + roleName, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getPermsByRole(trans, roleName); + switch(rp.status) { + case OK: + RosettaData data = permsDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_PERMISSIONS_BY_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getPermsByNS(AuthzTrans trans,HttpServletResponse resp,String ns) { + TimeTaken tt = trans.start(GET_PERMISSIONS_BY_NS + ' ' + ns, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getPermsByNS(trans, ns); + switch(rp.status) { + case OK: + RosettaData data = permsDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_PERMISSIONS_BY_NS); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* + * (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#createOrUpdatePerm(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, boolean, java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public Result renamePerm(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, + String origType, String origInstance, String origAction) { + String cmdDescription = UPDATE_PERMISSION; + TimeTaken tt = trans.start( cmdDescription + ' ' + origType + ' ' + origInstance + ' ' + origAction, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = permRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,cmdDescription); + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.renamePerm(trans,rreq, origType, origInstance, origAction); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,cmdDescription); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result updatePermDescription(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(UPDATE_PERM_DESC, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = permRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,UPDATE_PERM_DESC); + return Result.err(Status.ERR_BadData,"Invalid Input"); + + } + Result rp = service.updatePermDescription(trans, rreq); + switch(rp.status) { + case OK: + setContentType(resp,permRequestDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,UPDATE_PERM_DESC); + return Result.err(e); + } finally { + tt.done(); + } + } + + + @Override + public Result resetPermRoles(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(SET_PERMISSION_ROLES_TO, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = rolePermRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN, SET_PERMISSION_ROLES_TO); + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.resetPermRoles(trans, rreq); + + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,SET_PERMISSION_ROLES_TO); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deletePerm(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(DELETE_PERMISSION, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = permRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,DELETE_PERMISSION); + return Result.err(Status.ERR_BadData,"Invalid Input"); + + } + + Result rp = service.deletePerm(trans,rreq); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_PERMISSION); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deletePerm(AuthzTrans trans, HttpServletResponse resp, String type, String instance, String action) { + TimeTaken tt = trans.start(DELETE_PERMISSION + type + ' ' + instance + ' ' + action, Env.SUB|Env.ALWAYS); + try { + Result rp = service.deletePerm(trans,type,instance,action); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_PERMISSION); + return Result.err(e); + } finally { + tt.done(); + } + } + + public static final String CREATE_ROLE = "createRole"; + public static final String GET_ROLES_BY_USER = "getRolesByUser"; + public static final String GET_ROLES_BY_NS = "getRolesByNS"; + public static final String GET_ROLES_BY_NAME_ONLY = "getRolesByNameOnly"; + public static final String GET_ROLES_BY_NAME = "getRolesByName"; + public static final String GET_ROLES_BY_PERM = "getRolesByPerm"; + public static final String UPDATE_ROLE_DESC = "updateRoleDescription"; + public static final String ADD_PERM_TO_ROLE = "addPermissionToRole"; + public static final String DELETE_PERM_FROM_ROLE = "deletePermissionFromRole"; + public static final String UPDATE_MGTPERM_ROLE = "updateMgtPermRole"; + public static final String DELETE_ROLE = "deleteRole"; + public static final String GET_CERT_BY_ID = "getCertByID"; + + @Override + public Result createRole(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(CREATE_ROLE, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = roleRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,CREATE_ROLE); + return Result.err(Status.ERR_BadData,"Invalid Input"); + + } + Result rp = service.createRole(trans, rreq); + switch(rp.status) { + case OK: + setContentType(resp,roleRequestDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,CREATE_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getRolesByName(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getRolesByName(AuthzTrans trans, HttpServletResponse resp, String role) { + TimeTaken tt = trans.start(GET_ROLES_BY_NAME + ' ' + role, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getRolesByName(trans, role); + switch(rp.status) { + case OK: + RosettaData data = roleDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,roleDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_ROLES_BY_NAME); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getRolesByUser(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getRolesByUser(AuthzTrans trans,HttpServletResponse resp, String user) { + TimeTaken tt = trans.start(GET_ROLES_BY_USER + ' ' + user, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getRolesByUser(trans, user); + switch(rp.status) { + case OK: + RosettaData data = roleDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,roleDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_ROLES_BY_USER, user); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getRolesByUser(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getRolesByNS(AuthzTrans trans,HttpServletResponse resp, String ns) { + TimeTaken tt = trans.start(GET_ROLES_BY_NS + ' ' + ns, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getRolesByNS(trans, ns); + switch(rp.status) { + case OK: + if(!rp.isEmpty()) { + RosettaData data = roleDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + } else { + Question.logEncryptTrace(trans, NO_DATA); + } + setContentType(resp,roleDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_ROLES_BY_NS); + return Result.err(e); + } finally { + tt.done(); + } + } + + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getRolesByNameOnly(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getRolesByNameOnly(AuthzTrans trans,HttpServletResponse resp, String nameOnly) { + TimeTaken tt = trans.start(GET_ROLES_BY_NAME_ONLY + ' ' + nameOnly, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getRolesByNameOnly(trans, nameOnly); + switch(rp.status) { + case OK: + if(!rp.isEmpty()) { + RosettaData data = roleDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + } else { + Question.logEncryptTrace(trans, NO_DATA); + } + setContentType(resp,roleDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_ROLES_BY_NAME_ONLY); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getRolesByUser(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getRolesByPerm(AuthzTrans trans,HttpServletResponse resp, String type, String instance, String action) { + TimeTaken tt = trans.start(GET_ROLES_BY_PERM + type +' '+instance+' '+action, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getRolesByPerm(trans, type,instance,action); + switch(rp.status) { + case OK: + RosettaData data = roleDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,roleDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_ROLES_BY_PERM); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* + * (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#updateDescription(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public Result updateRoleDescription(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(UPDATE_ROLE_DESC, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = roleRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,UPDATE_ROLE_DESC); + return Result.err(Status.ERR_BadData,"Invalid Input"); + + } + Result rp = service.updateRoleDescription(trans, rreq); + switch(rp.status) { + case OK: + setContentType(resp,roleRequestDF.getOutType()); + return Result.ok(); + default: + return rp; + } + } catch (Exception e) { + trans.error().log(e,IN,UPDATE_ROLE_DESC); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result addPermToRole(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(ADD_PERM_TO_ROLE, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = rolePermRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,ADD_PERM_TO_ROLE); + return Result.err(Status.ERR_BadData,"Invalid Input"); + + } + Result rp = service.addPermToRole(trans, rreq); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + resp.getOutputStream().println(); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,ADD_PERM_TO_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result delPermFromRole(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(DELETE_PERM_FROM_ROLE, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = rolePermRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,DELETE_PERM_FROM_ROLE); + return Result.err(Status.ERR_BadData,"Invalid Input"); + + } + Result rp = service.delPermFromRole(trans, rreq); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + resp.getOutputStream().println(); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_PERM_FROM_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deleteRole(AuthzTrans trans, HttpServletResponse resp, String role) { + TimeTaken tt = trans.start(DELETE_ROLE + ' ' + role, Env.SUB|Env.ALWAYS); + try { + Result rp = service.deleteRole(trans, role); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deleteRole(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(DELETE_ROLE, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = roleRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN,CREATE_ROLE); + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.deleteRole(trans, rreq); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + public static final String CREATE_CRED = "createUserCred"; + private static final String GET_CREDS_BY_NS = "getCredsByNS"; + private static final String GET_CREDS_BY_ID = "getCredsByID"; + public static final String UPDATE_CRED = "updateUserCred"; + public static final String EXTEND_CRED = "extendUserCred"; + public static final String DELETE_CRED = "deleteUserCred"; + public static final String DOES_CRED_MATCH = "doesCredMatch"; + public static final String VALIDATE_BASIC_AUTH = "validateBasicAuth"; + + + + @Override + /** + * Create Credential + * + */ + public Result createUserCred(AuthzTrans trans, HttpServletRequest req) { + TimeTaken tt = trans.start(CREATE_CRED, Env.SUB|Env.ALWAYS); + try { + RosettaData data = credRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + return service.createUserCred(trans, data.asObject()); + } catch(APIException e) { + trans.error().log(e,"Bad Input data"); + return Result.err(Status.ERR_BadData, e.getLocalizedMessage()); + } catch (Exception e) { + trans.error().log(e,IN,CREATE_CRED); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result changeUserCred(AuthzTrans trans, HttpServletRequest req) { + TimeTaken tt = trans.start(UPDATE_CRED, Env.SUB|Env.ALWAYS); + try { + RosettaData data = credRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + return service.changeUserCred(trans, data.asObject()); + } catch(APIException e) { + trans.error().log(e,"Bad Input data"); + return Result.err(Status.ERR_BadData, e.getLocalizedMessage()); + } catch (Exception e) { + trans.error().log(e,IN,UPDATE_CRED); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#extendUserCred(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, int) + */ + @Override + public Result extendUserCred(AuthzTrans trans, HttpServletRequest req, String days) { + TimeTaken tt = trans.start(EXTEND_CRED, Env.SUB|Env.ALWAYS); + try { + RosettaData data = credRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + return service.extendUserCred(trans, data.asObject(), days); + } catch(APIException e) { + trans.error().log(e,"Bad Input data"); + return Result.err(Status.ERR_BadData, e.getLocalizedMessage()); + } catch (Exception e) { + trans.error().log(e,IN,EXTEND_CRED); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getCredsByNS(AuthzTrans trans, HttpServletResponse resp, String ns) { + TimeTaken tt = trans.start(GET_CREDS_BY_NS + ' ' + ns, Env.SUB|Env.ALWAYS); + + try { + Result ru = service.getCredsByNS(trans,ns); + switch(ru.status) { + case OK: + RosettaData data = usersDF.newData(trans).load(ru.value); + if(Question.willSpecialLog(trans,trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,usersDF.getOutType()); + return Result.ok(); + default: + return Result.err(ru); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_CREDS_BY_NS); + return Result.err(e); + } finally { + tt.done(); + } + + } + + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getCredsByID(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getCredsByID(AuthzTrans trans, HttpServletResponse resp, String id) { + TimeTaken tt = trans.start(GET_CREDS_BY_ID + ' ' + id, Env.SUB|Env.ALWAYS); + + try { + Result ru = service.getCredsByID(trans,id); + switch(ru.status) { + case OK: + RosettaData data = usersDF.newData(trans).load(ru.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,usersDF.getOutType()); + return Result.ok(); + default: + return Result.err(ru); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_CREDS_BY_ID); + return Result.err(e); + } finally { + tt.done(); + } + + } + + @Override + public Result deleteUserCred(AuthzTrans trans, HttpServletRequest req) { + TimeTaken tt = trans.start(DELETE_CRED, Env.SUB|Env.ALWAYS); + try { + RosettaData data = credRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + return service.deleteUserCred(trans, data.asObject()); + } catch(APIException e) { + trans.error().log(e,"Bad Input data"); + return Result.err(Status.ERR_BadData, e.getLocalizedMessage()); + } catch (Exception e) { + trans.error().log(e,IN,DELETE_CRED); + return Result.err(e); + } finally { + tt.done(); + } + } + + + @Override + public Result doesCredentialMatch(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(DOES_CRED_MATCH, Env.SUB|Env.ALWAYS); + try { + RosettaData data = credRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + return service.doesCredentialMatch(trans, data.asObject()); + } catch(APIException e) { + trans.error().log(e,"Bad Input data"); + return Result.err(Status.ERR_BadData, e.getLocalizedMessage()); + } catch (IOException e) { + trans.error().log(e,IN,DOES_CRED_MATCH); + return Result.err(e); + } finally { + tt.done(); + } + } + + + @Override + public Result validBasicAuth(AuthzTrans trans, HttpServletResponse resp, String basicAuth) { + TimeTaken tt = trans.start(VALIDATE_BASIC_AUTH, Env.SUB|Env.ALWAYS); + try { + Result result = service.validateBasicAuth(trans,basicAuth); + switch(result.status){ + case OK: + resp.getOutputStream().write(Chrono.utcStamp(result.value).getBytes()); + return Result.ok(); + } + return Result.err(result); + } catch (Exception e) { + trans.error().log(e,IN,VALIDATE_BASIC_AUTH); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getCertInfoByID(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getCertInfoByID(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, String id) { + TimeTaken tt = trans.start(GET_CERT_BY_ID, Env.SUB|Env.ALWAYS); + try { + Result rci = service.getCertInfoByID(trans,req,id); + + switch(rci.status) { + case OK: + if(Question.willSpecialLog(trans, trans.user())) { + RosettaData data = certsDF.newData(trans).load(rci.value); + Question.logEncryptTrace(trans,data.asString()); + data.to(resp.getOutputStream()); + } else { + certsDF.direct(trans, rci.value, resp.getOutputStream()); + } + setContentType(resp,certsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rci); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_CERT_BY_ID); + return Result.err(e); + } finally { + tt.done(); + } + } + + public static final String CREATE_DELEGATE = "createDelegate"; + public static final String UPDATE_DELEGATE = "updateDelegate"; + public static final String DELETE_DELEGATE = "deleteDelegate"; + public static final String GET_DELEGATE_USER = "getDelegatesByUser"; + public static final String GET_DELEGATE_DELG = "getDelegatesByDelegate"; + + @Override + public Result createDelegate(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(CREATE_DELEGATE, Env.SUB|Env.ALWAYS); + try { + Data data = delgRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + return service.createDelegate(trans, data.asObject()); + } catch (Exception e) { + trans.error().log(e,IN,CREATE_DELEGATE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result updateDelegate(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(UPDATE_DELEGATE, Env.SUB|Env.ALWAYS); + try { + Data data = delgRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + return service.updateDelegate(trans, data.asObject()); + } catch (Exception e) { + trans.error().log(e,IN,UPDATE_DELEGATE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deleteDelegate(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(DELETE_DELEGATE, Env.SUB|Env.ALWAYS); + try { + Data data = delgRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + return service.deleteDelegate(trans, data.asObject()); + } catch (Exception e) { + trans.error().log(e,IN,DELETE_DELEGATE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deleteDelegate(AuthzTrans trans, String userName) { + TimeTaken tt = trans.start(DELETE_DELEGATE + ' ' + userName, Env.SUB|Env.ALWAYS); + try { + return service.deleteDelegate(trans, userName); + } catch (Exception e) { + trans.error().log(e,IN,DELETE_DELEGATE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getDelegatesByUser(AuthzTrans trans, String user, HttpServletResponse resp) { + TimeTaken tt = trans.start(GET_DELEGATE_USER, Env.SUB|Env.ALWAYS); + try { + Result rd = service.getDelegatesByUser(trans, user); + + switch(rd.status) { + case OK: + RosettaData data = delgDF.newData(trans).load(rd.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,delgDF.getOutType()); + return Result.ok(); + default: + return Result.err(rd); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_DELEGATE_USER); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getDelegatesByDelegate(AuthzTrans trans, String delegate, HttpServletResponse resp) { + TimeTaken tt = trans.start(GET_DELEGATE_DELG, Env.SUB|Env.ALWAYS); + try { + Result rd = service.getDelegatesByDelegate(trans, delegate); + switch(rd.status) { + case OK: + RosettaData data = delgDF.newData(trans).load(rd.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + setContentType(resp,delgDF.getOutType()); + return Result.ok(); + default: + return Result.err(rd); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_DELEGATE_DELG); + return Result.err(e); + } finally { + tt.done(); + } + } + + private static final String REQUEST_USER_ROLE = "createUserRole"; + private static final String GET_USERROLES = "getUserRoles"; + private static final String GET_USERROLES_BY_ROLE = "getUserRolesByRole"; + private static final String GET_USERROLES_BY_USER = "getUserRolesByUser"; + private static final String SET_ROLES_FOR_USER = "setRolesForUser"; + private static final String SET_USERS_FOR_ROLE = "setUsersForRole"; + private static final String EXTEND_USER_ROLE = "extendUserRole"; + private static final String DELETE_USER_ROLE = "deleteUserRole"; + @Override + public Result requestUserRole(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(REQUEST_USER_ROLE, Env.SUB|Env.ALWAYS); + try { + REQUEST request; + try { + Data data = userRoleRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + request = data.asObject(); + } catch(APIException e) { + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.createUserRole(trans,request); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,REQUEST_USER_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getUserInRole(AuthzTrans trans, HttpServletResponse resp, String user, String role) { + TimeTaken tt = trans.start(GET_USERROLES + ' ' + user + '|' + role, Env.SUB|Env.ALWAYS); + try { + Result ru = service.getUserInRole(trans,user,role); + switch(ru.status) { + case OK: + RosettaData data = usersDF.newData(trans).load(ru.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,usersDF.getOutType()); + return Result.ok(); + default: + return Result.err(ru); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_USERROLES); + return Result.err(e); + } finally { + tt.done(); + } + + } + + @Override + public Result getUserRolesByUser(AuthzTrans trans, HttpServletResponse resp, String user) { + TimeTaken tt = trans.start(GET_USERROLES_BY_USER + ' ' + user, Env.SUB|Env.ALWAYS); + try { + Result ru = service.getUserRolesByUser(trans,user); + switch(ru.status) { + case OK: + RosettaData data = userrolesDF.newData(trans).load(ru.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,usersDF.getOutType()); + return Result.ok(); + default: + return Result.err(ru); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_USERROLES_BY_USER); + return Result.err(e); + } finally { + tt.done(); + } + + } + + @Override + public Result getUserRolesByRole(AuthzTrans trans, HttpServletResponse resp, String role) { + TimeTaken tt = trans.start(GET_USERROLES_BY_ROLE + ' ' + role, Env.SUB|Env.ALWAYS); + try { + Result ru = service.getUserRolesByRole(trans,role); + switch(ru.status) { + case OK: + RosettaData data = userrolesDF.newData(trans).load(ru.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,usersDF.getOutType()); + return Result.ok(); + default: + return Result.err(ru); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_USERROLES_BY_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + + } + + + @Override + public Result resetUsersForRole(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req) { + TimeTaken tt = trans.start(SET_USERS_FOR_ROLE, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = userRoleRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN, SET_USERS_FOR_ROLE); + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.resetUsersForRole(trans, rreq); + + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,SET_USERS_FOR_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + + } + + @Override + public Result resetRolesForUser(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req) { + TimeTaken tt = trans.start(SET_ROLES_FOR_USER, Env.SUB|Env.ALWAYS); + try { + REQUEST rreq; + try { + RosettaData data = userRoleRequestDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + rreq = data.asObject(); + } catch(APIException e) { + trans.error().log("Invalid Input",IN, SET_ROLES_FOR_USER); + return Result.err(Status.ERR_BadData,"Invalid Input"); + } + + Result rp = service.resetRolesForUser(trans, rreq); + + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,SET_ROLES_FOR_USER); + return Result.err(e); + } finally { + tt.done(); + } + + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#extendUserRoleExpiration(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String) + */ + @Override + public Result extendUserRoleExpiration(AuthzTrans trans, HttpServletResponse resp, String user, String role) { + TimeTaken tt = trans.start(EXTEND_USER_ROLE + ' ' + user + ' ' + role, Env.SUB|Env.ALWAYS); + try { + return service.extendUserRole(trans,user,role); + } catch (Exception e) { + trans.error().log(e,IN,EXTEND_USER_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result deleteUserRole(AuthzTrans trans, HttpServletResponse resp, String user, String role) { + TimeTaken tt = trans.start(DELETE_USER_ROLE + ' ' + user + ' ' + role, Env.SUB|Env.ALWAYS); + try { + Result rp = service.deleteUserRole(trans,user,role); + switch(rp.status) { + case OK: + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,DELETE_USER_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + private static final String UPDATE_APPROVAL = "updateApproval"; + private static final String GET_APPROVALS_BY_USER = "getApprovalsByUser."; + private static final String GET_APPROVALS_BY_TICKET = "getApprovalsByTicket."; + private static final String GET_APPROVALS_BY_APPROVER = "getApprovalsByApprover."; + + @Override + public Result updateApproval(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) { + TimeTaken tt = trans.start(UPDATE_APPROVAL, Env.SUB|Env.ALWAYS); + try { + Data data = approvalDF.newData().load(req.getInputStream()); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + Result rp = service.updateApproval(trans, data.asObject()); + + switch(rp.status) { + case OK: + setContentType(resp,approvalDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,UPDATE_APPROVAL); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getApprovalsByUser(AuthzTrans trans, HttpServletResponse resp, String user) { + TimeTaken tt = trans.start(GET_APPROVALS_BY_USER + ' ' + user, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getApprovalsByUser(trans, user); + switch(rp.status) { + case OK: + RosettaData data = approvalDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + data.to(resp.getOutputStream()); + + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_APPROVALS_BY_USER, user); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getApprovalsByApprover(AuthzTrans trans, HttpServletResponse resp, String approver) { + TimeTaken tt = trans.start(GET_APPROVALS_BY_APPROVER + ' ' + approver, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getApprovalsByApprover(trans, approver); + switch(rp.status) { + case OK: + RosettaData data = approvalDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_APPROVALS_BY_APPROVER,approver); + return Result.err(e); + } finally { + tt.done(); + } + } + + @Override + public Result getApprovalsByTicket(AuthzTrans trans, HttpServletResponse resp, String ticket) { + TimeTaken tt = trans.start(GET_APPROVALS_BY_TICKET, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getApprovalsByTicket(trans, ticket); + switch(rp.status) { + case OK: + RosettaData data = approvalDF.newData(trans).load(rp.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,permsDF.getOutType()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_APPROVALS_BY_TICKET); + return Result.err(e); + } finally { + tt.done(); + } + } + + + + public static final String GET_USERS_PERMISSION = "getUsersByPermission"; + public static final String GET_USERS_ROLE = "getUsersByRole"; + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getUsersByRole(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getUsersByRole(AuthzTrans trans, HttpServletResponse resp, String role) { + TimeTaken tt = trans.start(GET_USERS_ROLE + ' ' + role, Env.SUB|Env.ALWAYS); + try { + Result ru = service.getUsersByRole(trans,role); + switch(ru.status) { + case OK: + RosettaData data = usersDF.newData(trans).load(ru.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,usersDF.getOutType()); + return Result.ok(); + default: + return Result.err(ru); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_USERS_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getUsersByPermission(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public Result getUsersByPermission(AuthzTrans trans, HttpServletResponse resp, + String type, String instance, String action) { + TimeTaken tt = trans.start(GET_USERS_PERMISSION + ' ' + type + ' ' + instance + ' ' +action, Env.SUB|Env.ALWAYS); + try { + Result ru = service.getUsersByPermission(trans,type,instance,action); + switch(ru.status) { + case OK: + RosettaData data = usersDF.newData(trans).load(ru.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,usersDF.getOutType()); + return Result.ok(); + default: + return Result.err(ru); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_USERS_PERMISSION); + return Result.err(e); + } finally { + tt.done(); + } + } + + + public static final String GET_HISTORY_USER = "getHistoryByUser"; + public static final String GET_HISTORY_ROLE = "getHistoryByRole"; + public static final String GET_HISTORY_PERM = "getHistoryByPerm"; + public static final String GET_HISTORY_NS = "getHistoryByNS"; + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getHistoryByUser(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public Result getHistoryByUser(AuthzTrans trans, HttpServletResponse resp, String user, int[] yyyymm, final int sort) { + StringBuilder sb = new StringBuilder(); + sb.append(GET_HISTORY_USER); + sb.append(' '); + sb.append(user); + sb.append(" for "); + boolean first = true; + for(int i : yyyymm) { + if(first) { + first = false; + } else { + sb.append(','); + } + sb.append(i); + } + TimeTaken tt = trans.start(sb.toString(), Env.SUB|Env.ALWAYS); + + try { + Result rh = service.getHistoryByUser(trans,user,yyyymm,sort); + switch(rh.status) { + case OK: + RosettaData data = historyDF.newData(trans).load(rh.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,historyDF.getOutType()); + return Result.ok(); + default: + return Result.err(rh); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_HISTORY_USER); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getHistoryByRole(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, int[]) + */ + @Override + public Result getHistoryByRole(AuthzTrans trans, HttpServletResponse resp, String role, int[] yyyymm, final int sort) { + StringBuilder sb = new StringBuilder(); + sb.append(GET_HISTORY_ROLE); + sb.append(' '); + sb.append(role); + sb.append(" for "); + boolean first = true; + for(int i : yyyymm) { + if(first) { + first = false; + } else { + sb.append(','); + } + sb.append(i); + } + TimeTaken tt = trans.start(sb.toString(), Env.SUB|Env.ALWAYS); + try { + Result rh = service.getHistoryByRole(trans,role,yyyymm,sort); + switch(rh.status) { + case OK: + RosettaData data = historyDF.newData(trans).load(rh.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,historyDF.getOutType()); + return Result.ok(); + default: + return Result.err(rh); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_HISTORY_ROLE); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getHistoryByNS(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, int[]) + */ + @Override + public Result getHistoryByNS(AuthzTrans trans, HttpServletResponse resp, String ns, int[] yyyymm, final int sort) { + StringBuilder sb = new StringBuilder(); + sb.append(GET_HISTORY_NS); + sb.append(' '); + sb.append(ns); + sb.append(" for "); + boolean first = true; + for(int i : yyyymm) { + if(first) { + first = false; + } else { + sb.append(','); + } + sb.append(i); + } + TimeTaken tt = trans.start(sb.toString(), Env.SUB|Env.ALWAYS); + try { + Result rh = service.getHistoryByNS(trans,ns,yyyymm,sort); + switch(rh.status) { + case OK: + RosettaData data = historyDF.newData(trans).load(rh.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,historyDF.getOutType()); + return Result.ok(); + default: + return Result.err(rh); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_HISTORY_NS); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getHistoryByPerm(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, int[]) + */ + @Override + public Result getHistoryByPerm(AuthzTrans trans, HttpServletResponse resp, String perm, int[] yyyymm, final int sort) { + StringBuilder sb = new StringBuilder(); + sb.append(GET_HISTORY_PERM); + sb.append(' '); + sb.append(perm); + sb.append(" for "); + boolean first = true; + for(int i : yyyymm) { + if(first) { + first = false; + } else { + sb.append(','); + } + sb.append(i); + } + TimeTaken tt = trans.start(sb.toString(), Env.SUB|Env.ALWAYS); + try { + Result rh = service.getHistoryByPerm(trans,perm,yyyymm,sort); + switch(rh.status) { + case OK: + RosettaData data = historyDF.newData(trans).load(rh.value); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,historyDF.getOutType()); + return Result.ok(); + default: + return Result.err(rh); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_HISTORY_PERM); + return Result.err(e); + } finally { + tt.done(); + } + } + + public final static String CACHE_CLEAR = "cacheClear "; +// public final static String CACHE_VALIDATE = "validateCache"; + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#cacheClear(com.att.authz.env.AuthzTrans, java.lang.String) + */ + @Override + public Result cacheClear(AuthzTrans trans, String cname) { + TimeTaken tt = trans.start(CACHE_CLEAR + cname, Env.SUB|Env.ALWAYS); + try { + return service.cacheClear(trans,cname); + } catch (Exception e) { + trans.error().log(e,IN,CACHE_CLEAR); + return Result.err(e); + } finally { + tt.done(); + } + } + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#cacheClear(com.att.authz.env.AuthzTrans, java.lang.String, java.lang.Integer) + */ + @Override + public Result cacheClear(AuthzTrans trans, String cname, String segments) { + TimeTaken tt = trans.start(CACHE_CLEAR + cname + ", segments[" + segments + ']', Env.SUB|Env.ALWAYS); + try { + String[] segs = segments.split("\\s*,\\s*"); + int isegs[] = new int[segs.length]; + for(int i=0;i getAPI(AuthzTrans trans, HttpServletResponse resp, RServlet rservlet) { + TimeTaken tt = trans.start(API_REPORT, Env.SUB); + try { + Api api = new Api(); + Api.Route ar; + Method[] meths = AuthzCassServiceImpl.class.getDeclaredMethods(); + for(RouteReport rr : rservlet.routeReport()) { + api.getRoute().add(ar = new Api.Route()); + ar.setMeth(rr.meth.name()); + ar.setPath(rr.path); + ar.setDesc(rr.desc); + ar.getContentType().addAll(rr.contextTypes); + for(Method m : meths) { + ApiDoc ad; + if((ad = m.getAnnotation(ApiDoc.class))!=null && + rr.meth.equals(ad.method()) && + rr.path.equals(ad.path())) { + for(String param : ad.params()) { + ar.getParam().add(param); + } + for(String text : ad.text()) { + ar.getComments().add(text); + } + ar.setExpected(ad.expectedCode()); + for(int ec : ad.errorCodes()) { + ar.getExplicitErr().add(ec); + } + } + } + } + RosettaData data = apiDF.newData(trans).load(api); + if(Question.willSpecialLog(trans, trans.user())) { + Question.logEncryptTrace(trans,data.asString()); + } + + data.to(resp.getOutputStream()); + setContentType(resp,apiDF.getOutType()); + return Result.ok(); + + } catch (Exception e) { + trans.error().log(e,IN,API_REPORT); + return Result.err(e); + } finally { + tt.done(); + } + } + + + public final static String API_EXAMPLE = "apiExample"; + + /* (non-Javadoc) + * @see com.att.authz.facade.AuthzFacade#getAPIExample(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String) + */ + @Override + public Result getAPIExample(AuthzTrans trans, HttpServletResponse resp, String nameOrContentType, boolean optional) { + TimeTaken tt = trans.start(API_EXAMPLE, Env.SUB); + try { + String content =Examples.print(apiDF.getEnv(), nameOrContentType, optional); + resp.getOutputStream().print(content); + setContentType(resp,content.contains(" +{ + public AuthzFacade_2_0(AuthzEnv env, + AuthzService service, + Data.TYPE type) throws APIException { + super(env, service, type); + } +} diff --git a/authz-service/src/main/java/com/att/authz/service/AuthAPI.java b/authz-service/src/main/java/com/att/authz/service/AuthAPI.java new file mode 100644 index 00000000..e6e3c823 --- /dev/null +++ b/authz-service/src/main/java/com/att/authz/service/AuthAPI.java @@ -0,0 +1,331 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.service; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Properties; + +import com.att.aft.dme2.api.DME2Exception; +//import com.att.aft.dme2.api.DME2FilterHolder; +//import com.att.aft.dme2.api.DME2FilterHolder.RequestDispatcherType; +import com.att.aft.dme2.api.DME2Manager; +import com.att.aft.dme2.api.DME2Server; +import com.att.aft.dme2.api.DME2ServerProperties; +import com.att.aft.dme2.api.DME2ServiceHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder; +import com.att.aft.dme2.api.util.DME2FilterHolder.RequestDispatcherType; +import com.att.aft.dme2.api.util.DME2ServletHolder; +//import com.att.aft.dme2.api.DME2ServletHolder; +import com.att.authz.cadi.DirectAAFLur; +import com.att.authz.cadi.DirectAAFUserPass; +import com.att.authz.cadi.DirectCertIdentity; +import com.att.authz.env.AuthzEnv; +import com.att.authz.env.AuthzTrans; +import com.att.authz.env.AuthzTransFilter; +import com.att.authz.facade.AuthzFacadeFactory; +import com.att.authz.facade.AuthzFacade_2_0; +import com.att.authz.org.OrganizationFactory; +import com.att.authz.server.AbsServer; +import com.att.authz.service.api.API_Api; +import com.att.authz.service.api.API_Approval; +import com.att.authz.service.api.API_Creds; +import com.att.authz.service.api.API_Delegate; +import com.att.authz.service.api.API_History; +import com.att.authz.service.api.API_Mgmt; +import com.att.authz.service.api.API_NS; +import com.att.authz.service.api.API_Perms; +import com.att.authz.service.api.API_Roles; +import com.att.authz.service.api.API_User; +import com.att.authz.service.api.API_UserRole; +import com.att.authz.service.mapper.Mapper.API; +import com.att.cadi.CadiException; +import com.att.cadi.LocatorException; +import com.att.cadi.SecuritySetter; +import com.att.cadi.aaf.v2_0.AAFTrustChecker; +import com.att.cadi.config.Config; +import com.att.cadi.config.SecurityInfoC; +import com.att.cadi.http.HBasicAuthSS; +import com.att.cadi.http.HMangr; +import com.att.cadi.http.HX509SS; +import com.att.cadi.locator.DME2Locator; +import com.att.cadi.taf.basic.BasicHttpTaf; +import com.att.cssa.rserv.HttpMethods; +import com.att.dao.CassAccess; +import com.att.dao.aaf.cass.CacheInfoDAO; +import com.att.dao.aaf.hl.Question; +import com.att.inno.env.APIException; +import com.att.inno.env.Data; +import com.att.inno.env.Env; +import com.datastax.driver.core.Cluster; + +public class AuthAPI extends AbsServer { + + private static final String ORGANIZATION = "Organization."; + private static final String DOMAIN = "openecomp.org"; + +// TODO Add Service Metrics +// private Metric serviceMetric; + public final Question question; +// private final SessionFilter sessionFilter; + private AuthzFacade_2_0 facade; + private AuthzFacade_2_0 facade_XML; + private DirectAAFUserPass directAAFUserPass; + + /** + * Construct AuthzAPI with all the Context Supporting Routes that Authz needs + * + * @param env + * @param decryptor + * @throws APIException + */ + public AuthAPI(AuthzEnv env) throws Exception { + super(env,"AAF"); + + // Set "aaf_url" for peer communication based on Service DME2 URL + env.setProperty(Config.AAF_URL, "https://DME2RESOLVE/"+env.getProperty("DMEServiceName")); + + // Setup Log Names + env.setLog4JNames("log4j.properties","authz","authz|service","audit","init","trace"); + + final Cluster cluster = com.att.dao.CassAccess.cluster(env,null); + + // jg 4/2015 SessionFilter unneeded... DataStax already deals with Multithreading well + + // Setup Shutdown Hooks for Cluster and Pooled Sessions + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { +// sessionFilter.destroy(); + cluster.close(); + } + }); + + // Initialize Facade for all uses + AuthzTrans trans = env.newTrans(); + + // Initialize Organizations... otherwise, first pass may miss + int org_size = ORGANIZATION.length(); + for(String n : env.existingStaticSlotNames()) { + if(n.startsWith(ORGANIZATION)) { + OrganizationFactory.obtain(env, n.substring(org_size)); + } + } + + // Need Question for Security purposes (direct User/Authz Query in Filter) + // Start Background Processing + question = new Question(trans, cluster, CassAccess.KEYSPACE, true); + + DirectCertIdentity.set(question.certDAO); + + facade = AuthzFacadeFactory.v2_0(env,trans,Data.TYPE.JSON,question); + facade_XML = AuthzFacadeFactory.v2_0(env,trans,Data.TYPE.XML,question); + + directAAFUserPass = new DirectAAFUserPass( + trans.env(),question,trans.getProperty("Unknown")); + + + // Print results and cleanup + StringBuilder sb = new StringBuilder(); + trans.auditTrail(0, sb); + if(sb.length()>0)env.init().log(sb); + trans = null; + sb = null; + + //////////////////////////////////////////////////////////////////////////// + // Time Critical + // These will always be evaluated first + //////////////////////////////////////////////////////////////////////// + API_Creds.timeSensitiveInit(env, this, facade,directAAFUserPass); + API_Perms.timeSensitiveInit(this, facade); + //////////////////////////////////////////////////////////////////////// + // Service APIs + //////////////////////////////////////////////////////////////////////// + API_Creds.init(this, facade); + API_UserRole.init(this, facade); + API_Roles.init(this, facade); + API_Perms.init(this, facade); + API_NS.init(this, facade); + API_User.init(this, facade); + API_Delegate.init(this,facade); + API_Approval.init(this, facade); + API_History.init(this, facade); + + //////////////////////////////////////////////////////////////////////// + // Management APIs + //////////////////////////////////////////////////////////////////////// + // There are several APIs around each concept, and it gets a bit too + // long in this class to create. The initialization of these Management + // APIs have therefore been pushed to StandAlone Classes with static + // init functions + API_Mgmt.init(this, facade); + API_Api.init(this, facade); + + } + + /** + * Setup XML and JSON implementations for each supported Version type + * + * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties + * to do Versions and Content switches + * + */ + public void route(HttpMethods meth, String path, API api, Code code) throws Exception { + String version = "2.0"; + Class respCls = facade.mapper().getClass(api); + if(respCls==null) throw new Exception("Unknown class associated with " + api.getClass().getName() + ' ' + api.name()); + String application = applicationJSON(respCls, version); + + route(env,meth,path,code,application,"application/json;version=2.0","*/*"); + application = applicationXML(respCls, version); + route(env,meth,path,code.clone(facade_XML,false),application,"text/xml;version=2.0"); + } + + /** + * Start up AuthzAPI as DME2 Service + * @param env + * @param props + * @throws Exception + * @throws LocatorException + * @throws CadiException + * @throws NumberFormatException + * @throws IOException + * @throws GeneralSecurityException + * @throws APIException + */ + public void startDME2(Properties props) throws Exception { + DME2Manager dme2 = new DME2Manager("AuthzServiceDME2Manager",props); + String s = dme2.getStringProp(Config.AFT_DME2_SSL_INCLUDE_PROTOCOLS,null); + env.init().log("DME2 Service TLS Protocols are set to",(s==null?"DME2 Default":s)); + + DME2ServiceHolder svcHolder; + List slist = new ArrayList(); + svcHolder = new DME2ServiceHolder(); + String serviceName = env.getProperty("DMEServiceName",null); + if(serviceName!=null) { + svcHolder.setServiceURI(serviceName); + svcHolder.setManager(dme2); + svcHolder.setContext("/"); + DME2ServletHolder srvHolder = new DME2ServletHolder(this, new String[]{"/authz","/authn","/mgmt"}); + srvHolder.setContextPath("/*"); + slist.add(srvHolder); + + EnumSet edlist = EnumSet.of( + RequestDispatcherType.REQUEST, + RequestDispatcherType.FORWARD, + RequestDispatcherType.ASYNC + ); + + List flist = new ArrayList(); + + // Add DME2 Metrics + // DME2 removed the Metrics Filter in 2.8.8.5 + // flist.add(new DME2FilterHolder(new DME2MetricsFilter(serviceName),"/*",edlist)); + + // Note: Need CADI to fill out User for AuthTransFilter... so it's first + // Make sure there is no AAF TAF configured for Filters + env.setProperty(Config.AAF_URL,null); + + flist.add( + new DME2FilterHolder( + new AuthzTransFilter(env, null /* no connection to AAF... it is AAF */, + new AAFTrustChecker((Env)env), + new DirectAAFLur(env,question), // Note, this will be assigned by AuthzTransFilter to TrustChecker + new BasicHttpTaf(env, directAAFUserPass, + DOMAIN,Long.parseLong(env.getProperty(Config.AAF_CLEAN_INTERVAL, Config.AAF_CLEAN_INTERVAL_DEF)), + false + ) // Add specialty Direct TAF + ), + "/*", edlist)); + + svcHolder.setFilters(flist); + svcHolder.setServletHolders(slist); + + DME2Server dme2svr = dme2.getServer(); + + String hostname = env.getProperty("HOSTNAME",null); + if(hostname!=null) { + //dme2svr.setHostname(hostname); + hostname=null; + } + // dme2svr.setGracefulShutdownTimeMs(5000); + + env.init().log("Starting AAF Jetty/DME2 server..."); + dme2svr.start(); + try { +// if(env.getProperty("NO_REGISTER",null)!=null) + dme2.bindService(svcHolder); + //env.init().log("DME2 is available as HTTPS on port:",dme2svr.getPort()); + + // Start CacheInfo Listener + HMangr hman = new HMangr(env, new DME2Locator(env, dme2,"https://DME2RESOLVE/"+serviceName,true /*remove self from cache*/)); + SecuritySetter ss; + +// InetAddress ip = InetAddress.getByName(dme2svr.getHostname()); + SecurityInfoC si = new SecurityInfoC(env); + String mechID; + if((mechID=env.getProperty(Config.AAF_MECHID))==null) { + String alias = env.getProperty(Config.CADI_ALIAS); + if(alias==null) { + env.init().log(Config.CADI_ALIAS, "is required for AAF Authentication by Certificate. Alternately, set",Config.AAF_MECHID,"and",Config.AAF_MECHPASS); + System.exit(1); + } + ss = new HX509SS(alias,si,true); + env.init().log("X509 Certificate Client configured:", alias); + } else { + String pass = env.getProperty(Config.AAF_MECHPASS); + if(pass==null) { + env.init().log(Config.AAF_MECHPASS, "is required for AAF Authentication by ID/Pass"); + System.exit(1); + } + ss = new HBasicAuthSS(mechID,env.decrypt(pass, true),si,true); + env.init().log("BasicAuth (ID/Pass) Client configured."); + } + + //TODO Reenable Cache Update + //CacheInfoDAO.startUpdate(env, hman, ss, dme2svr.getHostname(), dme2svr.getPort()); + + while(true) { // Per DME2 Examples... + Thread.sleep(5000); + } + } catch(DME2Exception e) { // Error binding service doesn't seem to stop DME2 or Process + env.init().log(e,"DME2 Initialization Error"); + dme2svr.stop(); + System.exit(1); + } catch(InterruptedException e) { + env.init().log("AAF Jetty Server interrupted!"); + } + } else { + env.init().log("Properties must contain 'DMEServiceName'"); + } + } + + public static void main(String[] args) { + setup(AuthAPI.class,"authAPI.props"); + } +} diff --git a/authz-service/src/main/java/com/att/authz/service/AuthzCassServiceImpl.java b/authz-service/src/main/java/com/att/authz/service/AuthzCassServiceImpl.java new file mode 100644 index 00000000..55f41f5c --- /dev/null +++ b/authz-service/src/main/java/com/att/authz/service/AuthzCassServiceImpl.java @@ -0,0 +1,3973 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.att.authz.service; + +import static com.att.authz.layer.Result.OK; +import static com.att.cssa.rserv.HttpMethods.DELETE; +import static com.att.cssa.rserv.HttpMethods.GET; +import static com.att.cssa.rserv.HttpMethods.POST; +import static com.att.cssa.rserv.HttpMethods.PUT; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; + +import com.att.authz.common.Define; +import com.att.authz.env.AuthzTrans; +import com.att.authz.layer.Result; +import com.att.authz.org.Executor; +import com.att.authz.org.Organization; +import com.att.authz.org.Organization.Expiration; +import com.att.authz.org.Organization.Identity; +import com.att.authz.org.Organization.Policy; +import com.att.authz.service.mapper.Mapper; +import com.att.authz.service.mapper.Mapper.API; +import com.att.authz.service.validation.Validator; +import com.att.cadi.principal.BasicPrincipal; +import com.att.cssa.rserv.doc.ApiDoc; +import com.att.dao.DAOException; +import com.att.dao.aaf.cass.ApprovalDAO; +import com.att.dao.aaf.cass.CertDAO; +import com.att.dao.aaf.cass.CredDAO; +import com.att.dao.aaf.cass.DelegateDAO; +import com.att.dao.aaf.cass.FutureDAO; +import com.att.dao.aaf.cass.HistoryDAO; +import com.att.dao.aaf.cass.Namespace; +import com.att.dao.aaf.cass.NsDAO; +import com.att.dao.aaf.cass.NsDAO.Data; +import com.att.dao.aaf.cass.NsSplit; +import com.att.dao.aaf.cass.NsType; +import com.att.dao.aaf.cass.PermDAO; +import com.att.dao.aaf.cass.RoleDAO; +import com.att.dao.aaf.cass.Status; +import com.att.dao.aaf.cass.UserRoleDAO; +import com.att.dao.aaf.hl.CassExecutor; +import com.att.dao.aaf.hl.Function; +import com.att.dao.aaf.hl.Question; +import com.att.dao.aaf.hl.Question.Access; +import com.att.inno.env.Env; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.util.Chrono; +import com.att.inno.env.util.Split; + +import aaf.v2_0.CredRequest; + +/** + * AuthzCassServiceImpl implements AuthzCassService for + * + * + * @param + * @param + * @param + * @param + * @param + * @param + * @param + * @param + * @param + * @param + */ +public class AuthzCassServiceImpl + implements AuthzService { + + private Mapper mapper; + @Override + public Mapper mapper() {return mapper;} + + private static final String ASTERIX = "*"; + private static final String CACHE = "cache"; + + private final Question ques; + private final Function func; + + public AuthzCassServiceImpl(AuthzTrans trans, Mapper mapper,Question question) { + this.ques = question; + func = new Function(trans, question); + this.mapper = mapper; + + } + +/*********************************** + * NAMESPACE + ***********************************/ + /** + * createNS + * @throws DAOException + * @see com.att.authz.service.AuthzService#createNS(com.att.authz.env.AuthzTrans, java.lang.String, java.lang.String) + */ + @ApiDoc( + method = POST, + path = "/authz/ns", + params = {}, + expectedCode = 201, + errorCodes = { 403,404,406,409 }, + text = { "Namespace consists of: ", + "

", + "Note: Namespaces are dot-delimited (i.e. com.myCompany.myApp) and must be ", + "created with parent credentials (i.e. To create com.myCompany.myApp, you must ", + "be an admin of com.myCompany or com" + } + ) + @Override + public Result createNS(final AuthzTrans trans, REQUEST from, NsType type) { + final Result rnamespace = mapper.ns(trans, from); + final Validator v = new Validator(); + if(v.ns(rnamespace).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + final Namespace namespace = rnamespace.value; + final Result parentNs = ques.deriveNs(trans,namespace.name); + if(parentNs.notOK()) { + return Result.err(parentNs); + } + + if(namespace.name.lastIndexOf('.')<0) { // Root Namespace... Function will check if allowed + return func.createNS(trans, namespace, false); + } + + Result fd = mapper.future(trans, NsDAO.TABLE,from,namespace,true, + new Mapper.Memo() { + @Override + public String get() { + return "Create Namespace [" + namespace.name + ']'; + } + }, + new MayChange() { + private Result rnd; + @Override + public Result mayChange() { + if(rnd==null) { + rnd = ques.mayUser(trans, trans.user(), parentNs.value,Access.write); + } + return rnd; + } + }); + switch(fd.status) { + case OK: + Result> rfc = func.createFuture(trans, fd.value, namespace.name, trans.user(),parentNs.value, "C"); + if(rfc.isOK()) { + return Result.err(Status.ACC_Future, "NS [%s] is saved for future processing",namespace.name); + } else { + return Result.err(rfc); + } + case Status.ACC_Now: + return func.createNS(trans, namespace, false); + default: + return Result.err(fd); + } + } + + @ApiDoc( + method = POST, + path = "/authz/ns/:ns/admin/:id", + params = { "ns|string|true", + "id|string|true" + }, + expectedCode = 201, + errorCodes = { 403,404,406,409 }, + text = { "Add an Identity :id to the list of Admins for the Namespace :ns", + "Note: :id must be fully qualified (i.e. ab1234@csp.att.com)" } + ) + @Override + public Result addAdminNS(AuthzTrans trans, String ns, String id) { + return func.addUserRole(trans, id, ns,Question.ADMIN); + } + + @ApiDoc( + method = DELETE, + path = "/authz/ns/:ns/admin/:id", + params = { "ns|string|true", + "id|string|true" + }, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { "Remove an Identity :id from the list of Admins for the Namespace :ns", + "Note: :id must be fully qualified (i.e. ab1234@csp.att.com)" } + ) + @Override + public Result delAdminNS(AuthzTrans trans, String ns, String id) { + return func.delAdmin(trans,ns,id); + } + + @ApiDoc( + method = POST, + path = "/authz/ns/:ns/responsible/:id", + params = { "ns|string|true", + "id|string|true" + }, + expectedCode = 201, + errorCodes = { 403,404,406,409 }, + text = { "Add an Identity :id to the list of Responsibles for the Namespace :ns", + "Note: :id must be fully qualified (i.e. ab1234@csp.att.com)" } + ) + @Override + public Result addResponsibleNS(AuthzTrans trans, String ns, String id) { + return func.addUserRole(trans,id,ns,Question.OWNER); + } + + @ApiDoc( + method = DELETE, + path = "/authz/ns/:ns/responsible/:id", + params = { "ns|string|true", + "id|string|true" + }, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { "Remove an Identity :id to the list of Responsibles for the Namespace :ns", + "Note: :id must be fully qualified (i.e. ab1234@csp.att.com)", + "Note: A namespace must have at least 1 responsible party" + } + ) + @Override + public Result delResponsibleNS(AuthzTrans trans, String ns, String id) { + return func.delOwner(trans,ns,id); + } + + /* (non-Javadoc) + * @see com.att.authz.service.AuthzService#applyModel(com.att.authz.env.AuthzTrans, java.lang.Object) + */ + @ApiDoc( + method = POST, + path = "/authz/ns/:ns/attrib/:key/:value", + params = { "ns|string|true", + "key|string|true", + "value|string|true"}, + expectedCode = 201, + errorCodes = { 403,404,406,409 }, + text = { + "Create an attribute in the Namespace", + "You must be given direct permission for key by AAF" + } + ) + @Override + public Result createNsAttrib(AuthzTrans trans, String ns, String key, String value) { + TimeTaken tt = trans.start("Create NsAttrib " + ns + ':' + key + ':' + value, Env.SUB); + try { + // Check inputs + final Validator v = new Validator(); + if(v.ns(ns).err() || + v.key(key).err() || + v.value(value).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + // Check if exists already + Result> rlnsd = ques.nsDAO.read(trans, ns); + if(rlnsd.notOKorIsEmpty()) { + return Result.err(rlnsd); + } + NsDAO.Data nsd = rlnsd.value.get(0); + + // Check for Existence + if(nsd.attrib.get(key)!=null) { + return Result.err(Status.ERR_ConflictAlreadyExists, "NS Property %s:%s exists", ns, key); + } + + // Check if User may put + if(!ques.isGranted(trans, trans.user(), Define.ROOT_NS, Question.ATTRIB, + ":"+trans.org().getDomain()+".*:"+key, Access.write.name())) { + return Result.err(Status.ERR_Denied, "%s may not create NS Attrib [%s:%s]", trans.user(),ns, key); + } + + // Add Attrib + nsd.attrib.put(key, value); + ques.nsDAO.dao().attribAdd(trans,ns,key,value); + return Result.ok(); + } finally { + tt.done(); + } + } + + @ApiDoc( + method = GET, + path = "/authz/ns/attrib/:key", + params = { "key|string|true" }, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { + "Read Attributes for Namespace" + } + ) + @Override + public Result readNsByAttrib(AuthzTrans trans, String key) { + // Check inputs + final Validator v = new Validator(); + if(v.nullOrBlank("Key",key).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + // May Read + if(!ques.isGranted(trans, trans.user(), Define.ROOT_NS, Question.ATTRIB, + ":"+trans.org().getDomain()+".*:"+key, Question.READ)) { + return Result.err(Status.ERR_Denied,"%s may not read NS by Attrib '%s'",trans.user(),key); + } + + Result> rsd = ques.nsDAO.dao().readNsByAttrib(trans, key); + if(rsd.notOK()) { + return Result.err(rsd); + } + return mapper().keys(rsd.value); + } + + + @ApiDoc( + method = PUT, + path = "/authz/ns/:ns/attrib/:key/:value", + params = { "ns|string|true", + "key|string|true"}, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { + "Update Value on an existing attribute in the Namespace", + "You must be given direct permission for key by AAF" + } + ) + @Override + public Result updateNsAttrib(AuthzTrans trans, String ns, String key, String value) { + TimeTaken tt = trans.start("Update NsAttrib " + ns + ':' + key + ':' + value, Env.SUB); + try { + // Check inputs + final Validator v = new Validator(); + if(v.ns(ns).err() || + v.key(key).err() || + v.value(value).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + // Check if exists already (NS must exist) + Result> rlnsd = ques.nsDAO.read(trans, ns); + if(rlnsd.notOKorIsEmpty()) { + return Result.err(rlnsd); + } + NsDAO.Data nsd = rlnsd.value.get(0); + + // Check for Existence + if(nsd.attrib.get(key)==null) { + return Result.err(Status.ERR_NotFound, "NS Property %s:%s exists", ns, key); + } + + // Check if User may put + if(!ques.isGranted(trans, trans.user(), Define.ROOT_NS, Question.ATTRIB, + ":"+trans.org().getDomain()+".*:"+key, Access.write.name())) { + return Result.err(Status.ERR_Denied, "%s may not create NS Attrib [%s:%s]", trans.user(),ns, key); + } + + // Add Attrib + nsd.attrib.put(key, value); + + return ques.nsDAO.update(trans,nsd); + + } finally { + tt.done(); + } + } + + @ApiDoc( + method = DELETE, + path = "/authz/ns/:ns/attrib/:key", + params = { "ns|string|true", + "key|string|true"}, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { + "Delete an attribute in the Namespace", + "You must be given direct permission for key by AAF" + } + ) + @Override + public Result deleteNsAttrib(AuthzTrans trans, String ns, String key) { + TimeTaken tt = trans.start("Delete NsAttrib " + ns + ':' + key, Env.SUB); + try { + // Check inputs + final Validator v = new Validator(); + if(v.nullOrBlank("NS",ns).err() || + v.nullOrBlank("Key",key).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + // Check if exists already + Result> rlnsd = ques.nsDAO.read(trans, ns); + if(rlnsd.notOKorIsEmpty()) { + return Result.err(rlnsd); + } + NsDAO.Data nsd = rlnsd.value.get(0); + + // Check for Existence + if(nsd.attrib.get(key)==null) { + return Result.err(Status.ERR_NotFound, "NS Property [%s:%s] does not exist", ns, key); + } + + // Check if User may del + if(!ques.isGranted(trans, trans.user(), Define.ROOT_NS, "attrib", ":com.att.*:"+key, Access.write.name())) { + return Result.err(Status.ERR_Denied, "%s may not delete NS Attrib [%s:%s]", trans.user(),ns, key); + } + + // Add Attrib + nsd.attrib.remove(key); + ques.nsDAO.dao().attribRemove(trans,ns,key); + return Result.ok(); + } finally { + tt.done(); + } + } + + @ApiDoc( + method = GET, + path = "/authz/nss/:id", + params = { "id|string|true" }, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { + "Lists the Admin(s), Responsible Party(s), Role(s), Permission(s)", + "Credential(s) and Expiration of Credential(s) in Namespace :id", + } + ) + @Override + public Result getNSbyName(AuthzTrans trans, String ns) { + final Validator v = new Validator(); + if(v.nullOrBlank("NS", ns).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result> rlnd = ques.nsDAO.read(trans, ns); + if(rlnd.isOK()) { + if(rlnd.isEmpty()) { + return Result.err(Status.ERR_NotFound, "No data found for %s",ns); + } + Result rnd = ques.mayUser(trans, trans.user(), rlnd.value.get(0), Access.read); + if(rnd.notOK()) { + return Result.err(rnd); + } + + + Namespace namespace = new Namespace(rnd.value); + Result> rd = func.getOwners(trans, namespace.name, false); + if(rd.isOK()) { + namespace.owner = rd.value; + } + rd = func.getAdmins(trans, namespace.name, false); + if(rd.isOK()) { + namespace.admin = rd.value; + } + + NSS nss = mapper.newInstance(API.NSS); + return mapper.nss(trans, namespace, nss); + } else { + return Result.err(rlnd); + } + } + + @ApiDoc( + method = GET, + path = "/authz/nss/admin/:id", + params = { "id|string|true" }, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { "Lists all Namespaces where Identity :id is an Admin", + "Note: :id must be fully qualified (i.e. ab1234@csp.att.com)" + } + ) + @Override + public Result getNSbyAdmin(AuthzTrans trans, String user, boolean full) { + final Validator v = new Validator(); + if (v.nullOrBlank("User", user).err()) { + return Result.err(Status.ERR_BadData, v.errs()); + } + + Result> rn = loadNamepace(trans, user, ".admin", full); + if(rn.notOK()) { + return Result.err(rn); + } + if (rn.isEmpty()) { + return Result.err(Status.ERR_NotFound, "[%s] is not an admin for any namespaces",user); + } + NSS nss = mapper.newInstance(API.NSS); + // Note: "loadNamespace" already validates view of Namespace + return mapper.nss(trans, rn.value, nss); + + } + + @ApiDoc( + method = GET, + path = "/authz/nss/either/:id", + params = { "id|string|true" }, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { "Lists all Namespaces where Identity :id is either an Admin or an Owner", + "Note: :id must be fully qualified (i.e. ab1234@csp.att.com)" + } + ) + @Override + public Result getNSbyEither(AuthzTrans trans, String user, boolean full) { + final Validator v = new Validator(); + if (v.nullOrBlank("User", user).err()) { + return Result.err(Status.ERR_BadData, v.errs()); + } + + Result> rn = loadNamepace(trans, user, null, full); + if(rn.notOK()) { + return Result.err(rn); + } + if (rn.isEmpty()) { + return Result.err(Status.ERR_NotFound, "[%s] is not an admin or owner for any namespaces",user); + } + NSS nss = mapper.newInstance(API.NSS); + // Note: "loadNamespace" already validates view of Namespace + return mapper.nss(trans, rn.value, nss); + } + + private Result> loadNamepace(AuthzTrans trans, String user, String endsWith, boolean full) { + Result> urd = ques.userRoleDAO.readByUser(trans, user); + if(urd.notOKorIsEmpty()) { + return Result.err(urd); + } + Map lm = new HashMap(); + Map other = full || endsWith==null?null:new TreeMap(); + for(UserRoleDAO.Data urdd : urd.value) { + if(full) { + if(endsWith==null || urdd.role.endsWith(endsWith)) { + RoleDAO.Data rd = RoleDAO.Data.decode(urdd); + Result nsd = ques.mayUser(trans, user, rd, Access.read); + if(nsd.isOK()) { + Namespace namespace = lm.get(nsd.value.name); + if(namespace==null) { + namespace = new Namespace(nsd.value); + lm.put(namespace.name,namespace); + } + Result> rls = func.getAdmins(trans, namespace.name, false); + if(rls.isOK()) { + namespace.admin=rls.value; + } + + rls = func.getOwners(trans, namespace.name, false); + if(rls.isOK()) { + namespace.owner=rls.value; + } + } + } + } else { // Shortened version. Only Namespace Info available from Role. + if(Question.ADMIN.equals(urdd.rname) || Question.OWNER.equals(urdd.rname)) { + RoleDAO.Data rd = RoleDAO.Data.decode(urdd); + Result nsd = ques.mayUser(trans, user, rd, Access.read); + if(nsd.isOK()) { + Namespace namespace = lm.get(nsd.value.name); + if(namespace==null) { + if(other!=null) { + namespace = other.remove(nsd.value.name); + } + if(namespace==null) { + namespace = new Namespace(nsd.value); + namespace.admin=new ArrayList(); + namespace.owner=new ArrayList(); + } + if(endsWith==null || urdd.role.endsWith(endsWith)) { + lm.put(namespace.name,namespace); + } else { + other.put(namespace.name,namespace); + } + } + if(Question.OWNER.equals(urdd.rname)) { + namespace.owner.add(urdd.user); + } else { + namespace.admin.add(urdd.user); + } + } + } + } + } + return Result.ok(lm.values()); + } + + @ApiDoc( + method = GET, + path = "/authz/nss/responsible/:id", + params = { "id|string|true" }, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { "Lists all Namespaces where Identity :id is a Responsible Party", + "Note: :id must be fully qualified (i.e. ab1234@csp.att.com)" + } + ) + @Override + public Result getNSbyResponsible(AuthzTrans trans, String user, boolean full) { + final Validator v = new Validator(); + if (v.nullOrBlank("User", user).err()) { + return Result.err(Status.ERR_BadData, v.errs()); + } + Result> rn = loadNamepace(trans, user, ".owner",full); + if(rn.notOK()) { + return Result.err(rn); + } + if (rn.isEmpty()) { + return Result.err(Status.ERR_NotFound, "[%s] is not an owner for any namespaces",user); + } + NSS nss = mapper.newInstance(API.NSS); + // Note: "loadNamespace" prevalidates + return mapper.nss(trans, rn.value, nss); + } + + @ApiDoc( + method = GET, + path = "/authz/nss/children/:id", + params = { "id|string|true" }, + expectedCode = 200, + errorCodes = { 403,404 }, + text = { "Lists all Child Namespaces of Namespace :id", + "Note: This is not a cached read" + } + ) + @Override + public Result getNSsChildren(AuthzTrans trans, String parent) { + final Validator v = new Validator(); + if(v.nullOrBlank("NS", parent).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result rnd = ques.deriveNs(trans, parent); + if(rnd.notOK()) { + return Result.err(rnd); + } + rnd = ques.mayUser(trans, trans.user(), rnd.value, Access.read); + if(rnd.notOK()) { + return Result.err(rnd); + } + + Set lm = new HashSet(); + Result> rlnd = ques.nsDAO.dao().getChildren(trans, parent); + if(rlnd.isOK()) { + if(rlnd.isEmpty()) { + return Result.err(Status.ERR_NotFound, "No data found for %s",parent); + } + for(NsDAO.Data ndd : rlnd.value) { + Namespace namespace = new Namespace(ndd); + Result> rls = func.getAdmins(trans, namespace.name, false); + if(rls.isOK()) { + namespace.admin=rls.value; + } + + rls = func.getOwners(trans, namespace.name, false); + if(rls.isOK()) { + namespace.owner=rls.value; + } + + lm.add(namespace); + } + NSS nss = mapper.newInstance(API.NSS); + return mapper.nss(trans,lm, nss); + } else { + return Result.err(rlnd); + } + } + + + @ApiDoc( + method = PUT, + path = "/authz/ns", + params = {}, + expectedCode = 200, + errorCodes = { 403,404,406 }, + text = { "Replace the Current Description of a Namespace with a new one" + } + ) + @Override + public Result updateNsDescription(AuthzTrans trans, REQUEST from) { + final Result nsd = mapper.ns(trans, from); + final Validator v = new Validator(); + if(v.ns(nsd).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + if(v.nullOrBlank("description", nsd.value.description).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Namespace namespace = nsd.value; + Result> rlnd = ques.nsDAO.read(trans, namespace.name); + + if(rlnd.notOKorIsEmpty()) { + return Result.err(Status.ERR_NotFound, "Namespace [%s] does not exist",namespace.name); + } + + if (ques.mayUser(trans, trans.user(), rlnd.value.get(0), Access.write).notOK()) { + return Result.err(Status.ERR_Denied, "You do not have approval to change %s",namespace.name); + } + + Result rdr = ques.nsDAO.dao().addDescription(trans, namespace.name, namespace.description); + if(rdr.isOK()) { + return Result.ok(); + } else { + return Result.err(rdr); + } + } + + /** + * deleteNS + * @throws DAOException + * @see com.att.authz.service.AuthzService#deleteNS(com.att.authz.env.AuthzTrans, java.lang.String, java.lang.String) + */ + @ApiDoc( + method = DELETE, + path = "/authz/ns/:ns", + params = { "ns|string|true" }, + expectedCode = 200, + errorCodes = { 403,404,424 }, + text = { "Delete the Namespace :ns. Namespaces cannot normally be deleted when there ", + "are still credentials associated with them, but they can be deleted by setting ", + "the \"force\" property. To do this: Add 'force=true' as a query parameter", + "

WARNING: Using force will delete all credentials attached to this namespace. Use with care.

" + + "if the \"force\" property is set to 'force=move', then Permissions and Roles are not deleted," + + "but are retained, and assigned to the Parent Namespace. 'force=move' is not permitted " + + "at or below Application Scope" + } + ) + @Override + public Result deleteNS(AuthzTrans trans, String ns) { + return func.deleteNS(trans, ns); + } + + +/*********************************** + * PERM + ***********************************/ + + /* + * (non-Javadoc) + * @see com.att.authz.service.AuthzService#createOrUpdatePerm(com.att.authz.env.AuthzTrans, java.lang.Object, boolean, java.lang.String, java.lang.String, java.lang.String, java.util.List, java.util.List) + */ + @ApiDoc( + method = POST, + path = "/authz/perm", + params = {}, + expectedCode = 201, + errorCodes = {403,404,406,409}, + text = { "Permission consists of:", + "
  • type - a Namespace qualified identifier specifying what kind of resource " + + "is being protected
  • ", + "
  • instance - a key, possibly multi-dimensional, that identifies a specific " + + " instance of the type
  • ", + "
  • action - what kind of action is allowed
", + "Note: instance and action can be an *" + } + ) + @Override + public Result createPerm(final AuthzTrans trans,REQUEST rreq) { + final Result newPd = mapper.perm(trans, rreq); + final Validator v = new Validator(trans); + if(v.perm(newPd).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result fd = mapper.future(trans, PermDAO.TABLE, rreq, newPd.value,false, + new Mapper.Memo() { + @Override + public String get() { + return "Create Permission [" + + newPd.value.fullType() + '|' + + newPd.value.instance + '|' + + newPd.value.action + ']'; + } + }, + new MayChange() { + private Result nsd; + @Override + public Result mayChange() { + if(nsd==null) { + nsd = ques.mayUser(trans, trans.user(), newPd.value, Access.write); + } + return nsd; + } + }); + Result> nsr = ques.nsDAO.read(trans, newPd.value.ns); + if(nsr.notOKorIsEmpty()) { + return Result.err(nsr); + } + switch(fd.status) { + case OK: + Result> rfc = func.createFuture(trans,fd.value, + newPd.value.fullType() + '|' + newPd.value.instance + '|' + newPd.value.action, + trans.user(), + nsr.value.get(0), + "C"); + if(rfc.isOK()) { + return Result.err(Status.ACC_Future, "Perm [%s.%s|%s|%s] is saved for future processing", + newPd.value.ns, + newPd.value.type, + newPd.value.instance, + newPd.value.action); + } else { + return Result.err(rfc); + } + case Status.ACC_Now: + return func.createPerm(trans, newPd.value, true); + default: + return Result.err(fd); + } + } + + @ApiDoc( + method = GET, + path = "/authz/perms/:type", + params = {"type|string|true"}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "List All Permissions that match the :type element of the key" } + ) + @Override + public Result getPermsByType(AuthzTrans trans, final String permType) { + final Validator v = new Validator(); + if(v.nullOrBlank("PermType", permType).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result> rlpd = ques.getPermsByType(trans, permType); + if(rlpd.notOK()) { + return Result.err(rlpd); + } + +// We don't have instance & action for mayUserView... do we want to loop through all returned here as well as in mapper? +// Result r; +// if((r = ques.mayUserViewPerm(trans, trans.user(), permType)).notOK())return Result.err(r); + + PERMS perms = mapper.newInstance(API.PERMS); + if(!rlpd.isEmpty()) { + // Note: Mapper will restrict what can be viewed + return mapper.perms(trans, rlpd.value, perms, true); + } + return Result.ok(perms); + } + + @ApiDoc( + method = GET, + path = "/authz/perms/:type/:instance/:action", + params = {"type|string|true", + "instance|string|true", + "action|string|true"}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "List Permissions that match key; :type, :instance and :action" } + ) + @Override + public Result getPermsByName(AuthzTrans trans, String type, String instance, String action) { + final Validator v = new Validator(); + if(v.nullOrBlank("PermType", type).err() + || v.nullOrBlank("PermInstance", instance).err() + || v.nullOrBlank("PermAction", action).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result> rlpd = ques.getPermsByName(trans, type, instance, action); + if(rlpd.notOK()) { + return Result.err(rlpd); + } + + PERMS perms = mapper.newInstance(API.PERMS); + if(!rlpd.isEmpty()) { + // Note: Mapper will restrict what can be viewed + return mapper.perms(trans, rlpd.value, perms, true); + } + return Result.ok(perms); + } + + @ApiDoc( + method = GET, + path = "/authz/perms/user/:user", + params = {"user|string|true"}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "List All Permissions that match user :user", + "

'user' must be expressed as full identity (ex: id@full.domain.com)

"} + ) + @Override + public Result getPermsByUser(AuthzTrans trans, String user) { + final Validator v = new Validator(); + if(v.nullOrBlank("User", user).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result> rlpd = ques.getPermsByUser(trans, user, trans.forceRequested()); + if(rlpd.notOK()) { + return Result.err(rlpd); + } + + PERMS perms = mapper.newInstance(API.PERMS); + + if(rlpd.isEmpty()) { + return Result.ok(perms); + } + // Note: Mapper will restrict what can be viewed + // if user is the same as that which is looked up, no filtering is required + return mapper.perms(trans, rlpd.value, + perms, + !user.equals(trans.user())); + } + + @ApiDoc( + method = POST, + path = "/authz/perms/user/:user", + params = {"user|string|true"}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "List All Permissions that match user :user", + "

'user' must be expressed as full identity (ex: id@full.domain.com)

", + "", + "Present Queries as one or more Permissions (see ContentType Links below for format).", + "", + "If the Caller is Granted this specific Permission, and the Permission is valid", + " for the User, it will be included in response Permissions, along with", + " all the normal permissions on the 'GET' version of this call. If it is not", + " valid, or Caller does not have permission to see, it will be removed from the list", + "", + " *Note: This design allows you to make one call for all expected permissions", + " The permission to be included MUST be:", + " .access|:[:key]|", + " examples:", + " com.att.myns.access|:ns|write", + " com.att.myns.access|:role:myrole|create", + " com.att.myns.access|:perm:mytype:myinstance:myaction|read", + "" + } + ) + @Override + public Result getPermsByUser(AuthzTrans trans, PERMS _perms, String user) { + PERMS perms = _perms; + final Validator v = new Validator(); + if(v.nullOrBlank("User", user).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + ////////////// + Result> rlpd = ques.getPermsByUser(trans, user,trans.forceRequested()); + if(rlpd.notOK()) { + return Result.err(rlpd); + } + + /*//TODO + 1) See if allowed to query + 2) See if User is allowed + */ + Result> in = mapper.perms(trans, perms); + if(in.isOKhasData()) { + List out = rlpd.value; + boolean ok; + for(PermDAO.Data pdd : in.value) { + ok = false; + if("access".equals(pdd.type)) { + Access access = Access.valueOf(pdd.action); + String[] mdkey = Split.splitTrim(':',pdd.instance); + if(mdkey.length>1) { + String type = mdkey[1]; + if("role".equals(type)) { + if(mdkey.length>2) { + RoleDAO.Data rdd = new RoleDAO.Data(); + rdd.ns=pdd.ns; + rdd.name=mdkey[2]; + ok = ques.mayUser(trans, trans.user(), rdd, Access.read).isOK() && ques.mayUser(trans, user, rdd , access).isOK(); + } + } else if("perm".equals(type)) { + if(mdkey.length>4) { // also need instance/action + PermDAO.Data p = new PermDAO.Data(); + p.ns=pdd.ns; + p.type=mdkey[2]; + p.instance=mdkey[3]; + p.action=mdkey[4]; + ok = ques.mayUser(trans, trans.user(), p, Access.read).isOK() && ques.mayUser(trans, user, p , access).isOK(); + } + } else if("ns".equals(type)) { + NsDAO.Data ndd = new NsDAO.Data(); + ndd.name=pdd.ns; + ok = ques.mayUser(trans, trans.user(), ndd, Access.read).isOK() && ques.mayUser(trans, user, ndd , access).isOK(); + } + } + } + if(ok) { + out.add(pdd); + } + } + } + + perms = mapper.newInstance(API.PERMS); + if(rlpd.isEmpty()) { + return Result.ok(perms); + } + // Note: Mapper will restrict what can be viewed + // if user is the same as that which is looked up, no filtering is required + return mapper.perms(trans, rlpd.value, + perms, + !user.equals(trans.user())); + } + + @ApiDoc( + method = GET, + path = "/authz/perms/role/:role", + params = {"role|string|true"}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "List All Permissions that are granted to :role" } + ) + @Override + public Result getPermsByRole(AuthzTrans trans,String role) { + final Validator v = new Validator(); + if(v.nullOrBlank("Role", role).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result rrdd = RoleDAO.Data.decode(trans, ques,role); + if(rrdd.notOK()) { + return Result.err(rrdd); + } + + Result r = ques.mayUser(trans, trans.user(), rrdd.value, Access.read); + if(r.notOK()) { + return Result.err(r); + } + + PERMS perms = mapper.newInstance(API.PERMS); + + Result> rlpd = ques.getPermsByRole(trans, role, trans.forceRequested()); + if(rlpd.isOKhasData()) { + // Note: Mapper will restrict what can be viewed + return mapper.perms(trans, rlpd.value, perms, true); + } + return Result.ok(perms); + } + + @ApiDoc( + method = GET, + path = "/authz/perms/ns/:ns", + params = {"ns|string|true"}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "List All Permissions that are in Namespace :ns" } + ) + @Override + public Result getPermsByNS(AuthzTrans trans,String ns) { + final Validator v = new Validator(); + if(v.nullOrBlank("NS", ns).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result rnd = ques.deriveNs(trans, ns); + if(rnd.notOK()) { + return Result.err(rnd); + } + + rnd = ques.mayUser(trans, trans.user(), rnd.value, Access.read); + if(rnd.notOK()) { + return Result.err(rnd); + } + + Result> rlpd = ques.permDAO.readNS(trans, ns); + if(rlpd.notOK()) { + return Result.err(rlpd); + } + + PERMS perms = mapper.newInstance(API.PERMS); + if(!rlpd.isEmpty()) { + // Note: Mapper will restrict what can be viewed + return mapper.perms(trans, rlpd.value,perms, true); + } + return Result.ok(perms); + } + + @ApiDoc( + method = PUT, + path = "/authz/perm/:type/:instance/:action", + params = {"type|string|true", + "instance|string|true", + "action|string|true"}, + expectedCode = 200, + errorCodes = { 404,406, 409 }, + text = { "Rename the Permission referenced by :type :instance :action, and " + + "rename (copy/delete) to the Permission described in PermRequest" } + ) + @Override + public Result renamePerm(final AuthzTrans trans,REQUEST rreq, String origType, String origInstance, String origAction) { + final Result newPd = mapper.perm(trans, rreq); + final Validator v = new Validator(trans); + if(v.perm(newPd).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + if (ques.mayUser(trans, trans.user(), newPd.value,Access.write).notOK()) { + return Result.err(Status.ERR_Denied, "You do not have approval to change Permission [%s.%s|%s|%s]", + newPd.value.ns,newPd.value.type,newPd.value.instance,newPd.value.action); + } + + Result nss = ques.deriveNsSplit(trans, origType); + Result> origRlpd = ques.permDAO.read(trans, nss.value.ns, nss.value.name, origInstance, origAction); + + if(origRlpd.notOKorIsEmpty()) { + return Result.err(Status.ERR_PermissionNotFound, + "Permission [%s|%s|%s] does not exist", + origType,origInstance,origAction); + } + + PermDAO.Data origPd = origRlpd.value.get(0); + + if (!origPd.ns.equals(newPd.value.ns)) { + return Result.err(Status.ERR_Denied, "Cannot change namespace with rename command. " + + " must start with [" + origPd.ns + "]"); + } + + if ( origPd.type.equals(newPd.value.type) && + origPd.action.equals(newPd.value.action) && + origPd.instance.equals(newPd.value.instance) ) { + return Result.err(Status.ERR_ConflictAlreadyExists, "New Permission must be different than original permission"); + } + + Set origRoles = origPd.roles(false); + if (!origRoles.isEmpty()) { + Set roles = newPd.value.roles(true); + for (String role : origPd.roles) { + roles.add(role); + } + } + + newPd.value.description = origPd.description; + + Result rv = null; + + rv = func.createPerm(trans, newPd.value, false); + if (rv.isOK()) { + rv = func.deletePerm(trans, origPd, true, false); + } + return rv; + } + + @ApiDoc( + method = PUT, + path = "/authz/perm", + params = {}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "Add Description Data to Perm" } + ) + @Override + public Result updatePermDescription(AuthzTrans trans, REQUEST from) { + final Result pd = mapper.perm(trans, from); + final Validator v = new Validator(trans); + if(v.perm(pd).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + if(v.nullOrBlank("description", pd.value.description).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + final PermDAO.Data perm = pd.value; + if(ques.permDAO.read(trans, perm.ns, perm.type, perm.instance,perm.action).notOKorIsEmpty()) { + return Result.err(Status.ERR_NotFound, "Permission [%s.%s|%s|%s] does not exist", + perm.ns,perm.type,perm.instance,perm.action); + } + + if (ques.mayUser(trans, trans.user(), perm, Access.write).notOK()) { + return Result.err(Status.ERR_Denied, "You do not have approval to change Permission [%s.%s|%s|%s]", + perm.ns,perm.type,perm.instance,perm.action); + } + + Result> nsr = ques.nsDAO.read(trans, pd.value.ns); + if(nsr.notOKorIsEmpty()) { + return Result.err(nsr); + } + + Result rdr = ques.permDAO.addDescription(trans, perm.ns, perm.type, perm.instance, + perm.action, perm.description); + if(rdr.isOK()) { + return Result.ok(); + } else { + return Result.err(rdr); + } + + } + + @ApiDoc( + method = PUT, + path = "/authz/role/perm", + params = {}, + expectedCode = 201, + errorCodes = {403,404,406,409}, + text = { "Set a permission's roles to roles given" } + ) + + @Override + public Result resetPermRoles(final AuthzTrans trans, REQUEST rreq) { + final Result updt = mapper.permFromRPRequest(trans, rreq); + if(updt.notOKorIsEmpty()) { + return Result.err(updt); + } + + final Validator v = new Validator(trans); + if(v.perm(updt).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result nsd = ques.mayUser(trans, trans.user(), updt.value, Access.write); + if (nsd.notOK()) { + return Result.err(nsd); + } + + // Read full set to get CURRENT values + Result> rcurr = ques.permDAO.read(trans, + updt.value.ns, + updt.value.type, + updt.value.instance, + updt.value.action); + + if(rcurr.notOKorIsEmpty()) { + return Result.err(Status.ERR_PermissionNotFound, + "Permission [%s.%s|%s|%s] does not exist", + updt.value.ns,updt.value.type,updt.value.instance,updt.value.action); + } + + // Create a set of Update Roles, which are in Internal Format + Set updtRoles = new HashSet(); + Result nss; + for(String role : updt.value.roles(false)) { + nss = ques.deriveNsSplit(trans, role); + if(nss.isOK()) { + updtRoles.add(nss.value.ns + '|' + nss.value.name); + } else { + trans.error().log(nss.errorString()); + } + } + + Result rv = null; + + for(PermDAO.Data curr : rcurr.value) { + Set currRoles = curr.roles(false); + // must add roles to this perm, and add this perm to each role + // in the update, but not in the current + for (String role : updtRoles) { + if (!currRoles.contains(role)) { + Result key = RoleDAO.Data.decode(trans, ques, role); + if(key.isOKhasData()) { + Result> rrd = ques.roleDAO.read(trans, key.value); + if(rrd.isOKhasData()) { + for(RoleDAO.Data r : rrd.value) { + rv = func.addPermToRole(trans, r, curr, false); + if (rv.notOK() && rv.status!=Result.ERR_ConflictAlreadyExists) { + return Result.err(rv); + } + } + } else { + return Result.err(rrd); + } + } + } + } + // similarly, must delete roles from this perm, and delete this perm from each role + // in the update, but not in the current + for (String role : currRoles) { + if (!updtRoles.contains(role)) { + Result key = RoleDAO.Data.decode(trans, ques, role); + if(key.isOKhasData()) { + Result> rdd = ques.roleDAO.read(trans, key.value); + if(rdd.isOKhasData()) { + for(RoleDAO.Data r : rdd.value) { + rv = func.delPermFromRole(trans, r, curr, true); + if (rv.notOK() && rv.status!=Status.ERR_PermissionNotFound) { + return Result.err(rv); + } + } + } + } + } + } + } + return rv==null?Result.ok():rv; + } + + @ApiDoc( + method = DELETE, + path = "/authz/perm", + params = {}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "Delete the Permission referenced by PermKey.", + "You cannot normally delete a permission which is still granted to roles,", + "however the \"force\" property allows you to do just that. To do this: Add", + "'force=true' as a query parameter.", + "

WARNING: Using force will ungrant this permission from all roles. Use with care.

" } + ) + @Override + public Result deletePerm(final AuthzTrans trans, REQUEST from) { + Result pd = mapper.perm(trans, from); + if(pd.notOK()) { + return Result.err(pd); + } + final Validator v = new Validator(trans); + if(v.nullOrBlank(pd.value).err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + final PermDAO.Data perm = pd.value; + if (ques.permDAO.read(trans, perm).notOKorIsEmpty()) { + return Result.err(Status.ERR_PermissionNotFound, "Permission [%s.%s|%s|%s] does not exist", + perm.ns,perm.type,perm.instance,perm.action ); + } + + Result fd = mapper.future(trans,PermDAO.TABLE,from,perm,false, + new Mapper.Memo() { + @Override + public String get() { + return "Delete Permission [" + perm.fullPerm() + ']'; + } + }, + new MayChange() { + private Result nsd; + @Override + public Result mayChange() { + if(nsd==null) { + nsd = ques.mayUser(trans, trans.user(), perm, Access.write); + } + return nsd; + } + }); + + switch(fd.status) { + case OK: + Result> nsr = ques.nsDAO.read(trans, perm.ns); + if(nsr.notOKorIsEmpty()) { + return Result.err(nsr); + } + + Result> rfc = func.createFuture(trans, fd.value, + perm.encode(), trans.user(),nsr.value.get(0),"D"); + if(rfc.isOK()) { + return Result.err(Status.ACC_Future, "Perm Deletion [%s] is saved for future processing",perm.encode()); + } else { + return Result.err(rfc); + } + case Status.ACC_Now: + return func.deletePerm(trans,perm,trans.forceRequested(), false); + default: + return Result.err(fd); + } + } + + @ApiDoc( + method = DELETE, + path = "/authz/perm/:name/:type/:action", + params = {"type|string|true", + "instance|string|true", + "action|string|true"}, + expectedCode = 200, + errorCodes = { 404,406 }, + text = { "Delete the Permission referenced by :type :instance :action", + "You cannot normally delete a permission which is still granted to roles,", + "however the \"force\" property allows you to do just that. To do this: Add", + "'force=true' as a query parameter", + "

WARNING: Using force will ungrant this permission from all roles. Use with care.

"} + ) + @Override + public Result deletePerm(AuthzTrans trans, String type, String instance, String action) { + final Validator v = new Validator(trans); + if(v.nullOrBlank("Type",type) + .nullOrBlank("Instance",instance) + .nullOrBlank("Action",action) + .err()) { + return Result.err(Status.ERR_BadData,v.errs()); + } + + Result pd = ques.permFrom(trans, type, instance, action); + if(pd.isOK()) { + return func.deletePerm(trans, pd.value, trans.forceRequested(), false); + } else { + return Result.err(pd); + } + } + +/*********************************** + * ROLE + ***********************************/ + @ApiDoc( + method = POST, + path = "/authz/role", + params = {}, + expectedCode = 201, + errorCodes = {403,404,406,409}, + text = { + + "Roles are part of Namespaces", + "Examples:", + "