/** * 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); } }
/** * Create a new instance of the anonymous credentials, with the supplied attributes. * * @param attributeName the name of the attribute; may not be null * @param attributeValue the value of the attribute */ public AnonymousCredentials( String attributeName, Object attributeValue ) { setAttribute(attributeName, attributeValue); }
@Test public void shouldReturnPropertyAttributeValueGivenNameOfExistingAttribute() throws Exception { session = repository.login(new AnonymousCredentials("attribute1", "value1")); assertThat(session.getAttribute("attribute1"), is((Object)"value1")); }
@Override public ExecutionContext authenticate( Credentials credentials, String repositoryName, String workspaceName, ExecutionContext repositoryContext, Map<String, Object> sessionAttributes ) { if (credentials == null) { return repositoryContext.with(anonymousContext); } if (credentials instanceof AnonymousCredentials) { AnonymousCredentials creds = (AnonymousCredentials)credentials; sessionAttributes.putAll(creds.getAttributes()); return repositoryContext.with(anonymousContext); } if (credentials instanceof GuestCredentials) { return repositoryContext.with(anonymousContext); } return null; }
@Test public void shouldProvideAttributeNames() throws Exception { session = repository.login(new AnonymousCredentials("attribute1", "value1")); String[] names = session.getAttributeNames(); assertThat(names, notNullValue()); assertThat(names.length, is(1)); assertThat(names[0], is("attribute1")); }
@Override public ExecutionContext authenticate( Credentials credentials, String repositoryName, String workspaceName, ExecutionContext repositoryContext, Map<String, Object> sessionAttributes ) { if (credentials == null) { return repositoryContext.with(anonymousContext); } if (credentials instanceof AnonymousCredentials) { AnonymousCredentials creds = (AnonymousCredentials)credentials; sessionAttributes.putAll(creds.getAttributes()); return repositoryContext.with(anonymousContext); } if (credentials instanceof GuestCredentials) { return repositoryContext.with(anonymousContext); } return null; }
@Test public void shouldProvideEmptyAttributeNames() throws Exception { session = repository.login(new AnonymousCredentials()); // Get get the attribute names (there should be none) ... String[] names = session.getAttributeNames(); assertThat(names, notNullValue()); assertThat(names.length, is(0)); }
/** * Create a new instance of the anonymous credentials, with the supplied attributes. * * @param attributeName the name of the attribute; may not be null * @param attributeValue the value of the attribute */ public AnonymousCredentials( String attributeName, Object attributeValue ) { setAttribute(attributeName, attributeValue); }
/** * 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); } }
this.anonymousCredentialsIfSuppliedCredentialsFail = useAnonymouOnFailedLogins.get() ? new AnonymousCredentials() : null;
/** * Create a new instance of the anonymous credentials, with the supplied attributes. * * @param attribute1Name the name of the attribute; may not be null * @param attribute1Value the value of the attribute * @param attribute2Name the name of the attribute; may not be null * @param attribute2Value the value of the attribute */ public AnonymousCredentials( String attribute1Name, Object attribute1Value, String attribute2Name, Object attribute2Value ) { setAttribute(attribute1Name, attribute1Value); setAttribute(attribute2Name, attribute2Value); }
this.anonymousCredentialsIfSuppliedCredentialsFail = useAnonymouOnFailedLogins.get() ? new AnonymousCredentials() : null;
/** * Create a new instance of the anonymous credentials, with the supplied attributes. * * @param attribute1Name the name of the attribute; may not be null * @param attribute1Value the value of the attribute * @param attribute2Name the name of the attribute; may not be null * @param attribute2Value the value of the attribute */ public AnonymousCredentials( String attribute1Name, Object attribute1Value, String attribute2Name, Object attribute2Value ) { setAttribute(attribute1Name, attribute1Value); setAttribute(attribute2Name, attribute2Value); }
/** * Create a new instance of the anonymous credentials, with the supplied attributes. * * @param attribute1Name the name of the attribute; may not be null * @param attribute1Value the value of the attribute * @param attribute2Name the name of the attribute; may not be null * @param attribute2Value the value of the attribute * @param attribute3Name the name of the attribute; may not be null * @param attribute3Value the value of the attribute */ public AnonymousCredentials( String attribute1Name, Object attribute1Value, String attribute2Name, Object attribute2Value, String attribute3Name, Object attribute3Value ) { setAttribute(attribute1Name, attribute1Value); setAttribute(attribute2Name, attribute2Value); setAttribute(attribute3Name, attribute3Value); }
/** * Create a new instance of the anonymous credentials, with the supplied attributes. * * @param attribute1Name the name of the attribute; may not be null * @param attribute1Value the value of the attribute * @param attribute2Name the name of the attribute; may not be null * @param attribute2Value the value of the attribute * @param attribute3Name the name of the attribute; may not be null * @param attribute3Value the value of the attribute */ public AnonymousCredentials( String attribute1Name, Object attribute1Value, String attribute2Name, Object attribute2Value, String attribute3Name, Object attribute3Value ) { setAttribute(attribute1Name, attribute1Value); setAttribute(attribute2Name, attribute2Value); setAttribute(attribute3Name, attribute3Value); }