001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.auth.common; 019 020import org.modeshape.jcr.ExecutionContext; 021import org.modeshape.jcr.security.AuthorizationProvider; 022import org.modeshape.jcr.security.SecurityContext; 023import org.modeshape.jcr.value.Path; 024 025/** 026 * This is a pass-through security context for authenticated Fedora 027 * administrators. 028 * 029 * @author Gregory Jansen 030 */ 031public class FedoraAdminSecurityContext implements AuthorizationProvider, 032 SecurityContext { 033 034 private String username = null; 035 036 private boolean loggedIn = true; 037 038 /** 039 * @param username the user name 040 */ 041 public FedoraAdminSecurityContext(final String username) { 042 super(); 043 this.username = username; 044 } 045 046 /* 047 * (non-Javadoc) 048 * @see org.modeshape.jcr.security.SecurityContext#isAnonymous() 049 */ 050 @Override 051 public boolean isAnonymous() { 052 return username != null; 053 } 054 055 /* 056 * (non-Javadoc) 057 * @see org.modeshape.jcr.security.SecurityContext#getUserName() 058 */ 059 @Override 060 public String getUserName() { 061 return username; 062 } 063 064 /* 065 * (non-Javadoc) 066 * @see org.modeshape.jcr.security.SecurityContext#hasRole(java.lang.String) 067 */ 068 @Override 069 public boolean hasRole(final String roleName) { 070 return true; 071 } 072 073 /* 074 * (non-Javadoc) 075 * @see org.modeshape.jcr.security.SecurityContext#logout() 076 */ 077 @Override 078 public void logout() { 079 this.loggedIn = false; 080 } 081 082 /* 083 * (non-Javadoc) 084 * @see 085 * org.modeshape.jcr.security.AuthorizationProvider#hasPermission( 086 * org.modeshape.jcr.ExecutionContext, java.lang.String, 087 * java.lang.String, 088 * java.lang.String, org.modeshape.jcr.value.Path, java.lang.String[]) 089 */ 090 @Override 091 public boolean hasPermission(final ExecutionContext context, 092 final String repositoryName, 093 final String repositorySourceName, final String workspaceName, 094 final Path absPath, final String... actions) { 095 return this.loggedIn; 096 } 097 098}