summaryrefslogtreecommitdiffstats
path: root/authz-gui/src/main/java/com/att/authz/gui/pages/UserRoleExtend.java
blob: e54787b976ca9a75eca7b546b466a1ed26dd12b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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 org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.client.Future;
import org.onap.aaf.cadi.client.Rcli;
import org.onap.aaf.cadi.client.Retryable;
import org.onap.aaf.inno.env.APIException;
import org.onap.aaf.inno.env.Env;
import org.onap.aaf.inno.env.Slot;
import org.onap.aaf.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<HTMLGen> 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<HTMLGen, AuthGUI, AuthzTrans>() {
					@Override
					public void code(AuthGUI gui, AuthzTrans trans,	Cache<HTMLGen> 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<Void>() {
								@Override
								public Void code(Rcli<?> client)throws CadiException, ConnectException, APIException {
									Future<Void> 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();
						}
						
						
					}
				});
			}
			
		});
	}
}