javax.resource.spi.security.PasswordCredential Java Examples

The following examples show how to use javax.resource.spi.security.PasswordCredential. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSubjectFactory.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Subject createSubject(String securityDomain)
{
   //we just ignore atm the arg using a singleton for each security domain
   if (userName == null)
      throw new IllegalStateException("UserName is null");

   if (password == null)
      throw new IllegalStateException("Password is null");

   Subject subject = new Subject();

   Principal p = new SimplePrincipal(userName);
   subject.getPrincipals().add(p);

   PasswordCredential credential = new PasswordCredential(userName, password.toCharArray());
   subject.getPrivateCredentials().add(credential);

   return subject;
}
 
Example #2
Source File: AbstractConnectionManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a subject
 * @return The subject
 */
private Subject getSubject()
{
   Subject subject = null;

   if (subjectFactory != null && securityDomain != null)
   {
      subject = SecurityActions.createSubject(subjectFactory, securityDomain);

      Set<PasswordCredential> credentials = SecurityActions.getPasswordCredentials(subject);
      if (credentials != null && credentials.size() > 0)
      {
         ManagedConnectionFactory pcMcf = getManagedConnectionFactory();
         for (PasswordCredential pc : credentials)
         {
            pc.setManagedConnectionFactory(pcMcf);
         }
      }
   }

   log.tracef("Subject: %s", subject);

   return subject;
}
 
Example #3
Source File: DefaultSubjectFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Subject createSubject()
{
   if (userName == null)
      throw new IllegalStateException("UserName is null");

   if (password == null)
      throw new IllegalStateException("Password is null");

   Subject subject = new Subject();

   Principal p = new SimplePrincipal(userName);
   subject.getPrincipals().add(p);

   PasswordCredential credential = new PasswordCredential(userName, password.toCharArray());
   subject.getPrivateCredentials().add(credential);

   return subject;
}
 
Example #4
Source File: SecureIdentityLoginModule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean commit() throws LoginException
{
   Principal principal = new SimplePrincipal(username);
   SubjectActions.addPrincipals(subject, principal);
   sharedState.put("javax.security.auth.login.name", username);
   // Decode the encrypted password
   try
   {
      char[] decodedPassword = decode(password);
      PasswordCredential cred = new PasswordCredential(username, decodedPassword);
      SubjectActions.addCredentials(subject, cred);
   }
   catch(Exception e)
   {
      LoginException le = new LoginException(e.getLocalizedMessage());
      le.initCause(e);
      throw le;
   }
   return true;
}
 
Example #5
Source File: PBEIdentityLoginModule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean commit() throws LoginException
{
   Principal principal = new SimplePrincipal(username);
   SubjectActions.addPrincipals(subject, principal);
   sharedState.put("javax.security.auth.login.name", username);
   // Decode the encrypted password
   try
   {
      char[] decodedPassword = decode(password);
      PasswordCredential cred = new PasswordCredential(username, decodedPassword);
      SubjectActions.addCredentials(subject, cred);
   }
   catch(Exception e)
   {
      LoginException le = new LoginException(e.getLocalizedMessage());
      le.initCause(e);
      throw le;
   }
   return true;
}
 
Example #6
Source File: ConfiguredIdentityLoginModule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean login() throws LoginException
{
   PicketBoxLogger.LOGGER.traceBeginLogin();
   if (super.login())
      return true;

   Principal principal = new SimplePrincipal(principalName);
   SubjectActions.addPrincipals(subject, principal);
   // Put the principal name into the sharedState map
   sharedState.put("javax.security.auth.login.name", principalName);
   PasswordCredential cred = new PasswordCredential(userName, password.toCharArray());
   SubjectActions.addCredentials(subject, cred);
   super.loginOk = true;
   return true;
}
 
Example #7
Source File: CallerIdentityLoginModule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean commit() throws LoginException
{
   // Put the principal name into the sharedState map
   sharedState.put("javax.security.auth.login.name", userName);
   // Add any run-as roles if addRunAsRoles is true
   if( addRunAsRoles && runAsRoles != null )
   {
      SubjectActions.addRoles(subject, runAsRoles);         
   }

   // Add the PasswordCredential
   PasswordCredential cred = new PasswordCredential(userName, password);
   SubjectActions.addCredentials(subject, cred);
   return super.commit();
}
 
Example #8
Source File: UnifiedSecurityManagedConnectionMetaData.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns name of the user associated with the ManagedConnection instance
 *
 * @return Name of the user
 * @throws ResourceException Thrown if an error occurs
 */
@Override
public String getUserName() throws ResourceException
{
   log.trace("getUserName()");
   if (mc.getCri() != null)
   {
      return ((UnifiedSecurityCri) mc.getCri()).getUserName();
   }
   else if (mc.getSubject() != null)
   {
      Set<PasswordCredential> credentials = this.getPasswordCredentials(mc.getSubject());
      if (credentials != null && !credentials.isEmpty())
      {
         for (PasswordCredential pc : credentials)
         {
            return pc.getUserName();
         }
      }
   }

   return null;

}
 
