Package java.security

Examples of java.security.Principal


      //Get the active request
      Request request = ActiveRequestResponseCacheValve.activeRequest.get();
      if (request == null)
         throw new IllegalStateException("request is null");

      Principal p = null;
      if (credential instanceof String)
      {
         p = request.getContext().getRealm().authenticate(username, (String) credential);
      }
      else if (credential instanceof byte[])
View Full Code Here


      Session session = request.getSessionInternal(true);
      String username = request.getHeader("JBOSS_TEST_USER_NAME");
      String password = request.getHeader("JBOSS_TEST_CREDENTIAL");
      log.debug("Test UserName =" + username);
      log.debug("Test cred present?:" + (password != null));
      Principal principal = realm.authenticate(username,password);
      if(principal == null)
      {
         response.sendError(HttpServletResponse.SC_FORBIDDEN);
         return false;
      }
View Full Code Here

    */
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
         ServletException
   {
      HttpSession session = ((HttpServletRequest) request).getSession();
      Principal principal = (Principal) session.getAttribute(JBOSS_PRINCIPAL);
      if (principal == null)
      {
         principal = ((HttpServletRequest) request).getUserPrincipal();
         session.setAttribute(JBOSS_PRINCIPAL, principal);
         if (trace)
View Full Code Here

   public void invoke(Request request, Response response)
           throws IOException, ServletException
   {
      Session session = null;
      // Get the request caller which could be set due to SSO
      Principal caller = request.getPrincipal();
      // The cached web container principal
      JBossGenericPrincipal principal = null;
      HttpSession hsession = request.getSession(false);

      if( trace )
         log.trace("Begin invoke, caller="+caller);
     
      try
      {
         Wrapper servlet = null;
         try
         {
            servlet = request.getWrapper();
            if (servlet != null)
            {
               String name = servlet.getName();
               RunAsIdentityMetaData identity = metaData.getRunAsIdentity(name);
               RunAsIdentity runAsIdentity = null;
               if(identity != null)
               {
                  if (trace)
                     log.trace(name + ", runAs: " + identity);
                  runAsIdentity = new RunAsIdentity(identity.getRoleName(),
                        identity.getPrincipalName(), identity.getRunAsRoles());
               }
               SecurityAssociationActions.pushRunAsIdentity(runAsIdentity);
            }
            userPrincipal.set(caller);

            // If there is a session, get the tomcat session for the principal
            Manager manager = container.getManager();
            if (manager != null && hsession != null)
            {
               try
               {
                  session = manager.findSession(hsession.getId());
               }
               catch (IOException ignore)
               {
               }
            }

            if (caller == null || (caller instanceof JBossGenericPrincipal) == false)
            {
               // Look to the session for the active caller security context
               if (session != null)
               {
                  principal =
                     (JBossGenericPrincipal) session.getPrincipal();
               }
            }
            else
            {
               // Use the request principal as the caller identity
               principal = (JBossGenericPrincipal) caller;
            }

            // If there is a caller use this as the identity to propagate
            if (principal != null)
            {
               if (trace)
                  log.trace("Restoring principal info from cache");
               SecurityAssociationActions.setPrincipalInfo(principal.getAuthPrincipal(),
                  principal.getCredentials(), principal.getSubject())
            }
            // Put the authenticated subject in the session if requested
            if (subjectAttributeName != null)
            {
               javax.naming.Context securityNamingCtx = getSecurityNamingContext();
               if (securityNamingCtx != null)
               {
                  // Get the JBoss security manager from the ENC context
                  AuthenticationManager securityMgr = (AuthenticationManager) securityNamingCtx.lookup("securityMgr");
                  Subject subject = securityMgr.getActiveSubject();
                  request.getRequest().setAttribute(subjectAttributeName, subject);
               }
            }
         }
         catch (Throwable e)
         {
            log.debug("Failed to determine servlet", e);
         }
        
         // Perform the request
         getNext().invoke(request, response);
         if(servlet != null)
         {
            SecurityAssociationActions.popRunAsIdentity();
         }

         /* If the security domain cache is to be kept in synch with the
         session then flush the cache if the session has been invalidated.
         */
         if( secMgrService != null &&
            session != null && session.isValid() == false &&
            metaData.isFlushOnSessionInvalidation() == true )
         {
            if( principal != null )
            {
               String securityDomain = metaData.getSecurityDomain();
               if (trace)
               {
                  log.trace("Session is invalid, security domain: "+securityDomain
                     +", user="+principal);
               }
               try
               {
                  Principal authPrincipal = principal.getAuthPrincipal();
                  secMgrService.flushAuthenticationCache(securityDomain, authPrincipal);
               }
               catch(Exception e)
               {
                  log.debug("Failed to flush auth cache", e);
View Full Code Here

   public void event(Request request, Response response, HttpEvent event)
      throws IOException, ServletException
   {
      Session session = null;
      // Get the request caller which could be set due to SSO
      Principal caller = request.getPrincipal();
      // The cached web container principal
      JBossGenericPrincipal principal = null;
      HttpSession hsession = request.getSession(false);
     
      if( trace )
         log.trace("Begin invoke, caller="+caller);
     
      try
      {
         Wrapper servlet = null;
         try
         {
            servlet = request.getWrapper();
            if (servlet != null)
            {
               String name = servlet.getName();
               RunAsIdentityMetaData identity = metaData.getRunAsIdentity(name);
               RunAsIdentity runAsIdentity = null;
               if(identity != null)
               {
                  if (trace)
                     log.trace(name + ", runAs: " + identity);
                  runAsIdentity = new RunAsIdentity(identity.getRoleName(),
                        identity.getPrincipalName(), identity.getRunAsRoles());
               }
               SecurityAssociationActions.pushRunAsIdentity(runAsIdentity);
            }
            userPrincipal.set(caller);
           
            // If there is a session, get the tomcat session for the principal
            Manager manager = container.getManager();
            if (manager != null && hsession != null)
            {
               try
               {
                  session = manager.findSession(hsession.getId());
               }
               catch (IOException ignore)
               {
               }
            }
           
            if (caller == null || (caller instanceof JBossGenericPrincipal) == false)
            {
               // Look to the session for the active caller security context
               if (session != null)
               {
                  principal =
                     (JBossGenericPrincipal) session.getPrincipal();
               }
            }
            else
            {
               // Use the request principal as the caller identity
               principal = (JBossGenericPrincipal) caller;
            }
           
            // If there is a caller use this as the identity to propagate
            if (principal != null)
            {
               if (trace)
                  log.trace("Restoring principal info from cache");
               SecurityAssociationActions.setPrincipalInfo(principal.getAuthPrincipal(),
                     principal.getCredentials(), principal.getSubject())
            }
            // Put the authenticated subject in the session if requested
            if (subjectAttributeName != null)
            {
               javax.naming.Context securityNamingCtx = getSecurityNamingContext();
               if (securityNamingCtx != null)
               {
                  // Get the JBoss security manager from the ENC context
                  AuthenticationManager securityMgr = (AuthenticationManager) securityNamingCtx.lookup("securityMgr");
                  Subject subject = securityMgr.getActiveSubject();
                  request.getRequest().setAttribute(subjectAttributeName, subject);
               }
            }
         }
         catch (Throwable e)
         {
            log.debug("Failed to determine servlet", e);
         }
        
         // Perform the request
         getNext().event(request, response, event);
         if(servlet != null)
         {
            SecurityAssociationActions.popRunAsIdentity();
         }
        
         /* If the security domain cache is to be kept in synch with the
    session then flush the cache if the session has been invalidated.
          */
         if( secMgrService != null &&
               session != null && session.isValid() == false &&
               metaData.isFlushOnSessionInvalidation() == true )
         {
            if( principal != null )
            {
               String securityDomain = metaData.getSecurityDomain();
               if (trace)
               {
                  log.trace("Session is invalid, security domain: "+securityDomain
                        +", user="+principal);
               }
               try
               {
                  Principal authPrincipal = principal.getAuthPrincipal();
                  secMgrService.flushAuthenticationCache(securityDomain, authPrincipal);
               }
               catch(Exception e)
               {
                  log.debug("Failed to flush auth cache", e);
View Full Code Here

     * @return entity value
     */
    public static String getX509CertificateEntity(X509Certificate c, String entity) {
        // This assumes the keystore returns the last certificate in the chain
        // the actual certifcate that is signed by a CA or untrusted cert
        Principal subjectPrincipal = c.getSubjectDN();
        StringTokenizer t = new StringTokenizer(subjectPrincipal.getName(), ",");
        while (t.hasMoreTokens()) {
            String e = t.nextToken().trim();
            String f = entity.trim() + "=";
            if (e.toLowerCase().startsWith(f.toLowerCase())) {
                return e.substring(f.length()).trim();
View Full Code Here

            org.jboss.resteasy.auth.oauth.OAuthConsumer consumer,
            OAuthToken accessToken)
    {
        // Alternatively we can have an alias associated with a given key
        // Example: www.messageing.service : kermit
        final Principal principal = new SimplePrincipal(consumer.getKey());
        final Set<String> roles = getProvider().convertPermissionsToRoles(accessToken.getPermissions());
        return new HttpServletRequestWrapper(request){
            @Override
            public Principal getUserPrincipal(){
                return principal;
View Full Code Here

       
        Set<String> roles = oauthProvider.convertPermissionsToRoles(accessToken.getPermissions());
        Realm realm = new OAuthRealm(roles);
        context.setRealm(realm);
       
        final Principal principal = new GenericPrincipal(realm, consumer.getKey(), "", new ArrayList<String>(roles));
        ((Request)request).setUserPrincipal(principal);
        ((Request)request).setAuthType("OAuth");
    }
View Full Code Here

                                                       String openId)
    {
        int index = openId.lastIndexOf("/");
        String name = index != -1 ? openId.substring(index + 1) : openId;
       
        final Principal principal = new SimplePrincipal(name);
        final Set<String> roles = getRoles(name);
       
        return new HttpServletRequestWrapper(request){
            @Override
            public Principal getUserPrincipal(){
View Full Code Here

    }
   
    protected HttpServletRequest createSecurityContext(HttpServletRequest request,
            OAuthConsumer consumer, OAuthToken accessToken)
    {
        final Principal principal = new SimplePrincipal(consumer.getKey());
        final Set<String> roles = getRoles(consumer);
       
        return new HttpServletRequestWrapper(request){
            @Override
            public Principal getUserPrincipal(){
View Full Code Here

TOP

Related Classes of java.security.Principal

Copyright © 2018 www.massapicom. 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.