Skip to content

Commit

Permalink
[JBJCA-864] Take CRI into account for security+cri
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper Pedersen committed Jul 25, 2012
1 parent 860454a commit 9e61b72
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ protected synchronized Properties getConnectionProperties(Subject subject, Conne
props.putAll(connectionProps);
if (subject != null)
{
if (SubjectActions.addMatchingProperties(subject, props, this))
if (SubjectActions.addMatchingProperties(subject, cri, props, this))
return props;

throw new ResourceException("No matching credentials in Subject!");
Expand Down Expand Up @@ -1175,19 +1175,23 @@ static class SubjectActions implements PrivilegedAction<Boolean>
{
private final Subject subject;

private final ConnectionRequestInfo cri;

private final Properties props;

private final ManagedConnectionFactory mcf;

/**
* Constructor
* @param subject The subject
* @param cri The connection request info
* @param props The properties
* @param mcf The managed connection factory
*/
SubjectActions(Subject subject, Properties props, ManagedConnectionFactory mcf)
SubjectActions(Subject subject, ConnectionRequestInfo cri, Properties props, ManagedConnectionFactory mcf)
{
this.subject = subject;
this.cri = cri;
this.props = props;
this.mcf = mcf;
}
Expand All @@ -1210,6 +1214,17 @@ public Boolean run()
if (cred.getPassword() != null)
props.setProperty("password", new String(cred.getPassword()));

if (cri != null)
{
WrappedConnectionRequestInfo lcri = (WrappedConnectionRequestInfo)cri;

if (lcri.getUserName() != null)
props.setProperty("user", lcri.getUserName());

if (lcri.getPassword() != null)
props.setProperty("password", lcri.getPassword());
}

return Boolean.TRUE;
}
}
Expand All @@ -1220,13 +1235,14 @@ public Boolean run()
/**
* Add matching properties
* @param subject The subject
* @param cri The connection request info
* @param props The properties
* @param mcf The managed connection factory
* @return The result
*/
static boolean addMatchingProperties(Subject subject, Properties props, ManagedConnectionFactory mcf)
static boolean addMatchingProperties(Subject subject, ConnectionRequestInfo cri, Properties props, ManagedConnectionFactory mcf)
{
SubjectActions action = new SubjectActions(subject, props, mcf);
SubjectActions action = new SubjectActions(subject, cri, props, mcf);
Boolean matched = AccessController.doPrivileged(action);
return matched.booleanValue();
}
Expand Down

0 comments on commit 9e61b72

Please sign in to comment.