• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Identity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.takes.facets.auth.Identity的典型用法代码示例。如果您正苦于以下问题:Java Identity类的具体用法?Java Identity怎么用?Java Identity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Identity类属于org.takes.facets.auth包,在下文中一共展示了Identity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: act

import org.takes.facets.auth.Identity; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    final Identity identity = new RqAuth(request).identity();
    if (identity.equals(Identity.ANONYMOUS)) {
        throw new RsForward(
            new RsFlash("You must be logged in to view logs.")
        );
    }
    final String login = identity.properties().get("login");
    final String name = new RqHref.Smart(request).single("name");
    if (!name.startsWith(String.format("%s_", login))) {
        throw new RsForward(
            new RsFlash(
                String.format(
                    "Permission denied: \"%s\".", name
                )
            )
        );
    }
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    this.bucket.ocket(name).read(baos);
    return new RsText(baos.toByteArray());
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:24,代码来源:TkLog.java


示例2: decode

import org.takes.facets.auth.Identity; //导入依赖的package包/类
@Override
public Identity decode(final byte[] bytes) throws IOException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (InputStream gzip = new GZIPInputStream(
        new ByteArrayInputStream(bytes)
        )
    ) {
        while (true) {
            final int data = gzip.read();
            if (data < 0) {
                break;
            }
            out.write(data);
        }
    }
    return this.origin.decode(out.toByteArray());
}
 
开发者ID:yegor256,项目名称:takes,代码行数:18,代码来源:CcGzip.java


示例3: decode

import org.takes.facets.auth.Identity; //导入依赖的package包/类
@Override
public Identity decode(final byte[] bytes) throws IOException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    int idx = 0;
    while (idx < bytes.length) {
        if (bytes[idx] == '-') {
            ++idx;
            continue;
        }
        if (idx > bytes.length - 2) {
            throw new DecodingException("not enough data");
        }
        out.write(
            // @checkstyle MagicNumberCheck (1 line)
            (CcHex.decode(bytes[idx]) << 4) + CcHex.decode(bytes[idx + 1])
        );
        idx += 2;
    }
    return this.origin.decode(out.toByteArray());
}
 
开发者ID:yegor256,项目名称:takes,代码行数:21,代码来源:CcHex.java


示例4: decode

import org.takes.facets.auth.Identity; //导入依赖的package包/类
@Override
public Identity decode(final byte[] bytes) throws IOException {
    final Map<String, String> map = new HashMap<>(0);
    try (DataInputStream stream = new DataInputStream(
        new ByteArrayInputStream(bytes)
        )
    ) {
        final String urn = stream.readUTF();
        while (stream.available() > 0) {
            map.put(stream.readUTF(), stream.readUTF());
        }
        return new Identity.Simple(urn, map);
    } catch (final IOException ex) {
        throw new DecodingException(ex);
    }
}
 
开发者ID:yegor256,项目名称:takes,代码行数:17,代码来源:CcCompact.java


示例5: identity

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * Get user name from Twitter, with the token provided.
 * @param tkn Twitter access token
 * @return The user found in Twitter
 * @throws IOException If fails
 */
