当前位置: 首页>>代码示例>>Java>>正文


Java SimpleCredentials类代码示例

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


SimpleCredentials类属于javax.jcr包,在下文中一共展示了SimpleCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:20,代码来源:BaseRepositoryService.java

示例2: testReadNode

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
/** Create a node via Sling's http interface and verify that admin can
 *  read it via davex remote access.
 */
public void testReadNode() throws Exception {
    final String path = "/DavExNodeTest_1_" + System.currentTimeMillis();
    final String url = HTTP_BASE_URL + path;

    // add some properties to the node
    final Map<String, String> props = new HashMap<String, String>();
    props.put("name1", "value1");
    props.put("name2", "value2");

    testClient.createNode(url, props);

    // Oak does not support login without credentials, so to
    // verify that davex access works we do need valid repository credentials.
    final Credentials creds = new SimpleCredentials("admin", "admin".toCharArray());
    Session session = repository.login(creds);

    try {
        final Node node = session.getNode(path);
        assertNotNull(node);
        assertEquals("value1", node.getProperty("name1").getString());
        assertEquals("value2", node.getProperty("name2").getString());
    } finally {
        session.logout();
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:29,代码来源:DavExIntegrationTest.java

示例3: testCreateNodeWithAuthentication

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
@Test
public void testCreateNodeWithAuthentication() throws Exception {
    Exchange exchange = createExchangeWithBody("<message>hello!</message>");
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    String uuid = out.getOut().getBody(String.class);
    assertNotNull("Out body was null; expected JCR node UUID", uuid);
    Session session = getRepository().login(
            new SimpleCredentials("admin", "admin".toCharArray()));
    try {
        Node node = session.getNodeByIdentifier(uuid);
        assertNotNull(node);
        assertEquals(BASE_REPO_PATH + "/node", node.getPath());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:JcrAuthLoginTest.java

示例4: get

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
private byte[] get(final String path) throws LoginException, RepositoryException, IOException {
	byte[] ret = null;
	Session session = null;
	try {
		session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
		Binary b = session.getRootNode().getProperty(path).getBinary();
		ret = IOUtils.toByteArray(b.getStream());
		b.dispose();
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		if (session != null) {
			session.logout();
		}
	}
	return ret;
}
 
开发者ID:justcoke,项目名称:dropwizard-jcr-module,代码行数:18,代码来源:JcrDAO.java

示例5: getOcm

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
public ObjectContentManager getOcm() throws Exception {
	
	if(this.repository==null){
		logger.info("Creating Repository using factory: " + this.repositoryFactory.getClass().getName());
		this.repository = this.repositoryFactory.getFactoryInstance();
	}
	
	if(this.mapper==null){
		logger.info("Generating Mapper");
		generateMapper();
	}
	
	if(this.credentials==null){
		this.credentials = new SimpleCredentials(this.user, this.password.toCharArray());
	}
	Session session = repository.login(this.credentials);
	
	if(!this.mainNodesChecked){
		initialise(session);
		this.mainNodesChecked = true;
	}
	return new ObjectContentManagerImpl(session, this.mapper);
}
 
开发者ID:cheetah100,项目名称:gravity,代码行数:24,代码来源:OcmMapperFactory.java

示例6: 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;
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:30,代码来源:TokenProviderImpl.java

示例7: extractSimpleCredentials

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
@CheckForNull
private static SimpleCredentials extractSimpleCredentials(Credentials credentials) {
    if (credentials instanceof SimpleCredentials) {
        return (SimpleCredentials) credentials;
    }

    if (credentials instanceof ImpersonationCredentials) {
        Credentials base = ((ImpersonationCredentials) credentials).getBaseCredentials();
        if (base instanceof SimpleCredentials) {
            return (SimpleCredentials) base;
        }
    }

    // cannot extract SimpleCredentials
    return null;
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:17,代码来源:TokenProviderImpl.java

示例8: createAuthInfo

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
private AuthInfo createAuthInfo() {
    Credentials creds;
    if (credentials instanceof ImpersonationCredentials) {
        creds = ((ImpersonationCredentials) credentials).getBaseCredentials();
    } else {
        creds = credentials;
    }
    Map<String, Object> attributes = new HashMap<String, Object>();
    Object shared = sharedState.get(SHARED_KEY_ATTRIBUTES);
    if (shared instanceof Map) {
        for (Object key : ((Map) shared).keySet()) {
            attributes.put(key.toString(), ((Map) shared).get(key));
        }
    } else if (creds instanceof SimpleCredentials) {
        SimpleCredentials sc = (SimpleCredentials) creds;
        for (String attrName : sc.getAttributeNames()) {
            attributes.put(attrName, sc.getAttribute(attrName));
        }
    }
    return new AuthInfoImpl(userId, attributes, principals);
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:22,代码来源:LoginModuleImpl.java

示例9: 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));
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:22,代码来源:TokenProviderImplTest.java

示例10: 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();
        }
    }
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:18,代码来源:TokenLoginModuleTest.java

示例11: testValidTokenCredentials

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
@Test
public void testValidTokenCredentials() throws Exception {
    Root root = adminSession.getLatestRoot();
    TokenConfiguration tokenConfig = getSecurityProvider().getConfiguration(TokenConfiguration.class);
    TokenProvider tp = tokenConfig.getTokenProvider(root);

    SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
    TokenInfo info = tp.createToken(sc.getUserID(), Collections.<String, Object>emptyMap());

    ContentSession cs = login(new TokenCredentials(info.getToken()));
    try {
        assertEquals(sc.getUserID(), cs.getAuthInfo().getUserID());
    } finally {
        cs.close();
    }
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:17,代码来源:TokenLoginModuleTest.java

示例12: testAuthenticateResolvesToGroup

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
@Test
public void testAuthenticateResolvesToGroup() throws Exception {
    Group g = getUserManager(root).createGroup("g1");
    SimpleCredentials sc = new SimpleCredentials(g.getID(), "pw".toCharArray());
    Authentication a = new UserAuthentication(sc.getUserID(), getUserManager(root));

    try {
        a.authenticate(sc);
        fail("Authenticating Group should fail");
    } catch (LoginException e) {
        // success
    } finally {
        if (g != null) {
            g.remove();
            root.commit();
        }
    }
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:19,代码来源:UserAuthenticationTest.java

示例13: testAuthenticateInvalidSimpleCredentials

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
@Test
public void testAuthenticateInvalidSimpleCredentials() throws Exception {
    List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new SimpleCredentials(userId, "wrongPw".toCharArray()));
    invalid.add(new SimpleCredentials(userId, "".toCharArray()));
    invalid.add(new SimpleCredentials("unknownUser", "pw".toCharArray()));

    for (Credentials creds : invalid) {
        try {
            authentication.authenticate(creds);
            fail("LoginException expected");
        } catch (LoginException e) {
            // success
        }
    }
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:17,代码来源:UserAuthenticationTest.java

示例14: testAuthenticateInvalidImpersonationCredentials

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
@Test
public void testAuthenticateInvalidImpersonationCredentials() throws Exception {
   List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new ImpersonationCredentials(new GuestCredentials(), adminSession.getAuthInfo()));
    invalid.add(new ImpersonationCredentials(new SimpleCredentials(adminSession.getAuthInfo().getUserID(), new char[0]), new TestAuthInfo()));
    invalid.add(new ImpersonationCredentials(new SimpleCredentials("unknown", new char[0]), adminSession.getAuthInfo()));
    invalid.add(new ImpersonationCredentials(new SimpleCredentials("unknown", new char[0]), new TestAuthInfo()));

    for (Credentials creds : invalid) {
        try {
            authentication.authenticate(creds);
            fail("LoginException expected");
        } catch (LoginException e) {
            // success
        }
    }
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:18,代码来源:UserAuthenticationTest.java

示例15: testAnonymousLogin

import javax.jcr.SimpleCredentials; //导入依赖的package包/类
@Test
public void testAnonymousLogin() throws Exception {
    String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters());

    UserManager userMgr = getUserManager(root);

    // verify initial user-content looks like expected
    Authorizable anonymous = userMgr.getAuthorizable(anonymousID);
    assertNotNull(anonymous);
    assertFalse(root.getTree(anonymous.getPath()).hasProperty(UserConstants.REP_PASSWORD));

    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(anonymousID, new char[0]));
        fail("Login with anonymousID should fail since the initial setup doesn't provide a password.");
    } catch (LoginException e) {
        // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:24,代码来源:LoginModuleImplTest.java


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