@Override public URN urn() { return this.identity.urn(); }
@Override public String name() { return this.identity.name(); }
@Override public URI photo() { return this.identity.photo(); }
/** * 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); }
/** * 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() ); }
/** * 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; }
/** * Authentication inset. * @return The inset */ @Inset.Runtime public final AuthInset auth() { return new AuthInset(this, Manifests.read("Aintshy-SecurityKey")); }
/** * 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); }
@Override public String toString() { return this.urn().toString(); } @Override
@Override public Link link() { return new Link( "rexsl:facebook", UriBuilder .fromUri("https://www.facebook.com/dialog/oauth") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{client_id}") .queryParam("redirect_uri", "{redirect_uri}") .build(this.app, this.redirectUri()) ); }
@Override public Link link() { return new Link( "rexsl:github", UriBuilder .fromUri("https://github.com/login/oauth/authorize") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{client_id}") .queryParam("redirect_uri", "{redirect_uri}") .build(this.app, this.redirectUri()) ); }
@Override public Link link() { return new Link( "rexsl:linkedin", UriBuilder .fromUri("https://www.linkedin.com/uas/oauth2/authorization") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{client_id}") .queryParam("redirect_uri", "{redirect_uri}") .queryParam("state", "{state}") .build(this.app, this.redirectUri(), LinkedIn.STATE) ); }
@Override public Identity identity() throws IOException { final List<String> headers = this.resource.httpHeaders() .getRequestHeader(HttpHeaders.AUTHORIZATION); Identity identity = Identity.ANONYMOUS; if (headers != null && !headers.isEmpty()) { identity = this.parse(headers.get(0)); } return identity; }
/** * 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() ) ) ); }
/** * 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; }
/** * 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; }
/** * 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; }