1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.taf;
\r
25 import java.io.IOException;
\r
26 import java.net.URI;
\r
27 import java.util.List;
\r
29 import javax.servlet.http.HttpServletResponse;
\r
31 import org.onap.aaf.cadi.Access;
\r
32 import org.onap.aaf.cadi.Locator;
\r
33 import org.onap.aaf.cadi.Access.Level;
\r
34 import org.onap.aaf.cadi.Locator.Item;
\r
36 public class LoginPageTafResp extends AbsTafResp {
\r
37 private final HttpServletResponse httpResp;
\r
38 private final String loginPageURL;
\r
40 private LoginPageTafResp(Access access, final HttpServletResponse resp, String loginPageURL) {
\r
41 super(access, null, "Multiple Possible HTTP Logins available. Redirecting to Login Choice Page");
\r
43 this.loginPageURL = loginPageURL;
\r
47 public RESP authenticate() throws IOException {
\r
48 httpResp.sendRedirect(loginPageURL);
\r
49 return RESP.HTTP_REDIRECT_INVOKED;
\r
53 public RESP isAuthenticated() {
\r
54 return RESP.TRY_AUTHENTICATING;
\r
57 public static TafResp create(Access access, Locator<URI> locator, final HttpServletResponse resp, List<Redirectable> redir) {
\r
60 Item item = locator.best();
\r
61 URI uri = locator.get(item);
\r
63 StringBuilder sb = new StringBuilder(uri.toString());
\r
64 String query = uri.getQuery();
\r
65 boolean first = query==null || query.length()==0;
\r
67 for(Redirectable t : redir) {
\r
72 else sb.append('&');
\r
76 if(count>0)return new LoginPageTafResp(access, resp, sb.toString());
\r
78 } catch (Exception e) {
\r
79 access.log(e, "Error deriving Login Page location");
\r
81 } else if(!redir.isEmpty()) {
\r
82 access.log(Level.DEBUG,"LoginPage Locator is not configured. Taking first Redirectable Taf");
\r
83 return redir.get(0);
\r
85 return NullTafResp.singleton();
\r