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    
021    import org.apache.geronimo.common.propertyeditor.PropertyEditorException;
022    import org.apache.geronimo.common.propertyeditor.TextPropertyEditorSupport;
023    
024    
025    /**
026     * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
027     */
028    public class LoginDomainPrincipalInfo extends PrincipalInfo {
029    
030        static {
031            PropertyEditorManager.registerEditor(LoginDomainPrincipalInfo.class, LoginDomainPrincipalEditor.class);
032        }
033    
034        public LoginDomainPrincipalInfo(String domainName, String className, String principalName, boolean designatedRunAs) {
035            super(className, principalName, designatedRunAs);
036            this.domainName = domainName;
037        }
038    
039        private final String domainName;
040    
041        public String getDomain() {
042            return domainName;
043        }
044    
045        public static class LoginDomainPrincipalEditor extends TextPropertyEditorSupport {
046    
047            public void setAsText(String text) {
048                if (text != null) {
049                    String[] parts = text.split(",");
050                    if (parts.length != 4) {
051                        throw new PropertyEditorException("Principal should have the form 'domain,class,name,run-as'");
052                    }
053                    LoginDomainPrincipalInfo principal = new LoginDomainPrincipalInfo(parts[0], parts[1], parts[2], Boolean.valueOf(parts[3]).booleanValue());
054                    setValue(principal);
055                } else {
056                    setValue(null);
057                }
058            }
059    
060            public String getAsText() {
061                LoginDomainPrincipalInfo principal = (LoginDomainPrincipalInfo) getValue();
062                if (principal == null) {
063                    return null;
064                }
065                return principal.getPrincipalName() + "," + principal.getClassName() + "," + principal.isDesignatedRunAs() + "," + principal.getDomain();
066            }
067        }
068    }