1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 21 package org.apache.directory.api.ldap.model.ldif.anonymizer; 22 23 24 import java.util.Map; 25 26 27 /** 28 * An anonymizer for the TelephoneNumber attribute. We simply replace the digits by random digits. 29 * 30 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 31 */ 32 public class TelephoneNumberAnonymizer extends IntegerAnonymizer 33 { 34 35 /** 36 * Creates a new instance of TelephoneNumberAnonymizer. 37 */ 38 public TelephoneNumberAnonymizer() 39 { 40 super(); 41 } 42 43 44 /** 45 * Creates a new instance of TelephoneNumberAnonymizer. 46 * 47 * @param latestIntegerMap The map containing the latest integer value for each length 48 */ 49 public TelephoneNumberAnonymizer( Map<Integer, String> latestIntegerMap ) 50 { 51 super( latestIntegerMap ); 52 } 53 54 /** 55 * Anonymize an attribute using pure random values (either chars of bytes, depending on the Attribute type) 56 * 57 public Attribute anonymize( Map<Value<String>, Value<String>> valueMap, Set<Value<String>> valueSet, Attribute attribute ) 58 { 59 Attribute result = new DefaultAttribute( attribute.getAttributeType() ); 60 61 for ( Value<?> value : attribute ) 62 { 63 Value<String> anonymized = valueMap.get( value ); 64 65 if ( anonymized != null ) 66 { 67 try 68 { 69 result.add( anonymized.getString() ); 70 } 71 catch ( LdapInvalidAttributeValueException e ) 72 { 73 // TODO : handle that 74 } 75 } 76 else 77 { 78 if ( value instanceof StringValue ) 79 { 80 String strValue = value.getNormValue().toString(); 81 int length = strValue.length(); 82 83 // Same size 84 char[] newValue = new char[length]; 85 86 for ( int i = 0; i < length; i++ ) 87 { 88 char c = ( strValue.charAt( i ) ); 89 90 if ( Character.isDigit( c ) ) 91 { 92 newValue[i] = ( char ) ( random.nextInt( '9' - '0' ) + '0' ); 93 } 94 else 95 { 96 newValue[i] = c; 97 } 98 } 99 100 try 101 { 102 String newValueStr = new String( newValue ); 103 result.add( newValueStr ); 104 105 Value<String> anonValue = new StringValue( attribute.getAttributeType(), newValueStr ); 106 valueMap.put( ( Value<String> ) value, anonValue ); 107 } 108 catch ( LdapInvalidAttributeValueException e ) 109 { 110 // TODO : handle that 111 } 112 } 113 else 114 { 115 byte[] byteValue = value.getBytes(); 116 117 // Same size 118 byte[] newValue = new byte[byteValue.length]; 119 120 for ( int i = 0; i < byteValue.length; i++ ) 121 { 122 newValue[i] = ( byte ) random.nextInt(); 123 } 124 125 try 126 { 127 result.add( newValue ); 128 } 129 catch ( LdapInvalidAttributeValueException e ) 130 { 131 // TODO : handle that 132 } 133 } 134 } 135 } 136 137 return result; 138 }*/ 139 }