📄 writetopolicy.java
字号:
//NodeList targetDomSpecs = e.getElementsByTagName("TargetDomainSpec");
Element child = this.policyDocument.DOM.createElement("TargetDomainSpec");
child.setAttribute("ID", "WebResources");
for (int i=0; i<this.pwiz.pwslide7b.urlItemList.getListData().length; i++) {
String loc = (String)this.pwiz.pwslide7b.urlItemList.getListData()[i];
Element include = this.policyDocument.DOM.createElement("Include");
include.setAttribute("URL", loc);
child.appendChild(include);
}
this.policyDocument.addItem(child, e);
}
/**
* Writes the SOA Policy, when the users option in the wizard is anyone.
*
* This will delete any users defined Administrators, and then create
* a new Element with an LDAP DN of null.
*/
public void writeSOAPolicy() {
//delete any SOASpecs...
Element e = (Element)this.policyDocument.DOM.getElementsByTagName("SOAPolicy").item(0);
NodeList soaSpecs = e.getElementsByTagName("SOASpec");
for (int i=soaSpecs.getLength()-1; i>=0; i--) {
this.policyDocument.deleteItem((Element)soaSpecs.item(i), e);
}
Element child = this.policyDocument.DOM.createElement("SOASpec");
child.setAttribute("ID", rbl.getString("Slide4_Option_Anyone"));
child.setAttribute("LDAPDN", "null");
Element soaPolicy = (Element)this.policyDocument.DOM.getDocumentElement().getElementsByTagName("SOAPolicy").item(0);
this.policyDocument.addItem(child, soaPolicy);
}
/**
* Contains steps needed to write to the policy to the dom.
* Called when this component is displayed in the policy wizard.
*/
public void writePolicy() {
this.policyDocument.DOM.getDocumentElement().setAttribute("OID", this.pwiz.pwslide2.policyName.getText());
if (this.pwiz.pwslide3.anywhereRbutton.isSelected()) {
writeSubjectPolicy();
}
if (this.pwiz.pwslide4.anyoneRbutton.isSelected()) {
writeSOAPolicy();
}
if (!this.pwiz.pwslide5.specificRButton.isSelected()) {
//delete any items that may have been added specifically...
Element e = (Element)PWizard.finishWizard.policyDocument.DOM.getElementsByTagName("RoleHierarchyPolicy").item(0);
NodeList roleSpecs = e.getElementsByTagName("RoleSpec");
for (int i=roleSpecs.getLength()-1; i>=0; i--) {
Element el = (Element)roleSpecs.item(i);
if (!el.getAttribute("Type").equals("eduPersonAffiliation") &&
!el.getAttribute("Type").equals("eduPersonNickname") &&
!el.getAttribute("Type").equals("eduPersonOrgDN") &&
!el.getAttribute("Type").equals("eduPersonOrgUnitDN") &&
!el.getAttribute("Type").equals("eduPersonPrimaryAffiliation") &&
!el.getAttribute("Type").equals("eduPersonPrincipalName") &&
!el.getAttribute("Type").equals("loa") &&
!el.getAttribute("Type").equals("permisRole"))
this.policyDocument.deleteItem(el, e);
}
}
if (this.pwiz.pwslide6.infiniteRbutton.isSelected() || this.pwiz.pwslide6.noDelegationRbutton.isSelected()) {
Element RoleAssignmentPolicy = (Element)this.policyDocument.DOM.getElementsByTagName("RoleAssignmentPolicy").item(0);
//delete any items that may have been added specifically...
NodeList roleSpec = RoleAssignmentPolicy.getElementsByTagName("RoleAssignment");
for (int i=roleSpec.getLength()-1; i>=0; i--) {
this.policyDocument.deleteItem((Element)roleSpec.item(i), RoleAssignmentPolicy);
}
Element SOAPolicy = (Element)this.policyDocument.DOM.getElementsByTagName("SOAPolicy").item(0);
NodeList soaSpecs = SOAPolicy.getElementsByTagName("SOASpec");
Element SubjectPolicy = (Element)this.policyDocument.DOM.getElementsByTagName("SubjectPolicy").item(0);
NodeList subjectSpecs = SubjectPolicy.getElementsByTagName("SubjectDomainSpec");
Element RoleHierarchyPolicy = (Element)PWizard.finishWizard.policyDocument.DOM.getElementsByTagName("RoleHierarchyPolicy").item(0);
NodeList roleSpecs = RoleHierarchyPolicy.getElementsByTagName("RoleSpec");
int roleAssignNum = 1;
for (int i=0; i<soaSpecs.getLength(); i++) {
for (int j=0; j<subjectSpecs.getLength(); j++) {
Element child = this.policyDocument.DOM.createElement("RoleAssignment");
child.setAttribute("ID", "RoleAssignment" + roleAssignNum);
roleAssignNum++;
Element SubjectDomain = this.policyDocument.DOM.createElement("SubjectDomain");
SubjectDomain.setAttribute("ID", ((Element)subjectSpecs.item(j)).getAttribute("ID"));
child.appendChild((Node)SubjectDomain);
Element RoleList = this.policyDocument.DOM.createElement("RoleList");
for (int h=0; h<roleSpecs.getLength(); h++) {
Element Role = this.policyDocument.DOM.createElement("Role");
Role.setAttribute("Type", ((Element)roleSpecs.item(h)).getAttribute("Type"));
RoleList.appendChild((Node)Role);
}
child.appendChild((Node)RoleList);
Element Delegate = this.policyDocument.DOM.createElement("Delegate");
if (this.pwiz.pwslide6.noDelegationRbutton.isSelected())
Delegate.setAttribute("Depth", "0");
child.appendChild((Node)Delegate);
Element SOA = this.policyDocument.DOM.createElement("SOA");
SOA.setAttribute("ID", ((Element)soaSpecs.item(i)).getAttribute("ID"));
child.appendChild((Node)SOA);
Element Validity = this.policyDocument.DOM.createElement("Validity");
child.appendChild((Node)Validity);
RoleAssignmentPolicy.appendChild((Node)child);
}
}
}
viewXML.setXMLEditor(this.policyDocument);
viewXML.getXML();
}
/**
* File Filter to return directories or files of type xml in the File
* chooser of the saveMethod().
*/
public FileFilter ff = new FileFilter() {
public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(".xml")
|| f.isDirectory();
}
public String getDescription() {
return "PERMIS Policy (*.xml)";
}
};
/**
* Saves the Policy Created to disk.
* <p>
* The user specifies the location where to save the policy.
* <p>
* If a policy is saved ok, the method will return true, otherwise it
* will return false.
*
* @return a boolean value with the success of the saving method.
*/
public boolean saveMethod() {
JFileChooser fc = new JFileChooser(); //filedialog
JDialog.setDefaultLookAndFeelDecorated(true);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); //Able to select files only
fc.setCurrentDirectory(new File(".")); //Set current Directory
fc.setFileFilter(ff); //Set filter for XML files only
int returnVal = fc.showSaveDialog(this); //return if Ok or Cancel where pressed
if (returnVal == JFileChooser.APPROVE_OPTION) //if Ok was pressed
{
try {
String filename = fc.getSelectedFile().getAbsolutePath();
if (!filename.endsWith(".xml")) {
filename += ".xml";
}
FileOutputStream file = new FileOutputStream(filename);
OutputFormat format = new OutputFormat();
format.setLineSeparator(LineSeparator.Windows); // "\n" wouldnt work well..
format.setIndenting(true);
XMLSerializer serializer = new XMLSerializer(file, format);
serializer.serialize(this.policyDocument.DOM);
file.close();
return true;
} catch(IOException e) {
}
}
return false;
}
//what to do when the dropdown list is selected.
public void actionPerformed(ActionEvent e) {
JComboBox cb = ((JComboBox)e.getSource());
//if (this.tse == null) return;
if (cb.getSelectedItem().toString().intern().equals("XML")) {
viewXML.that.setContentType("text/plain");
viewXML.mimeType = "text/plain";
} else if (cb.getSelectedItem().toString().intern().equals("Readable Policy")) {
viewXML.that.setContentType("text/html");
viewXML.mimeType = "text/html";
}
if (viewXML.getXMLEditor() != null)
viewXML.getXML();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -