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.batch.actions;
24 import java.io.IOException;
25 import java.util.List;
27 import org.onap.aaf.auth.batch.helpers.UserRole;
28 import org.onap.aaf.auth.dao.cass.Status;
29 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
30 import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.layer.Result;
33 import org.onap.aaf.misc.env.APIException;
35 import com.datastax.driver.core.Cluster;
37 public class URModify extends ActionDAO<UserRole,Void,URModify.Modify> {
38 public URModify(AuthzTrans trans, Cluster cluster, boolean dryRun) throws APIException, IOException {
39 super(trans, cluster,dryRun);
42 public URModify(AuthzTrans trans, ActionDAO<?,?,?> adao) {
47 public Result<Void> exec(AuthzTrans trans, UserRole ur,Modify modify) {
49 trans.info().printf("Would Update %s %s", ur.user(), ur.role());
52 Result<List<Data>> rr = q.userRoleDAO.read(trans, ur.user(),ur.role());
53 if (rr.notOKorIsEmpty()) {
54 return Result.err(rr);
56 for (Data d : rr.value) {
58 if (!(ur.expires().equals(d.expires))) {
59 ur.expires(d.expires);
61 if (ur.user().equals(d.user) && ur.role().equals(d.role)){
62 Result<Void> rv = q.userRoleDAO.update(trans, d);
64 trans.info().printf("Updated %s %s to %s", ur.user(), ur.role(), d.toString());
66 trans.info().log(rv.errorString());
69 return Result.err(Status.ERR_Denied, "You cannot change the key of this Data");
72 return Result.err(Status.ERR_UserRoleNotFound,"No User Role with %s %s",ur.user(),ur.role());
76 public static interface Modify {
77 void change(UserRoleDAO.Data ur);