Example #9
Source File: ActiveMQRACredential.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Run
 *
 * @return The credential
 */
@Override
public PasswordCredential run() {
   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("run()");
   }

   Set<PasswordCredential> creds = subject.getPrivateCredentials(PasswordCredential.class);
   PasswordCredential pwdc = null;

   for (PasswordCredential curCred : creds) {
      if (curCred.getManagedConnectionFactory().equals(mcf)) {
         pwdc = curCred;
         break;
      }
   }
   return pwdc;
}
 
Example #10
Source File: UnifiedSecurityManagedConnectionFactory.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 *
 * @param subject The subject
 * @return The instances
 */
private Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(
         (PrivilegedAction<Set<PasswordCredential>>) () -> subject.getPrivateCredentials(PasswordCredential.class));
}
 
Example #11
Source File: UnifiedSecurityManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 *
 * @param subject The subject
 * @return The instances
 */
private Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(
         (PrivilegedAction<Set<PasswordCredential>>) () -> subject.getPrivateCredentials(PasswordCredential.class));
}
 
Example #12
Source File: UnifiedSecurityManagedConnectionMetaData.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 *
 * @param subject The subject
 * @return The instances
 */
private Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(
         (PrivilegedAction<Set<PasswordCredential>>) () -> subject.getPrivateCredentials(PasswordCredential.class));
}
 
Example #13
Source File: SubjectTestCase.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
private PasswordCredential getPasswordCredential(Subject s)
{
   Set<PasswordCredential> credentials = this.getPasswordCredentials(s);
   assertNotNull(credentials);
   assertFalse(credentials.isEmpty());
   return credentials.iterator().next();
}
 
Example #14
Source File: SubjectTestCase.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 *
 * @param subject The subject
 * @return The instances
 */
private Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(
         (PrivilegedAction<Set<PasswordCredential>>) () -> subject.getPrivateCredentials(PasswordCredential.class));
}
 
Example #15
Source File: FlushMethodCallSubjectTestCase.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
private PasswordCredential getPasswordCredential(Subject s)
{
   Set<PasswordCredential> credentials = this.getPasswordCredentials(s);
   assertNotNull(credentials);
   assertFalse(credentials.isEmpty());
   return credentials.iterator().next();
}
 
Example #16
Source File: FlushMethodCallSubjectTestCase.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 *
 * @param subject The subject
 * @return The instances
 */
private Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(
         (PrivilegedAction<Set<PasswordCredential>>) () -> subject.getPrivateCredentials(PasswordCredential.class));
}
 
Example #17
Source File: PrefillSubjectTestCase.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
private PasswordCredential getPasswordCredential(Subject s)
{
   Set<PasswordCredential> credentials = this.getPasswordCredentials(s);
   assertNotNull(credentials);
   assertFalse(credentials.isEmpty());
   return credentials.iterator().next();
}
 
Example #18
Source File: PrefillSubjectTestCase.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 *
 * @param subject The subject
 * @return The instances
 */
private Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(
         (PrivilegedAction<Set<PasswordCredential>>) () -> subject.getPrivateCredentials(PasswordCredential.class));
}
 
Example #19
Source File: SecurityActions.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 * @param subject The subject
 * @return The instances
 */
static Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(new PrivilegedAction<Set<PasswordCredential>>() 
   {
      public Set<PasswordCredential> run()
      {
         return subject.getPrivateCredentials(PasswordCredential.class);
      }
   });
}
 
Example #20
Source File: SecurityActions.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 * @param subject The subject
 * @return The instances
 */
static Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(new PrivilegedAction<Set<PasswordCredential>>() 
   {
      public Set<PasswordCredential> run()
      {
         return subject.getPrivateCredentials(PasswordCredential.class);
      }
   });
}
 
Example #21
Source File: SecurityActions.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 * @param subject The subject
 * @return The instances
 */
static Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(new PrivilegedAction<Set<PasswordCredential>>() 
   {
      public Set<PasswordCredential> run()
      {
         return subject.getPrivateCredentials(PasswordCredential.class);
      }
   });
}
 
Example #22
Source File: ManagedConnectionImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetConnectionWithSubject() throws ResourceException {
    String user = new String("user");
    char[] password = {'a', 'b', 'c'};
    PasswordCredential creds = new PasswordCredential(user, password);
    creds.setManagedConnectionFactory(factory);
    subj.getPrivateCredentials().add(creds);
    Object o = mci.getConnection(subj, cri);

    verifyProxyInterceptors(o);
}
 
Example #23
Source File: PoolBySubject.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a subject
 * @param subjectFactory The subject factory
 * @param securityDomain The security domain
 * @param mcf The managed connection factory
 * @param jndiName The jndi-name
 * @return The subject; <code>null</code> in case of an error
 */
