本文整理汇总了Java中org.takes.facets.auth.Identity.Simple方法的典型用法代码示例。如果您正苦于以下问题:Java Identity.Simple方法的具体用法?Java Identity.Simple怎么用?Java Identity.Simple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.takes.facets.auth.Identity
的用法示例。
在下文中一共展示了Identity.Simple方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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
);
}
示例3: 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)
);
}
示例4: 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)
);
}
示例5: 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;
}
示例6: decode
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
@Override
public Identity decode(final byte[] bytes) throws IOException {
final String[] parts = new Utf8String(bytes).string().split(";");
final Map<String, String> map = new HashMap<>(parts.length);
for (int idx = 1; idx < parts.length; ++idx) {
final String[] pair = parts[idx].split("=");
try {
map.put(pair[0], CcPlain.decode(pair[1]));
} catch (final IllegalArgumentException ex) {
throw new DecodingException(ex);
}
}
return new Identity.Simple(CcPlain.decode(parts[0]), map);
}
示例7: parse
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
/**
* Make identity from JSON object.
* @param json JSON received from Github
* @return Identity found
*/
private static Identity parse(final JsonObject json) {
final String fname = "firstName";
final String lname = "lastName";
final String unknown = "?";
final Map<String, String> props = new HashMap<>(json.size());
props.put(fname, json.getString(fname, unknown));
props.put(lname, json.getString(lname, unknown));
return new Identity.Simple(
String.format("urn:linkedin:%s", json.getString("id")), props
);
}
示例8: parse
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
/**
* Make identity from JSON object.
* @param json JSON received from Twitter
* @return Identity found
*/
private static Identity parse(final JsonObject json) {
final Map<String, String> props = new HashMap<>(json.size());
props.put(PsTwitter.NAME, json.getString(PsTwitter.NAME));
props.put("picture", json.getString("profile_image_url"));
return new Identity.Simple(
String.format("urn:twitter:%d", json.getInt("id")),
props
);
}
示例9: enter
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
@Override
public Opt<Identity> enter(final Request trequest)
throws IOException {
final Href href = new RqHref.Base(trequest).href();
final Iterator<String> code = href.param(PsFacebook.CODE).iterator();
if (!code.hasNext()) {
throw new HttpException(
HttpURLConnection.HTTP_BAD_REQUEST,
"code is not provided by Facebook"
);
}
final User user = this.fetch(
this.token(href.toString(), code.next())
);
final Map<String, String> props = new HashMap<>(0);
props.put("name", user.getName());
props.put(
PsFacebook.PICTURE,
new Href("https://graph.facebook.com/")
.path(user.getId())
.path(PsFacebook.PICTURE)
.toString()
);
return new Opt.Single<Identity>(
new Identity.Simple(
String.format("urn:facebook:%s", user.getId()),
props
)
);
}
示例10: parse
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
/**
* Make identity from JSON object.
* @param json JSON received from Github
* @return Identity found
*/
private static Identity parse(final JsonObject json) {
final Map<String, String> props = new HashMap<>(json.size());
// @checkstyle MultipleStringLiteralsCheck (1 line)
props.put(PsGithub.LOGIN, json.getString(PsGithub.LOGIN, "unknown"));
props.put("avatar", json.getString("avatar_url", "#"));
return new Identity.Simple(
String.format("urn:github:%d", json.getInt("id")), props
);
}
示例11: encodes
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
/**
* CcPlain can encode.
* @throws IOException If some problem inside
*/
@Test
public void encodes() throws IOException {
final Identity identity = new Identity.Simple(
"urn:test:3",
new ImmutableMap.Builder<String, String>()
.put("name", "Jeff Lebowski")
.build()
);
MatcherAssert.assertThat(
new String(new CcPlain().encode(identity)),
Matchers.equalTo("urn%3Atest%3A3;name=Jeff+Lebowski")
);
}
示例12: encodesAndDecodes
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
/**
* CcAES can encode and decode.
* @throws Exception any unexpected exception to throw
*/
@Test
public void encodesAndDecodes() throws Exception {
final int length = 128;
final KeyGenerator generator = KeyGenerator.getInstance("AES");
generator.init(length);
final byte[] key = generator.generateKey().getEncoded();
final String plain = "This is a [email protected]@**";
final Codec codec = new CcAes(
new Codec() {
@Override
public Identity decode(final byte[] bytes) throws IOException {
return new Identity.Simple(new String(bytes));
}
@Override
public byte[] encode(final Identity identity)
throws IOException {
return identity.urn().getBytes();
}
},
key
);
MatcherAssert.assertThat(
codec.decode(codec.encode(new Identity.Simple(plain))).urn(),
Matchers.equalTo(plain)
);
}
示例13: encodes
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
/**
* CcHex can encode.
* @throws IOException If some problem inside
*/
@Test
public void encodes() throws IOException {
final Identity identity = new Identity.Simple("urn:test:3");
MatcherAssert.assertThat(
new String(new CcHex(new CcPlain()).encode(identity)),
Matchers.equalTo("75726E25-33417465-73742533-4133")
);
}
示例14: encodesAndDecodes
import org.takes.facets.auth.Identity; //导入方法依赖的package包/类
/**
* CcHex can encode and decode.
* @throws IOException If some problem inside
*/
@Test
public void encodesAndDecodes() throws IOException {
final String urn = "urn:test:8";
final Identity identity = new Identity.Simple(urn);
final Codec codec = new CcHex(new CcPlain());
MatcherAssert.assertThat(
codec.decode(codec.encode(identity)).urn(),
Matchers.equalTo(urn)
);
}