1 Reply Latest reply on Nov 12, 2008 4:19 PM by Shane Bryzak

    Restrict not loggedIn not working in WebService

    Shervin Asgari Master

      Hello,


      I have looked on how the Seambay example works like, and they have a method login and logout, and another with @Restrict.
      However, they are using JavaScript to use the webservice, whilst I have the more common Axis way of doing it.


      However, when I use my stub to call the login, I can see in the server that it logs in correctly, and then when I call my restricted method, I get an exception that it is not logged in.


      This is my webservice:


      Name("relationService")
      @Stateless
      @WebService(name = "RelationService", serviceName = "RelationService")
      @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
      public class RelationService implements RelationServiceLocal {
      
              @WebMethod
              public boolean login(@WebParam(name = "username")
              String username, @WebParam(name = "password")
              String password) {
                      Identity.instance().setUsername(username);
                      Identity.instance().setPassword(password);
                      Identity.instance().login();
                      return Identity.instance().isLoggedIn();
              }
      
              @WebMethod
              public boolean logout() {
                      Identity.instance().logout();
                      return !Identity.instance().isLoggedIn();
              }
      
              @WebMethod
              @Restrict("#{identity.loggedIn}")
              public List<RelationCanonical> getRelationsFromPerson(@WebParam(name = "foedselsnummer") { 
                   .....
              }



      And this is my @Test class using the stub. The problem may be that I am not familiar in using webservice.



      RelationServiceStub stub = new RelationServiceStub();
                      assert stub != null;
      
                      // We need to first log in, then perform action, then log out
                      RelationServiceStub.Login login = new RelationServiceStub.Login();
                      login.setUsername("she");
                      login.setPassword("shepwd");
      
                      RelationServiceStub.LoginE loginImpl = new RelationServiceStub.LoginE();
                      loginImpl.setLogin(login);
      
                      RelationServiceStub.LoginResponseE loginRes = stub.login(loginImpl);
                      // stub.startlogin(loginImpl, callback)
                      assert loginRes != null;
                      
                      RelationServiceStub.LoginResponse rslr = loginRes.getLoginResponse();
                      boolean isLoggedIn = rslr.get_return();
                      assert isLoggedIn == true;
      
                      // stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,
                      // Boolean.FALSE);
      
                      RelationServiceStub.GetRelationsFromPerson getRFP = new RelationServiceStub.GetRelationsFromPerson();
                      getRFP.setFoedselsnummer("16060897127");
                      RelationServiceStub.GetRelationsFromPersonE rfpImpl = new RelationServiceStub.GetRelationsFromPersonE();
                      rfpImpl.setGetRelationsFromPerson(getRFP);
      
                      RelationServiceStub.GetRelationsFromPersonResponseE response = stub.getRelationsFromPerson(rfpImpl);



      The console shows that I do infact log in, but the last line throws notLoggedIn Exception.