private Identity identity(final String tkn) throws IOException {
    return parse(
        this.user
            .uri()
            .set(
                URI.create(
                    new Href(PsTwitter.VERIFY_URL)
                        .with(PsTwitter.ACCESS_TOKEN, tkn)
                        .toString()
                )
            )
            .back()
            .header("accept", "application/json")
            .fetch().as(RestResponse.class)
            .assertStatus(HttpURLConnection.HTTP_OK)
            .as(JsonResponse.class)
            .json()
            .readObject()
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:27,代码来源:PsTwitter.java


示例6: fetch

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * Get user name from Google, with the token provided.
 * @param token Google access token
 * @return The user found in Google
 * @throws IOException If fails
 */
private Identity fetch(final String token) throws IOException {
    // @checkstyle LineLength (1 line)
    final String uri = new Href(this.gapi).path("plus").path("v1")
        .path("people")
        .path("me")
        .with(PsGoogle.ACCESS_TOKEN, token)
        .toString();
    final JsonObject json = new JdkRequest(uri).fetch()
        .as(JsonResponse.class).json()
        .readObject();
    if (json.containsKey(PsGoogle.ERROR)) {
        throw new HttpException(
            HttpURLConnection.HTTP_BAD_REQUEST,
            String.format(
                "could not retrieve id from Google, possible cause: %s.",
                json.getJsonObject(PsGoogle.ERROR).get("message")
            )
        );
    }
    return PsGoogle.parse(json);
}
 
开发者ID:yegor256,项目名称:takes,代码行数:28,代码来源:PsGoogle.java


示例7: parse

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * Make identity from JSON object.
 * @param json JSON received from Google
 * @return Identity found
 */
private static Identity parse(final JsonObject json) {
    final Map<String, String> props = new HashMap<>(json.size());
    final JsonObject image = json.getJsonObject("image");
    if (image == null) {
        props.put(PsGoogle.PICTURE, "#");
    } else {
        props.put(PsGoogle.PICTURE, image.getString("url", "#"));
    }
    if (json.containsKey(PsGoogle.DISPLAY_NAME)
        && json.get(PsGoogle.DISPLAY_NAME) != null) {
        props.put(PsGoogle.NAME, json.getString(PsGoogle.DISPLAY_NAME));
    } else {
        props.put(PsGoogle.NAME, "unknown");
    }
    return new Identity.Simple(
        String.format("urn:google:%s", json.getString("id")), props
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:24,代码来源:PsGoogle.java


示例8: matchesIfAuthenticatedUser

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * FkAuthenticated can match by user status.
 * @throws IOException If some problem inside
 */
@Test
public void matchesIfAuthenticatedUser() throws IOException {
    MatcherAssert.assertThat(
        new FkAuthenticated(new TkEmpty()).route(
            new RqFake("GET", "/hel?a=1")
        ).has(),
        Matchers.is(false)
    );
    MatcherAssert.assertThat(
        new FkAuthenticated(new TkEmpty()).route(
            new RqWithHeader(
                new RqFake("PUT", "/hello"),
                TkAuth.class.getSimpleName(),
                new String(
                    new CcPlain().encode(new Identity.Simple("urn:test:1"))
                )
            )
        ).has(),
        Matchers.is(true)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:FkAuthenticatedTest.java


示例9: encodesAndDecodes

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * CcXor can encode and decode.
 * @throws IOException If some problem inside
 */
@Test
public void encodesAndDecodes() throws IOException {
    final String urn = "urn:domain:9";
    final Codec codec = new CcXor(
        new Codec() {
            @Override
            public byte[] encode(final Identity identity) {
                return identity.urn().getBytes();
            }
            @Override
            public Identity decode(final byte[] bytes) {
                return new Identity.Simple(new String(bytes));
            }
        },
        "secret"
    );
    MatcherAssert.assertThat(
        codec.decode(codec.encode(new Identity.Simple(urn))).urn(),
        Matchers.equalTo(urn)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:CcXorTest.java


示例10: passesValid

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * CcStrict can pass valid Identities.
 * @throws IOException If some problem inside
 */
@Test
public void passesValid() throws IOException {
    MatcherAssert.assertThat(
        new String(
            new CcStrict(new CcPlain()).encode(
                new Identity.Simple("urn:test:1")
            )
        ), Matchers.equalTo("urn%3Atest%3A1")
    );
    MatcherAssert.assertThat(
        new String(
            new CcStrict(new CcPlain()).encode(
                new Identity.Simple("urn:test-domain-org:valid:1")
            )
        ), Matchers.equalTo("urn%3Atest-domain-org%3Avalid%3A1")
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:22,代码来源:CcStrictTest.java


示例11: encodesAndDecodes

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * CcCompact can encode and decode.
 * @throws IOException If some problem inside
 */
@Test
public void encodesAndDecodes() throws IOException {
    final String urn = "urn:test:3";
    final Identity identity = new Identity.Simple(
        urn,
        new ImmutableMap.Builder<String, String>()
            .put("name", "Jeff Lebowski")
            .build()
    );
    final byte[] bytes = new CcCompact().encode(identity);
    MatcherAssert.assertThat(
        new CcCompact().decode(bytes).urn(),
        Matchers.equalTo(urn)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:20,代码来源:CcCompactTest.java


示例12: decodesInvalidData

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * CcHex can decode invalid data.
 * @throws IOException If some problem inside
 */
@Test
public void decodesInvalidData() throws IOException {
    MatcherAssert.assertThat(
        new CcSafe(new CcCompact()).decode(
            " % tjw".getBytes()
        ),
        Matchers.equalTo(Identity.ANONYMOUS)
    );
    MatcherAssert.assertThat(
        new CcSafe(new CcCompact()).decode(
            "75726E253".getBytes()
        ),
        Matchers.equalTo(Identity.ANONYMOUS)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:20,代码来源:CcCompactTest.java


示例13: encodesAndDecodes

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * CcBase64 can encode and decode.
 * @throws IOException If some problem inside
 */
@Test
public void encodesAndDecodes() throws IOException {
    final String urn = "urn:test:Hello World!";
    final Map<String, String> properties =
        ImmutableMap.of("userName", "user");
    final Codec codec = new CcBase64(new CcPlain());
    final Identity expected = codec.decode(
        codec.encode(new Identity.Simple(urn, properties))
    );
    MatcherAssert.assertThat(
        expected.urn(),
        Matchers.equalTo(urn)
    );
    MatcherAssert.assertThat(
        expected.properties(),
        Matchers.equalTo(properties)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:23,代码来源:CcBase64Test.java


示例14: decodesInvalidData

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * CcSalted can decode.
 * @throws IOException If some problem inside
 */
@Test
public void decodesInvalidData() throws IOException {
    MatcherAssert.assertThat(
        new CcSafe(new CcSalted(new CcPlain())).decode(
            " % tjw".getBytes()
        ),
        Matchers.equalTo(Identity.ANONYMOUS)
    );
    MatcherAssert.assertThat(
        new CcSafe(new CcSalted(new CcPlain())).decode(
            "75726E253".getBytes()
        ),
        Matchers.equalTo(Identity.ANONYMOUS)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:20,代码来源:CcSaltedTest.java


示例15: decodesInvalidData

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * CcHex can decode.
 * @throws IOException If some problem inside
 */
@Test
public void decodesInvalidData() throws IOException {
    MatcherAssert.assertThat(
        new CcSafe(new CcHex(new CcPlain())).decode(
            " % tjw".getBytes()
        ),
        Matchers.equalTo(Identity.ANONYMOUS)
    );
    MatcherAssert.assertThat(
        new CcSafe(new CcHex(new CcPlain())).decode(
            "75-72-6E-253".getBytes()
        ),
        Matchers.equalTo(Identity.ANONYMOUS)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:20,代码来源:CcHexTest.java


示例16: exec

import org.takes.facets.auth.Identity; //导入依赖的package包/类
@Override
public void exec(final URI home) throws IOException {
    final Identity identity = new PsLinkedin(
        new Href(String.format("%s/uas/oauth2/accessToken", home)),
        new Href(String.format("%s/v1/people", home)),
        this.lapp,
        this.lkey
    ).enter(new RqFake("GET", String.format("?code=%s", this.code)))
        .get();
    MatcherAssert.assertThat(
        identity.urn(),
        CoreMatchers.equalTo(
            String.format("urn:linkedin:%s", this.identifier)
        )
    );
    MatcherAssert.assertThat(
        identity.properties(),
        Matchers.allOf(
            Matchers.hasEntry(this.firstname, this.frodo),
            Matchers.hasEntry(this.lastname, this.baggins)
        )
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:24,代码来源:PsLinkedinTest.java


示例17: enter

import org.takes.facets.auth.Identity; //导入依赖的package包/类
@Override
public Opt<Identity> enter(final Request req) throws IOException {
    final Opt<Identity> user;
    if (TkAppAuth.TESTING) {
        final Iterator<String> login =
            new RqHref.Base(req).href().param("user").iterator();
        final String name;
        if (login.hasNext()) {
            name = login.next();
        } else {
            name = "tester";
        }
        user = new Opt.Single<Identity>(
            new Identity.Simple(
                String.format("urn:test:%s", name),
                new ArrayMap<String, String>().with("login", name)
            )
        );
    } else {
        user = new Opt.Empty<>();
    }
    return user;
}
 
开发者ID:yegor256,项目名称:thindeck,代码行数:24,代码来源:TkAppAuth.java


示例18: user

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * Get user name (GitHub handle).
 * @return The user found
 * @throws IOException If fails
 */
private User user() throws IOException {
    final Identity identity = new RqAuth(this.request).identity();
    if (identity.equals(Identity.ANONYMOUS)) {
        throw new RsForward(
            new RsFlash("You must be logged in.")
        );
    }
    return this.base.user(
        identity.properties().get("login").toLowerCase(Locale.ENGLISH)
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:17,代码来源:RqUser.java


示例19: name

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * Get user name (GitHub handle).
 * @return Name
 * @throws IOException If fails
 */
public String name() throws IOException {
    final Identity identity = new RqAuth(this).identity();
    final String urn = identity.urn();
    final Matcher mtr = RqUser.PTN.matcher(urn);
    if (!mtr.matches()) {
        throw new IllegalArgumentException(
            String.format("URN \"%s\" is not from GitHub", urn)
        );
    }
    return identity.properties().get("login");
}
 
开发者ID:yegor256,项目名称:jare,代码行数:17,代码来源:RqUser.java


示例20: urn

import org.takes.facets.auth.Identity; //导入依赖的package包/类
/**
 * Get URN.
 * @return URN
 * @throws IOException If fails
 */
public String urn() throws IOException {
    final Identity identity = new RqAuth(this).identity();
    if (identity.equals(Identity.ANONYMOUS)) {
        throw new HttpException(
            HttpURLConnection.HTTP_FORBIDDEN,
            "you're not authorized"
        );
    }
    return identity.urn();
}
 
开发者ID:yegor256,项目名称:wring,代码行数:16,代码来源:RqUser.java



注:本文中的org.takes.facets.auth.Identity类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MQBrokerException类代码示例发布时间:2022-05-22
下一篇:
Java DateTimePath类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap