View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  package org.apache.geronimo.security.deploy;
19  
20  import java.beans.PropertyEditorManager;
21  
22  import org.apache.geronimo.common.propertyeditor.PropertyEditorException;
23  import org.apache.geronimo.common.propertyeditor.TextPropertyEditorSupport;
24  
25  
26  /**
27   * @version $Rev: 470785 $ $Date: 2006-11-03 04:44:30 -0800 (Fri, 03 Nov 2006) $
28   */
29  public class RealmPrincipalInfo extends LoginDomainPrincipalInfo {
30  
31      static {
32          PropertyEditorManager.registerEditor(RealmPrincipalInfo.class, RealmPrincipalEditor.class);
33      }
34  
35      private final String realm;
36  
37      public RealmPrincipalInfo(String realm, String domainName, String className, String principalName, boolean designatedRunAs) {
38          super(domainName, className, principalName, designatedRunAs);
39          this.realm = realm;
40      }
41  
42      public String getRealm() {
43          return realm;
44      }
45  
46      public static class RealmPrincipalEditor extends TextPropertyEditorSupport {
47  
48          public void setAsText(String text) {
49              if (text != null) {
50                  String[] parts = text.split(",");
51                  if (parts.length != 5) {
52                      throw new PropertyEditorException("Principal should have the form 'realm,domain,class,name,run-as'");
53                  }
54                  RealmPrincipalInfo principal = new RealmPrincipalInfo(parts[0], parts[1], parts[2], parts[3], Boolean.valueOf(parts[4]).booleanValue());
55                  setValue(principal);
56              } else {
57                  setValue(null);
58              }
59          }
60  
61          public String getAsText() {
62              RealmPrincipalInfo principal = (RealmPrincipalInfo) getValue();
63              if (principal == null) {
64                  return null;
65              }
66              // output from getAsText() should match with the input expected by setAsText()
67              return principal.getRealm() + "," + principal.getDomain() + "," + principal.getClassName() + "," + principal.getPrincipalName() + "," + principal.isDesignatedRunAs();
68          }
69      }
70  }