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.oauth.mapper;
26 import org.onap.aaf.auth.dao.cass.OAuthTokenDAO.Data;
27 import org.onap.aaf.auth.layer.Result;
28 import org.onap.aaf.auth.oauth.service.OAuthService.CLIENT_TYPE;
30 import aafoauth.v2_0.Introspect;
32 public class MapperIntrospect1_0 implements MapperIntrospect<Introspect> {
34 public Result<Introspect> introspect(Result<Data> rs) {
35 if (rs.isOKhasData()) {
37 Introspect ti = new Introspect();
38 ti.setAccessToken(data.id);
39 ti.setActive(data.active);
40 ti.setClientId(data.client_id);
41 for (CLIENT_TYPE ct : CLIENT_TYPE.values()) {
42 if (data.type==ct.ordinal()) {
43 ti.setClientType(ct.name());
47 if (ti.getClientType()==null) {
48 ti.setClientType(CLIENT_TYPE.unknown.name());
50 ti.setActive(data.active);
51 ti.setScope(getScopes(data.scopes(false)));
52 ti.setContent(data.content);
53 ti.setUsername(data.user);
54 ti.setExp(data.exp_sec); // want seconds from Jan 1, 1970
57 return Result.err(rs);
60 protected static String getScopes(Set<String> scopes) {
61 StringBuilder sb = new StringBuilder();
63 for (String s : scopes) {