@Override public URN urn() { return this.identity.urn(); }
/** * Make identity from JSON object. * @param json JSON received from Amazon * @return Identity found */ private Identity parse(final JsonObject json) { return new Identity.Simple( URN.create(String.format("urn:amazon:%d", json.getInt("user_id"))), json.getString("name", Identity.ANONYMOUS.name()), Identity.ANONYMOUS.photo() ); }
@Override public URI photo() { return this.identity.photo(); }
@Override public String name() { return this.identity.name(); }
/** * With this URN. * @param urn The URN * @return This object */ public IdentityMocker withURN(final URN urn) { Mockito.doReturn(urn).when(this.identity).urn(); return this; }
/** * Make identity from JSON object. * @param json JSON received from Google * @return Identity found */ private Identity parse(final JsonObject json) { return new Identity.Simple( URN.create(String.format("urn:google:%s", json.getString("id"))), json.getString("name", Identity.ANONYMOUS.name()), URI.create( json.getString( "picture", Identity.ANONYMOUS.photo().toString() ) ) ); }
/** * With this photo. * @param photo The photo * @return This object */ public IdentityMocker withPhoto(final URI photo) { Mockito.doReturn(photo).when(this.identity).photo(); return this; }
/** * With this name. * @param name The name * @return This object */ public IdentityMocker withName(final String name) { Mockito.doReturn(name).when(this.identity).name(); return this; }
/** * Get current user. * @return User */ protected final User user() { final Identity identity = this.auth().identity(); if (identity.equals(Identity.ANONYMOUS)) { throw FlashInset.forward( this.uriInfo().getBaseUriBuilder().clone() .path(IndexRs.class) .build(), "please login first", Level.SEVERE ); } return this.base().user(identity.urn()); }
/** * Make identity from JSON object. * @param json JSON received from Github * @return Identity found */ private Identity parse(final JsonObject json) { return new Identity.Simple( URN.create(String.format("urn:github:%d", json.getInt("id"))), json.getString("login", Identity.ANONYMOUS.name()), URI.create( json.getString( "avatar_url", Identity.ANONYMOUS.photo().toString() ) ) ); }
/** * Public ctor. */ public IdentityMocker() { this.withName("Mocked Joe"); this.withURN(URN.create("urn:rexsl:mocked")); this.withPhoto(Identity.ANONYMOUS.photo()); }
/** * Get current human. * @return Human * @throws IOException If fails */ protected final Human human() throws IOException { final Identity identity = this.auth().identity(); if (identity.equals(Identity.ANONYMOUS)) { throw this.flash().redirect( this.uriInfo().getBaseUri(), "please login", Level.INFO ); } try { return this.base().human(identity.urn()); } catch (final Base.HumanNotFoundException ex) { throw new WebApplicationException( ex, Response.seeOther(this.uriInfo().getBaseUri()) .cookie(this.auth().logout()) .entity(ex.getLocalizedMessage()) .build() ); } }
/** * Make identity from JSON object. * @param json JSON received from LinkedIn * @return Identity found */ private Identity parse(final JsonObject json) { return new Identity.Simple( URN.create(String.format("urn:linkedin:%d", json.getInt("id"))), String.format( "%s %s", json.getString("first_name", Identity.ANONYMOUS.name()), json.getString("last_name", "") ).trim(), URI.create( json.getString( "picture-url", Identity.ANONYMOUS.photo().toString() ) ) ); }