@Override public void render(final BasePage<?, ?> page, final Response.ResponseBuilder builder) { if (!BaseRs.this.auth().identity().equals(Identity.ANONYMOUS)) { try { page.append(new JxHuman(BaseRs.this.human())); } catch (final IOException ex) { throw new IllegalStateException(ex); } } } };
/** * Authentication inset. * @return The inset */ @Inset.Runtime public final AuthInset auth() { return new AuthInset(this, Manifests.read("Stateful-SecurityKey")) .with(new Auth(this, this.base())) // @checkstyle LineLength (3 lines) .with(new Facebook(this, Manifests.read("Stateful-FbId"), Manifests.read("Stateful-FbSecret"))) .with(new Google(this, Manifests.read("Stateful-GoogleId"), Manifests.read("Stateful-GoogleSecret"))) .with(new Github(this, Manifests.read("Stateful-GithubId"), Manifests.read("Stateful-GithubSecret"))) .with(BaseRs.TESTER); }
/** * Encrypt identity into text. * @param identity The identity to encrypt * @return Encrypted text for cookie * @since 0.5 */ public String encrypt(@NotNull final Identity identity) { return AuthInset.encrypt(identity, this.key); }
/** * Get user's identity ({@link AuthException} * if not authenticated). * @return Identity, if authenticated */ @Cacheable(lifetime = 1, unit = TimeUnit.SECONDS) public Identity identity() { Identity identity = this.ofProviders(); if (identity.equals(Identity.ANONYMOUS)) { identity = this.ofCookies(); } return identity; }
@Override public void render(@NotNull final BasePage<?, ?> page, @NotNull final Response.ResponseBuilder builder) { final Identity identity = this.identity(); if (identity.equals(Identity.ANONYMOUS)) { for (final Provider prov : this.providers) { .add("photo", identity.photo().toString()) .up() .add("token", this.encrypt(identity)) .up() ); builder.cookie(this.cookie(identity)); builder.header("X-Rexsl-Identity", identity.urn()); .replaceQuery("") .build() ).cookie(this.logout()).build(), String.format( "redirecting because of '%s' flag in HTTP query",
/** * 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() ); } }
.build() .cookie(this.cookie(identity)) .build(), Logger.format(
/** * Authentication inset. * @return The inset */ @Inset.Runtime public final AuthInset auth() { return new AuthInset(this, Manifests.read("Aintshy-SecurityKey")); }
URI.create("http://img.aintshy.com/no-photo.png") ); final NewCookie cookie = this.auth().cookie(identity); throw new WebApplicationException( Response.seeOther(this.uriInfo().getBaseUri())
/** * 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()); }
@Override public void render(final BasePage<?, ?> page, final Response.ResponseBuilder builder) { if (!BaseRs.this.auth().identity().equals(Identity.ANONYMOUS)) { try { page.append( new JaxbBundle("token", BaseRs.this.user().token()) ); } catch (final IOException ex) { throw new IllegalStateException(ex); } page.link(new Link("user:refresh", "/u/refresh")); } } };
@Override public void render(final BasePage<?, ?> page, final Response.ResponseBuilder builder) { if (!BaseRs.this.auth().identity().equals(Identity.ANONYMOUS)) { page.link(new Link("menu:home", "/")); page.link(new Link("menu:counters", "/counters")); page.link(new Link("menu:locks", "/k")); } } };
@Path("/") public Response index() throws IOException { if (!this.auth().identity().equals(Identity.ANONYMOUS)) { final Iterable<Talk> talks = new SafeHuman(this.human(), this).next();