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