2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.actions;
24 import java.io.IOException;
25 import java.util.Date;
26 import java.util.GregorianCalendar;
28 import org.onap.aaf.auth.dao.cass.FutureDAO;
29 import org.onap.aaf.auth.dao.cass.NsDAO;
30 import org.onap.aaf.auth.dao.hl.Function;
31 import org.onap.aaf.auth.dao.hl.Question;
32 import org.onap.aaf.auth.dao.hl.Function.FUTURE_OP;
33 import org.onap.aaf.auth.env.AuthzTrans;
34 import org.onap.aaf.auth.helpers.Approval;
35 import org.onap.aaf.auth.helpers.UserRole;
36 import org.onap.aaf.auth.layer.Result;
37 import org.onap.aaf.auth.org.Organization.Expiration;
38 import org.onap.aaf.misc.env.APIException;
39 import org.onap.aaf.misc.env.util.Chrono;
41 import com.datastax.driver.core.Cluster;
43 public class URFutureApprove extends ActionDAO<UserRole, String,String> implements Action<UserRole,String,String>, Key<UserRole> {
44 private final Date start, expires;
46 public URFutureApprove(AuthzTrans trans, Cluster cluster, boolean dryRun) throws APIException, IOException {
47 super(trans,cluster, dryRun);
48 GregorianCalendar gc = new GregorianCalendar();
50 expires = trans.org().expiration(gc, Expiration.Future).getTime();
53 public URFutureApprove(AuthzTrans trans, ActionDAO<?,?,?> adao) {
55 GregorianCalendar gc = new GregorianCalendar();
57 expires = trans.org().expiration(gc, Expiration.Future).getTime();
61 public Result<String> exec(AuthzTrans trans, UserRole ur,String text) {
63 return Result.ok(text);
65 Result<NsDAO.Data> rns = q.deriveNs(trans, ur.ns());
68 FutureDAO.Data data = new FutureDAO.Data();
69 data.id=null; // let Create function assign UUID
70 data.target=Function.FOP_USER_ROLE;
74 data.expires = ur.expires();
76 data.construct = ur.urdd().bytify();
77 } catch (IOException e) {
80 Result<String> rfuture = f.createFuture(trans, data, Function.FOP_USER_ROLE, ur.user(), rns.value, FUTURE_OP.A);
82 trans.info().log(rfuture.value, text, ur.user(), data.memo);
84 trans.error().log(rfuture.details, text);
88 return Result.err(rns);
94 public String key(UserRole ur) {
96 if(expires.before(start)) {
97 expire = "' - EXPIRED ";
99 expire = "' - expiring ";
102 if(Question.OWNER.equals(ur.rname())) {
103 return Approval.RE_VALIDATE_OWNER + ur.ns() + expire + Chrono.dateOnlyStamp(ur.expires());
104 } else if(Question.ADMIN.equals(ur.rname())) {
105 return Approval.RE_VALIDATE_ADMIN + ur.ns() + expire + Chrono.dateOnlyStamp(ur.expires());
107 return Approval.RE_APPROVAL_IN_ROLE + ur.role() + expire + Chrono.dateOnlyStamp(ur.expires());