本文整理汇总了Java中org.takes.facets.auth.Identity类的典型用法代码示例。如果您正苦于以下问题:Java Identity类的具体用法?Java Identity怎么用?Java Identity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Identity类属于org.takes.facets.auth包,在下文中一共展示了Identity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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());
}
示例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());
}
示例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);
}
}
示例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()
);
}
示例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);
}
示例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
);
}
示例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)
);
}
示例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)
);
}
示例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")
);
}
示例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)
);
}
示例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)
);
}
示例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)
);
}
示例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)
);
}
示例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)
);
}