* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.onap.aaf.auth.cm.data.CertDrop;
import org.onap.aaf.auth.cm.data.CertRenew;
import org.onap.aaf.auth.dao.cass.CertDAO;
import org.onap.aaf.auth.env.AuthzTrans;
import org.onap.aaf.auth.layer.Result;
-import org.onap.aaf.cadi.util.FQI;
import org.onap.aaf.cadi.util.Vars;
import aaf.v2_0.Error;
public class Mapper2_0 implements Mapper<BaseRequest,CertInfo,Artifacts,Error> {
-
+
@Override
public Class<?> getClass(API api) {
switch(api) {
////////////// Mapping Functions /////////////
@Override
- public Error errorFromMessage(StringBuilder holder, String msgID, String text, String... var) {
+ public Error errorFromMessage(StringBuilder holder, String msgID, String text, Object ... 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);
+ for (Object s : var) {
+ err.getVariables().add(s.toString());
}
return err;
}
*/
@Override
public Result<CertInfo> toCert(AuthzTrans trans, Result<CertResp> in, boolean withTrustChain) throws IOException {
- if(!in.isOK()) {
+ if (!in.isOK()) {
CertResp cin = in.value;
CertInfo cout = newInstance(API.CERT);
cout.setPrivatekey(cin.privateString());
String value;
- if((value=cin.challenge())!=null) {
+ if ((value=cin.challenge())!=null) {
cout.setChallenge(value);
}
cout.getCerts().add(cin.asCertString());
- if(cin.trustChain()!=null) {
- for(String c : cin.trustChain()) {
+ if (cin.trustChain()!=null) {
+ for (String c : cin.trustChain()) {
cout.getCerts().add(c);
}
}
- if(cin.notes()!=null) {
+ if (cin.notes()!=null) {
boolean first = true;
StringBuilder sb = new StringBuilder();
- for(String n : cin.notes()) {
- if(first) {
+ for (String n : cin.notes()) {
+ if (first) {
first = false;
} else {
sb.append('\n');
}
cout.setNotes(sb.toString());
}
-
+
List<String> caIssuerDNs = cout.getCaIssuerDNs();
- for(String s : cin.caIssuerDNs()) {
+ for (String s : cin.caIssuerDNs()) {
caIssuerDNs.add(s);
}
@Override
public Result<CertInfo> toCert(AuthzTrans trans, Result<List<CertDAO.Data>> in) {
- if(in.isOK()) {
+ if (in.isOK()) {
CertInfo cout = newInstance(API.CERT);
List<String> certs = cout.getCerts();
- for(CertDAO.Data cdd : in.value) {
+ for (CertDAO.Data cdd : in.value) {
certs.add(cdd.x509);
}
return Result.ok(cout);
CertificateRequest in;
try {
in = (CertificateRequest)req;
- } catch(ClassCastException e) {
+ } catch (ClassCastException e) {
return Result.err(Result.ERR_BadData,"Request is not a CertificateRequest");
}
v.isNull("CertRequest", req)
.nullOrBlank("MechID", out.mechid=in.getMechid());
v.nullBlankMin("FQDNs", out.fqdns=in.getFqdns(),1);
- if(v.err()) {
+ if (v.err()) {
return Result.err(Result.ERR_BadData, v.errs());
}
@Override
public List<ArtiDAO.Data> toArtifact(AuthzTrans trans, Artifacts artifacts) {
List<ArtiDAO.Data> ladd = new ArrayList<>();
- for(Artifact arti : artifacts.getArtifact()) {
+ for (Artifact arti : artifacts.getArtifact()) {
ArtiDAO.Data data = new ArtiDAO.Data();
- data.mechid = arti.getMechid();
- data.machine = arti.getMachine();
+ data.mechid = trim(arti.getMechid());
+ data.machine = trim(arti.getMachine());
+ if(arti.getType()!=null) {
+ Set<String> ss = data.type(true);
+ for(String t : arti.getType()) {
+ ss.add(t.trim());
+ }
+ }
data.type(true).addAll(arti.getType());
- data.ca = arti.getCa();
- data.dir = arti.getDir();
- data.os_user = arti.getOsUser();
+ data.ca = trim(arti.getCa());
+ data.dir = trim(arti.getDir());
+ data.os_user = trim(arti.getOsUser());
// Optional (on way in)
- data.ns = arti.getNs();
+ data.ns = trim(arti.getNs());
data.renewDays = arti.getRenewDays();
- data.notify = arti.getNotification();
-
+ data.notify = trim(arti.getNotification());
+
// Ignored on way in for create/update
- data.sponsor = arti.getSponsor();
+ data.sponsor = trim(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.ns==null ) {
- data.ns=FQI.reverseDomain(data.machine);
- }
+ if(arti.getSans()!=null) {
+ Set<String> ss = data.sans(true);
+ for(String s : arti.getSans()) {
+ ss.add(s.trim());
+ }
}
- data.sans(true).addAll(arti.getSans());
ladd.add(data);
}
return ladd;
}
+ private String trim(String s) {
+ if(s==null) {
+ return s;
+ } else {
+ return s.trim();
+ }
+ }
+
/* (non-Javadoc)
* @see org.onap.aaf.auth.cm.mapper.Mapper#fromArtifacts(org.onap.aaf.auth.layer.test.Result)
*/
@Override
public Result<Artifacts> fromArtifacts(Result<List<Data>> lArtiDAO) {
- if(lArtiDAO.isOK()) {
+ if (lArtiDAO.isOK()) {
Artifacts artis = new Artifacts();
- for(ArtiDAO.Data arti : lArtiDAO.value) {
+ for (ArtiDAO.Data arti : lArtiDAO.value) {
Artifact a = new Artifact();
a.setMechid(arti.mechid);
a.setMachine(arti.machine);
return Result.err(lArtiDAO);
}
}
-
-
+
+
}
\ No newline at end of file