001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.xml.mbeanserver;
023:
024: import java.util.ArrayList;
025: import java.util.Arrays;
026: import java.util.Map;
027: import java.util.Iterator;
028: import javax.security.auth.login.AppConfigurationEntry;
029:
030: /**
031: * @author Scott.Stark@jboss.org
032: * @version $Revision: 57211 $
033: */
034: public class AuthenticationInfo {
035: private String name;
036: private ArrayList loginModules = new ArrayList();
037:
038: public AuthenticationInfo() {
039: //System.out.println("AuthenticationInfo");
040: }
041:
042: public AuthenticationInfo(String name) {
043: this .name = name;
044: //System.out.println("AuthenticationInfo.ctor, name="+name);
045: }
046:
047: public String getName() {
048: return name;
049: }
050:
051: public void setName(String name) {
052: //System.out.println("AuthenticationInfo, name="+name);
053: this .name = name;
054: }
055:
056: /** Get a copy of the application authentication configuration. This requires
057: an AuthPermission("getLoginConfiguration") access.
058: */
059: public AppConfigurationEntry[] copyAppConfigurationEntry() {
060: AppConfigurationEntry[] copy = new AppConfigurationEntry[loginModules
061: .size()];
062: for (int i = 0; i < copy.length; i++) {
063: AppConfigurationEntry entry = (AppConfigurationEntry) loginModules
064: .get(i);
065: copy[i] = new AppConfigurationEntry(entry
066: .getLoginModuleName(), entry.getControlFlag(),
067: entry.getOptions());
068: }
069: return copy;
070: }
071:
072: public void addAppConfigurationEntry(AppConfigurationEntry entry) {
073: //System.out.println("AuthenticationInfo, addAppConfigurationEntry="+name);
074: loginModules.add(entry);
075: }
076:
077: /** Get an application authentication configuration. This requires an
078: AuthPermission("getLoginConfiguration") access.
079: */
080: public AppConfigurationEntry[] getAppConfigurationEntry() {
081: AppConfigurationEntry[] entries = new AppConfigurationEntry[loginModules
082: .size()];
083: loginModules.toArray(entries);
084: return entries;
085: }
086:
087: /** Set an application authentication configuration. This requires an
088: AuthPermission("setLoginConfiguration") access.
089: */
090: public void setAppConfigurationEntry(
091: AppConfigurationEntry[] loginModules) {
092: this .loginModules.addAll(Arrays.asList(loginModules));
093: }
094:
095: public String toString() {
096: StringBuffer buffer = new StringBuffer(
097: "AppConfigurationEntry[]:\n");
098: for (int i = 0; i < loginModules.size(); i++) {
099: AppConfigurationEntry entry = (AppConfigurationEntry) loginModules
100: .get(i);
101: buffer.append("[" + i + "]");
102: buffer.append("\nLoginModule Class: "
103: + entry.getLoginModuleName());
104: buffer.append("\nControlFlag: " + entry.getControlFlag());
105: buffer.append("\nOptions:");
106: Map options = entry.getOptions();
107: Iterator iter = options.entrySet().iterator();
108: while (iter.hasNext()) {
109: Map.Entry e = (Map.Entry) iter.next();
110: buffer.append("name=" + e.getKey());
111: buffer.append(", value=" + e.getValue());
112: buffer.append("\n");
113: }
114: }
115: return buffer.toString();
116: }
117:
118: }
|