001/**
002 * Copyright 2015 DuraSpace, Inc.
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 */
016package org.fcrepo.auth.common;
017
018import org.modeshape.jcr.ExecutionContext;
019import org.modeshape.jcr.security.AuthorizationProvider;
020import org.modeshape.jcr.security.SecurityContext;
021import org.modeshape.jcr.value.Path;
022
023/**
024 * This is a pass-through security context for authenticated Fedora
025 * administrators.
026 *
027 * @author Gregory Jansen
028 */
029public class FedoraAdminSecurityContext implements AuthorizationProvider,
030        SecurityContext {
031
032    private String username = null;
033
034    private boolean loggedIn = true;
035
036    /**
037     * @param username the user name
038     */
039    public FedoraAdminSecurityContext(final String username) {
040        super();
041        this.username = username;
042    }
043
044    /*
045     * (non-Javadoc)
046     * @see org.modeshape.jcr.security.SecurityContext#isAnonymous()
047     */
048    @Override
049    public boolean isAnonymous() {
050        return username != null;
051    }
052
053    /*
054     * (non-Javadoc)
055     * @see org.modeshape.jcr.security.SecurityContext#getUserName()
056     */
057    @Override
058    public String getUserName() {
059        return username;
060    }
061
062    /*
063     * (non-Javadoc)
064     * @see org.modeshape.jcr.security.SecurityContext#hasRole(java.lang.String)
065     */
066    @Override
067    public boolean hasRole(final String roleName) {
068        return true;
069    }
070
071    /*
072     * (non-Javadoc)
073     * @see org.modeshape.jcr.security.SecurityContext#logout()
074     */
075    @Override
076    public void logout() {
077        this.loggedIn = false;
078    }
079
080    /*
081     * (non-Javadoc)
082     * @see
083     * org.modeshape.jcr.security.AuthorizationProvider#hasPermission(
084     * org.modeshape.jcr.ExecutionContext, java.lang.String,
085     * java.lang.String,
086     * java.lang.String, org.modeshape.jcr.value.Path, java.lang.String[])
087     */
088    @Override
089    public boolean hasPermission(final ExecutionContext context,
090            final String repositoryName,
091            final String repositorySourceName, final String workspaceName,
092            final Path absPath, final String... actions) {
093        return this.loggedIn;
094    }
095
096}