?? securitymanagertest.java
字號:
package org.rapla.server;
import java.util.Date;
import java.util.Locale;
import org.rapla.ServletTestBase;
import org.rapla.components.util.DateTools;
import org.rapla.entities.domain.Allocatable;
import org.rapla.entities.domain.Appointment;
import org.rapla.entities.domain.Reservation;
import org.rapla.entities.dynamictype.ClassificationFilter;
import org.rapla.entities.dynamictype.DynamicType;
import org.rapla.facade.ClientFacade;
import org.rapla.storage.RaplaSecurityException;
public class SecurityManagerTest extends ServletTestBase {
ServerService raplaServer;
protected ClientFacade facade1;
Locale locale;
public SecurityManagerTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
// start the server
raplaServer = (ServerService) getContext().lookup(
ServerService.ROLE + "/" + getStorageName());
// start the client service
facade1 = (ClientFacade) getContext().lookup(
ClientFacade.ROLE + "/remote-facade");
/* facade2 = (ClientFacade) getContext().lookup(
ClientFacade.ROLE + "/remote-facade-2");*/
locale = Locale.getDefault();
}
protected String getStorageName()
{
return "storage-file";
}
public void testConflictForbidden() throws Exception
{
// We test conflict prevention for an appointment that is in the future
Date start = new Date(facade1.today().getTime() + DateTools.MILLISECONDS_PER_DAY + 10 * DateTools.MILLISECONDS_PER_HOUR);
Date end = new Date( start.getTime() + 2 * DateTools.MILLISECONDS_PER_HOUR);
facade1.login("homer", "duffs".toCharArray());
DynamicType roomType = facade1.getDynamicType("room");
ClassificationFilter filter = roomType.newClassificationFilter();
filter.addEqualsRule("name", "erwin");
Allocatable resource = facade1.getAllocatables( filter.toArray())[0];
{
// First we create a reservation for the resource
Reservation event = facade1.newReservation();
event.getClassification().setValue("name", "taken");
event.addAppointment( facade1.newAppointment( start, end ) );
event.addAllocatable( resource );
facade1.store( event );
}
facade1.logout();
// Now we login as a non admin user, who isnt allowed to create conflicts on the resource erwin
facade1.login("monty", "burns".toCharArray());
{
Reservation event = facade1.newReservation();
// A new event with the same time for the same resource should fail.
event.getClassification().setValue("name", "conflicting event");
Appointment app = facade1.newAppointment( start, end ) ;
event.addAppointment( app);
event.addAllocatable( resource );
try
{
facade1.store( event );
fail("Security Exception expected");
}
catch ( Exception ex)
{
Throwable ex1 = ex;
boolean secExceptionFound = false;
while ( ex1 != null)
{
if ( ex1 instanceof RaplaSecurityException)
{
secExceptionFound = true;
}
ex1 = ex1.getCause();
}
if ( !secExceptionFound)
{
ex.printStackTrace();
fail("Exception expected but was not security exception");
}
}
// moving the start of the second appointment to the end of the first one should work
app.move( end );
facade1.store( event );
}
{
// We have to reget the event
DynamicType eventType = facade1.getDynamicType("event");
ClassificationFilter eventFilter = eventType.newClassificationFilter();
eventFilter.addEqualsRule("name", "conflicting event");
Reservation event = facade1.getReservations( null, null, null, eventFilter.toArray())[0];
// But moving back the appointment to today should fail
event = (Reservation) facade1.edit( event );
Date startPlus1 = new Date( start.getTime() + DateTools.MILLISECONDS_PER_HOUR) ;
event.getAppointments()[0].move( startPlus1,end);
try
{
facade1.store( event );
fail("Security Exception expected");
}
catch ( Exception ex)
{
Throwable ex1 = ex;
boolean secExceptionFound = false;
while ( ex1 != null)
{
if ( ex1 instanceof RaplaSecurityException)
{
secExceptionFound = true;
}
ex1 = ex1.getCause();
}
if ( !secExceptionFound)
{
ex.printStackTrace();
fail("Exception expected but was not security exception");
}
}
facade1.logout();
Thread.sleep(100);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -