001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. 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: 545781 $ $Date: 2007-06-09 13:44:02 -0400 (Sat, 09 Jun 2007) $
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) {
035 super(className, principalName);
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 != 3) {
051 throw new PropertyEditorException("Principal should have the form 'domain,class,name'");
052 }
053 LoginDomainPrincipalInfo principal = new LoginDomainPrincipalInfo(parts[0], parts[1], parts[2]);
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.getDomain();
066 }
067 }
068 }