Coverage Report - org.acegisecurity.userdetails.memory.UserAttributeEditor
 
Classes in this File Line Coverage Branch Coverage Complexity
UserAttributeEditor
100% 
100% 
7
 
 1  
 /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
 2  
  *
 3  
  * Licensed under the Apache License, Version 2.0 (the "License");
 4  
  * you may not use this file except in compliance with the License.
 5  
  * You may obtain a copy of the License at
 6  
  *
 7  
  *     http://www.apache.org/licenses/LICENSE-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing, software
 10  
  * distributed under the License is distributed on an "AS IS" BASIS,
 11  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
  * See the License for the specific language governing permissions and
 13  
  * limitations under the License.
 14  
  */
 15  
 
 16  
 package org.acegisecurity.userdetails.memory;
 17  
 
 18  
 import java.beans.PropertyEditorSupport;
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import org.springframework.util.StringUtils;
 23  
 
 24  
 /**
 25  
  * Property editor that creates a {@link UserAttribute} from a  comma separated list of values.
 26  
  *
 27  
  * @author Ben Alex
 28  
  * @version $Id: UserAttributeEditor.java 1642 2006-09-04 21:54:15Z carlossg $
 29  
  */
 30  52
 public class UserAttributeEditor extends PropertyEditorSupport {
 31  
     //~ Methods ========================================================================================================
 32  
 
 33  
     public void setAsText(String s) throws IllegalArgumentException {
 34  61
         if (StringUtils.hasText(s)) {
 35  58
             String[] tokens = StringUtils.commaDelimitedListToStringArray(s);
 36  58
             UserAttribute userAttrib = new UserAttribute();
 37  
             
 38  58
             List authoritiesAsString = new ArrayList();
 39  
 
 40  276
             for (int i = 0; i < tokens.length; i++) {
 41  218
                 String currentToken = tokens[i].trim();
 42  
 
 43  218
                 if (i == 0) {
 44  58
                     userAttrib.setPassword(currentToken);
 45  
                 } else {
 46  160
                     if (currentToken.toLowerCase().equals("enabled")) {
 47  47
                         userAttrib.setEnabled(true);
 48  113
                     } else if (currentToken.toLowerCase().equals("disabled")) {
 49  2
                         userAttrib.setEnabled(false);
 50  
                     } else {
 51  111
                         authoritiesAsString.add(currentToken);
 52  
                     }
 53  
                 }
 54  
             }
 55  58
             userAttrib.setAuthoritiesAsString(authoritiesAsString);
 56  
 
 57  58
             if (userAttrib.isValid()) {
 58  55
                 setValue(userAttrib);
 59  
             } else {
 60  3
                 setValue(null);
 61  
             }
 62  58
         } else {
 63  3
             setValue(null);
 64  
         }
 65  61
     }
 66  
 }