001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Wojciech Sulejman 016 */ 017 018package org.nuxeo.ecm.platform.signature.core.user; 019 020import java.util.Arrays; 021import java.util.HashSet; 022import java.util.List; 023import java.util.Set; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XObject; 027import org.nuxeo.ecm.platform.signature.api.exception.CertException; 028 029/** 030 * Provides default values for new user certificates. 031 * 032 * @author <a href="mailto:ws@nuxeo.com">Wojciech Sulejman</a> 033 */ 034 035@XObject("userDescriptor") 036public class CUserDescriptor { 037 038 /** 039 * An ISO 3166 code to be set in new user certificates 040 */ 041 @XNode("countryCode") 042 protected String countryCode; 043 044 /** 045 * Your organization name to be set in new user certificates 046 */ 047 @XNode("organization") 048 protected String organization; 049 050 /** 051 * Your organizational unit name to be set in new user certificates 052 */ 053 @XNode("organizationalUnit") 054 protected String organizationalUnit; 055 056 public String getCountryCode() { 057 return countryCode; 058 } 059 060 public void setCountryCode(String countryCode) { 061 if (!validateCountryCode(countryCode)) { 062 throw new CertException("Invalid country code for user certificate"); 063 } 064 this.countryCode = countryCode; 065 } 066 067 public String getOrganization() { 068 return organization; 069 } 070 071 public void setOrganization(String organization) { 072 this.organization = organization; 073 } 074 075 public String getOrganizationalUnit() { 076 return organizationalUnit; 077 } 078 079 public void setOrganizationalUnit(String organizationalUnit) { 080 this.organizationalUnit = organizationalUnit; 081 } 082 083 boolean validateCountryCode(String countryCode) { 084 String[] validCountryCodes = { "AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", 085 "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", 086 "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", 087 "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", 088 "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", 089 "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", 090 "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", 091 "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", 092 "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", 093 "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", 094 "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", 095 "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", 096 "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", 097 "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", 098 "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW" }; 099 List<String> countryCodeList = Arrays.asList(validCountryCodes); 100 Set<String> validCountryCodeSet = new HashSet<String>(countryCodeList); 101 return validCountryCodeSet.contains(countryCode); 102 } 103 104}