private AuthenticationFailedException newException(final String message, final Exception cause) { final String fullMessage = "PKCSAuthenticator: Authentication of client failed due to: " + message; if (cause != null) { return new AuthenticationFailedException(fullMessage, cause); } else { return new AuthenticationFailedException(fullMessage); } }
@Override public Object authenticate(final Properties credentials) throws AuthenticationFailedException { String user = credentials.getProperty(ResourceConstants.USER_NAME); String password = credentials.getProperty(ResourceConstants.PASSWORD); User userObj = this.userNameToUser.get(user); if (userObj == null) { throw new AuthenticationFailedException("TestSecurityManager: wrong username/password"); } if (user != null && !userObj.password.equals(password) && !"".equals(user)) { throw new AuthenticationFailedException("TestSecurityManager: wrong username/password"); } return user; }
@Override public Object authenticate(final Properties credentials) throws AuthenticationFailedException { String username = credentials.getProperty("security-username"); String password = credentials.getProperty("security-password"); if (username != null && username.equals(password)) { return username; } throw new AuthenticationFailedException("invalid username/password"); }
@Override public Object authenticate(final Properties credentials) throws AuthenticationFailedException { String username = credentials.getProperty("security-username"); String password = credentials.getProperty("security-password"); if (username != null && username.equals(password)) { return username; } throw new AuthenticationFailedException("invalid username/password"); }
@Override public Object authenticate(final Properties credentials) throws AuthenticationFailedException { String user = credentials.getProperty(ResourceConstants.USER_NAME); String password = credentials.getProperty(ResourceConstants.PASSWORD); User userObj = this.userNameToUser.get(user); if (userObj == null) { throw new AuthenticationFailedException("ExampleSecurityManager: wrong username/password"); } if (user != null && !userObj.password.equals(password) && !"".equals(user)) { throw new AuthenticationFailedException("ExampleSecurityManager: wrong username/password"); } return user; }
@Override public Principal authenticate(Properties props, DistributedMember member) throws AuthenticationFailedException { throw new AuthenticationFailedException("expected authenticate error"); }
@Override public Properties getCredentials(final Properties securityProperties, final DistributedMember server, final boolean isPeer) throws AuthenticationFailedException { String userName = securityProperties.getProperty(USER_NAME); if (userName == null) { throw new AuthenticationFailedException( "UserPasswordAuthInit: user name property [" + USER_NAME + "] not set."); } String password = securityProperties.getProperty(PASSWORD); if (password == null) { password = ""; } Properties securityPropertiesCopy = new Properties(); securityPropertiesCopy.setProperty(USER_NAME, userName); securityPropertiesCopy.setProperty(PASSWORD, password); return securityPropertiesCopy; }
@Override public Properties getCredentials(Properties props, DistributedMember server, boolean isPeer) throws AuthenticationFailedException { throw new AuthenticationFailedException("expected get credential error"); }
@Override public Properties getCredentials(Properties props, DistributedMember server, boolean isPeer) throws AuthenticationFailedException { throw new AuthenticationFailedException("expected get credential error"); }
@Override public void init(LogWriter systemLogger, LogWriter securityLogger) throws AuthenticationFailedException { throw new AuthenticationFailedException("expected init error"); }
@Override public Properties getCredentials(Properties props, DistributedMember server, boolean isPeer) throws AuthenticationFailedException { throw new AuthenticationFailedException("expected get credential error"); }
@Override public void init(Properties securityProps, LogWriter systemLogger, LogWriter securityLogger) throws AuthenticationFailedException { throw new AuthenticationFailedException("expected init error"); }
@Override public void init(final Properties securityProperties) throws NotAuthorizedException { String jsonPropertyValue = securityProperties != null ? securityProperties.getProperty(SECURITY_JSON) : null; if (jsonPropertyValue == null) { jsonPropertyValue = DEFAULT_JSON_FILE_NAME; } if (!initializeFromJsonResource(jsonPropertyValue)) { throw new AuthenticationFailedException("TestSecurityManager: unable to find json resource \"" + jsonPropertyValue + "\" as specified by [" + SECURITY_JSON + "]."); } }
@Override public Principal authenticate(Properties props, DistributedMember member) throws AuthenticationFailedException { // Expect "security-username" and "security-password" to (a) match and (b) define permissions. String username = props.getProperty("security-username"); String password = props.getProperty("security-password"); if (StringUtils.isNotBlank(username) && !username.equals(password)) { throw new AuthenticationFailedException( "SimpleAuthenticator expects username to match password."); } return new UsernamePrincipal(username); }
@Override public void init(final Properties securityProperties) throws NotAuthorizedException { String jsonPropertyValue = securityProperties != null ? securityProperties.getProperty(SECURITY_JSON) : null; if (jsonPropertyValue == null) { jsonPropertyValue = DEFAULT_JSON_FILE_NAME; } if (!initializeFromJsonResource(jsonPropertyValue)) { throw new AuthenticationFailedException( "ExampleSecurityManager: unable to find json resource \"" + jsonPropertyValue + "\" as specified by [" + SECURITY_JSON + "]."); } }
private Properties getValidJavaSSLProperties() { final File jks = findTrustedJKS(); try { final Properties props = new Properties(); props.setProperty("javax.net.ssl.trustStore", jks.getCanonicalPath()); props.setProperty("javax.net.ssl.trustStorePassword", "password"); props.setProperty("javax.net.ssl.keyStore", jks.getCanonicalPath()); props.setProperty("javax.net.ssl.keyStorePassword", "password"); return props; } catch (IOException ex) { throw new AuthenticationFailedException( "SSL: Exception while opening the key store: " + ex.getMessage(), ex); } }
private Properties getInvalidJavaSSLProperties() { final File jks = findUntrustedJKS(); try { final Properties props = new Properties(); props.setProperty("javax.net.ssl.trustStore", jks.getCanonicalPath()); props.setProperty("javax.net.ssl.trustStorePassword", "password"); props.setProperty("javax.net.ssl.keyStore", jks.getCanonicalPath()); props.setProperty("javax.net.ssl.keyStorePassword", "password"); return props; } catch (IOException ex) { throw new AuthenticationFailedException( "SSL: Exception while opening the key store: " + ex.getMessage(), ex); } }
@Override public void init(final Properties securityProperties, final LogWriter systemLogWriter, final LogWriter securityLogWriter) throws AuthenticationFailedException { this.systemLogWriter = systemLogWriter; this.securityLogWriter = securityLogWriter; this.pubKeyFilePath = securityProperties.getProperty(PUBLIC_KEY_FILE); if (this.pubKeyFilePath == null) { throw new AuthenticationFailedException("PKCSAuthenticator: property " + PUBLIC_KEY_FILE + " not specified as the public key file."); } this.pubKeyPass = securityProperties.getProperty(PUBLIC_KEYSTORE_PASSWORD); this.aliasCertificateMap = new HashMap(); populateMap(); }
@Override public Principal authenticate(final Properties credentials, final DistributedMember member) throws AuthenticationFailedException { final String userName = credentials.getProperty(UserPasswordAuthInit.USER_NAME); if (userName == null) { throw new AuthenticationFailedException("DummyAuthenticator: user name property [" + UserPasswordAuthInit.USER_NAME + "] not provided"); } final String password = credentials.getProperty(UserPasswordAuthInit.PASSWORD); if (password == null) { throw new AuthenticationFailedException("DummyAuthenticator: password property [" + UserPasswordAuthInit.PASSWORD + "] not provided"); } if (userName.equals(password) && checkValidName(userName)) { return new UsernamePrincipal(userName); } else { throw new AuthenticationFailedException( "DummyAuthenticator: Invalid user name [" + userName + "], password supplied."); } }
protected void readMessage(DataInputStream dis, DataOutputStream dos, byte acceptanceCode, DistributedMember member) throws IOException, AuthenticationRequiredException, AuthenticationFailedException, ServerRefusedConnectionException { String message = dis.readUTF(); if (message.length() == 0 && acceptanceCode != REPLY_WAN_CREDENTIALS) { return; // success } switch (acceptanceCode) { case REPLY_EXCEPTION_AUTHENTICATION_REQUIRED: throw new AuthenticationRequiredException(message); case REPLY_EXCEPTION_AUTHENTICATION_FAILED: throw new AuthenticationFailedException(message); case REPLY_EXCEPTION_DUPLICATE_DURABLE_CLIENT: throw new ServerRefusedConnectionException(member, message); case REPLY_WAN_CREDENTIALS: checkIfAuthenticWanSite(dis, dos, member); break; default: throw new ServerRefusedConnectionException(member, message); } }