protected Subject createSubject(final SubjectFactory subjectFactory,
                                final String securityDomain,
                                final ManagedConnectionFactory mcf,
                                final String jndiName)
{
   if (subjectFactory == null)
      throw new IllegalArgumentException("SubjectFactory is null");

   if (securityDomain == null)
      throw new IllegalArgumentException("SecurityDomain is null");

   return AccessController.doPrivileged(new PrivilegedAction<Subject>() 
   {
      public Subject run()
      {
         try
         {
            Subject subject = subjectFactory.createSubject(securityDomain);

            Set<PasswordCredential> pcs = subject.getPrivateCredentials(PasswordCredential.class);
            if (pcs.size() > 0)
            {
               for (PasswordCredential pc : pcs)
               {
                  pc.setManagedConnectionFactory(mcf);
               }
            }

            return subject;
         }
         catch (Throwable t)
         {
            log.exceptionDuringCreateSubject(jndiName, t.getMessage(), t);
         }

         return null;
      }
   });
}
 
Example #24
Source File: SecurityActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the PasswordCredential from the Subject
 * @param subject The subject
 * @return The instances
 */
static Set<PasswordCredential> getPasswordCredentials(final Subject subject)
{
   if (System.getSecurityManager() == null)
      return subject.getPrivateCredentials(PasswordCredential.class);

   return AccessController.doPrivileged(new PrivilegedAction<Set<PasswordCredential>>() 
   {
      public Set<PasswordCredential> run()
      {
         return subject.getPrivateCredentials(PasswordCredential.class);
      }
   });
}
 
Example #25
Source File: SubjectActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Void run()
{
   Iterator<PasswordCredential> i = subject.getPrivateCredentials(PasswordCredential.class).iterator();
   while (i.hasNext())
   {
      i.remove();
   }
   return null;
}
 
Example #26
Source File: ActiveMQRACredential.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Get credentials
 *
 * @param mcf     The managed connection factory
 * @param subject The subject
 * @param info    The connection request info
 * @return The credentials
 * @throws SecurityException Thrown if the credentials can't be retrieved
 */
public static ActiveMQRACredential getCredential(final ManagedConnectionFactory mcf,
                                                 final Subject subject,
                                                 final ConnectionRequestInfo info) throws SecurityException {
   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("getCredential(" + mcf + ", " + subject + ", " + info + ")");
   }

   ActiveMQRACredential jc = new ActiveMQRACredential();
   if (subject == null && info != null) {
      jc.setUserName(((ActiveMQRAConnectionRequestInfo) info).getUserName());
      jc.setPassword(((ActiveMQRAConnectionRequestInfo) info).getPassword());
   } else if (subject != null) {
      PasswordCredential pwdc = GetCredentialAction.getCredential(subject, mcf);

      if (pwdc == null) {
         throw new SecurityException("No password credentials found");
      }

      jc.setUserName(pwdc.getUserName());
      jc.setPassword(new String(pwdc.getPassword()));
   } else {
      throw new SecurityException("No Subject or ConnectionRequestInfo set, could not get credentials");
   }

   return jc;
}
 
Example #27
Source File: ActiveMQRACredential.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Get credentials
 *
 * @param subject The subject
 * @param mcf     The managed connection factory
 * @return The credential
 */
static PasswordCredential getCredential(final Subject subject, final ManagedConnectionFactory mcf) {
   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("getCredential(" + subject + ", " + mcf + ")");
   }

   GetCredentialAction action = new GetCredentialAction(subject, mcf);
   return AccessController.doPrivileged(action);
}
 
Example #28
Source File: ManagedConnectionImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetConnectionWithDudSubjectB() throws ResourceException {
    String user = new String("user");
    char[] password = {'a', 'b', 'c'};
    PasswordCredential creds = new PasswordCredential(user, password);
    subj.getPrivateCredentials().add(creds);
    Object o = mci.getConnection(subj, cri);

    verifyProxyInterceptors(o);
}
 
Example #29
Source File: UnifiedSecurityManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * get the user name
 * @return the user name
 */
String getUserName()
{
   if (cri != null && cri instanceof UnifiedSecurityCri)
   {
      return ((UnifiedSecurityCri) cri).getUserName();
   }
   if (subject != null)
   {
      PasswordCredential pc = getPasswordCredential(subject);
      return pc.getUserName();
   }

   return null;
}
 
Example #30
Source File: UnifiedSecurityManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * get the password
 * @return the password
 */
String getPassword()
{
   if (cri != null && cri instanceof UnifiedSecurityCri)
   {
      return ((UnifiedSecurityCri) cri).getPassword();
   }
   if (subject != null)
   {
      PasswordCredential pc = getPasswordCredential(subject);
      return pc.getPassword().toString();
   }

   return null;
}