001/*
002 * (C) Copyright 2006-2019 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.core.api.local;
023
024import java.security.Principal;
025
026import javax.security.auth.Subject;
027
028import org.nuxeo.runtime.api.login.LoginComponent;
029
030/**
031 * This class is deprecated and now delegates to {@link LoginComponent}.
032 *
033 * @deprecated since 11.1
034 */
035@Deprecated
036public class LoginStack {
037
038    public void clear() {
039        LoginComponent.getPrincipalStack().clear();
040    }
041
042    public void push(Principal principal, Object credential, Subject subject) {
043        // credential and subject are ignored
044        LoginComponent.pushPrincipal(principal);
045    }
046
047    public Entry pop() {
048        Principal principal = LoginComponent.popPrincipal();
049        return principal == null ? null : new Entry(principal, null, null);
050    }
051
052    public Entry peek() {
053        Principal principal = LoginComponent.getPrincipalStack().peekLast();
054        return principal == null ? null : new Entry(principal, null, null);
055    }
056
057    public boolean isEmpty() {
058        return LoginComponent.getPrincipalStack().isEmpty();
059    }
060
061    public int size() {
062        return LoginComponent.getPrincipalStack().size();
063    }
064
065    public Entry[] toArray() {
066        return (Entry[]) LoginComponent.getPrincipalStack()
067                                       .stream()
068                                       .map(principal -> new Entry(principal, null, null))
069                                       .toArray();
070    }
071
072    /** @deprecated since 11.1 */
073    @Deprecated
074    public static class Entry {
075        protected final Principal principal;
076
077        protected final Object credential;
078
079        protected final Subject subject;
080
081        public Entry(Principal principal, Object credential, Subject subject) {
082            this.principal = principal;
083            this.credential = credential;
084            this.subject = subject;
085        }
086
087        public Principal getPrincipal() {
088            return principal;
089        }
090
091        /** @deprecated since 11.1, unused */
092        @Deprecated
093        public Object getCredential() {
094            return credential;
095        }
096
097        /** @deprecated since 11.1, unused */
098        @Deprecated
099        public Subject getSubject() {
100            return subject;
101        }
102    }
103
104}