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.aaf;
\r
25 import java.security.Principal;
\r
26 import java.util.regex.Pattern;
\r
28 import org.onap.aaf.cadi.Transmutate;
\r
29 import org.onap.aaf.cadi.lur.ConfigPrincipal;
\r
30 import org.onap.aaf.cadi.principal.BasicPrincipal;
\r
31 import org.onap.aaf.cadi.principal.CSPPrincipal_T;
\r
36 * Each System determines the mechanisms for which one Principal is transmutated to another, such as whether it is created
\r
37 * independently, etc.
\r
39 * For AAF, the only important thing is that these are valid ATTUID/mechIDs, to avoid unnecessary user hits
\r
41 * attUIDs look like ab1234 or AB1234 or AZ123a
\r
42 * mechids look like m12345
\r
46 public final class AAFTransmutate implements Transmutate<Principal> {
\r
47 private Pattern pattern = Pattern.compile("[a-zA-Z]\\w\\d\\d\\d\\w");
\r
49 public Principal mutate(Principal p) {
\r
50 // Accept these three internal kinds of Principals
\r
51 if(p instanceof CSPPrincipal_T
\r
52 || p instanceof BasicPrincipal
\r
53 || p instanceof ConfigPrincipal) {
\r
57 final String name = p.getName();
\r
58 final int idx = name.indexOf('@');
\r
60 if(idx>0) { // strip off any domain
\r
61 shortName = name.substring(0,idx);
\r
66 // Check for ATTUID specs before creating CSP_T
\r
67 return pattern.matcher(shortName).matches()?
\r
68 new CSP_T(name): // Note: use REAL name, short name for CSP_T
\r
74 * Essential Principal reflecting CSP Principal
\r
78 private final class CSP_T implements CSPPrincipal_T {
\r
79 private String name;
\r
80 public CSP_T(String name) {
\r
83 public String getName() {
\r