/** * Stores an attribute in this credentials instance. * * @param name a <code>String</code> specifying the name of the attribute * @param value the <code>Object</code> to be stored */ public void setAttribute(String name, Object value) { // name cannot be null if (name == null) { throw new IllegalArgumentException("name cannot be null"); } // null value is the same as removeAttribute() if (value == null) { removeAttribute(name); return; } synchronized (attributes) { attributes.put(name, value); } }
/** * @param name */ public void removeAttribute(String name) { simpleCredentials.removeAttribute(name); }
public void removeAttribute(String name) { registrySimpleCredentials.removeAttribute(name); }
/** * {@inheritDoc} */ @Override public Session impersonate(Credentials otherCredentials) throws LoginException, RepositoryException { // check sanity of this session sanityCheck(); if (!(otherCredentials instanceof SimpleCredentials)) { String msg = "impersonate failed: incompatible credentials, SimpleCredentials expected"; log.debug(msg); throw new RepositoryException(msg); } // set IMPERSONATOR_ATTRIBUTE attribute of given credentials // with subject of current session SimpleCredentials creds = (SimpleCredentials) otherCredentials; creds.setAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE, subject); try { return getRepository().login( otherCredentials, getWorkspace().getName()); } catch (NoSuchWorkspaceException nswe) { // should never get here... String msg = "impersonate failed"; log.error(msg, nswe); throw new RepositoryException(msg, nswe); } finally { // make sure IMPERSONATOR_ATTRIBUTE is removed creds.removeAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE); } }
/** * {@inheritDoc} */ @Override public Session impersonate(Credentials otherCredentials) throws LoginException, RepositoryException { // check sanity of this session sanityCheck(); if (!(otherCredentials instanceof SimpleCredentials)) { String msg = "impersonate failed: incompatible credentials, SimpleCredentials expected"; log.debug(msg); throw new RepositoryException(msg); } // set IMPERSONATOR_ATTRIBUTE attribute of given credentials // with subject of current session SimpleCredentials creds = (SimpleCredentials) otherCredentials; creds.setAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE, subject); try { return getRepository().login( otherCredentials, getWorkspace().getName()); } catch (NoSuchWorkspaceException nswe) { // should never get here... String msg = "impersonate failed"; log.error(msg, nswe); throw new RepositoryException(msg, nswe); } finally { // make sure IMPERSONATOR_ATTRIBUTE is removed creds.removeAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE); } }
public void testDisabledTokenCredentials() throws Exception { simpleCredentials.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, ""); try { AuthContext ac = getAuthContext(simpleCredentials, DISABLE_TOKEN_CONFIG); ac.login(); Subject subject = ac.getSubject(); assertFalse(subject.getPrincipals().isEmpty()); assertFalse(subject.getPublicCredentials().isEmpty()); assertFalse(subject.getPublicCredentials(SimpleCredentials.class).isEmpty()); assertTrue(subject.getPublicCredentials(TokenCredentials.class).isEmpty()); assertEquals(1, subject.getPublicCredentials(Credentials.class).size()); ac.logout(); } finally { simpleCredentials.removeAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE); } }
public void testTokenConfigurationWithJaas() throws Exception { // define the location of the JAAS configuration System.setProperty( "java.security.auth.login.config", "target/test-classes/jaas.config"); simpleCredentials.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, ""); try { AuthContext ac = getJAASAuthContext(simpleCredentials, "defaultLoginModuleTest"); ac.login(); Subject subject = ac.getSubject(); assertFalse(subject.getPrincipals().isEmpty()); assertFalse(subject.getPublicCredentials().isEmpty()); assertFalse(subject.getPublicCredentials(SimpleCredentials.class).isEmpty()); assertTrue(subject.getPublicCredentials(TokenCredentials.class).isEmpty()); assertEquals(1, subject.getPublicCredentials(Credentials.class).size()); ac.logout(); } finally { simpleCredentials.removeAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE); } }
assertTrue(subject.getPublicCredentials(TokenCredentials.class).isEmpty()); } finally { simpleCredentials.removeAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE);
public void testDisabledTokenCredentials2() throws Exception { simpleCredentials.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, ""); try { AuthContext ac = getAuthContext(simpleCredentials, DEFAULT_CONFIG); ac.login(); Subject subj = ac.getSubject(); assertFalse(subj.getPublicCredentials(SimpleCredentials.class).isEmpty()); assertFalse(subj.getPublicCredentials(TokenCredentials.class).isEmpty()); TokenCredentials tokenCredentials = subj.getPublicCredentials(TokenCredentials.class).iterator().next(); ac.logout(); // test login with token credentials ac = getAuthContext(tokenCredentials, DEFAULT_CONFIG); ac.login(); ac.logout(); // test login with token credentials if token-auth is disabled. try { ac = getAuthContext(tokenCredentials, DISABLE_TOKEN_CONFIG); ac.login(); ac.logout(); fail(); } catch (LoginException e) { // success } } finally { simpleCredentials.removeAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE); } }