Search in sources :

Example 21 with PasswordCredential

use of com.sun.enterprise.security.auth.login.common.PasswordCredential in project Payara by payara.

the class RealmIdentityStore method login.

protected Subject login(UsernamePasswordCredential credential, String realmName) {
    String username = credential.getCaller();
    char[] password = credential.getPassword().getValue();
    Subject subject = new Subject();
    privileged(() -> subject.getPrivateCredentials().add(new PasswordCredential(username, password, getValidRealm(realmName))));
    WebAndEjbToJaasBridge.login(subject, PasswordCredential.class);
    return subject;
}
Also used : PasswordCredential(com.sun.enterprise.security.auth.login.common.PasswordCredential) UsernamePasswordCredential(javax.security.enterprise.credential.UsernamePasswordCredential) Subject(javax.security.auth.Subject)

Example 22 with PasswordCredential

use of com.sun.enterprise.security.auth.login.common.PasswordCredential in project javaee7-samples by javaee-samples.

the class PayaraEJBContextProvider method getContextWithCredentialsSet.

@Override
public Context getContextWithCredentialsSet(String username, String password) {
    // Create a new subject with a password credential
    Subject subject = new Subject();
    subject.getPrivateCredentials().add(new PasswordCredential(username, password.toCharArray(), "default"));
    // Store this subject into a global variable where the CORBA/IIOP code will pick it up.
    ClientSecurityContext.setCurrent(new ClientSecurityContext(username, subject));
    // by jndi.properties in the glassfish-naming.jar on the classpath.
    try {
        return new InitialContext();
    } catch (NamingException e) {
        throw new IllegalStateException(e);
    }
}
Also used : PasswordCredential(com.sun.enterprise.security.auth.login.common.PasswordCredential) ClientSecurityContext(com.sun.enterprise.security.common.ClientSecurityContext) NamingException(javax.naming.NamingException) Subject(javax.security.auth.Subject) InitialContext(javax.naming.InitialContext)

Aggregations

PasswordCredential (com.sun.enterprise.security.auth.login.common.PasswordCredential)22 Subject (javax.security.auth.Subject)15 LoginException (com.sun.enterprise.security.auth.login.common.LoginException)9 PrivilegedAction (java.security.PrivilegedAction)7 X509CertificateCredential (com.sun.enterprise.security.auth.login.common.X509CertificateCredential)5 LoginContext (javax.security.auth.login.LoginContext)5 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)4 InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)3 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)3 ClientSecurityContext (com.sun.enterprise.security.common.ClientSecurityContext)3 SecurityContext (com.sun.enterprise.common.iiop.security.SecurityContext)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 LoginException (javax.security.auth.login.LoginException)2 AnonCredential (com.sun.enterprise.common.iiop.security.AnonCredential)1 GSSUPName (com.sun.enterprise.common.iiop.security.GSSUPName)1 DistinguishedPrincipalCredential (com.sun.enterprise.security.auth.login.DistinguishedPrincipalCredential)1 LoginContextDriver.getValidSubject (com.sun.enterprise.security.auth.login.LoginContextDriver.getValidSubject)1 LoginContextDriver.throwLoginException (com.sun.enterprise.security.auth.login.LoginContextDriver.throwLoginException)1 IOException (java.io.IOException)1