+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package com.att.cmd.user;\r
-\r
-import com.att.cadi.CadiException;\r
-import com.att.cadi.LocatorException;\r
-import com.att.cadi.client.Future;\r
-import com.att.cadi.client.Rcli;\r
-import com.att.cadi.client.Retryable;\r
-import com.att.cmd.AAFcli;\r
-import com.att.cmd.Cmd;\r
-import com.att.cmd.Param;\r
-import com.att.cssa.rserv.HttpMethods;\r
-import com.att.inno.env.APIException;\r
-\r
-import aaf.v2_0.CredRequest;\r
-\r
-public class Cred extends Cmd {\r
- private static final String CRED_PATH = "/authn/cred";\r
- private static final String[] options = {"add","del","reset","extend"/*,"clean"*/};\r
-// private Clean clean;\r
- public Cred(User parent) {\r
- super(parent,"cred",\r
- new Param(optionsToString(options),true),\r
- new Param("id",true),\r
- new Param("password (! D|E)",false),\r
- new Param("entry# (if multi)",false)\r
- );\r
-// clean = new Clean(this);\r
- }\r
-\r
- @Override\r
- public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException { \r
- int idx = _idx;\r
- String key = args[idx++];\r
- final int option = whichOption(options,key);\r
-\r
- final CredRequest cr = new CredRequest();\r
- cr.setId(args[idx++]);\r
- if(option!=1 && option!=3) {\r
- if(idx>=args.length) throw new CadiException("Password Required");\r
- cr.setPassword(args[idx++]);\r
- }\r
- if(args.length>idx)\r
- cr.setEntry(args[idx++]);\r
- \r
- // Set Start/End commands\r
- setStartEnd(cr);\r
-// final int cleanIDX = _idx+1;\r
- Integer ret = same(new Retryable<Integer>() {\r
- @Override\r
- public Integer code(Rcli<?> client) throws CadiException, APIException {\r
- Future<CredRequest> fp=null;\r
- String verb =null;\r
- switch(option) {\r
- case 0:\r
- fp = client.create(\r
- CRED_PATH, \r
- getDF(CredRequest.class), \r
- cr\r
- );\r
- verb = "Added Credential [";\r
- break;\r
- case 1:\r
-// if(aafcli.addForce())cr.setForce("TRUE");\r
- setQueryParamsOn(client);\r
- fp = client.delete(CRED_PATH,\r
- getDF(CredRequest.class),\r
- cr\r
- );\r
- verb = "Deleted Credential [";\r
- break;\r
- case 2:\r
- fp = client.update(\r
- CRED_PATH,\r
- getDF(CredRequest.class),\r
- cr\r
- );\r
- verb = "Reset Credential [";\r
- break;\r
- case 3:\r
- fp = client.update(\r
- CRED_PATH+"/5",\r
- getDF(CredRequest.class),\r
- cr\r
- );\r
- verb = "Extended Credential [";\r
- break;\r
-// case 4:\r
-// return clean.exec(cleanIDX, args);\r
- }\r
- if(fp.get(AAFcli.timeout())) {\r
- pw().print(verb);\r
- pw().print(cr.getId());\r
- pw().println(']');\r
- } else if(fp.code()==202) {\r
- pw().println("Credential Action Accepted, but requires Approvals before actualizing");\r
- } else if(fp.code()==406 && option==1) {\r
- pw().println("You cannot delete this Credential");\r
- } else {\r
- error(fp);\r
- }\r
- return fp.code();\r
- }\r
- });\r
- if(ret==null)ret = -1;\r
- return ret;\r
- }\r
- \r
- @Override\r
- public void detailedHelp(int _indent, StringBuilder sb) {\r
- int indent = _indent;\r
- detailLine(sb,indent,"Add, Delete or Reset Credential");\r
- indent+=2;\r
- detailLine(sb,indent,"id - the ID to create/delete/reset within AAF");\r
- detailLine(sb,indent,"password - Company Policy compliant Password (not required for Delete)");\r
- detailLine(sb,indent,"entry - selected option when deleting/resetting a cred with multiple entries");\r
- sb.append('\n');\r
- detailLine(sb,indent,"The Domain can be related to any Namespace you have access to *");\r
- detailLine(sb,indent,"The Domain is in reverse order of Namespace, i.e. ");\r
- detailLine(sb,indent+2,"NS of com.att.myapp can create user of XY1234@myapp.att.com");\r
- sb.append('\n');\r
- detailLine(sb,indent,"NOTE: AAF does support multiple creds with the same ID. Check with your org if you");\r
- detailLine(sb,indent+2,"have this implemented. (For example, this is implemented for MechIDs at AT&T)");\r
- sb.append('\n'); \r
- detailLine(sb,indent,"Delegates can be listed by the User or by the Delegate");\r
- indent-=2;\r
- api(sb,indent,HttpMethods.POST,"authn/cred",CredRequest.class,true);\r
- api(sb,indent,HttpMethods.DELETE,"authn/cred",CredRequest.class,false);\r
- api(sb,indent,HttpMethods.PUT,"authn/cred",CredRequest.class,false);\r
- }\r
-}\r