📄 nonemembershipservice.java
字号:
// FIXME bondolo@jxta.org 20030409 should check for duplicate elements and for peergroup element } /** * Add a listener * * @param listener the listener **/ public void addPropertyChangeListener( PropertyChangeListener listener ) { support.addPropertyChangeListener(listener ); } /** * Add a listener * * @param propertyName the property to watch * @param listener the listener **/ public void addPropertyChangeListener( String propertyName, PropertyChangeListener listener ) { support.addPropertyChangeListener( propertyName, listener ); } /** * Remove a listener * * @param listener the listener **/ public void removePropertyChangeListener( PropertyChangeListener listener ) { support.removePropertyChangeListener( listener ); } /** * Remove a listener * * @param propertyName the property which was watched * @param listener the listener **/ public void removePropertyChangeListener( String propertyName, PropertyChangeListener listener ) { support.removePropertyChangeListener( propertyName, listener ); } } /** * Authenticator Class for the None Membership Service. Pre-filled in and * ready for <code>join()</code>. **/ public final static class NoneAuthenticator implements Authenticator { MembershipService source; AuthenticationCredential application; String whoami = "nobody"; /** * Creates an authenticator for the null membership service. Anything entered * into the identity info section of the Authentication credential is * ignored. * * @param source The instance of the null membership service which * created this authenticator. * @param application Anything entered into the identity info section of * the Authentication credential is ignored. **/ NoneAuthenticator( NoneMembershipService source, AuthenticationCredential application ) { this.source = source; this.application = application; } /** * Returns the service which generated this authenticator. **/ public MembershipService getSourceService() { return source; } /** * {@inheritDoc} * * <p/>This implementation is <strong>always</strong> ready for * <code>join()</code> **/ synchronized public boolean isReadyForJoin() { // always ready. return true; } /** * {@inheritDoc} **/ public String getMethodName() { return "NullAuthentication"; } /** * {@inheritDoc} **/ public AuthenticationCredential getAuthenticationCredential() { return application; } public void setAuth1Identity( String who ) { if( null == who ) { throw new IllegalArgumentException( "You must supply an identity" ); } whoami = who; } public String getAuth1Identity() { return whoami; } } private ModuleImplAdvertisement implAdvertisement = null; /** * The peergroup we live in. **/ private PeerGroup peergroup = null; /** * our current credentials **/ private List principals; /** * our current auth credentials **/ private List principalsAuth; /** * the default "nobody" credential **/ private NoneCredential defaultCredential = null; /** * property change support **/ private PropertyChangeSupport support; /** * default constructor. Normally called only by the peer group. **/ public NoneMembershipService() throws PeerGroupException { principals = new ArrayList(); principalsAuth = new ArrayList(); support = new PropertyChangeSupport(getInterface()); } /** * Add a listener * * @param listener the listener **/ public void addPropertyChangeListener( PropertyChangeListener listener ) { support.addPropertyChangeListener(listener ); } /** * Add a listener * * @param propertyName the property to watch * @param listener the listener **/ public void addPropertyChangeListener( String propertyName, PropertyChangeListener listener ) { support.addPropertyChangeListener( propertyName, listener ); } /** * Remove a listener * * @param listener the listener **/ public void removePropertyChangeListener( PropertyChangeListener listener ) { support.removePropertyChangeListener( listener ); } /** * Remove a listener * * @param propertyName the property which was watched * @param listener the listener **/ public void removePropertyChangeListener( String propertyName, PropertyChangeListener listener ) { support.removePropertyChangeListener( propertyName, listener ); } /** * {@inheritDoc} **/ public void init( PeerGroup group, ID assignedID, Advertisement impl ) throws PeerGroupException { implAdvertisement = (ModuleImplAdvertisement) impl; peergroup = group; if (LOG.isEnabledFor(Level.INFO)) { StringBuffer configInfo = new StringBuffer( "Configuring None Membership Service : " + assignedID ); configInfo.append( "\n\tImplementation:" ); configInfo.append("\n\t\tModule Spec ID: " + implAdvertisement.getModuleSpecID()); configInfo.append("\n\t\tImpl Description : " + implAdvertisement.getDescription()); configInfo.append("\n\t\tImpl URI : " + implAdvertisement.getUri()); configInfo.append("\n\t\tImpl Code : " + implAdvertisement.getCode()); configInfo.append( "\n\tGroup Params:" ); configInfo.append( "\n\t\tGroup: " + group.getPeerGroupName() ); configInfo.append( "\n\t\tGroup ID: " + group.getPeerGroupID() ); configInfo.append( "\n\t\tPeer ID: " + group.getPeerID() ); LOG.info( configInfo ); } defaultCredential = new NoneCredential( this, "nobody" ); resign(); } /** * {@inheritDoc} **/ public Service getInterface() { return this; // we have no method access control } /** * {@inheritDoc} **/ public int startApp(String[] arg) { return 0; } /** * {@inheritDoc} **/ public void stopApp() { resign(); peergroup = null; } /** * {@inheritDoc} **/ public Advertisement getImplAdvertisement() { return implAdvertisement; } /** * {@inheritDoc} **/ public Authenticator apply(AuthenticationCredential application) throws PeerGroupException, ProtocolNotSupportedException { String method = application.getMethod(); if( (null != method) && !"StringAuthentication".equals( method ) && !"NoneAuthentication".equals( method ) ) { throw new ProtocolNotSupportedException( "Authentication method not recognized" ); } return new NoneAuthenticator( this, application ); } /** * {@inheritDoc} **/ public Credential getDefaultCredential() { return defaultCredential; } /** * {@inheritDoc} **/ public synchronized Enumeration getCurrentCredentials() { return Collections.enumeration(principals); } /** * {@inheritDoc} **/ public synchronized Enumeration getAuthCredentials() { return Collections.enumeration(principalsAuth); } /** * {@inheritDoc} **/ public Credential join(Authenticator authenticated) throws PeerGroupException { if( !(authenticated instanceof NoneAuthenticator) ) { throw new ClassCastException( "This is not my authenticator!" ); } if( !authenticated.isReadyForJoin() ) { throw new PeerGroupException( "Not ready to join()!" ); } NoneAuthenticator myAuthenticated = (NoneAuthenticator) authenticated; Credential newCred; synchronized( this ) { newCred = new NoneCredential( this, myAuthenticated.getAuth1Identity() ); principals.add( newCred ); principalsAuth.add( myAuthenticated.application ); } support.firePropertyChange( "addCredential", null, newCred ); return newCred; } /** * {@inheritDoc} **/ public void resign() { List allCreds = new ArrayList(); allCreds.addAll( principals ); allCreds.remove( defaultCredential ); synchronized( this ) { // remove all existing credentials principals.clear(); principalsAuth.clear(); // re-add the default credential. principals.add( defaultCredential ); } Iterator eachCred = allCreds.iterator(); while( eachCred.hasNext() ) { NoneCredential aCred = (NoneCredential) eachCred.next(); aCred.setValid( false ); } } /** * {@inheritDoc} **/ public Credential makeCredential(Element element) throws PeerGroupException, Exception { return new NoneCredential( this, element ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -