• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 1025

Show
Ignore:
Timestamp:
10/09/06 19:05:53 (2 years ago)
Author:
jmoore
Message:

#326 Implemented WeakHashMap?<Object,EventContext?> for stateful services.

Location:
trunk/components/server/src/ome
Files:
6 modified

  • logic/AbstractBean.java (modified) (3 diffs)
  • security/basic/BasicSecuritySystem.java (modified) (1 diff)
  • security/basic/CurrentDetails.java (modified) (1 diff)
  • security/basic/EventHandler.java (modified) (5 diffs)
  • services/RawPixelsBean.java (modified) (2 diffs)
  • services/RenderingBean.java (modified) (1 diff)

Legend:

Unmodified
Added
Removed
  • trunk/components/server/src/ome/logic/AbstractBean.java

    r903 r1025  
    5050import ome.security.SecuritySystem; 
    5151import ome.services.query.QueryFactory; 
     52import ome.system.EventContext; 
    5253import ome.system.OmeroContext; 
    5354import ome.system.Principal; 
    … …  
    8283    private @Resource SessionContext sessionContext; 
    8384 
     85    protected boolean contextLoaded = true; // always true for stateless services. 
     86 
    8487    // ~ Lifecycle implementations 
    8588        // ========================================================================= 
    … …  
    109112                    (ProxyFactoryBean) applicationContext.getBean(factoryName), 
    110113                    context ); 
     114            if (!contextLoaded) 
     115            { 
     116                adapter.getUserAttributes().put( EventContext.class, Boolean.TRUE ); 
     117                contextLoaded = true; 
     118            } 
    111119            return adapter.proceed( );    
    112120        } catch (Throwable t) { 
  • trunk/components/server/src/ome/security/basic/BasicSecuritySystem.java

    r1006 r1025  
    10131013        { 
    10141014                final Principal p = clearAndCheckPrincipal(); 
    1015                 throw new UnsupportedOperationException("not implemented."); 
     1015                 
     1016                if ( ! (context instanceof BasicEventContext) ) 
     1017                        throw new ApiUsageException( "BasicSecuritySystem can only accept " + 
     1018                                        "BasicEventContext instances."); 
     1019                 
     1020                final BasicEventContext bec = (BasicEventContext) context; 
     1021                final String u_name = bec.getCurrentUserName(); 
     1022                final String g_name = bec.getCurrentGroupName(); 
     1023                final String t_name = bec.getCurrentEventType(); 
     1024                 
     1025                if ( p.getName().equals( u_name ) &&  
     1026                                p.getGroup().equals( g_name ) && 
     1027                                p.getEventType().equals( t_name )) 
     1028                { 
     1029                        cd.setCurrentEventContext( bec ); 
     1030                }  
     1031                 
     1032                else 
     1033                { 
     1034                        throw new InternalException(String.format( 
     1035                                        "Principal:%s/%s/%s does not match Context:%s/%s/%s", 
     1036                                        p.getName(),p.getGroup(),p.getEventType(), 
     1037                                        u_name,g_name,t_name)); 
     1038                } 
    10161039        } 
    10171040 
  • trunk/components/server/src/ome/security/basic/CurrentDetails.java

    r992 r1025  
    9696        return data.get(); 
    9797    } 
     98     
     99    void setCurrentEventContext( BasicEventContext bec ) 
     100    { 
     101        data.set( bec ); 
     102    } 
    98103 
    99104    private Details getDetails() 
  • trunk/components/server/src/ome/security/basic/EventHandler.java

    r992 r1025  
    5858import ome.model.meta.EventLog; 
    5959import ome.system.EventContext; 
     60import ome.tools.spring.AOPAdapter; 
    6061 
    6162/** 
    … …  
    8687     
    8788    // for StatefulServices TODO 
    88     private Map<Session, Event> events = Collections 
    89     .synchronizedMap(new WeakHashMap<Session, Event>()); 
     89    private Map<Object, EventContext> objCtxMap = Collections 
     90    .synchronizedMap(new WeakHashMap<Object, EventContext>()); 
    9091 
    9192    /** only public constructor, used for dependency injection. Requires an  
    … …  
    113114    { 
    114115        boolean readOnly = checkReadOnly(arg0); 
    115         secSys.loadEventContext(readOnly); 
    116         // TODO check for an existing session here. 
     116        boolean stateful = StatefulServiceInterface.class.isAssignableFrom( 
     117                        arg0.getThis().getClass()); 
     118         
     119        if ( stateful ) 
     120        { 
     121                        EventContext prevCtx = objCtxMap.get( arg0.getThis() ); 
     122                        boolean      needCtx = false; 
     123                        if ( arg0 instanceof AOPAdapter ) 
     124                        { 
     125                                // TODO needs refactoring. Perhaps better to add this to 
     126                                // SecuritySystem. Or when OmeroContext is reworked, that this 
     127                                // is added to that interface. 
     128                                AOPAdapter adapter = (AOPAdapter) arg0; 
     129                                Map attributes = adapter.getUserAttributes(); 
     130                                if ( attributes != null ) 
     131                                { 
     132                                        Object o = attributes.get( EventContext.class ); 
     133                                        if ( o instanceof Boolean && ((Boolean)o).booleanValue() ) 
     134                                        { 
     135                                                needCtx = true; 
     136                                        } 
     137                                } 
     138                        } 
     139 
     140                        if ( null == prevCtx ) 
     141                        { 
     142                                if ( ! needCtx ) 
     143                                { 
     144                                        throw new InternalException(  
     145                                                "Stateful service missing context." ); 
     146                                } 
     147                                 
     148                                else  
     149                                { 
     150                                        secSys.loadEventContext(false); 
     151                                        objCtxMap.put( arg0.getThis(), secSys.getEventContext() ); 
     152                                        prevCtx = secSys.getEventContext(); 
     153                                }        
     154                        } 
     155                        secSys.setEventContext( prevCtx ); 
     156        } 
     157         
     158        else // stateless 
     159        { 
     160                // this is usually done manually by stateful services  
     161                // in their @PostConstruct methods 
     162                secSys.loadEventContext(readOnly); 
     163        } 
    117164 
    118165        // now the user can be considered to be logged in. 
    … …  
    134181        } finally { 
    135182                try { 
    136                          
    137                         boolean stateful = (arg0.getThis() instanceof StatefulServiceInterface); 
    138183 
    139184                        // on failure, we want to make sure that no one attempts  
    … …  
    293338        public Object doInHibernate(Session session)  
    294339        throws HibernateException, SQLException { 
    295                 if (session.isDirty()) 
     340                boolean dirty = session.isDirty(); 
     341                if (dirty) 
    296342                { 
    297343                        throw new InternalException("Session is dirty. Cannot properly " + 
  • trunk/components/server/src/ome/services/RawPixelsBean.java

    r903 r1025  
    100100    } 
    101101     
     102    public RawPixelsBean() 
     103    { 
     104        super.contextLoaded = false; 
     105    } 
     106     
    102107    public final void setPixelsMetadata(IPixels metaService) 
    103108    { 
    … …  
    142147    // ========================================================================= 
    143148     
    144     @RolesAllowed("user")  
     149    @RolesAllowed("user") 
    145150    public void setPixelsId( long pixelsId ) 
    146151    { 
  • trunk/components/server/src/ome/services/RenderingBean.java

    r1024 r1025  
    185185    private transient ReentrantReadWriteLock         rwl  
    186186        = new ReentrantReadWriteLock(); 
     187 
     188    public RenderingBean() 
     189    { 
     190        super.contextLoaded = false; 
     191    } 
    187192     
    188193    /** set injector. For use during configuration. Can only be called once. */ 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/