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.roles.common;
017
018import static com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty;
019
020import javax.jcr.RepositoryException;
021import javax.jcr.Session;
022
023import com.hp.hpl.jena.rdf.model.Property;
024
025/**
026 * Reference values for access roles node types and paths.
027 *
028 * @author Gregory Jansen
029 */
030public class Constants {
031
032    /**
033     * No public constructor for utility class
034     */
035    private Constants() {
036    }
037
038    /**
039     * Authorization JCR names
040     *
041     * @author Gregory Jansen
042     */
043    public static enum JcrName {
044        rbaclAssignable(), Rbacl(), Assignment(), rbacl(), assignment(),
045        principal(), role();
046
047        private String expandedName;
048
049        private String qualifiedName;
050
051        private Property property;
052
053        public static final String NS_URI =
054                "http://fedora.info/definitions/v4/authorization#";
055
056        public static final String NS_PREFIX = "authz";
057
058        JcrName() {
059            this.expandedName = '{' + NS_URI + '}' + this.name();
060            this.qualifiedName = NS_PREFIX + ':' + this.name();
061            this.property = createProperty(NS_URI + this.name());
062        }
063
064        /**
065         * Get the fully qualified name of this JCR type.
066         *
067         * @return expanded name
068         */
069        public String getExpanded() {
070            return this.expandedName;
071        }
072
073        /**
074         * Get the qualified name of this JCR type.
075         *
076         * @return qualified name
077         */
078        public String getQualified() {
079            return this.qualifiedName;
080        }
081
082        /**
083         * Get the property for this URI.
084         *
085         * @return a Jena property
086         */
087        public Property getProperty() {
088            return this.property;
089        }
090
091        /*
092         * (non-Javadoc)
093         * @see java.lang.Enum#toString()
094         */
095        @Override
096        public String toString() {
097            return getQualified();
098        }
099
100    }
101
102    /**
103     * Adds access roles prefix "authz" to the given session.
104     * @param session session
105     * @throws RepositoryException if repository exception occurred
106     */
107    public static void registerPrefixes(final Session session)
108        throws RepositoryException {
109        session.setNamespacePrefix(JcrName.NS_PREFIX, JcrName.NS_URI);
110    }
111}