Package org.atomojo.www.util

Examples of org.atomojo.www.util.Identity


         authForm.add("Passwd", password);
         request.setEntity(authForm.getWebRepresentation());
         Response response = client.handle(request);
         if (response.getStatus().isSuccess()) {
            context.getLogger().info("Authenticated "+username);
            actor.authenticated(form,new Identity(UUID.randomUUID().toString(),username,username,username,email));
         } else {
            context.getLogger().info("Authorization request for "+username+" returned: "+response.getStatus().getCode());
            actor.unauthorized();
         }
      } else {
         Request request = new Request(Method.GET,service);
         request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,username,password));
         Response response = client.handle(request);
         if (response.getStatus().isSuccess()) {
            XMLRepresentationParser parser = new XMLRepresentationParser();
            try {
               Document doc = parser.load(response.getEntity());
               String session = doc.getDocumentElement().getAttributeValue("id");
               String id = doc.getDocumentElement().getAttributeValue("user-id");
               String alias = doc.getDocumentElement().getAttributeValue("user-alias");
               Element nameE = doc.getDocumentElement().getFirstElementNamed(NAME);
               Element emailE = doc.getDocumentElement().getFirstElementNamed(EMAIL);
               Identity identity = new Identity(session,id,alias,nameE==null ? null : nameE.getText(),emailE==null ? null : emailE.getText());
               context.getLogger().info("Authenticated "+username);
               actor.authenticated(form,identity);
            } catch (Exception ex) {
               context.getLogger().log(Level.SEVERE,"Cannot parse auth result.",ex);
               actor.unauthorized();
View Full Code Here


   }
  
  
   public Representation get()
   {
      Identity identity = (Identity)getRequest().getAttributes().get(Identity.IDENTITY_ATTR);
      Representation rep = null;
      if (identity==null) {
         rep = new StringRepresentation("<none/>",MediaType.APPLICATION_XML);
      } else {
         String xml = "<identity id='"+identity.getId()+"' alias='"+identity.getAlias()+"'>";
         if (identity.getName()!=null) {
            xml += "<name>"+identity.getName()+"</name>";
         }
         if (identity.getEmail()!=null) {
            xml += "<email>"+identity.getEmail()+"</email>";
         }
         Map<UUID,String> roles = identity.getRoles();
         if (roles!=null) {
            for (UUID id : roles.keySet()) {
               String name = roles.get(id);
               xml += "<role id='"+id+"' name='"+name+"'/>";
            }
         }
         Map<UUID,String> groups = identity.getGroups();
         if (groups!=null) {
            for (UUID id : groups.keySet()) {
               String name = groups.get(id);
               xml += "<group id='"+id+"' name='"+name+"'/>";
            }
View Full Code Here

      }
      confCookieName = getContext().getParameters().getFirstValue("cookie.name");
   }
  
   protected int beforeHandle(final Request request, final Response response) {
      Identity identity = (Identity)request.getAttributes().get(Identity.IDENTITY_ATTR);
      if (identity==null) {
         ChallengeResponse authResponse = request.getChallengeResponse();
         if (authResponse!=null) {
            Reference service = ActionResource.getReferenceAttribute(request,"auth-service",confService);
            if (service==null) {
               getLogger().warning("No authentication service has been configured.");
               return Filter.CONTINUE;
            }
            String username = authResponse.getIdentifier();
            String password = new String(authResponse.getSecret());
            LoginAction.LoginActor actor = new LoginAction.LoginActor() {
               public void authenticated(Form authForm,Identity identity) {
                  String name = getCookieName(request);
                  if (name!=null) {
                     CookieSetting cookie = new CookieSetting("I",identity.getSession());
                     cookie.setPath(getCookiePath(request));
                     response.getCookieSettings().add(cookie);
                  }
                  if (name!=null && idManager!=null) {
                     idManager.add(identity.getSession(), identity);
                  }
                  IdentityFilter.addIdentity(request, identity);
               }
               public void unauthorized() {
               }
View Full Code Here

   }
  
  
   public Representation get()
   {
      Identity identity = (Identity)getRequest().getAttributes().get(Identity.IDENTITY_ATTR);
      getResponse().setStatus(identity==null ? Status.CLIENT_ERROR_UNAUTHORIZED : Status.SUCCESS_NO_CONTENT);
      return null;
   }
View Full Code Here

   }
  
  
   public Representation get()
   {
      Identity identity = (Identity)getRequest().getAttributes().get(Identity.IDENTITY_ATTR);
      Form form = getRequest().getResourceRef().getQueryAsForm();
      return get(identity,form);
   }
View Full Code Here

                     remoteResponse = client.handle(remoteRequest);
                  }
                  if (remoteResponse!=null && remoteResponse.getStatus().isSuccess()) {
                     final Representation feedResource = remoteResponse.getEntity();
                     response.setStatus(Status.SUCCESS_OK);
                     final Identity identity = (Identity)request.getAttributes().get(Identity.IDENTITY_ATTR);
                     final Map<String,Object> attrs = request.getAttributes();
                     releaseScript = null;
                     Representation rep = new OutputRepresentation(script.getMediaType()) {
                        public void write(OutputStream os)
                           throws IOException
                        {
                           try {
                              Transformer xform = script.getTransformer();
                              xform.clearParameters();
                              if (identity!=null) {
                                 xform.setParameter("user.session",identity.getSession());
                                 xform.setParameter("user.id",identity.getId());
                                 xform.setParameter("user.alias",identity.getAlias());
                                 if (identity.getName()!=null) {
                                    xform.setParameter("user.name",identity.getName());
                                 }
                                 if (identity.getEmail()!=null) {
                                    xform.setParameter("user.email",identity.getEmail());
                                 }
                              }
                              xform.setParameter("request.resource.path",request.getResourceRef().getPath());
                              xform.setParameter("request.resource.authority",request.getResourceRef().getAuthority());
                              xform.setParameter("request.resource.scheme",request.getResourceRef().getScheme());
View Full Code Here

               public void write(OutputStream os)
                  throws IOException
               {
                  try {
                     xform.clearParameters();
                     final Identity identity = (Identity)getRequest().getAttributes().get(Identity.IDENTITY_ATTR);
                     if (identity!=null) {
                        xform.setParameter("user.session",identity.getSession());
                        xform.setParameter("user.id",identity.getId());
                        xform.setParameter("user.alias",identity.getAlias());
                        if (identity.getName()!=null) {
                           xform.setParameter("user.name",identity.getName());
                        }
                        if (identity.getEmail()!=null) {
                           xform.setParameter("user.email",identity.getEmail());
                        }
                     }
                     xform.setParameter("request.resource.path",getRequest().getResourceRef().getPath());
                     xform.setParameter("request.resource.authority",getRequest().getResourceRef().getAuthority());
                     xform.setParameter("request.resource.scheme",getRequest().getResourceRef().getScheme());
View Full Code Here

TOP

Related Classes of org.atomojo.www.util.Identity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.