1 16 package org.apache.cocoon.webapps.authentication.generation; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.avalon.framework.service.ServiceException; 21 import org.apache.avalon.framework.service.ServiceManager; 22 23 import org.apache.cocoon.ProcessingException; 24 import org.apache.cocoon.components.source.SourceUtil; 25 import org.apache.cocoon.environment.ObjectModelHelper; 26 import org.apache.cocoon.environment.Request; 27 import org.apache.cocoon.environment.Response; 28 import org.apache.cocoon.environment.Session; 29 import org.apache.cocoon.generation.ServiceableGenerator; 30 import org.apache.cocoon.webapps.authentication.AuthenticationManager; 31 import org.apache.cocoon.webapps.authentication.context.AuthenticationContext; 32 import org.apache.cocoon.webapps.authentication.user.RequestState; 33 import org.apache.cocoon.webapps.authentication.user.UserHandler; 34 import org.apache.cocoon.xml.IncludeXMLConsumer; 35 import org.apache.cocoon.xml.XMLConsumer; 36 import org.apache.cocoon.xml.XMLUtils; 37 import org.apache.cocoon.xml.dom.DOMUtil; 38 39 import org.apache.excalibur.source.Source; 40 import org.apache.excalibur.source.SourceException; 41 import org.apache.excalibur.source.SourceParameters; 42 import org.apache.excalibur.xml.xpath.XPathProcessor; 43 import org.w3c.dom.Document ; 44 import org.w3c.dom.Element ; 45 import org.w3c.dom.Node ; 46 import org.w3c.dom.NodeList ; 47 import org.xml.sax.SAXException ; 48 import org.xml.sax.helpers.DefaultHandler ; 49 50 import java.io.IOException ; 51 import java.util.Enumeration ; 52 import java.util.Map ; 53 54 60 public final class ConfigurationGenerator extends ServiceableGenerator { 61 62 63 public static final String REQ_PARAMETER_STATE = "authstate"; 64 public static final String REQ_PARAMETER_ROLE = "authrole"; 65 public static final String REQ_PARAMETER_ID = "authid"; 66 public static final String REQ_PARAMETER_USER = "authuser"; 67 68 private static final String SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE = "org.apache.cocoon.webapps.generation.ConfigurationGenerator.simple-role"; 69 70 71 protected XPathProcessor xpathProcessor; 72 73 76 public void dispose() { 77 if ( this.manager != null ) { 78 this.manager.release( this.xpathProcessor ); 79 this.xpathProcessor = null; 80 } 81 super.dispose(); 82 } 83 84 87 public void service(ServiceManager manager) throws ServiceException { 88 super.service(manager); 89 this.xpathProcessor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE); 90 } 91 92 95 public void generate() 96 throws IOException , SAXException , ProcessingException { 97 98 AuthenticationManager authManager = null; 99 RequestState state = null; 100 try { 101 authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE); 102 state = authManager.getState(); 103 104 } catch (Exception ignore) { 105 } 106 107 this.xmlConsumer.startDocument(); 108 if ( state != null ) { 109 try { 110 UserHandler userhandler = state.getHandler(); 111 112 Configuration conf = state.getModuleConfiguration("single-role-user-management"); 113 if (conf == null) { 114 throw new ProcessingException("Module configuration 'single-role-user-management' for authentication user management generator not found."); 115 } 116 UserManagementHandler handler = new UserManagementHandler(conf, 117 state.getApplicationName()); 118 this.showConfiguration(this.xmlConsumer, this.source, handler, userhandler.getContext()); 119 120 } catch (ConfigurationException ex) { 121 throw new ProcessingException("ConfigurationException: " + ex, ex); 122 } 123 } 124 125 this.xmlConsumer.endDocument(); 126 } 127 128 129 135 public void showConfiguration(XMLConsumer consumer, 136 String src, 137 UserManagementHandler handler, 138 AuthenticationContext context) 139 throws ProcessingException, SAXException , IOException { 140 if (this.getLogger().isDebugEnabled() == true) { 142 this.getLogger().debug("BEGIN showConfiguration consumer=" + consumer + ", SRC="+src); 143 } 144 145 Request request = ObjectModelHelper.getRequest(this.objectModel); 147 Response response = ObjectModelHelper.getResponse(this.objectModel); 148 Session session = request.getSession(); 149 150 boolean isAdmin = (src == null || src.equals("admin")); 151 152 consumer.startElement("", "configuration", "configuration", XMLUtils.EMPTY_ATTRIBUTES); 154 155 String uri = response.encodeURL(request.getRequestURI()); 160 consumer.startElement("", "uri", "uri", XMLUtils.EMPTY_ATTRIBUTES); 161 consumer.characters(uri.toCharArray(), 0, uri.length()); 162 consumer.endElement("", "uri", "uri"); 163 164 if (isAdmin == true) { 165 consumer.startElement("", "menue", "menue", XMLUtils.EMPTY_ATTRIBUTES); 167 168 if (handler.getNewRoleResource() != null) { 169 consumer.startElement("", "addrole", "addrole", XMLUtils.EMPTY_ATTRIBUTES); 170 consumer.endElement("", "addrole", "addrole"); 171 } 172 if (handler.getDeleteRoleResource() != null) { 173 consumer.startElement("", "delrole", "delrole", XMLUtils.EMPTY_ATTRIBUTES); 174 consumer.endElement("", "delrole", "delrole"); 175 } 176 177 consumer.endElement("", "menue", "menue"); 178 } 179 180 181 synchronized (session) { 182 183 String state = request.getParameter(REQ_PARAMETER_STATE); 184 if (state == null) { 185 state = (isAdmin == true ? "main" : "seluser"); 186 } 187 188 if (state.equals("addrole") == true) { 189 String role = request.getParameter(REQ_PARAMETER_ROLE); 190 if (role != null && role.trim().length() > 0) { 191 SourceParameters pars = new SourceParameters(); 192 Enumeration requestParameters = request.getParameterNames(); 194 String current; 195 while (requestParameters.hasMoreElements() == true) { 196 current = (String )requestParameters.nextElement(); 197 pars.setParameter(current, request.getParameter(current)); 198 } 199 this.addRole(role, pars, handler); 200 } else { 201 role = null; 202 } 203 session.removeAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE); 204 } 205 206 if (state.equals("delrole") == true) { 207 try { 208 String role = request.getParameter(REQ_PARAMETER_ROLE); 209 if (role != null) { 210 Document userDF = this.getUsers(role, null, handler); 212 NodeList users = null; 213 if (userDF != null) users = DOMUtil.selectNodeList(userDF, "users/user", this.xpathProcessor); 214 if (users != null) { 215 for(int i = 0; i < users.getLength(); i++) { 216 this.deleteUser(role, DOMUtil.getValueOf(users.item(i), "ID", this.xpathProcessor), null, handler); 217 } 218 } 219 this.deleteRole(role, null, handler); 220 } 221 session.removeAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE); 222 } catch (javax.xml.transform.TransformerException local) { 223 throw new ProcessingException("TransformerException: " + local, local); 224 } 225 } 226 227 228 if (state.equals("chguser") == true) { 229 String role; 230 String id; 231 String user; 232 233 if (isAdmin == false) { 234 Map pars = context.getContextInfo(); 235 id = (String ) pars.get("ID"); 236 role = (String ) pars.get("role"); 237 user = "old"; 238 } else { 239 role = request.getParameter(REQ_PARAMETER_ROLE); 240 id = request.getParameter(REQ_PARAMETER_ID); 241 user = request.getParameter(REQ_PARAMETER_USER); 242 } 243 244 boolean addingNewUserFailed = false; 245 if (role != null && id != null && user != null) { 246 if (user.equals("new") == true) { 247 SourceParameters pars = new SourceParameters(); 248 Enumeration requestParameters = request.getParameterNames(); 250 String current; 251 while (requestParameters.hasMoreElements() == true) { 252 current = (String )requestParameters.nextElement(); 253 pars.setParameter(current, request.getParameter(current)); 254 } 255 addingNewUserFailed = !this.addUser(role, id, pars, handler); 256 if (addingNewUserFailed == false) { 257 consumer.startElement("", "addeduser", "addeduser", XMLUtils.EMPTY_ATTRIBUTES); 258 consumer.characters(id.toCharArray(), 0, id.length()); 259 consumer.endElement("", "addeduser", "addeduser"); 260 } 261 } else { 262 String delete = request.getParameter("authdeluser"); 263 if (delete != null && delete.equals("true") == true) { 264 this.deleteUser(role, id, null, handler); 265 } else { 266 SourceParameters pars = new SourceParameters(); 267 Enumeration requestParameters = request.getParameterNames(); 269 String current; 270 while (requestParameters.hasMoreElements() == true) { 271 current = (String )requestParameters.nextElement(); 272 pars.setParameter(current, request.getParameter(current)); 273 } 274 this.changeUser(role, id, pars, handler); 275 } 276 } 277 session.removeAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE); 278 } 279 if (addingNewUserFailed == false) { 280 state = (isAdmin == true ? "adduser" : "seluser"); 281 } else { 282 state = "erruser"; 283 } 284 } 285 286 if (state.equals("seluser") == true) { 287 String role; 288 String id; 289 290 if (isAdmin == false) { 291 Map pars = context.getContextInfo(); 292 id = (String ) pars.get("ID"); 293 role = (String ) pars.get("role"); 294 } else { 295 role = request.getParameter(REQ_PARAMETER_ROLE); 296 id = request.getParameter(REQ_PARAMETER_ID); 297 } 298 if (role != null && id != null) { 299 session.setAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role); 300 301 Document userDF = this.getUsers(role, id, handler); 303 Element users = null; 304 try { 305 if (userDF != null) users = (Element )DOMUtil.getSingleNode(userDF, "users/user", this.xpathProcessor); 306 } catch (javax.xml.transform.TransformerException local) { 307 throw new ProcessingException("TransformerException: " + local, local); 308 } 309 consumer.startElement("", "uservalues", "uservalues", XMLUtils.EMPTY_ATTRIBUTES); 310 if (users != null && users.hasChildNodes() == true) { 311 NodeList childs = users.getChildNodes(); 312 for(int i = 0; i < childs.getLength(); i++) { 313 if (childs.item(i).getNodeType() == Node.ELEMENT_NODE) 314 IncludeXMLConsumer.includeNode(childs.item(i), consumer, consumer); 315 } 316 } 317 consumer.endElement("", "uservalues", "uservalues"); 318 } 319 consumer.startElement("", "user", "user", XMLUtils.EMPTY_ATTRIBUTES); 320 consumer.characters("old".toCharArray(), 0, 3); 321 consumer.endElement("", "user", "user"); 322 if (isAdmin == false) { 323 consumer.startElement("", "role", "role", XMLUtils.EMPTY_ATTRIBUTES); 324 consumer.characters(role.toCharArray(), 0, role.length()); 325 consumer.endElement("", "role", "role"); 326 } 327 } 328 329 if (state.equals("erruser") == true) { 330 String role; 331 String id; 332 333 if (isAdmin == false) { 334 Map pars = context.getContextInfo(); 335 id = (String ) pars.get("ID"); 336 role = (String ) pars.get("role"); 337 } else { 338 role = request.getParameter(REQ_PARAMETER_ROLE); 339 id = request.getParameter(REQ_PARAMETER_ID); 340 } 341 if (role != null && id != null) { 342 session.setAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role); 343 344 Document userDF = this.getUsers(role, id, handler); 346 Element users = null; 347 try { 348 if (userDF != null) users = (Element )DOMUtil.getSingleNode(userDF, "users/user", this.xpathProcessor); 349 } catch (javax.xml.transform.TransformerException local) { 350 throw new ProcessingException("TransformerException: " + local, local); 351 } 352 consumer.startElement("", "uservalues", "uservalues", XMLUtils.EMPTY_ATTRIBUTES); 353 if (users != null && users.hasChildNodes() == true) { 354 NodeList childs = users.getChildNodes(); 355 for(int i = 0; i < childs.getLength(); i++) { 356 if (childs.item(i).getNodeType() == Node.ELEMENT_NODE) 357 IncludeXMLConsumer.includeNode(childs.item(i), consumer, consumer); 358 } 359 } 360 consumer.endElement("", "uservalues", "uservalues"); 361 } 362 consumer.startElement("", "user", "user", XMLUtils.EMPTY_ATTRIBUTES); 363 consumer.characters("error".toCharArray(), 0, 5); 364 consumer.endElement("", "user", "user"); 365 if (isAdmin == false) { 366 consumer.startElement("", "role", "role", XMLUtils.EMPTY_ATTRIBUTES); 367 consumer.characters(role.toCharArray(), 0, role.length()); 368 consumer.endElement("", "role", "role"); 369 } 370 } 371 372 if (state.equals("adduser") == true) { 373 consumer.startElement("", "user", "user", XMLUtils.EMPTY_ATTRIBUTES); 374 consumer.characters("new".toCharArray(), 0, 3); 375 consumer.endElement("", "user", "user"); 376 } 377 378 if (state.equals("selrole") == true) { 379 String role = request.getParameter(REQ_PARAMETER_ROLE); 380 session.setAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role); 381 Document userDF = this.getUsers(role, null, handler); 383 Node users = null; 384 try { 385 if (userDF != null) users = DOMUtil.getSingleNode(userDF, "users", this.xpathProcessor); 386 } catch (javax.xml.transform.TransformerException local) { 387 throw new ProcessingException("TransformerException: " + local, local); 388 } 389 IncludeXMLConsumer.includeNode(users, consumer, consumer); 390 } 391 392 if (isAdmin == true) { 393 Document rolesDF = this.getRoles(handler); 395 Node roles = null; 396 try { 397 if (rolesDF != null) roles = DOMUtil.getSingleNode(rolesDF, "roles", this.xpathProcessor); 398 } catch (javax.xml.transform.TransformerException local) { 399 throw new ProcessingException("TransformerException: " + local, local); 400 } 401 IncludeXMLConsumer.includeNode(roles, consumer, consumer); 402 403 String role = (String )session.getAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE); 405 if (role != null) { 406 consumer.startElement("", "role", "role", XMLUtils.EMPTY_ATTRIBUTES); 407 consumer.characters(role.toCharArray(), 0, role.length()); 408 consumer.endElement("", "role", "role"); 409 } 410 } 411 } 413 consumer.endElement("", "configuration", "configuration"); 414 if (this.getLogger().isDebugEnabled() == true) { 415 this.getLogger().debug("END showConfiguration"); 416 } 417 } 418 419 436 public Document getUsers(String role, String ID, UserManagementHandler handler) 437 throws IOException , ProcessingException, SAXException { 438 if (this.getLogger().isDebugEnabled() == true) { 440 this.getLogger().debug("BEGIN getUsers role="+role+", ID="+ID); 441 } 442 Document frag = null; 443 444 if (handler.getLoadUsersResource() != null) { 445 final String loadUsersResource = handler.getLoadUsersResource(); 446 final SourceParameters loadParameters = handler.getLoadUsersResourceParameters(); 447 SourceParameters parameters = (loadParameters == null) ? new SourceParameters() 448 : (SourceParameters)loadParameters; 449 if (handler.getApplicationName() != null) { 450 parameters.setSingleParameterValue("application", handler.getApplicationName()); 451 } 452 if (ID != null) { 453 parameters.setSingleParameterValue("type", "user"); 454 parameters.setSingleParameterValue("ID", ID); 455 } else { 456 parameters.setSingleParameterValue("type", "users"); 457 } 458 if (role != null) parameters.setSingleParameterValue("role", role); 459 frag = this.loadResource(loadUsersResource, parameters); 460 461 } 462 463 if (this.getLogger().isDebugEnabled() == true) { 464 this.getLogger().debug("END getUsers fragment="+(frag == null ? "null" : XMLUtils.serializeNode(frag, XMLUtils.createPropertiesForXML(false)))); 465 } 466 return frag; 467 } 468 469 477 public Document getRoles(UserManagementHandler handler) 478 throws IOException , ProcessingException, SAXException { 479 if (this.getLogger().isDebugEnabled() == true) { 481 this.getLogger().debug("BEGIN getRoles"); 482 } 483 Document frag = null; 484 485 if (handler.getLoadRolesResource() != null) { 486 final String loadRolesResource = handler.getLoadRolesResource(); 487 final SourceParameters loadParameters = handler.getLoadRolesResourceParameters(); 488 SourceParameters parameters = (loadParameters == null) ? new SourceParameters() 489 : (SourceParameters)loadParameters.clone(); 490 if (handler.getApplicationName() != null) 491 parameters.setSingleParameterValue("application", handler.getApplicationName()); 492 parameters.setSingleParameterValue("type", "roles"); 493 frag = this.loadResource(loadRolesResource, parameters); 494 } 495 496 if (this.getLogger().isDebugEnabled() == true) { 497 this.getLogger().debug("END getRoles fragment="+frag); 498 } 499 return frag; 500 } 501 502 505 private void addRole(String name, SourceParameters parameters, UserManagementHandler handler) 506 throws IOException , ProcessingException, SAXException { 507 if (this.getLogger().isDebugEnabled() == true) { 509 this.getLogger().debug("BEGIN addRole role="+name+", parameters="+parameters); 510 } 511 if (handler.getNewRoleResource() != null) { 512 final String newRoleResource = handler.getNewRoleResource(); 513 final SourceParameters handlerPars = handler.getNewRoleResourceParameters(); 514 if (parameters == null) parameters = new SourceParameters(); 515 parameters.add(handlerPars); 516 517 if (handler.getApplicationName() != null) 518 parameters.setSingleParameterValue("application", handler.getApplicationName()); 519 parameters.setSingleParameterValue("type", "role"); 520 parameters.setSingleParameterValue("role", name); 521 522 this.invokeResource(newRoleResource, parameters); 523 } 524 525 if (this.getLogger().isDebugEnabled() == true) { 526 this.getLogger().debug("END addRole"); 527 } 528 } 529 530 534 public boolean addUser(String role, String ID, SourceParameters parameters, UserManagementHandler handler) 535 throws IOException , ProcessingException, SAXException { 536 if (this.getLogger().isDebugEnabled() == true) { 538 this.getLogger().debug("BEGIN addUser role="+role+", ID="+ID+", parameters="+parameters); 539 } 540 boolean result = false; 541 542 if (handler.getNewUserResource() != null 543 && ID != null 544 && ID.trim().length() > 0) { 545 Document user = this.getUsers(null, null, handler); 547 Node node = null; 548 if (user != null) { 549 try { 550 node = DOMUtil.getSingleNode(user, "users/user/ID[text()='"+ID+"']", this.xpathProcessor); 551 } catch (javax.xml.transform.TransformerException local) { 552 throw new ProcessingException("Transformer exception: " + local, local); 553 } 554 } 555 if (user == null || node == null) { 556 final String newUserResource = handler.getNewUserResource(); 557 final SourceParameters newUsersPars = handler.getNewUserResourceParameters(); 558 if (parameters == null) parameters = new SourceParameters(); 559 parameters.add(newUsersPars); 560 561 if (handler.getApplicationName() != null) 562 parameters.setSingleParameterValue("application", handler.getApplicationName()); 563 parameters.setSingleParameterValue("type", "user"); 564 parameters.setSingleParameterValue("role", role); 565 parameters.setSingleParameterValue("ID", ID); 566 567 this.invokeResource(newUserResource, parameters); 568 result = true; 569 } 570 } 571 572 if (this.getLogger().isDebugEnabled() == true) { 573 this.getLogger().debug("END addUser success="+result); 574 } 575 return result; 576 } 577 578 581 private void deleteRole(String name, SourceParameters parameters, UserManagementHandler handler) 582 throws IOException , ProcessingException, SAXException { 583 if (this.getLogger().isDebugEnabled() == true) { 585 this.getLogger().debug("BEGIN deleteRole role="+name+", parameters="+parameters); 586 } 587 if (handler.getDeleteRoleResource() != null) { 588 final String deleteRoleResource = handler.getDeleteRoleResource(); 589 final SourceParameters handlerPars = handler.getDeleteRoleResourceParameters(); 590 if (parameters == null) parameters = new SourceParameters(); 591 parameters.add(handlerPars); 592 593 if (handler.getApplicationName() != null) 594 parameters.setSingleParameterValue("application", handler.getApplicationName()); 595 parameters.setSingleParameterValue("type", "role"); 596 parameters.setSingleParameterValue("role", name); 597 598 this.invokeResource(deleteRoleResource, parameters); 599 } 600 601 if (this.getLogger().isDebugEnabled() == true) { 602 this.getLogger().debug("END deleteRole"); 603 } 604 } 605 606 609 private void deleteUser(String role, String name, SourceParameters parameters, UserManagementHandler handler) 610 throws IOException , ProcessingException, SAXException { 611 if (this.getLogger().isDebugEnabled() == true) { 613 this.getLogger().debug("BEGIN deleteUser role="+role+", ID="+name+", parameters="+parameters); 614 } 615 if (handler.getDeleteUserResource() != null) { 616 final String deleteUserResource = handler.getDeleteUserResource(); 617 final SourceParameters handlerPars = handler.getDeleteUserResourceParameters(); 618 if (parameters == null) parameters = new SourceParameters(); 619 parameters.add(handlerPars); 620 621 if (handler.getApplicationName() != null) 622 parameters.setSingleParameterValue("application", handler.getApplicationName()); 623 parameters.setSingleParameterValue("type", "user"); 624 parameters.setSingleParameterValue("role", role); 625 parameters.setSingleParameterValue("ID", name); 626 627 this.invokeResource(deleteUserResource, parameters); 628 } 629 630 if (this.getLogger().isDebugEnabled() == true) { 631 this.getLogger().debug("END deleteUser"); 632 } 633 } 634 635 638 private void changeUser(String role, String name, SourceParameters parameters, UserManagementHandler handler) 639 throws IOException , ProcessingException, SAXException { 640 if (this.getLogger().isDebugEnabled() == true) { 642 this.getLogger().debug("BEGIN changeUser role="+role+", ID="+name+", parameters="+parameters); 643 } 644 if (handler.getChangeUserResource() != null) { 645 final String changeUserResource = handler.getChangeUserResource(); 646 final SourceParameters handlerPars = handler.getChangeUserResourceParameters(); 647 if (parameters == null) parameters = new SourceParameters(); 648 parameters.add(handlerPars); 649 650 if (handler.getApplicationName() != null) 651 parameters.setSingleParameterValue("application", handler.getApplicationName()); 652 parameters.setSingleParameterValue("type", "user"); 653 parameters.setSingleParameterValue("role", role); 654 parameters.setSingleParameterValue("ID", name); 655 656 this.invokeResource(changeUserResource, parameters); 657 } 658 659 if (this.getLogger().isDebugEnabled() == true) { 660 this.getLogger().debug("END changeUser"); 661 } 662 } 663 664 667 private void invokeResource(String resource, 668 SourceParameters parameters) 669 throws IOException , ProcessingException, SAXException { 670 Source source = null; 671 try { 672 source = SourceUtil.getSource(resource, 673 null, 674 parameters, 675 this.resolver); 676 SourceUtil.parse(this.manager, source, new DefaultHandler ()); 677 } catch (SourceException se) { 678 throw SourceUtil.handle(se); 679 } finally { 680 this.resolver.release(source); 681 } 682 } 683 684 687 private Document loadResource(String resource, 688 SourceParameters parameters) 689 throws IOException , ProcessingException, SAXException { 690 Source source = null; 691 try { 692 source = SourceUtil.getSource(resource, 693 null, 694 parameters, 695 this.resolver); 696 return SourceUtil.toDOM(source); 697 } catch (SourceException se) { 698 throw SourceUtil.handle(se); 699 } finally { 700 this.resolver.release(source); 701 } 702 } 703 } 704 705 final class UserManagementHandler { 706 707 708 private String applicationName; 709 710 711 private String loadUsersResource; 712 private SourceParameters loadUsersResourceParameters; 713 714 715 private String loadRolesResource; 716 private SourceParameters loadRolesResourceParameters; 717 718 719 private String newUserResource; 720 private SourceParameters newUserResourceParameters; 721 722 723 private String newRoleResource; 724 private SourceParameters newRoleResourceParameters; 725 726 727 private String deleteRoleResource; 728 private SourceParameters deleteRoleResourceParameters; 729 730 731 private String deleteUserResource; 732 private SourceParameters deleteUserResourceParameters; 733 734 735 private String changeUserResource; 736 private SourceParameters changeUserResourceParameters; 737 738 741 public UserManagementHandler(Configuration conf, 742 String appName) 743 throws ConfigurationException { 744 Configuration child; 745 746 this.applicationName = appName; 747 748 child = conf.getChild("load-users", false); 750 if (child != null) { 751 this.loadUsersResource = child.getAttribute("uri"); 752 this.loadUsersResourceParameters = SourceParameters.create(child); 753 } 754 755 child = conf.getChild("load-roles", false); 757 if (child != null) { 758 this.loadRolesResource = child.getAttribute("uri"); 759 this.loadRolesResourceParameters = SourceParameters.create(child); 760 } 761 762 child = conf.getChild("new-user", false); 764 if (child != null) { 765 this.newUserResource = child.getAttribute("uri"); 766 this.newUserResourceParameters = SourceParameters.create(child); 767 } 768 769 child = conf.getChild("new-role", false); 771 if (child != null) { 772 this.newRoleResource = child.getAttribute("uri"); 773 this.newRoleResourceParameters = SourceParameters.create(child); 774 } 775 776 child = conf.getChild("delete-user", false); 778 if (child != null) { 779 this.deleteUserResource = child.getAttribute("uri"); 780 this.deleteUserResourceParameters = SourceParameters.create(child); 781 } 782 783 child = conf.getChild("delete-role", false); 785 if (child != null) { 786 this.deleteRoleResource = child.getAttribute("uri"); 787 this.deleteRoleResourceParameters = SourceParameters.create(child); 788 } 789 790 child = conf.getChild("change-user", false); 792 if (child != null) { 793 this.changeUserResource = child.getAttribute("uri"); 794 this.changeUserResourceParameters = SourceParameters.create(child); 795 } 796 } 797 798 801 public String getApplicationName() { return this.applicationName; } 802 803 806 public String getLoadUsersResource() { return this.loadUsersResource; } 807 public SourceParameters getLoadUsersResourceParameters() { return this.loadUsersResourceParameters; } 808 809 812 public String getLoadRolesResource() { return this.loadRolesResource; } 813 public SourceParameters getLoadRolesResourceParameters() { return this.loadRolesResourceParameters; } 814 815 818 public String getNewUserResource() { return this.newUserResource; } 819 public SourceParameters getNewUserResourceParameters() { return this.newUserResourceParameters; } 820 821 824 public String getNewRoleResource() { return this.newRoleResource; } 825 public SourceParameters getNewRoleResourceParameters() { return this.newRoleResourceParameters; } 826 827 828 public String getDeleteUserResource() { return this.deleteUserResource; } 829 public SourceParameters getDeleteUserResourceParameters() { return this.deleteUserResourceParameters; } 830 831 832 public String getDeleteRoleResource() { return this.deleteRoleResource; } 833 public SourceParameters getDeleteRoleResourceParameters() { return this.deleteRoleResourceParameters; } 834 835 836 public String getChangeUserResource() { return this.changeUserResource; } 837 public SourceParameters getChangeUserResourceParameters() { return this.changeUserResourceParameters; } 838 } 839 | Popular Tags |