001/* 002 * (C) Copyright 2014 Nuxeo SA (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 */ 018package org.nuxeo.ecm.user.invite; 019 020import org.apache.commons.logging.Log; 021import org.apache.commons.logging.LogFactory; 022import org.nuxeo.ecm.core.api.DocumentModel; 023import org.nuxeo.ecm.core.api.PropertyException; 024import org.nuxeo.runtime.api.Framework; 025 026/** 027 * @author <a href="mailto:akervern@nuxeo.com">Arnaud Kervern</a> 028 */ 029 030public class RegistrationRules { 031 public static final String FACET_REGISTRATION_CONFIGURATION = "RegistrationConfiguration"; 032 033 public static final String SCHEMA_REGISTRATION_RULES = "registrationconfiguration"; 034 035 public static final String FIELD_ALLOW_USER_CREATION = SCHEMA_REGISTRATION_RULES + ":" + "allowUserCreation"; 036 037 public static final String FIELD_ALLOW_DIRECT_VALIDATION = SCHEMA_REGISTRATION_RULES + ":" 038 + "allowDirectValidationForExistingUser"; 039 040 public static final String FIELD_FORCE_RIGHT = SCHEMA_REGISTRATION_RULES + ":" + "forceRightAssignment"; 041 042 public static final String FIELD_CONFIGURATION_NAME = SCHEMA_REGISTRATION_RULES + ":" + "name"; 043 044 public static final String FIELD_DISPLAY_LOCAL_TAB = SCHEMA_REGISTRATION_RULES + ":" 045 + "displayLocalRegistrationTab"; 046 047 protected DocumentModel requestContainer; 048 049 private static final Log log = LogFactory.getLog(RegistrationRules.class); 050 051 public RegistrationRules(DocumentModel requestContainer) { 052 this.requestContainer = requestContainer; 053 } 054 055 public boolean allowUserCreation() { 056 try { 057 return (Boolean) requestContainer.getPropertyValue(FIELD_ALLOW_USER_CREATION); 058 } catch (PropertyException e) { 059 log.warn("Unable to fetch AllowUserCreation flag using default value: " + e.getMessage()); 060 return true; 061 } 062 } 063 064 public boolean allowDirectValidationForExistingUser() { 065 try { 066 return (Boolean) requestContainer.getPropertyValue(FIELD_ALLOW_DIRECT_VALIDATION); 067 } catch (PropertyException e) { 068 log.warn("Unable to fetch AllowDirectValidation flag using default value: " + e.getMessage()); 069 return false; 070 } 071 } 072 073 public boolean isForcingRight() { 074 try { 075 return (Boolean) requestContainer.getPropertyValue(FIELD_FORCE_RIGHT); 076 } catch (PropertyException e) { 077 log.warn("Unable to fetch ForceRight flag using default value: " + e.getMessage()); 078 return false; 079 } 080 } 081 082 public boolean isDisplayLocalTab() { 083 try { 084 return (Boolean) requestContainer.getPropertyValue(FIELD_DISPLAY_LOCAL_TAB); 085 } catch (PropertyException e) { 086 log.warn("Unable to fetch display local tab flag using default value: " + e.getMessage()); 087 return true; 088 } 089 } 090 091 public boolean allowDirectValidationForNonExistingUser() { 092 return Framework.isBooleanPropertyTrue("nuxeo.user.registration.force.validation.non.existing"); 093 } 094}