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


Java Credentials类代码示例

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


Credentials类属于javax.jcr包,在下文中一共展示了Credentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReadNode

import javax.jcr.Credentials; //导入依赖的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

示例2: login

import javax.jcr.Credentials; //导入依赖的package包/类
@Override
public boolean login() throws LoginException {
    tokenProvider = getTokenProvider();
    if (tokenProvider == null) {
        return false;
    }

    Credentials credentials = getCredentials();
    if (credentials instanceof TokenCredentials) {
        TokenCredentials tc = (TokenCredentials) credentials;
        TokenAuthentication authentication = new TokenAuthentication(tokenProvider);
        if (authentication.authenticate(tc)) {
            tokenCredentials = tc;
            tokenInfo = authentication.getTokenInfo();
            userId = tokenInfo.getUserId();
            principals = getPrincipals(userId);

            log.debug("Login: adding login name to shared state.");
            sharedState.put(SHARED_KEY_LOGIN_NAME, userId);
            return true;
        }
    }

    return false;
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:26,代码来源:TokenLoginModule.java

示例3: createToken

import javax.jcr.Credentials; //导入依赖的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

示例4: extractSimpleCredentials

import javax.jcr.Credentials; //导入依赖的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

示例5: createAuthInfo

import javax.jcr.Credentials; //导入依赖的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

示例6: getLoginContext

import javax.jcr.Credentials; //导入依赖的package包/类
@Override
@Nonnull
public LoginContext getLoginContext(Credentials credentials, String workspaceName)
        throws LoginException {
    Subject subject = getSubject();
    if (subject != null && credentials == null) {
        log.debug("Found pre-authenticated subject: No further login actions required.");
        return new PreAuthContext(subject);
    }

    if (subject == null) {
        subject = new Subject();
    }
    CallbackHandler handler = getCallbackHandler(credentials, workspaceName);
    return new JaasLoginContext(appName, subject, handler, getConfiguration());
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:17,代码来源:LoginContextProviderImpl.java

示例7: login

import javax.jcr.Credentials; //导入依赖的package包/类
@Nonnull
@Override
public ContentSession login(Credentials credentials, String workspaceName)
        throws LoginException, NoSuchWorkspaceException {
    if (workspaceName == null) {
        workspaceName = defaultWorkspaceName;
    }

    // TODO: support multiple workspaces. See OAK-118
    if (!defaultWorkspaceName.equals(workspaceName)) {
        throw new NoSuchWorkspaceException(workspaceName);
    }

    LoginContextProvider lcProvider = securityProvider.getConfiguration(AuthenticationConfiguration.class).getLoginContextProvider(this);
    LoginContext loginContext = lcProvider.getLoginContext(credentials, workspaceName);
    loginContext.login();

    return new ContentSessionImpl(loginContext, securityProvider, workspaceName, nodeStore,
            commitHook, queryEngineSettings, indexProvider);
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:21,代码来源:ContentRepositoryImpl.java

示例8: testAuthenticateInvalidSimpleCredentials

import javax.jcr.Credentials; //导入依赖的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

示例9: testAuthenticateInvalidImpersonationCredentials

import javax.jcr.Credentials; //导入依赖的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

示例10: testGetCredentialsFromSharedState

import javax.jcr.Credentials; //导入依赖的package包/类
@Test
public void testGetCredentialsFromSharedState() {
    Map<String, Credentials> sharedState = new HashMap<String, Credentials>();

    sharedState.put(AbstractLoginModule.SHARED_KEY_CREDENTIALS, new TestCredentials());
    AbstractLoginModule lm = initLoginModule(TestCredentials.class, sharedState);
    assertTrue(lm.getCredentials() instanceof TestCredentials);

    SimpleCredentials sc = new SimpleCredentials("test", "test".toCharArray());
    sharedState.put(AbstractLoginModule.SHARED_KEY_CREDENTIALS, sc);
    lm = initLoginModule(TestCredentials.class, sharedState);
    assertNull(lm.getCredentials());

    sharedState.put(AbstractLoginModule.SHARED_KEY_CREDENTIALS, sc);
    lm = initLoginModule(SimpleCredentials.class, sharedState);
    assertTrue(lm.getCredentials() instanceof SimpleCredentials);

    sharedState.clear();
    lm = initLoginModule(TestCredentials.class, sharedState);
    assertNull(lm.getCredentials());
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:22,代码来源:AbstractLoginModuleTest.java

示例11: getSessionFactory

import javax.jcr.Credentials; //导入依赖的package包/类
private JcrSessionFactory getSessionFactory() {
  final Credentials adminCredentials = new SimpleCredentials(
      "admin", "admin".toCharArray());
  return new JcrSessionFactory() {
    @Override
    public Session newAdminSession() {
      final Session session;
      try {
        session = repo.login(adminCredentials);
      } catch (RepositoryException e) {
        throw new RuntimeException(e);
      }
      assertThat(session.isLive()).isTrue();
      return session;
    }
  };
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:18,代码来源:JcrSessionFactoryTest.java

示例12: createFlow

import javax.jcr.Credentials; //导入依赖的package包/类
/**
 * Create a new flow and save it in the local repository. The the supplied
 * parameter map containing custom properties that a user has set based on a
 * template flow and creates a new flow.
 * 
 * @returns URI of the new flow.
 */
public synchronized String createFlow(Credentials credentials,HashMap<String, String> paramMap,
		String flowUri, long userId) throws MeandreServerException {
	WBFlowDescription flowDesc = MeandreConverter.FlowDescriptionConverter
	.convert(getFlowDescription(credentials,flowUri));
	String name = flowDesc.getName();
	name = name + System.currentTimeMillis();
	flowDesc.setName(name);
	flowDesc.setDescription("Derived from " + flowUri);
	flowDesc.setRights("owned by user");
	flowDesc.setCreationDate(new Date());
	flowDesc.updateParameters(flowUri, paramMap);
	String fileLocation = saveFlow(flowDesc, userId);
	logger.info("Saved new flow to the following location:  "
			+ fileLocation);
	return fileLocation;
}
 
开发者ID:kumaramit01,项目名称:FlowService,代码行数:24,代码来源:MeandreFlowStore.java

示例13: collectPrincipals

import javax.jcr.Credentials; //导入依赖的package包/类
private Set<Principal> collectPrincipals(final Credentials credentials) {
    final Set<Principal> principals = new HashSet<>();

    // TODO add exception handling for principal providers
    for (final PrincipalProvider p : this.getPrincipalProviders()) {
        // if the provider is DelegateHeader, it is either already processed (if logged user has fedora admin role)
        // or should be ignored completely (the user was not in admin role, so on-behalf-of header must be ignored)
        if (!(p instanceof DelegateHeaderPrincipalProvider)) {
            final Set<Principal> ps = p.getPrincipals(credentials);

            if (ps != null) {
                principals.addAll(p.getPrincipals(credentials));
            }
        }
    }

    return principals;
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:19,代码来源:ServletContainerAuthenticationProvider.java

示例14: assertSystemUser

import javax.jcr.Credentials; //导入依赖的package包/类
private void assertSystemUser(String name) throws RepositoryException {
    final SlingRepository repo = teleporter.getService(SlingRepository.class);
    final Session s = repo.loginAdministrative(null);
    try {
        final Credentials creds = new SimpleCredentials(name, new char[] {});
        try {
            s.impersonate(creds);
        } catch(RepositoryException rex) {
            fail("Impersonation as " + name + " failed: " + rex.toString());
        }
    } finally { 
        s.logout();
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:15,代码来源:SystemUsersTest.java

示例15: checkLogin

import javax.jcr.Credentials; //导入依赖的package包/类
private boolean checkLogin(Repository repository) throws RepositoryException {
	boolean loginSuccessful = true;
	Credentials credentials = new SimpleCredentials(userId, userPassword.toCharArray());
	try {
		repository.login(credentials).logout();
	} catch (LoginException e) {
		loginSuccessful = false;
	}
	return loginSuccessful;
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:11,代码来源:CheckPassword.java


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