Examples of LoginContext


Examples of javax.security.auth.login.LoginContext

    }

    public boolean authenticate(final String username, final String password, final ServerSession session) {
        try {
            Subject subject = new Subject();
            LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler() {
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for (Callback callback : callbacks) {
                        if (callback instanceof NameCallback) {
                            ((NameCallback) callback).setName(username);
                        } else if (callback instanceof PasswordCallback) {
                            ((PasswordCallback) callback).setPassword(password.toCharArray());
                        } else {
                            throw new UnsupportedCallbackException(callback);
                        }
                    }
                }
            });
            loginContext.login();
            if (role != null && role.length() > 0) {
                String clazz = "org.apache.karaf.jaas.modules.RolePrincipal";
                String name = role;
                int idx = role.indexOf(':');
                if (idx > 0) {
View Full Code Here

Examples of javax.security.auth.login.LoginContext

        // Establish a LoginContext to use for authentication
        try {

            if ((principalName != null) && (!principalName.equals(""))) {
                LoginContext loginContext = null;
                if (appName == null)
                    appName = "Tomcat";

                if (log.isDebugEnabled())
                    log.debug(sm.getString("jaasRealm.beginLogin", principalName, appName));

                // What if the LoginModule is in the container class loader ?
                ClassLoader ocl = null;

                if (isUseContextClassLoader()) {
                    ocl = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
                }

                try {
                    loginContext = ContextManager.login(appName, callbackHandler);
                } catch (AccountExpiredException e) {
                    if (log.isDebugEnabled())
                        log.debug(sm.getString("jaasRealm.accountExpired", principalName));
                    return (null);
                } catch (CredentialExpiredException e) {
                    if (log.isDebugEnabled())
                        log.debug(sm.getString("jaasRealm.credentialExpired", principalName));
                    return (null);
                } catch (FailedLoginException e) {
                    if (log.isDebugEnabled())
                        log.debug(sm.getString("jaasRealm.failedLogin", principalName));
                    return (null);
                } catch (LoginException e) {
                    log.warn(sm.getString("jaasRealm.loginException", principalName), e);
                    return (null);
                } catch (Throwable e) {
                    log.error(sm.getString("jaasRealm.unexpectedError"), e);
                    return (null);
                } finally {
                    if (isUseContextClassLoader()) {
                        Thread.currentThread().setContextClassLoader(ocl);
                    }
                }

                if (log.isDebugEnabled())
                    log.debug("Login context created " + principalName);

                // Negotiate a login via this LoginContext
                Subject subject = loginContext.getSubject();
                ContextManager.setCallers(subject, subject);

                if (log.isDebugEnabled())
                    log.debug(sm.getString("jaasRealm.loginContextCreated", principalName));
View Full Code Here

Examples of javax.security.auth.login.LoginContext

    public Object login(String user, String pass) throws LoginException {
        return login("OpenEJB", user, pass);
    }

    public Object login(String securityRealm, String user, String pass) throws LoginException {
        LoginContext context = ContextManager.login(securityRealm, new UsernamePasswordCallbackHandler(user, pass));

        Subject subject = context.getSubject();
        return ContextManager.getSubjectId(subject);
    }
View Full Code Here

Examples of javax.security.auth.login.LoginContext

                } else {
                    throw new LoginException("Cannot extract credentials from class: " + credentials.getClass().getName());
                }

                //set up the login context
                LoginContext loginContext = ContextManager.login(securityRealmName, callbackHandler);
                callbackHandler.clear();

                Subject subject = loginContext.getSubject();
                ContextManager.setCallers(subject, subject);

                //login success
                userPrincipal = new JAASJettyPrincipal(username);
                userPrincipal.setSubject(subject);
View Full Code Here

Examples of javax.security.auth.login.LoginContext

        registerSubject(EMPTY);
    }

    public static LoginContext login(String realm, CallbackHandler callbackHandler) throws LoginException {
        Subject subject = new Subject();
        LoginContext loginContext = new LoginContext(realm, subject, callbackHandler);
        loginContext.login();
        SubjectId id = ContextManager.registerSubject(subject);
        IdentificationPrincipal principal = new IdentificationPrincipal(id);
        subject.getPrincipals().add(principal);
        return loginContext;
    }
View Full Code Here

Examples of javax.security.auth.login.LoginContext

       
        try {
           
           
            CallbackHandler handler = getCallbackHandler(name, password)
            LoginContext ctx = new LoginContext(getContextName(), null, handler, loginConfig)
           
            ctx.login();
           
            Subject subject = ctx.getSubject();
           
            message.put(SecurityContext.class, createSecurityContext(subject));
        } catch (LoginException ex) {
            String errorMessage = "Unauthorized : " + ex.getMessage();
            LOG.fine(errorMessage);
View Full Code Here

Examples of javax.security.auth.login.LoginContext

        }

        try
        {
            System.setProperty( "javax.security.auth.useSubjectCredsOnly", "true" );
            LoginContext loginContext = new LoginContext( request.getLoginContextName(),
                new SaslCallbackHandler( request ) );
            loginContext.login();

            final GssApiRequest requetFinal = request;
            return ( BindFuture ) Subject.doAs( loginContext.getSubject(), new PrivilegedExceptionAction<Object>()
            {
                public Object run() throws Exception
                {
                    return bindSasl( requetFinal );
                }
View Full Code Here

Examples of javax.security.auth.login.LoginContext

        // Establish a LoginContext to use for authentication
        try {

            if ( (principalName!=null) && (!principalName.equals("")) ) {
              LoginContext loginContext = null;
              if (appName == null)
                  appName = "Tomcat";

              if (log.isDebugEnabled())
                  log.debug(sm.getString("jaasRealm.beginLogin", principalName, appName));

              // What if the LoginModule is in the container class loader ?
              ClassLoader ocl = null;

              if (isUseContextClassLoader()) {
                  ocl = Thread.currentThread().getContextClassLoader();
                  Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
              }

              try {
                  loginContext = new LoginContext(appName, callbackHandler);
              } catch (Throwable e) {
                  log.error(sm.getString("jaasRealm.unexpectedError"), e);
                  return (null);
              } finally {
                  if (isUseContextClassLoader()) {
                      Thread.currentThread().setContextClassLoader(ocl);
                  }
              }

              if (log.isDebugEnabled())
                  log.debug("Login context created " + principalName);

              // Negotiate a login via this LoginContext
              Subject subject;
              try {
                  loginContext.login();
                  Subject tempSubject = loginContext.getSubject();
                  if (tempSubject == null) {
                      if (log.isDebugEnabled())
                          log.debug(sm.getString("jaasRealm.failedLogin", principalName));
                      return (null);
                  }
View Full Code Here

Examples of javax.security.auth.login.LoginContext

            }
            if (contextAndServiceNameCallback.getServiceName() == null) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "kerberosCallbackServiceNameNotSupplied");
            }

            LoginContext loginContext = new LoginContext(contextAndServiceNameCallback.getContextName(), callbackHandler);
            loginContext.login();

            Subject clientSubject = loginContext.getSubject();
            Set<Principal> clientPrincipals = clientSubject.getPrincipals();
            if (clientPrincipals.isEmpty()) {
                throw new WSSecurityException(
                        WSSecurityException.ErrorCode.FAILURE,
                        "kerberosLoginError", "No Client principals found after login"
View Full Code Here

Examples of javax.security.auth.login.LoginContext

            }
            if (contextAndServiceNameCallback.getServiceName() == null) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "kerberosCallbackServiceNameNotSupplied");
            }

            LoginContext loginContext = new LoginContext(contextAndServiceNameCallback.getContextName(), callbackHandler);
            loginContext.login();

            // Get the service name to use - fall back on the principal
            this.subject = loginContext.getSubject();

            String service = contextAndServiceNameCallback.getServiceName();
            if (service == null) {
                Set<Principal> principals = subject.getPrincipals();
                if (principals.isEmpty()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.