本文整理汇总了Java中javax.jcr.SimpleCredentials.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleCredentials.setAttribute方法的具体用法?Java SimpleCredentials.setAttribute怎么用?Java SimpleCredentials.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jcr.SimpleCredentials
的用法示例。
在下文中一共展示了SimpleCredentials.setAttribute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setApplicationContext
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
try {
repository = repositoryBuilder.getRepository();
SimpleCredentials cred = new SimpleCredentials("admin", "admin".toCharArray());
cred.setAttribute("AutoRefresh", true);
session = repository.login(cred, null);
versionManager = session.getWorkspace().getVersionManager();
lockManager=session.getWorkspace().getLockManager();
Collection<RepositoryInteceptor> repositoryInteceptors=applicationContext.getBeansOfType(RepositoryInteceptor.class).values();
if(repositoryInteceptors.size()==0){
repositoryInteceptor=new DefaultRepositoryInteceptor();
}else{
repositoryInteceptor=repositoryInteceptors.iterator().next();
}
} catch (Exception ex) {
throw new RuleException(ex);
}
}
示例2: createToken
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
/**
* Create a separate token node underneath a dedicated token store within
* the user home node. That token node contains the hashed token, the
* expiration time and additional mandatory attributes that will be verified
* during login.
*
* @param credentials The current credentials.
* @return A new {@code TokenInfo} or {@code null} if the token could not
* be created.
*/
@Override
public TokenInfo createToken(Credentials credentials) {
SimpleCredentials sc = extractSimpleCredentials(credentials);
TokenInfo tokenInfo = null;
if (sc != null) {
String[] attrNames = sc.getAttributeNames();
Map<String, String> attributes = new HashMap<String, String>(attrNames.length);
for (String attrName : sc.getAttributeNames()) {
attributes.put(attrName, sc.getAttribute(attrName).toString());
}
tokenInfo = createToken(sc.getUserID(), attributes);
if (tokenInfo != null) {
// also set the new token to the simple credentials.
sc.setAttribute(TOKEN_ATTRIBUTE, tokenInfo.getToken());
}
}
return tokenInfo;
}
示例3: testDoCreateToken
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testDoCreateToken() throws Exception {
assertFalse(tokenProvider.doCreateToken(new GuestCredentials()));
assertFalse(tokenProvider.doCreateToken(new TokenCredentials("token")));
assertFalse(tokenProvider.doCreateToken(getAdminCredentials()));
SimpleCredentials sc = new SimpleCredentials("uid", "pw".toCharArray());
assertFalse(tokenProvider.doCreateToken(sc));
sc.setAttribute("any_attribute", "value");
assertFalse(tokenProvider.doCreateToken(sc));
sc.setAttribute("rep:token_key", "value");
assertFalse(tokenProvider.doCreateToken(sc));
sc.setAttribute(".token", "existing");
assertFalse(tokenProvider.doCreateToken(sc));
sc.setAttribute(".token", "");
assertTrue(tokenProvider.doCreateToken(sc));
}
示例4: testSimpleCredentialsWithAttribute
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testSimpleCredentialsWithAttribute() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = new SimpleCredentials("test", new char[0]);
sc.setAttribute(".token", "");
cs = login(sc);
fail("Unsupported credentials login should fail");
} catch (LoginException e) {
// success
} finally {
if (cs != null) {
cs.close();
}
}
}
示例5: testLoginWithAttributes
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testLoginWithAttributes( ) throws Exception {
ContentSession cs = null;
try {
createTestUser();
SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray());
sc.setAttribute("attr", "value");
cs = login(sc);
AuthInfo authInfo = cs.getAuthInfo();
assertTrue(Arrays.asList(authInfo.getAttributeNames()).contains("attr"));
assertEquals("value", authInfo.getAttribute("attr"));
cs.close();
} finally {
if (cs != null) {
cs.close();
}
}
}
示例6: testInvalidSimpleCredentialsWithAttribute
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testInvalidSimpleCredentialsWithAttribute() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = new SimpleCredentials("test", new char[0]);
sc.setAttribute(".token", "");
cs = login(sc);
fail("Invalid simple credentials login should fail");
} catch (LoginException e) {
// success
} finally {
if (cs != null) {
cs.close();
}
}
}
示例7: testTokenCreationAndLogin
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testTokenCreationAndLogin() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
cs = login(sc);
Object token = sc.getAttribute(".token").toString();
assertNotNull(token);
TokenCredentials tc = new TokenCredentials(token.toString());
cs.close();
cs = login(tc);
} finally {
if (cs != null) {
cs.close();
}
}
}
示例8: testTokenCreationAndImpersonation
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testTokenCreationAndImpersonation() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
ImpersonationCredentials ic = new ImpersonationCredentials(sc, new AuthInfoImpl(((SimpleCredentials) getAdminCredentials()).getUserID(), Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
cs = login(ic);
Object token = sc.getAttribute(".token").toString();
assertNotNull(token);
TokenCredentials tc = new TokenCredentials(token.toString());
cs.close();
cs = login(tc);
} finally {
if (cs != null) {
cs.close();
}
}
}
示例9: testTokenCreationWithAttributes
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testTokenCreationWithAttributes() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
sc.setAttribute(".token.mandatory", "something");
sc.setAttribute("attr", "val");
cs = login(sc);
AuthInfo ai = cs.getAuthInfo();
Set<String> attrNames = ImmutableSet.copyOf(ai.getAttributeNames());
assertTrue(attrNames.contains("attr"));
assertFalse(attrNames.contains(".token"));
assertFalse(attrNames.contains(".token.mandatory"));
} finally {
if (cs != null) {
cs.close();
}
}
}
示例10: testTokenCreationWithImpersonationAttributes
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testTokenCreationWithImpersonationAttributes() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
sc.setAttribute(".token.mandatory", "something");
sc.setAttribute("attr", "val");
ImpersonationCredentials ic = new ImpersonationCredentials(sc, new AuthInfoImpl(((SimpleCredentials) getAdminCredentials()).getUserID(), Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
cs = login(ic);
AuthInfo ai = cs.getAuthInfo();
Set<String> attrNames = ImmutableSet.copyOf(ai.getAttributeNames());
assertTrue(attrNames.contains("attr"));
assertFalse(attrNames.contains(".token"));
assertFalse(attrNames.contains(".token.mandatory"));
} finally {
if (cs != null) {
cs.close();
}
}
}
示例11: testCreateTokenWithExpirationParam
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testCreateTokenWithExpirationParam() throws Exception {
SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
sc.setAttribute(TokenProvider.PARAM_TOKEN_EXPIRATION, 100000);
TokenInfo info = tokenProvider.createToken(sc);
assertTokenInfo(info, userId);
Tree tokenTree = getTokenTree(info);
assertNotNull(tokenTree);
assertTrue(tokenTree.exists());
assertTrue(tokenTree.hasProperty(TokenProvider.PARAM_TOKEN_EXPIRATION));
assertEquals(100000, tokenTree.getProperty(TokenProvider.PARAM_TOKEN_EXPIRATION).getValue(Type.LONG).longValue());
}
示例12: testCreateTokenWithInvalidExpirationParam
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testCreateTokenWithInvalidExpirationParam() throws Exception {
SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
sc.setAttribute(TokenProvider.PARAM_TOKEN_EXPIRATION, "invalid");
try {
tokenProvider.createToken(sc);
fail();
} catch (NumberFormatException e) {
// success
}
}
示例13: testSimpleCredentialsWithAttribute
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testSimpleCredentialsWithAttribute() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
cs = login(sc);
} finally {
if (cs != null) {
cs.close();
}
}
}
示例14: testTokenAuthInfo
import javax.jcr.SimpleCredentials; //导入方法依赖的package包/类
@Test
public void testTokenAuthInfo() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
cs = login(sc);
assertEquals("userid must be correct", "admin", cs.getAuthInfo().getUserID());
} finally {
if (cs != null) {
cs.close();
}
}
}