Changeset 961
- Timestamp:
- 10/19/07 00:38:46 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotation.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/filters/stubPasswordFilter.php (modified) (7 diffs)
- trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/ipo/request/filters/stubPasswordFilterTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotation.php
r731 r961 28 28 * @var int 29 29 */ 30 protected $minLength = 6; 30 protected $minLength = 6; 31 /** 32 * the encoder class to be used 33 * 34 * @var stubReflectionClass 35 */ 36 protected $encoderClass = null; 31 37 32 38 /** … … 41 47 42 48 /** 49 * sets the encoder class to be used 50 * 51 * @param stubReflectionClass $encoder 52 */ 53 public function setEncoder(stubReflectionClass $encoderClass) 54 { 55 $this->encoderClass = $encoderClass; 56 } 57 58 /** 43 59 * returns the filter defined by the annotation 44 60 * … … 48 64 protected function doGetFilter() 49 65 { 50 $passwordFilter = new stubPasswordFilter($this->createRVEFactory(), new stubMinLengthValidator($this->minLength)); 66 $passwordFilter = new stubPasswordFilter($this->createRVEFactory(), new stubMinLengthValidator($this->minLength)); 67 if (null !== $this->encoderClass) { 68 $passwordFilter->setEncoder($this->encoderClass->newInstance()); 69 } 70 51 71 return $passwordFilter; 52 72 } trunk/src/main/php/net/stubbles/ipo/request/filters/stubPasswordFilter.php
r880 r961 7 7 * @subpackage ipo_request_filters 8 8 */ 9 stubClassLoader::load('net.stubbles.ipo.request.filters.stubAbstractFilter'); 9 stubClassLoader::load('net.stubbles.ipo.request.filters.stubAbstractFilter', 10 'net.stubbles.php.string.stubStringEncoder' 11 ); 10 12 /** 11 13 * Class for filtering passwords. … … 14 16 * for a password. A minimum length validator can check the length of the password. 15 17 * Additionally its possible to check against a list of non-allowed passwords 16 * (e.g. the username or the login name). The returned value is a md5- 17 * representation of the password. 18 * (e.g. the username or the login name). The returned value is an encoded 19 * representation of the password. By default the password will be encoded in 20 * md5. This can be changed by setting an instance of 21 * net.stubbles.php.string.stubStringEncoder via the setEncoder() method. 18 22 * If the value is an array the fields with key 0 and 1 are compared. If they are 19 23 * not equal the password is not allowed (can be used to prevent mistyped … … 44 48 */ 45 49 protected $nonAllowedValues = array(); 50 /** 51 * the encoder to be used for encoding the password 52 * 53 * @var stubStringEncoder 54 */ 55 protected $encoder; 46 56 47 57 /** … … 100 110 101 111 /** 112 * sets the encoder to be used to encode the password 113 * 114 * @param stubStringEncoder $encoder 115 */ 116 public function setEncoder($encoder) 117 { 118 $this->encoder = $encoder; 119 } 120 121 /** 122 * returns the encoder to be used to encode the password 123 * 124 * @return stubStringEncoder 125 */ 126 public function getEncoder() 127 { 128 return $this->encoder; 129 } 130 131 /** 102 132 * check if entered passwords fulfill password conditions 103 133 * … … 108 138 public function execute($value) 109 139 { 110 if (is_array($value) == true) {111 if ($value[0] != $value[1]) {140 if (is_array($value) === true) { 141 if ($value[0] !== $value[1]) { 112 142 throw new stubFilterException($this->rveFactory->create('PASSWORDS_NOT_EQUAL')); 113 143 } … … 116 146 } 117 147 118 if (false == $this->isRequired && strlen($value)== 0) {148 if (false === $this->isRequired && strlen($value) === 0) { 119 149 return null; 120 150 } 121 151 122 if ($this->minLength->validate($value) == false) {152 if ($this->minLength->validate($value) === false) { 123 153 throw new stubFilterException($this->rveFactory->create('STRING_TOO_SHORT')->setValues($this->minLength->getCriteria())); 124 154 } 125 155 126 if (in_array($value, $this->nonAllowedValues) == true) {156 if (in_array($value, $this->nonAllowedValues) === true) { 127 157 throw new stubFilterException($this->rveFactory->create('PASSWORD_INVALID')); 128 158 } … … 145 175 protected function secure($password) 146 176 { 177 if (null !== $this->encoder) { 178 return $this->encoder->encode($password); 179 } 180 147 181 return md5($password); 148 182 } trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php
r731 r961 37 37 { 38 38 $passwordFilter = $this->passwordFilterAnnotation->getFilter(); 39 $passwordFilter = $this->passwordFilterAnnotation->getFilter();40 39 $this->assertIsA($passwordFilter, 'stubPasswordFilter'); 41 40 $this->assertIsA($passwordFilter->getMinLengthValidator(), 'stubMinLengthValidator'); 42 41 $this->assertEqual($passwordFilter->getMinLengthValidator()->getValue(), 6); 42 $this->assertNull($passwordFilter->getEncoder()); 43 43 } 44 44 … … 53 53 $this->assertIsA($passwordFilter->getMinLengthValidator(), 'stubMinLengthValidator'); 54 54 $this->assertEqual($passwordFilter->getMinLengthValidator()->getValue(), 8); 55 $this->assertNull($passwordFilter->getEncoder()); 56 } 57 58 /** 59 * assert that the encoder is set correct 60 */ 61 public function testWithEncoder() 62 { 63 $this->passwordFilterAnnotation->setEncoder(new stubReflectionClass('net.stubbles.php.string.stubMd5Encoder')); 64 $passwordFilter = $this->passwordFilterAnnotation->getFilter(); 65 $this->assertIsA($passwordFilter, 'stubPasswordFilter'); 66 $this->assertIsA($passwordFilter->getEncoder(), 'stubMd5Encoder'); 55 67 } 56 68 } trunk/src/test/php/net/stubbles/ipo/request/filters/stubPasswordFilterTestCase.php
r880 r961 10 10 Mock::generate('stubRequestValueErrorFactory'); 11 11 Mock::generate('stubValidator'); 12 Mock::generate('stubStringEncoder'); 12 13 /** 13 14 * Tests for ipo.request.filters.stubPasswordFilter … … 110 111 $this->passwordFilter->execute(array('abcdd', 'abcdd')); 111 112 } 113 114 /** 115 * test that the encoder is used if set 116 */ 117 public function testWithEncoder() 118 { 119 $this->mockMinLengthValidator->setReturnValue('validate', true); 120 $mockEncoder = new MockstubStringEncoder(); 121 $mockEncoder->setReturnValue('encode', 'encodedValue'); 122 $mockEncoder->expectOnce('encode'); 123 $this->passwordFilter->setEncoder($mockEncoder); 124 $this->assertEqual($this->passwordFilter->execute('foo'), 'encodedValue'); 125 } 112 126 } 113 127 ?>
