本文整理汇总了Java中org.takes.facets.auth.TkAuth类的典型用法代码示例。如果您正苦于以下问题:Java TkAuth类的具体用法?Java TkAuth怎么用?Java TkAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TkAuth类属于org.takes.facets.auth包,在下文中一共展示了TkAuth类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matchesIfAuthenticatedUser
import org.takes.facets.auth.TkAuth; //导入依赖的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)
);
}
示例2: auth
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* Authenticated.
* @param take Take
* @return Authenticated takes
*/
private static Take auth(final Take take) {
final String key = Manifests.read("libre-FacebookId");
return new TkAuth(
take,
new PsChain(
new PsFake(key.startsWith("XXXX") || key.startsWith("${")),
new PsByFlag(
new PsByFlag.Pair(
PsFacebook.class.getSimpleName(),
new PsFacebook(
key,
Manifests.read("libre-FacebookSecret")
)
),
new PsByFlag.Pair(
PsLogout.class.getSimpleName(),
new PsLogout()
)
),
new PsCookie(
new CcSafe(
new CcHex(
new CcXOR(
new CcSalted(new CcCompact()),
Manifests.read("libre-SecurityKey")
)
)
)
)
)
);
}
示例3: returnsListOfDocsOfSingleUser
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* TkAdmin can return a list of docs of single user.
* @throws Exception If fails.
*/
@Test
public void returnsListOfDocsOfSingleUser() throws Exception {
final Base base = new MkBase();
final String urn = "urn:test:1";
final User user = base.user(urn);
final String content = "hello, world!";
user.docs().doc("test.txt").write(
new ByteArrayInputStream(content.getBytes()), content.length()
);
final String second = "hello!";
user.docs().doc("test-2.txt").write(
new ByteArrayInputStream(second.getBytes()), second.length()
);
MatcherAssert.assertThat(
new RsPrint(
new TkAdmin(base).act(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(new Identity.Simple(urn))
)
)
)
).printBody(),
XhtmlMatchers.hasXPaths(
"/page/docs[count(doc)=2]",
"/page/docs/doc[path='urn:test:1/test.txt']",
"/page/docs/doc[path='urn:test:1/test-2.txt']"
)
);
}
示例4: returnsListOfDocs
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* TkDocs can return a list of docs.
* @throws Exception If fails.
*/
@Test
public void returnsListOfDocs() throws Exception {
final Base base = new MkBase();
final User user = base.user(TkDocsTest.FAKE_URN);
final byte[] helloworld = "hello, world!".getBytes();
user.docs().doc("test.txt").write(
new ByteArrayInputStream(helloworld), helloworld.length
);
final byte[] hello = "hello!".getBytes();
user.docs().doc("test-2.txt").write(
new ByteArrayInputStream(hello), hello.length
);
MatcherAssert.assertThat(
new RsPrint(
new TkDocs(base).act(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(
new Identity.Simple(TkDocsTest.FAKE_URN)
)
)
)
)
).printBody(),
XhtmlMatchers.hasXPaths(
"/page/user[balance=0]",
"/page/docs[count(doc)=2]",
"/page/account/size",
"/page/docs/doc[name='test.txt']",
"/page/docs/doc/links/link[@rel='read']"
)
);
}
示例5: addsShortLinkInHTML
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* TkDocs can add short link to document in HTML.
* @throws IOException In case of error
*/
@Test
public void addsShortLinkInHTML() throws IOException {
final Base base = new MkBase();
final String file = "short.txt";
final Doc doc = base.user(TkDocsTest.FAKE_URN).docs().doc(file);
doc.write(new ByteArrayInputStream("hi".getBytes()), 2L);
MatcherAssert.assertThat(
IOUtils.toString(
new RsXSLT(
new TkDocs(base).act(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(
new Identity.Simple(TkDocsTest.FAKE_URN)
)
)
)
)
).body()
),
XhtmlMatchers.hasXPaths(
String.format("//xhtml:a[@href='%s']", doc.shortUrl())
)
);
}
示例6: formatsDate
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* TkDocs can format date.
* @throws IOException In case of error
*/
@Test
public void formatsDate() throws IOException {
final Base base = new MkBase();
final String file = "test4.txt";
final Doc doc = base.user(TkDocsTest.FAKE_URN).docs().doc(file);
final byte[] bytes = "hey!".getBytes();
doc.write(new ByteArrayInputStream(bytes), bytes.length);
MatcherAssert.assertThat(
IOUtils.toString(
new RsXSLT(
new TkDocs(base).act(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(
new Identity.Simple(TkDocsTest.FAKE_URN)
)
)
)
)
).body()
),
Matchers.containsString(
String.format(
"] %s",
new SimpleDateFormat("yyyy-MM-dd", Locale.US)
.format(doc.attributes().created())
)
)
);
}
示例7: RqWithTester
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* Ctor.
* @param req Original request
* @throws IOException If fails
*/
public RqWithTester(final Request req) throws IOException {
super(
new RqWithHeader(
req,
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(
new Identity.Simple("urn:test:1")
)
)
)
);
}
示例8: make
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* Authenticated.
* @param take Take
* @return Authenticated take
*/
private static Take make(final Take take) {
return new TkAuth(
take,
new PsChain(
new TkAppAuth.FakePass(),
new PsByFlag(
new PsByFlag.Pair(
PsGithub.class.getSimpleName(),
new PsGithub(
Manifests.read("Thindeck-GithubId"),
Manifests.read("Thindeck-GithubSecret")
)
),
new PsByFlag.Pair(
"fake-user",
new TkAppAuth.FakePass()
),
new PsByFlag.Pair(
PsLogout.class.getSimpleName(),
new PsLogout()
)
),
new PsCookie(
new CcSafe(
new CcHex(
new CcXOR(
new CcSalted(new CcCompact()),
Manifests.read("Thindeck-SecurityKey")
)
)
)
)
)
);
}
示例9: auth
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* Auth.
* @param take Takes
* @return Authenticated takes
*/
private static Take auth(final Take take) {
return new TkAuth(
new TkFork(
new FkParams(
PsByFlag.class.getSimpleName(),
Pattern.compile(".+"),
new TkRedirect()
),
new FkFixed(take)
),
new PsChain(
new PsFake(
Manifests.read("ThreeCopies-DynamoKey").startsWith("AAAA")
),
new PsByFlag(
new PsByFlag.Pair(
PsGithub.class.getSimpleName(),
new PsGithub(
Manifests.read("ThreeCopies-GithubId"),
Manifests.read("ThreeCopies-GithubSecret")
)
),
new PsByFlag.Pair(
PsLogout.class.getSimpleName(),
new PsLogout()
)
),
new PsCookie(
new CcSafe(
new CcHex(
new CcXor(
new CcSalted(new CcCompact()),
Manifests.read("ThreeCopies-SecurityKey")
)
)
)
)
)
);
}
示例10: make
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* Authenticated.
* @param take Takes
* @return Authenticated takes
*/
private static Take make(final Take take) {
return new TkAuth(
new TkFork(
new FkParams(
PsByFlag.class.getSimpleName(),
Pattern.compile(".+"),
new TkRedirect()
),
new FkFixed(take)
),
new PsChain(
new PsFake(
Manifests.read("Jare-DynamoKey").startsWith("AAAA")
),
new PsByFlag(
new PsByFlag.Pair(
PsGithub.class.getSimpleName(),
new PsGithub(
Manifests.read("Jare-GithubId"),
Manifests.read("Jare-GithubSecret")
)
),
new PsByFlag.Pair(
PsLogout.class.getSimpleName(),
new PsLogout()
)
),
new PsCookie(
new CcSafe(
new CcHex(
new CcXor(
new CcSalted(new CcCompact()),
Manifests.read("Jare-SecurityKey")
)
)
)
)
)
);
}
示例11: make
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* Authenticated.
* @param take Takes
* @return Authenticated takes
*/
private static Take make(final Take take) {
return new TkAuth(
new TkFork(
new FkParams(
PsByFlag.class.getSimpleName(),
Pattern.compile(".+"),
new TkRedirect()
),
new FkFixed(take)
),
new PsChain(
new PsFake(
Manifests.read("Wring-DynamoKey").startsWith("AAAA")
),
new PsByFlag(
new PsByFlag.Pair(
PsGithub.class.getSimpleName(),
new PsGithub(
Manifests.read("Wring-GithubId"),
Manifests.read("Wring-GithubSecret")
)
),
new PsByFlag.Pair(
PsLogout.class.getSimpleName(),
new PsLogout()
)
),
new PsCookie(
new CcSafe(
new CcHex(
new CcXor(
new CcSalted(new CcCompact()),
Manifests.read("Wring-SecurityKey")
)
)
)
)
)
);
}
示例12: returnsListOfDocsOfSeveralUsers
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* TkAdmin can return a list of docs of several users.
* @throws Exception If fails.
*/
@Test
@Ignore
public void returnsListOfDocsOfSeveralUsers() throws Exception {
final Base base = new MkBase();
final String urn = "urn:test:2";
final User user = base.user(urn);
final String content = "User1. File1";
user.docs().doc("test_u1.txt").write(
new ByteArrayInputStream(content.getBytes()),
content.length()
);
final String second = "User1. File2";
user.docs().doc("test_u1_2.txt").write(
new ByteArrayInputStream(second.getBytes()),
second.length()
);
final String third = "User2. File1";
final User another = base.user("urn:test:3");
another.docs().doc("test_u2.txt").write(
new ByteArrayInputStream(third.getBytes()),
third.length()
);
final String fourth = "User2. File2";
another.docs().doc("test_u2_2.txt").write(
new ByteArrayInputStream(fourth.getBytes()),
fourth.length()
);
MatcherAssert.assertThat(
new RsPrint(
new TkAdmin(base).act(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(new Identity.Simple(urn))
)
)
)
).printBody(),
XhtmlMatchers.hasXPaths(
"/page/docs[count(doc)=4]",
"/page/docs/doc[path='urn:test:1/test_u1.txt']",
"/page/docs/doc[path='urn:test:1/test_u1_2.txt']",
"/page/docs/doc[path='urn:test:2/test_u2.txt']",
"/page/docs/doc[path='urn:test:2/test_u2_2.txt']"
)
);
}
示例13: addsDocumentLinksInHTML
import org.takes.facets.auth.TkAuth; //导入依赖的package包/类
/**
* TkDocs can add document links in HTML.
* @throws IOException In case of error
*/
@Test
public void addsDocumentLinksInHTML() throws IOException {
final Base base = new MkBase();
final String file = "test3.txt";
final byte[] bytes = "hi!".getBytes();
base.user(TkDocsTest.FAKE_URN).docs()
.doc(file).write(new ByteArrayInputStream(bytes), bytes.length);
MatcherAssert.assertThat(
IOUtils.toString(
new RsXSLT(
new TkDocs(base).act(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(
new Identity.Simple(TkDocsTest.FAKE_URN)
)
)
)
)
).body()
),
XhtmlMatchers.hasXPaths(
String.format(
// @checkstyle LineLength (1 line)
"//xhtml:a[@href='http://www.example.com/doc/read?file=%s']",
file
),
String.format(
// @checkstyle LineLength (1 line)
"//xhtml:a[@href='http://www.example.com/doc/delete?file=%s']",
file
),
String.format(
// @checkstyle LineLength (1 line)
"//xhtml:form[@action='http://www.example.com/doc/set-visibility?file=%s']",
file
)
)
);
}