aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/main/java/org/onap/aaf/cadi/principal
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/onap/aaf/cadi/principal')
-rw-r--r--core/src/main/java/org/onap/aaf/cadi/principal/BasicPrincipal.java117
-rw-r--r--core/src/main/java/org/onap/aaf/cadi/principal/BearerPrincipal.java36
-rw-r--r--core/src/main/java/org/onap/aaf/cadi/principal/CSPPrincipal_T.java33
-rw-r--r--core/src/main/java/org/onap/aaf/cadi/principal/CachedBasicPrincipal.java65
-rw-r--r--core/src/main/java/org/onap/aaf/cadi/principal/TGuardPrincipal.java80
-rw-r--r--core/src/main/java/org/onap/aaf/cadi/principal/TGuardPrincipal_T.java33
-rw-r--r--core/src/main/java/org/onap/aaf/cadi/principal/TrustPrincipal.java67
-rw-r--r--core/src/main/java/org/onap/aaf/cadi/principal/X509Principal.java92
8 files changed, 0 insertions, 523 deletions
diff --git a/core/src/main/java/org/onap/aaf/cadi/principal/BasicPrincipal.java b/core/src/main/java/org/onap/aaf/cadi/principal/BasicPrincipal.java
deleted file mode 100644
index e84caeb..0000000
--- a/core/src/main/java/org/onap/aaf/cadi/principal/BasicPrincipal.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.principal;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Date;
-
-import org.onap.aaf.cadi.BasicCred;
-import org.onap.aaf.cadi.GetCred;
-import org.onap.aaf.cadi.Symm;
-
-public class BasicPrincipal extends BearerPrincipal implements GetCred {
- private static byte[] basic = "Basic ".getBytes();
-
- private String name = null;
- private String shortName = null;
- private byte[] cred = null;
-
- private long created;
-
- public BasicPrincipal(String content,String domain) throws IOException {
- created = System.currentTimeMillis();
- ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes());
- // Read past "Basic ", ensuring it starts with it.
- for(int i=0;i<basic.length;++i) {
- if(bis.read()!=basic[i]) {
- name=content;
- cred = null;
- return;
- }
- }
- BasicOS bos = new BasicOS(content.length());
- Symm.base64.decode(bis,bos); // note: writes directly to name until ':'
- if(name==null) throw new IOException("Invalid Coding");
- else cred = bos.toCred();
- int at;
- if((at=name.indexOf('@'))>0) {
- domain=name.substring(at+1);
- shortName=name.substring(0, at);
- } else {
- shortName = name;
- name = name + '@' + domain;
- }
- }
-
- public BasicPrincipal(BasicCred bc, String domain) {
- name = bc.getUser();
- cred = bc.getCred();
- }
-
- private class BasicOS extends OutputStream {
- private boolean first = true;
- private ByteArrayOutputStream baos;
-
- public BasicOS(int size) {
- baos = new ByteArrayOutputStream(size);
- }
-
- @Override
- public void write(int b) throws IOException {
- if(b==':' && first) {
- first = false;
- name = new String(baos.toByteArray());
- baos.reset(); //
- } else {
- baos.write(b);
- }
- }
-
- private byte[] toCred() {
- return baos.toByteArray();
- }
- }
-
- public String getName() {
- return name;
- }
-
- public String getShortName() {
- return shortName;
- }
-
- public byte[] getCred() {
- return cred;
- }
-
- public long created() {
- return created;
- }
-
- public String toString() {
- return "Basic Authorization for " + name + " evaluated on " + new Date(created).toString();
- }
-}
diff --git a/core/src/main/java/org/onap/aaf/cadi/principal/BearerPrincipal.java b/core/src/main/java/org/onap/aaf/cadi/principal/BearerPrincipal.java
deleted file mode 100644
index 08793c5..0000000
--- a/core/src/main/java/org/onap/aaf/cadi/principal/BearerPrincipal.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.principal;
-
-import java.security.Principal;
-
-public abstract class BearerPrincipal implements Principal {
- private String bearer = null;
- public BearerPrincipal setBearer(String bearer) {
- this.bearer = bearer;
- return this;
- }
- public String getBearer() {
- return bearer;
- }
-}
diff --git a/core/src/main/java/org/onap/aaf/cadi/principal/CSPPrincipal_T.java b/core/src/main/java/org/onap/aaf/cadi/principal/CSPPrincipal_T.java
deleted file mode 100644
index 3694584..0000000
--- a/core/src/main/java/org/onap/aaf/cadi/principal/CSPPrincipal_T.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.principal;
-
-import java.security.Principal;
-
-/**
- * Indicate a CSP Principal that is trusted as a CSPPrincipal.
- *
- */
-public interface CSPPrincipal_T extends Principal {
-
-}
diff --git a/core/src/main/java/org/onap/aaf/cadi/principal/CachedBasicPrincipal.java b/core/src/main/java/org/onap/aaf/cadi/principal/CachedBasicPrincipal.java
deleted file mode 100644
index 9a33dc6..0000000
--- a/core/src/main/java/org/onap/aaf/cadi/principal/CachedBasicPrincipal.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.principal;
-
-import java.io.IOException;
-
-import org.onap.aaf.cadi.BasicCred;
-import org.onap.aaf.cadi.CachedPrincipal;
-import org.onap.aaf.cadi.taf.HttpTaf;
-
-/**
- * Cached Principals need to be able to revalidate in the Background
- *
- *
- */
-public class CachedBasicPrincipal extends BasicPrincipal implements CachedPrincipal {
- private final HttpTaf creator;
- private long timeToLive;
- private long expires;
-
- public CachedBasicPrincipal(HttpTaf creator, BasicCred bc, String domain, long timeToLive) {
- super(bc, domain);
- this.creator = creator;
- this.timeToLive = timeToLive;
- expires = System.currentTimeMillis()+timeToLive;
- }
-
- public CachedBasicPrincipal(HttpTaf creator, String content, String domain, long timeToLive) throws IOException {
- super(content, domain);
- this.creator = creator;
- this.timeToLive = timeToLive;
- expires = System.currentTimeMillis()+timeToLive;
- }
-
- public CachedPrincipal.Resp revalidate() {
- Resp resp = creator.revalidate(this);
- if(resp.equals(Resp.REVALIDATED))expires = System.currentTimeMillis()+timeToLive;
- return resp;
- }
-
- public long expires() {
- return expires;
- }
-
-}
diff --git a/core/src/main/java/org/onap/aaf/cadi/principal/TGuardPrincipal.java b/core/src/main/java/org/onap/aaf/cadi/principal/TGuardPrincipal.java
deleted file mode 100644
index b55f86a..0000000
--- a/core/src/main/java/org/onap/aaf/cadi/principal/TGuardPrincipal.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.principal;
-
-public class TGuardPrincipal extends BearerPrincipal {
-
- private String name, tresp;
-
- public TGuardPrincipal(String tresp) {
- this.tresp=tresp;
- }
-
- /**
- * TODO Need to figure out what Organizations TGuard entities should be part of.
- *
- */
- public String getName() {
- if(name==null) {
- String temp = get("iv-user");
- if(temp==null)return null;
- StringBuilder sb = new StringBuilder();
- int at = temp.indexOf('@');
- if(at<0) {
- sb.append(temp);
- } else {
- sb.append(temp.substring(0, at));
- }
- if(temp.endsWith("@uverse.com"))sb.append("@uverse.tguard.att.com");
- else if(temp.endsWith("@att.com"))sb.append("@com.tguard.att.com");
- else if(temp.endsWith("@att.net"))sb.append("@net.tguard.att.com");
- else sb.append("@tguard.att.com");
- name = sb.toString();
- }
- return name;
- }
-
- /**
- * Get a value from a named TGuard Property
- *
- * TGuard response info is very dynamic. They can add new properties at any time, so we dare not code field names for these values.
- * @param key
- * @return
- */
- public String get(String key) {
- if(key==null)return null;
- int idx=0,equal=0,amp=0;
- while(idx>=0 && (equal = tresp.indexOf('=',idx))>=0) {
- amp = tresp.indexOf('&',equal);
- if(key.regionMatches(0, tresp, idx, equal-idx)) {
- return amp>=0?tresp.substring(equal+1, amp):tresp.substring(equal+1);
- }
- idx=amp+(amp>0?1:0);
- }
- return null;
- }
-
- public String info() {
- return tresp;
- }
-}
diff --git a/core/src/main/java/org/onap/aaf/cadi/principal/TGuardPrincipal_T.java b/core/src/main/java/org/onap/aaf/cadi/principal/TGuardPrincipal_T.java
deleted file mode 100644
index 235c74c..0000000
--- a/core/src/main/java/org/onap/aaf/cadi/principal/TGuardPrincipal_T.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.principal;
-
-import java.security.Principal;
-
-/**
- * Indicate a TGuard Principal that is trusted as a TGuardPrincipal.
- *
- */
-public interface TGuardPrincipal_T extends Principal {
-
-}
diff --git a/core/src/main/java/org/onap/aaf/cadi/principal/TrustPrincipal.java b/core/src/main/java/org/onap/aaf/cadi/principal/TrustPrincipal.java
deleted file mode 100644
index 4add242..0000000
--- a/core/src/main/java/org/onap/aaf/cadi/principal/TrustPrincipal.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.principal;
-
-import java.security.Principal;
-
-import org.onap.aaf.cadi.UserChain;
-
-public class TrustPrincipal extends BearerPrincipal implements UserChain {
- private final String name;
- private final Principal original;
- private String userChain;
-
- public TrustPrincipal(final Principal actual, final String asName) {
- this.original = actual;
- name = asName.trim();
- if(actual instanceof UserChain) {
- UserChain uc = (UserChain)actual;
- userChain = uc.userChain();
- } else if(actual instanceof X509Principal) {
- userChain="x509";
- } else if(actual instanceof BasicPrincipal) {
- userChain="BAth";
- } else {
- userChain = actual.getClass().getSimpleName();
- }
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- public String getOrigName() {
- return original.getName() + '[' + userChain + ']';
- }
-
- @Override
- public String userChain() {
- return userChain;
- }
-
- public Principal original() {
- return original;
- }
-
-}
diff --git a/core/src/main/java/org/onap/aaf/cadi/principal/X509Principal.java b/core/src/main/java/org/onap/aaf/cadi/principal/X509Principal.java
deleted file mode 100644
index 2f3fd28..0000000
--- a/core/src/main/java/org/onap/aaf/cadi/principal/X509Principal.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.principal;
-
-import java.io.IOException;
-import java.security.cert.CertificateEncodingException;
-import java.security.cert.X509Certificate;
-import java.util.regex.Pattern;
-
-import org.onap.aaf.cadi.GetCred;
-
-public class X509Principal extends BearerPrincipal implements GetCred {
- private static final Pattern pattern = Pattern.compile("[a-zA-Z0-9]*\\@[a-zA-Z0-9.]*");
- private byte[] content;
- private X509Certificate cert;
- private String name;
-
- public X509Principal(String identity, X509Certificate cert, byte[] content) {
- name = identity;
- this.content = content;
- this.cert = cert;
- }
-
- public X509Principal(X509Certificate cert, byte[] content) throws IOException {
- this.content=content;
- this.cert = cert;
- String subj = cert.getSubjectDN().getName();
- int cn = subj.indexOf("OU=");
- if(cn>=0) {
- cn+=3;
- int space = subj.indexOf(',',cn);
- if(space>=0) {
- String id = subj.substring(cn, space);
- if(pattern.matcher(id).matches()) {
- name = id;
- }
- }
- }
- if(name==null)
- throw new IOException("X509 does not have Identity as CN");
-
- }
-
-
- public String getAsHeader() throws IOException {
- try {
- if(content==null)
- content=cert.getEncoded();
- } catch (CertificateEncodingException e) {
- throw new IOException(e);
- }
- return "X509 " + content;
- }
-
- public String toString() {
- return "X509 Authentication for " + name;
- }
-
-
- public byte[] getCred() {
- try {
- return content==null?(content=cert.getEncoded()):content;
- } catch (CertificateEncodingException e) {
- return null;
- }
- }
-
-
- public String getName() {
- return name;
- }
-}