<message>
<community>ivo://ast.cam.ac.uk</community>
<name>dave</name>
<pass>####</pass>
</message>
<response>
<account>ivo://ast.cam.ac.uk/dave</account>
<token>2347834589tafc\sd9q359\sv</token>
</response>
public class ComponentAction extends AbstractAction
{
....
public Map act(....)
{
//
// Create a SecurityContextHelper.
SecurityContextHelper securityContext = new CocoonSecurityContextHelper(request, session, objectModel) ;
//
// Get the current Account from the SecurityContextHelper.
AccountDetails account = securityContext.getAccount() ;
....
}
}
<header>
<wsse:UsernameToken>
<wsse:Username>ivo://ast.cam.ac.uk/dave|ivo://star.le.ac.uk/xray-studies</wsse:Username>
<astrogrid:IdentityToken>2347834589tafc\sd9q359\sv</astrogrid:IdentityToken>
</wsee:UsernameToken>
</header>
<message>
<job>
<query>details of the ADQL query</query>
....
</job>
</message>
public Object jobEntryMethod(Object params ...)
{
//
// Get a SecurityDelegate.
SecurityDelegate securityDelegate = SecurityDelegateFactory.getSecurityDelegate() ;
//
// Get the message SecurityContext from the delegate
SecurityContext securityContext = securityDelegate.getSecurityContext() ;
//
// Check that the message sender has been authenticated.
if (securityContext.isAuthenticated())
{
//
// Perform the service for an authenticated Account.
//
}
//
// If the message sender has not been authenticated.
else {
//
// Perform the service for an anonymous user ?
//
}
}
To check that the message sender is allowed to schedule jobs, the JobEntrySystem? can query the current SecurityContext?.
public Object jobEntryMethod(Object params ...)
{
....
{
//
// Check that the message sender is allowed to schedule jobs.
Permission permisson = securityContext.checkPermissions("job-scheduler", "insert") ;
if (permission.isValid())
{
//
// Schedule the job ....
//
}
}
....
}
public Object jobEntryMethod(Object params ...)
{
....
{
....
{
//
// Save the current SecurityContext.
database.store(securityContext) ;
}
}
....
}
When the job is ready to execute, the JobScheduler? will want to restore the original SecurityContext?.
public Object jobSchedulerMethod(Object params ...)
{
//
// Restore the original SecurityContext.
SecurityContext originalContext = database.load(identifier) ;
//
// Set the current SecurityContext for this Thread.
securityDelegate.setSecurityContext(originalContext) ;
....
}
The JobScheduler? will then want to send messages to other services, e.g. DataCenter?, using this restored context.
public Object jobSchedulerMethod(Object params ...)
{
//
// Restore the original SecurityContext.
SecurityContext originalContext = database.load(identifier) ;
//
// Get a SecurityDelegate.
SecurityDelegate securityDelegate = SecurityDelegateFactory.getSecurityDelegate() ;
//
// Set the current SecurityContext for this Thread.
securityDelegate.setSecurityContext(originalContext) ;
....
//
// Call DataCenter to perform the query.
DataCenterDelegate dataCenterDelegate = DataCenterDelegateFactory.getDataCenterDelegate() ;
//
// Setup the query details ....
//
dataCenterDelegate.dataCenterMethod(query) ;
}
Setting the current SecurityContext? on the SecurityDelegate? means that any subsequent outbound calls to other services
automatically have the SecurityContext? details added to their message headers.
<header>
<wsse:UsernameToken>
<wsse:Username>ivo://ast.cam.ac.uk/dave|ivo://star.le.ac.uk/xray-studies</wsse:Username>
<astrogrid:IdentityToken>2347834589tafc\sd9q359\sv</astrogrid:IdentityToken>
</wsee:UsernameToken>
</header>
<message>
<query>details of the ADQL query</query>
</message>
public Object dataCenterMethod(Object params ...)
{
//
// Get a SecurityDelegate.
SecurityDelegate securityDelegate = SecurityDelegateFactory.getSecurityDelegate() ;
//
// Get the message SecurityContext from the delegate
SecurityContext securityContext = securityDelegate.getSecurityContext() ;
//
// Check that the message sender has been authenticated.
if (securityContext.isAuthenticated())
{
//
// Perform the service for an authenticated Account.
//
}
//
// If the message sender has not been authenticated.
else {
//
// Perform the service for an anonymous Account ?
//
}
}
To check that the message sender is allowed to access a database table, the DataCenter? can query the current SecurityContext?.
public Object dataCenterMethod(Object params ...)
{
....
{
//
// Check that the message sender is allowed to access the database table.
Permission permisson = securityContext.checkPermissions("table-name", "select") ;
if (permission.isValid())
{
//
// Perform the database query ....
//
}
}
....
}
public Object dataCenterMethod(Object params ...)
{
....
{
{
//
// Perform the database query ....
....
//
// Get the Account details.
AccountDetails account = securityContext.getAccountDetails() ;
//
// Get the MySpace 'home' reference.
MySpaceReference myspaceHome = account.getMySpaceHome() ;
//
// Create a MySpace delegate.
MySpaceManagerDelegate mySpaceDelegate =
MySpaceManagerDelegateFactory.getMySpaceManagerDelegate(myspaceHome) ;
//
// Negotiate space for the results.
MySpaceReference destination = mySpaceDelegate.method(params) ;
//
// Send the results to the Account MySpace.
OutputStream stream = destination.getOutputStream() ;
.....
}
}
....
}
Again, the current SecurityContext? headers are added to all of the outbound service calls from the DataCenter? to the MySpaceManager.
<header>
<wsse:UsernameToken>
<wsse:Username>ivo://ast.cam.ac.uk/dave|ivo://star.le.ac.uk/xray-studies</wsse:Username>
<astrogrid:IdentityToken>2347834589tafc\sd9q359\sv</astrogrid:IdentityToken>
</wsee:UsernameToken>
</header>
<message>
<request>details of the MySpace message</request>
</message>
The MySpaceManager can then request the current SecurityContext? and perform its own policy checking before allocating space for the data.
public Object mySpaceManagerMethod(Object params ...)
{
//
// Get a SecurityDelegate.
SecurityDelegate securityDelegate = SecurityDelegateFactory.getSecurityDelegate() ;
//
// Get the message SecurityContext from the delegate
SecurityContext securityContext = securityDelegate.getSecurityContext() ;
//
// Check that the message sender has been authenticated.
if (securityContext.isAuthenticated())
{
//
// Perform the service for an authenticated Account.
//
}
}
public Object someServiceMethod(Object params ...)
{
//
// Get a SecurityDelegate.
SecurityDelegate securityDelegate = SecurityDelegateFactory.getSecurityDelegate() ;
//
// Get the message SecurityContext from the delegate
SecurityContext originalContext = securityDelegate.getSecurityContext() ;
....
//
// Outbound messages use the original SecurityContext, from the inbound message.
//
....
//
// Create a new SecurityContext.
SecurityContext specialContext = securityDelegate.newSecurityContext(
account,
group,
token
) ;
//
// Make this the current SecurityContext for outbound messages.
securityDelegate.setSecurityContext(specialContext) ;
....
//
// Outbound messages use the new SecurityContext, created internally.
//
....
//
// Change back to the original SecurityContext, from the inbound message
securityDelegate.setSecurityContext(originalContext) ;
....
//
// Outbound messages use the original SecurityContext, from the inbound message.
//
....
}
public Object someServiceMethod(Object params ...)
{
//
// Get a SecurityDelegate.
SecurityDelegate securityDelegate = SecurityDelegateFactory.getSecurityDelegate() ;
//
// Get the message SecurityContext from the delegate
SecurityContext originalContext = securityDelegate.getSecurityContext() ;
....
//
// Outbound messages use the original SecurityContext, from the inbound message.
//
....
//
// Set the SecurityContext to null
securityDelegate.setSecurityContext(null) ;
....
//
// Outbound messages do not have the SecurityContext hedares.
//
....
//
// Change back to the original SecurityContext, from the inbound message
securityDelegate.setSecurityContext(originalContext) ;
....
//
// Outbound messages use the original SecurityContext, from the inbound message.
//
....
}
<header>
<wsse:UsernameToken>
<wsse:Username>ivo://ast.cam.ac.uk/dave|ivo://star.le.ac.uk/xray-studies</wsse:Username>
<astrogrid:IdentityToken>2347834589tafc\sd9q359\sv</astrogrid:IdentityToken>
</wsee:UsernameToken>
</header>
<message>
<response>details of the MySpace response</response>
</message>
Probably not applicable for the current implementation.
![]() |
Click here for the AstroGrid Service Web |
This is the AstroGrid Development Wiki |
|