javax.jcr.Credentials Java Examples
The following examples show how to use
javax.jcr.Credentials.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Saml2LoginModule.java From sling-whiteboard with Apache License 2.0 | 6 votes |
/** * Method to authenticate a {@code Subject} (phase 1). * * <p> The implementation of this method authenticates * a {@code Subject}. For example, it may prompt for * {@code Subject} information such * as a username and password and then attempt to verify the password. * This method saves the result of the authentication attempt * as private state within the LoginModule. * * <p> * * @return true if the authentication succeeded, or false if this * {@code LoginModule} should be ignored. * @throws LoginException if the authentication fails */ @Override public boolean login() throws LoginException { Credentials credentials = getCredentials(); if (credentials instanceof Saml2Credentials) { final String userId = ((Saml2Credentials) credentials).getUserId(); if (userId == null) { logger.warn("Could not extract userId from credentials"); } else { sharedState.put(SHARED_KEY_PRE_AUTH_LOGIN, new PreAuthenticatedLogin(userId)); sharedState.put(SHARED_KEY_CREDENTIALS, new SimpleCredentials(userId, new char[0])); sharedState.put(SHARED_KEY_LOGIN_NAME, userId); logger.debug("Adding pre-authenticated login user '{}' to shared state.", userId); } } return false; }
Example #2
Source File: RepositoryAddress.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * Returns JCR credentials from the URI or {@code null} if no user info * is specified. * @return the creds */ @Nullable public Credentials getCredentials() { String userinfo = uri.getUserInfo(); if (userinfo == null) { return null; } else { int idx = userinfo.indexOf(':'); if (idx < 0) { return new SimpleCredentials(userinfo, new char[0]); } else { return new SimpleCredentials( userinfo.substring(0, idx), userinfo.substring(idx+1).toCharArray()); } } }
Example #3
Source File: JackrabbitRepositoryWrapper.java From sling-whiteboard with Apache License 2.0 | 5 votes |
@Override public Session login(Credentials credentials, String workspaceName, Map<String, Object> attributes) throws LoginException, NoSuchWorkspaceException, RepositoryException { Session jcrSession = jcr.login(credentials, workspaceName, attributes); if (attributes == null) { attributes = new HashMap<>(); } attributes.put(RepositoryWrapper.class.getPackage().getName() + ".PARENT_SESSION", jcrSession); return jcrSession instanceof JackrabbitSession ? new JackrabbitSessionWrapper(this, (JackrabbitSession) jcrSession) : new SessionWrapper<>(this, jcrSession); }
Example #4
Source File: JcrSessionFactory.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
/** * Constructor containing all the fields available. * * @param repository * @param workspaceName * @param credentials * @param sessionHolderProviderManager */ public JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials, SessionHolderProviderManager sessionHolderProviderManager) { this.repository = repository; this.workspaceName = workspaceName; this.credentials = credentials; this.sessionHolderProviderManager = sessionHolderProviderManager; }
Example #5
Source File: CheckPassword.java From APM with Apache License 2.0 | 5 votes |
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; }
Example #6
Source File: VltContext.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public Session login(RepositoryAddress mountpoint) throws RepositoryException { Repository rep = repProvider.getRepository(mountpoint); Credentials creds = credsProvider.getCredentials(mountpoint); Session s = rep.login(creds); // hack to store credentials credsProvider.storeCredentials(mountpoint, creds); return s; }
Example #7
Source File: ConfigCredentialsStore.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public void storeCredentials(RepositoryAddress mountpoint, Credentials creds) { if (!(creds instanceof SimpleCredentials)) { if (creds != null) { log.error("Unable to store non-simple credentials of type " + creds.getClass().getName()); } return; } Credentials currentCreds = fetchCredentials(mountpoint); if (creds.equals(currentCreds)) { // don't update if already stored return; } SimpleCredentials simpleCredentials = (SimpleCredentials) creds; if (storeEnabled || "admin".equals(simpleCredentials.getUserID()) && "admin".equals(new String(simpleCredentials.getPassword()))) { VaultAuthConfig.RepositoryConfig cfg = new VaultAuthConfig.RepositoryConfig(getLookupId(mountpoint)); cfg.addCredsConfig(new SimpleCredentialsConfig(simpleCredentials)); config.addRepositoryConfig(cfg); try { config.save(); log.warn("Credentials for {} updated in {}.", mountpoint, config.getConfigFile().getPath()); } catch (IOException e) { log.error("Error while saving auth configuration: {} ", e.toString()); } } }
Example #8
Source File: ConfigCredentialsStore.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private Credentials fetchCredentials(RepositoryAddress mountpoint) { VaultAuthConfig.RepositoryConfig cfg = config.getRepoConfig(getLookupId(mountpoint)); if (cfg == null) { return null; } return cfg.getCredsConfig().getCredentials(); }
Example #9
Source File: ConfigCredentialsStore.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public Credentials getCredentials(RepositoryAddress mountpoint) { if (credentials != null) { return credentials; } Credentials creds = fetchCredentials(mountpoint); return creds == null ? defaultCreds : creds; }
Example #10
Source File: ConfigCredentialsStore.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private static Credentials fromUserPass(String userPass) { if (userPass != null) { int idx = userPass.indexOf(':'); if (idx > 0) { return new SimpleCredentials(userPass.substring(0, idx), userPass.substring(idx + 1).toCharArray()); } else { return new SimpleCredentials(userPass, new char[0]); } } return null; }
Example #11
Source File: AggregateManagerImpl.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Creates a new artifact manager that is rooted at the given path using * the provided repository, credentials and workspace to create the * session. * * @param config fs config * @param wspFilter the workspace filter * @param rep the jcr repository * @param credentials the credentials * @param mountpoint the address of the mountpoint * @return an artifact manager * @throws RepositoryException if an error occurs. */ public static AggregateManager mount(VaultFsConfig config, WorkspaceFilter wspFilter, Repository rep, Credentials credentials, RepositoryAddress mountpoint) throws RepositoryException { if (config == null) { config = getDefaultConfig(); } if (wspFilter == null) { wspFilter = getDefaultWorkspaceFilter(); } Node rootNode; String wspName = mountpoint.getWorkspace(); try { rootNode = rep.login(credentials, wspName).getNode(mountpoint.getPath()); } catch (LoginException e) { if (wspName == null) { // try again with default workspace // todo: make configurable rootNode = rep.login(credentials, "crx.default").getNode(mountpoint.getPath()); } else { throw e; } } return new AggregateManagerImpl(config, wspFilter, mountpoint, rootNode, true); }
Example #12
Source File: RcpTaskManagerImpl.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Override public RcpTask addTask(RepositoryAddress src, Credentials srcCreds, String dst, String id, List<String> excludes, boolean recursive) throws ConfigurationException { if (id != null && id.length() > 0 && tasks.containsKey(id)) { throw new IllegalArgumentException("Task with id " + id + " already exists."); } RcpTaskImpl task = new RcpTaskImpl(this, src, srcCreds, dst, id, excludes, recursive); tasks.put(task.getId(), task); return task; }
Example #13
Source File: RcpTaskManagerImpl.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Override public RcpTask addTask(RepositoryAddress src, Credentials srcCreds, String dst, String id, WorkspaceFilter srcFilter, boolean recursive) { if (id != null && id.length() > 0 && tasks.containsKey(id)) { throw new IllegalArgumentException("Task with id " + id + " already exists."); } RcpTaskImpl task = new RcpTaskImpl(this, src, srcCreds, dst, id, srcFilter, recursive); tasks.put(task.getId(), task); return task; }
Example #14
Source File: RepositoryWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public Session login(Credentials credentials, String workspaceName) throws LoginException, NoSuchWorkspaceException, RepositoryException { return objectWrapper.wrap(this, jcr.login(credentials, workspaceName)); }
Example #15
Source File: JcrSessionFactory.java From mycollab with GNU Affero General Public License v3.0 | 4 votes |
/** * @return Returns the credentials. */ public Credentials getCredentials() { return credentials; }
Example #16
Source File: TransactionAwareRepository.java From mycollab with GNU Affero General Public License v3.0 | 4 votes |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on Repository interface coming in... // check method invocation if (method.getName().equals("login")) { boolean matched = false; // check method signature Class<?>[] paramTypes = method.getParameterTypes(); // a. login() if (paramTypes.length == 0) { // match the sessionFactory definitions matched = (sessionFactory.getWorkspaceName() == null && sessionFactory.getCredentials() == null); } else if (paramTypes.length == 1) { // b. login(java.lang.String workspaceName) if (paramTypes[0] == String.class) matched = ObjectUtils.nullSafeEquals(args[0], sessionFactory.getWorkspaceName()); // c. login(Credentials credentials) if (Credentials.class.isAssignableFrom(paramTypes[0])) matched = ObjectUtils.nullSafeEquals(args[0], sessionFactory.getCredentials()); } else if (paramTypes.length == 2) { // d. login(Credentials credentials, java.lang.String // workspaceName) matched = ObjectUtils.nullSafeEquals(args[0], sessionFactory.getCredentials()) && ObjectUtils.nullSafeEquals(args[1], sessionFactory.getWorkspaceName()); } if (matched) { Session session = SessionFactoryUtils.getSession(sessionFactory, isAllowCreate()); Class<?>[] ifcs = ClassUtils.getAllInterfaces(session); return Proxy.newProxyInstance(getClass().getClassLoader(), ifcs, new TransactionAwareInvocationHandler(session, sessionFactory)); } } else if (method.getName().equals("equals")) { // Only consider equal when proxies are identical. return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE); } else if (method.getName().equals("hashCode")) { // Use hashCode of Repository proxy. return hashCode(); } Repository target = getTargetRepository(); // Invoke method on target Repository. try { return method.invoke(target, args); } catch (InvocationTargetException ex) { throw ex.getTargetException(); } }
Example #17
Source File: VaultFsApp.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
public void storeCredentials(RepositoryAddress mountpoint, Credentials creds) { base.storeCredentials(mountpoint, creds); }
Example #18
Source File: SimpleCredentialsConfig.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
public Credentials getCredentials() { return creds; }
Example #19
Source File: RepositoryWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public Session login(Credentials credentials) throws LoginException, RepositoryException { return login(credentials, null); }
Example #20
Source File: MockedResourceResolver.java From sling-samples with Apache License 2.0 | 4 votes |
private Session createSession() throws RepositoryException { final Credentials credentials = new SimpleCredentials("admin", "admin".toCharArray()); return repository.login(credentials, "default"); }
Example #21
Source File: RcpTaskImpl.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
public RcpTaskImpl(RcpTaskManagerImpl mgr, RepositoryAddress src, Credentials srcCreds, String dst, String id, List<String> excludes, boolean recursive) throws ConfigurationException { this(mgr, src, srcCreds, dst, id, createFilterForExcludes(excludes), recursive); this.excludes = excludes; }
Example #22
Source File: SessionWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public Session impersonate(Credentials credentials) throws LoginException, RepositoryException { return wrappedSession.impersonate(credentials); }
Example #23
Source File: RcpTaskImpl.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
public RcpTaskImpl(RcpTaskManagerImpl mgr, RepositoryAddress src, Credentials srcCreds, String dst, String id) { this(mgr, src, srcCreds, dst, id, (WorkspaceFilter)null, false); }
Example #24
Source File: RcpTaskManager.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
RcpTask addTask(RepositoryAddress src, Credentials srcCreds, String dst, String id, List<String> excludes, boolean recursive) throws ConfigurationException;
Example #25
Source File: RepositoryImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public Session login(Credentials credentials) throws LoginException, RepositoryException { return session; }
Example #26
Source File: RepositoryImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public Session login(Credentials credentials, String workspaceName) throws LoginException, NoSuchWorkspaceException, RepositoryException { return session; }
Example #27
Source File: SessionImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public Session impersonate(Credentials credentials) throws LoginException, RepositoryException { return this; }
Example #28
Source File: MockUser.java From APM with Apache License 2.0 | 4 votes |
@Override public Credentials getCredentials() throws RepositoryException { return null; }
Example #29
Source File: Mounter.java From jackrabbit-filevault with Apache License 2.0 | 3 votes |
/** * Mounts a new Vault filesystem that is rooted at the given path using * the provided repository, credentials and workspace to create the * session. * * @param config vault fs config * @param wspFilter the workspace filter * @param rep the jcr repository * @param credentials the credentials * @param mountpoint the repository address of the mountpoint * @param rootPath path of root file. used for remapping * @return an aggregate manager * @throws RepositoryException if an error occurs. * @throws IOException if an I/O error occurs. */ public static VaultFileSystem mount(VaultFsConfig config, WorkspaceFilter wspFilter, Repository rep, Credentials credentials, RepositoryAddress mountpoint, String rootPath) throws RepositoryException, IOException { return new VaultFileSystemImpl( AggregateManagerImpl.mount(config, wspFilter, rep, credentials, mountpoint).getRoot(), rootPath, true); }
Example #30
Source File: JcrSessionFactory.java From mycollab with GNU Affero General Public License v3.0 | 2 votes |
/** * @param credentials * The credentials to set. */ public void setCredentials(Credentials credentials) { this.credentials = credentials; }