001 /**
002 *
003 * Copyright 2004 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.security.deploy;
018
019 import java.beans.PropertyEditorManager;
020 import java.io.Serializable;
021
022 import org.apache.geronimo.common.propertyeditor.PropertyEditorException;
023 import org.apache.geronimo.common.propertyeditor.TextPropertyEditorSupport;
024
025
026 /**
027 * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
028 */
029 public class PrincipalInfo implements Serializable {
030
031 static {
032 PropertyEditorManager.registerEditor(PrincipalInfo.class, PrincipalEditor.class);
033 }
034
035 private final String className;
036 private final String principalName;
037 private final boolean designatedRunAs;
038
039 public PrincipalInfo(String className, String principalName, boolean designatedRunAs) {
040 this.className = className;
041 this.principalName = principalName;
042 this.designatedRunAs = designatedRunAs;
043 }
044
045 public String getClassName() {
046 return className;
047 }
048
049 public String getPrincipalName() {
050 return principalName;
051 }
052
053 public boolean isDesignatedRunAs() {
054 return designatedRunAs;
055 }
056
057 public static class PrincipalEditor extends TextPropertyEditorSupport {
058
059 public void setAsText(String text) {
060 if (text != null) {
061 String[] parts = text.split(",");
062 if (parts.length != 3) {
063 throw new PropertyEditorException("Principal should have the form 'name,class,run-as'");
064 }
065 PrincipalInfo principalInfo = new PrincipalInfo(parts[0], parts[1], Boolean.valueOf(parts[2]).booleanValue());
066 setValue(principalInfo);
067 } else {
068 setValue(null);
069 }
070 }
071
072 public String getAsText() {
073 PrincipalInfo principalInfo = (PrincipalInfo) getValue();
074 if (principalInfo == null) {
075 return null;
076 }
077 return principalInfo.getPrincipalName() + "," + principalInfo.getClassName() + "," + principalInfo.isDesignatedRunAs();
078 }
079 }
080 }