28 import java.io.ByteArrayOutputStream; |
28 import java.io.ByteArrayOutputStream; |
29 import java.io.File; |
29 import java.io.File; |
30 import java.io.FileOutputStream; |
30 import java.io.FileOutputStream; |
31 import java.io.IOException; |
31 import java.io.IOException; |
32 import java.io.InputStream; |
32 import java.io.InputStream; |
|
33 import java.io.ObjectInput; |
33 import java.io.ObjectInputStream; |
34 import java.io.ObjectInputStream; |
34 import java.io.OutputStream; |
35 import java.io.OutputStream; |
35 import java.io.PrintStream; |
36 import java.io.PrintStream; |
36 import java.io.PrintWriter; |
37 import java.io.PrintWriter; |
37 import java.io.Serializable; |
38 import java.io.Serializable; |
103 import java.util.concurrent.ConcurrentHashMap; |
104 import java.util.concurrent.ConcurrentHashMap; |
104 import sun.rmi.log.LogHandler; |
105 import sun.rmi.log.LogHandler; |
105 import sun.rmi.log.ReliableLog; |
106 import sun.rmi.log.ReliableLog; |
106 import sun.rmi.registry.RegistryImpl; |
107 import sun.rmi.registry.RegistryImpl; |
107 import sun.rmi.runtime.NewThreadAction; |
108 import sun.rmi.runtime.NewThreadAction; |
108 import sun.rmi.server.UnicastServerRef; |
|
109 import sun.rmi.transport.LiveRef; |
109 import sun.rmi.transport.LiveRef; |
110 import sun.security.provider.PolicyFile; |
110 import sun.security.provider.PolicyFile; |
111 import com.sun.rmi.rmid.ExecPermission; |
111 import com.sun.rmi.rmid.ExecPermission; |
112 import com.sun.rmi.rmid.ExecOptionPermission; |
112 import com.sun.rmi.rmid.ExecOptionPermission; |
113 |
113 |
486 getGroupEntry(id).inactiveGroup(incarnation, false); |
489 getGroupEntry(id).inactiveGroup(incarnation, false); |
487 } |
490 } |
488 } |
491 } |
489 |
492 |
490 |
493 |
|
494 /** |
|
495 * SameHostOnlyServerRef checks that access is from a local client |
|
496 * before the parameters are deserialized. The unmarshalCustomCallData |
|
497 * hook is used to check the network address of the caller |
|
498 * with RegistryImpl.checkAccess(). |
|
499 * The kind of access is retained for an exception if one is thrown. |
|
500 */ |
|
501 static class SameHostOnlyServerRef extends UnicastServerRef { |
|
502 private static final long serialVersionUID = 1234L; |
|
503 private String accessKind; // an exception message |
|
504 |
|
505 /** |
|
506 * Construct a new SameHostOnlyServerRef from a LiveRef. |
|
507 * @param lref a LiveRef |
|
508 */ |
|
509 SameHostOnlyServerRef(LiveRef lref, String accessKind) { |
|
510 super(lref); |
|
511 this.accessKind = accessKind; |
|
512 } |
|
513 |
|
514 @Override |
|
515 protected void unmarshalCustomCallData(ObjectInput in) throws IOException, ClassNotFoundException { |
|
516 RegistryImpl.checkAccess(accessKind); |
|
517 super.unmarshalCustomCallData(in); |
|
518 } |
|
519 } |
|
520 |
491 class ActivationSystemImpl |
521 class ActivationSystemImpl |
492 extends RemoteServer |
522 extends RemoteServer |
493 implements ActivationSystem |
523 implements ActivationSystem |
494 { |
524 { |
495 private static final long serialVersionUID = 9100152600327688967L; |
525 private static final long serialVersionUID = 9100152600327688967L; |
503 { |
533 { |
504 /* Server ref must be created and assigned before remote object |
534 /* Server ref must be created and assigned before remote object |
505 * 'this' can be exported. |
535 * 'this' can be exported. |
506 */ |
536 */ |
507 LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf); |
537 LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf); |
508 UnicastServerRef uref = new UnicastServerRef(lref); |
538 UnicastServerRef uref = new SameHostOnlyServerRef(lref, |
|
539 "ActivationSystem.nonLocalAccess"); |
509 ref = uref; |
540 ref = uref; |
510 uref.exportObject(this, null); |
541 uref.exportObject(this, null); |
511 } |
542 } |
512 |
543 |
513 public ActivationID registerObject(ActivationDesc desc) |
544 public ActivationID registerObject(ActivationDesc desc) |
514 throws ActivationException, UnknownGroupException, RemoteException |
545 throws ActivationException, UnknownGroupException, RemoteException |
515 { |
546 { |
516 checkShutdown(); |
547 checkShutdown(); |
517 RegistryImpl.checkAccess("ActivationSystem.registerObject"); |
548 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
518 |
549 // during unmarshallCustomData and is not applicable to local access. |
519 ActivationGroupID groupID = desc.getGroupID(); |
550 ActivationGroupID groupID = desc.getGroupID(); |
520 ActivationID id = new ActivationID(activatorStub); |
551 ActivationID id = new ActivationID(activatorStub); |
521 getGroupEntry(groupID).registerObject(id, desc, true); |
552 getGroupEntry(groupID).registerObject(id, desc, true); |
522 return id; |
553 return id; |
523 } |
554 } |
524 |
555 |
525 public void unregisterObject(ActivationID id) |
556 public void unregisterObject(ActivationID id) |
526 throws ActivationException, UnknownObjectException, RemoteException |
557 throws ActivationException, UnknownObjectException, RemoteException |
527 { |
558 { |
528 checkShutdown(); |
559 checkShutdown(); |
529 RegistryImpl.checkAccess("ActivationSystem.unregisterObject"); |
560 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
|
561 // during unmarshallCustomData and is not applicable to local access. |
530 getGroupEntry(id).unregisterObject(id, true); |
562 getGroupEntry(id).unregisterObject(id, true); |
531 } |
563 } |
532 |
564 |
533 public ActivationGroupID registerGroup(ActivationGroupDesc desc) |
565 public ActivationGroupID registerGroup(ActivationGroupDesc desc) |
534 throws ActivationException, RemoteException |
566 throws ActivationException, RemoteException |
535 { |
567 { |
536 checkShutdown(); |
568 checkShutdown(); |
537 RegistryImpl.checkAccess("ActivationSystem.registerGroup"); |
569 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
|
570 // during unmarshallCustomData and is not applicable to local access. |
538 checkArgs(desc, null); |
571 checkArgs(desc, null); |
539 |
572 |
540 ActivationGroupID id = new ActivationGroupID(systemStub); |
573 ActivationGroupID id = new ActivationGroupID(systemStub); |
541 GroupEntry entry = new GroupEntry(id, desc); |
574 GroupEntry entry = new GroupEntry(id, desc); |
542 // table insertion must take place before log update |
575 // table insertion must take place before log update |
549 ActivationInstantiator group, |
582 ActivationInstantiator group, |
550 long incarnation) |
583 long incarnation) |
551 throws ActivationException, UnknownGroupException, RemoteException |
584 throws ActivationException, UnknownGroupException, RemoteException |
552 { |
585 { |
553 checkShutdown(); |
586 checkShutdown(); |
554 RegistryImpl.checkAccess("ActivationSystem.activeGroup"); |
587 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
|
588 // during unmarshallCustomData and is not applicable to local access. |
555 |
589 |
556 getGroupEntry(id).activeGroup(group, incarnation); |
590 getGroupEntry(id).activeGroup(group, incarnation); |
557 return monitor; |
591 return monitor; |
558 } |
592 } |
559 |
593 |
560 public void unregisterGroup(ActivationGroupID id) |
594 public void unregisterGroup(ActivationGroupID id) |
561 throws ActivationException, UnknownGroupException, RemoteException |
595 throws ActivationException, UnknownGroupException, RemoteException |
562 { |
596 { |
563 checkShutdown(); |
597 checkShutdown(); |
564 RegistryImpl.checkAccess("ActivationSystem.unregisterGroup"); |
598 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
|
599 // during unmarshallCustomData and is not applicable to local access. |
565 |
600 |
566 // remove entry before unregister so state is updated before |
601 // remove entry before unregister so state is updated before |
567 // logged |
602 // logged |
568 removeGroupEntry(id).unregisterGroup(true); |
603 removeGroupEntry(id).unregisterGroup(true); |
569 } |
604 } |
571 public ActivationDesc setActivationDesc(ActivationID id, |
606 public ActivationDesc setActivationDesc(ActivationID id, |
572 ActivationDesc desc) |
607 ActivationDesc desc) |
573 throws ActivationException, UnknownObjectException, RemoteException |
608 throws ActivationException, UnknownObjectException, RemoteException |
574 { |
609 { |
575 checkShutdown(); |
610 checkShutdown(); |
576 RegistryImpl.checkAccess("ActivationSystem.setActivationDesc"); |
611 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
|
612 // during unmarshallCustomData and is not applicable to local access. |
577 |
613 |
578 if (!getGroupID(id).equals(desc.getGroupID())) { |
614 if (!getGroupID(id).equals(desc.getGroupID())) { |
579 throw new ActivationException( |
615 throw new ActivationException( |
580 "ActivationDesc contains wrong group"); |
616 "ActivationDesc contains wrong group"); |
581 } |
617 } |
585 public ActivationGroupDesc setActivationGroupDesc(ActivationGroupID id, |
621 public ActivationGroupDesc setActivationGroupDesc(ActivationGroupID id, |
586 ActivationGroupDesc desc) |
622 ActivationGroupDesc desc) |
587 throws ActivationException, UnknownGroupException, RemoteException |
623 throws ActivationException, UnknownGroupException, RemoteException |
588 { |
624 { |
589 checkShutdown(); |
625 checkShutdown(); |
590 RegistryImpl.checkAccess( |
626 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
591 "ActivationSystem.setActivationGroupDesc"); |
627 // during unmarshallCustomData and is not applicable to local access. |
592 |
628 |
593 checkArgs(desc, null); |
629 checkArgs(desc, null); |
594 return getGroupEntry(id).setActivationGroupDesc(id, desc, true); |
630 return getGroupEntry(id).setActivationGroupDesc(id, desc, true); |
595 } |
631 } |
596 |
632 |
597 public ActivationDesc getActivationDesc(ActivationID id) |
633 public ActivationDesc getActivationDesc(ActivationID id) |
598 throws ActivationException, UnknownObjectException, RemoteException |
634 throws ActivationException, UnknownObjectException, RemoteException |
599 { |
635 { |
600 checkShutdown(); |
636 checkShutdown(); |
601 RegistryImpl.checkAccess("ActivationSystem.getActivationDesc"); |
637 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
|
638 // during unmarshallCustomData and is not applicable to local access. |
602 |
639 |
603 return getGroupEntry(id).getActivationDesc(id); |
640 return getGroupEntry(id).getActivationDesc(id); |
604 } |
641 } |
605 |
642 |
606 public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID id) |
643 public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID id) |
607 throws ActivationException, UnknownGroupException, RemoteException |
644 throws ActivationException, UnknownGroupException, RemoteException |
608 { |
645 { |
609 checkShutdown(); |
646 checkShutdown(); |
610 RegistryImpl.checkAccess |
647 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
611 ("ActivationSystem.getActivationGroupDesc"); |
648 // during unmarshallCustomData and is not applicable to local access. |
612 |
649 |
613 return getGroupEntry(id).desc; |
650 return getGroupEntry(id).desc; |
614 } |
651 } |
615 |
652 |
616 /** |
653 /** |
617 * Shutdown the activation system. Destroys all groups spawned by |
654 * Shutdown the activation system. Destroys all groups spawned by |
618 * the activation daemon and exits the activation daemon. |
655 * the activation daemon and exits the activation daemon. |
619 */ |
656 */ |
620 public void shutdown() throws AccessException { |
657 public void shutdown() throws AccessException { |
621 RegistryImpl.checkAccess("ActivationSystem.shutdown"); |
658 // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef |
|
659 // during unmarshallCustomData and is not applicable to local access. |
622 |
660 |
623 Object lock = startupLock; |
661 Object lock = startupLock; |
624 if (lock != null) { |
662 if (lock != null) { |
625 synchronized (lock) { |
663 synchronized (lock) { |
626 // nothing |
664 // nothing |