123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- import java.io.Externalizable;
- import java.io.IOException;
- import java.io.ObjectInput;
- import java.io.ObjectOutput;
- import java.sql.SQLException;
- import com.cognos.CAM_AAA.authentication.IAccount;
- import com.cognos.CAM_AAA.authentication.IBiBusHeader;
- import com.cognos.CAM_AAA.authentication.ICredential;
- import com.cognos.CAM_AAA.authentication.IRestorableVisa;
- import com.cognos.CAM_AAA.authentication.ITrustedCredential;
- import com.cognos.CAM_AAA.authentication.ReadOnlyDisplayObject;
- import com.cognos.CAM_AAA.authentication.SystemRecoverableException;
- import com.cognos.CAM_AAA.authentication.TextNoEchoDisplayObject;
- import com.cognos.CAM_AAA.authentication.UnrecoverableException;
- import com.cognos.CAM_AAA.authentication.UserRecoverableException;
- public class RestorableJDBCVisa extends Visa implements IRestorableVisa
- {
-
-
- private boolean hasChanged = false;
- private Account account = null;
- private String username;
- private String password;
-
- public void init(String username, String password) throws UnrecoverableException
- {
- try
- {
- ConnectionManager connectionManager = ConnectionManager.get();
-
- account = QueryUtil.createAccount(connectionManager, username, password);
- QueryUtil.updateMembership(connectionManager, this);
- this.username = username;
- this.password = password;
-
-
-
- hasChanged = true;
- }
- catch (final SQLException e)
- {
- throw new UnrecoverableException("Connection Error", "Database connection failure. Reason: "
- + ConnectionManager.getSqlExceptionDetails(e));
- }
- }
- @Override
- public ITrustedCredential generateTrustedCredential(IBiBusHeader theAuthRequest) throws UserRecoverableException,
- SystemRecoverableException, UnrecoverableException
- {
-
- JDBCSample.Credential credential = JDBCSample.getCredentialValues(theAuthRequest);
- if (credential.isEmpty())
- {
-
- credential = JDBCSample.getFormFieldValues(theAuthRequest);
- }
- if (credential.isEmpty() || !credential.getUsername().equals(username))
- {
- credential.setUsername(username);
- credential.setPassword(password);
- }
- if (!validateConnection(credential))
- {
- final UserRecoverableException e =
- new UserRecoverableException("Please type your credentials for authentication.",
- "The provided credentials are invalid.");
- e.addDisplayObject(new ReadOnlyDisplayObject("User ID:", "CAMUsername", this.username));
- e.addDisplayObject(new TextNoEchoDisplayObject("Password:", "CAMPassword"));
- throw e;
- }
- final TrustedCredential tc = new TrustedCredential();
- tc.addCredentialValue("username", this.username);
- tc.addCredentialValue("password", this.password);
- return tc;
- }
- @Override
- public ICredential generateCredential(IBiBusHeader theBiBusHeader) throws UserRecoverableException, SystemRecoverableException,
- UnrecoverableException
- {
- if (!this.validateConnection(this.username, this.password))
- {
- final UnrecoverableException e =
- new UnrecoverableException("Could not generate credentials for the user.", "Visa contains invalid credentials.");
- throw e;
- }
- final Credential credentials = new Credential();
- credentials.addCredentialValue("username", this.username);
- credentials.addCredentialValue("password", this.password);
- return credentials;
- }
- @Override
- public IAccount getAccount()
- {
- return account;
- }
-
- private boolean validateConnection(final JDBCSample.Credential credential)
- {
- return validateConnection(credential.getUsername(), credential.getPassword());
- }
-
- private boolean validateConnection(final String theUsername, final String thePassword)
- {
- try
- {
- QueryUtil.createAccount(ConnectionManager.get(), theUsername, thePassword);
- username = theUsername;
- password = thePassword;
- }
- catch (UnrecoverableException ex)
- {
- return false;
- }
- return true;
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeUTF(username);
- out.writeUTF(password);
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- try
- {
- String username = in.readUTF();
- String password = in.readUTF();
- init(username, password);
- }
- catch (UnrecoverableException e)
- {
- throw new IOException(e);
- }
- }
-
- public boolean hasStateChanged()
- {
- return hasChanged;
- }
-
- public void resetChangeIndicator()
- {
- hasChanged = false;
- }
- }
|