Examples of Subject


Examples of javax.security.auth.Subject

   *
   */
  public void notYetTestChangeUser() {
    final boolean[] exceptionCatched = new boolean[1];
    final Store store = new MemoryStoreImpl();
    Subject subject = new Subject();
    System.setSecurityManager(new SecurityManager());
    try {
      Subject.doAsPrivileged(subject, new PrivilegedExceptionAction() {
        public Object run() throws Exception {
          Source source = new SourceImpl("http://example.org/graph-source");
          Subject subject2 = new Subject();
          try {
            Subject.doAsPrivileged(null, new PrivilegedExceptionAction() {
              public Object run() throws Exception {
                Source source = new SourceImpl("http://example.org/graph-source");
                try {
View Full Code Here

Examples of javax.security.auth.Subject

  @Override
  public Subject getSubjectInContext(String securityDomain) {
    SecurityContext sc = SecurityActions.getSecurityContext();
    if (sc != null && sc.getSecurityDomain().equals(securityDomain)) {
      SubjectInfo si = sc.getSubjectInfo();
      Subject subject = si.getAuthenticatedSubject();
      return subject;
    }   
    return null;
  }
View Full Code Here

Examples of javax.security.auth.Subject

  @Override
  public boolean sameSubject(String securityDomain, Object context, Subject subject) {
    Assertion.isNotNull(context);
    SecurityContext previousContext = (SecurityContext)context;
    Subject previousUser = previousContext.getSubjectInfo().getAuthenticatedSubject();
   
    SecurityContext currentContext = SecurityActions.getSecurityContext();
    if (currentContext != null && currentContext.getSecurityDomain().equals(securityDomain)) {
      Subject currentUser = currentContext.getSubjectInfo().getAuthenticatedSubject();
      if (previousUser.equals(currentUser)) {
        return true;
      }
    }
    return false;
View Full Code Here

Examples of javax.security.auth.Subject

      Principal p = Mockito.mock(Principal.class);
      Mockito.stub(p.getName()).toReturn("alreadylogged"); //$NON-NLS-1$
      HashSet<Principal> principals = new HashSet<Principal>();
      principals.add(p);
     
      Subject subject = new Subject(false, principals, new HashSet(), new HashSet());
      SecurityHelper sh = Mockito.mock(SecurityHelper.class);
      Mockito.stub(sh.getSubjectInContext("passthrough")).toReturn(subject); //$NON-NLS-1$
     
        TeiidLoginContext membershipService = new TeiidLoginContext(sh) {
      public LoginContext createLoginContext(String domain, CallbackHandler handler) throws LoginException {
View Full Code Here

Examples of javax.security.auth.Subject

    Model resultModel = ModelFactory.createDefaultModel();
    for (Source source : sources) {
      Resource sourceRes = resultModel.createResource(source.getURIRef());
      sourceRes.addProperty(RDF.type, METAMODEL.Source);
    }
    Subject subject = Subject.getSubject(AccessController.getContext());
    Set<GVSPrincipal> gvsPrincipals = subject.getPrincipals(GVSPrincipal.class);
    for (GVSPrincipal principal : gvsPrincipals) {
      resultModel.add(org.wymiwyg.commons.jena.JenaUtil.getExpandedResource(principal.getUserResource(), 2));
    }
    response.setBody(JenaUtil.getGraphFromModel(resultModel, true));
  }
View Full Code Here

Examples of javax.security.auth.Subject

 
 
  public void handle(final Request request, final Response response, final Handler wrapped)
      throws HandlerException {
    if (request.getRequestURI().getPath().equals("/meta/account-manager")) {
      Subject subject = new Subject();
      subject.getPrincipals().add(SuperUserGVSPrincipal.instance);
      try {
        Subject.doAsPrivileged(subject, new PrivilegedExceptionAction() {
          public Object run() throws Exception {
            wrapped.handle(request, response);
            return null;
          }
        }, null);
      } catch (PrivilegedActionException e) {
        throw new RuntimeException(e);
      }
    } else {
      LoginContext loginContext;
      try {
        loginContext = new LoginContext("GVS-Auth", new CookieCallbackHandler(request));
        loginContext.login();
      } catch (LoginException e) {
        /*response.setResponseStatus(ResponseStatus.FORBIDDEN);
        log.info(e);
        response.setBody(new MessageBody2Read() {
 
          public ReadableByteChannel read() throws IOException {
            return Channels.newChannel(new ByteArrayInputStream("Login Failed".getBytes()));
          }
         
        });
        return;*/
        try {
          Cookie loginCookie = new Cookie("login", "-");
          loginCookie.setMaxAge(-1);
          response.setHeader(HeaderName.SET_COOKIE, loginCookie.toString());

          loginContext = new LoginContext("GVS-Auth", new CallbackHandler() {

            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
              for (int i = 0; i < callbacks.length; i++) {
                if (callbacks[i] instanceof NameCallback) {
                  ((NameCallback) callbacks[i]).setName("");
                } else if (callbacks[i] instanceof PasswordCallback) {
                  ((PasswordCallback) callbacks[i]).setPassword(""
                      .toCharArray());
                } else {
                  throw new UnsupportedCallbackException(callbacks[i],
                      "Callback class not supported");
                }

              }
             
            }
         
          });
          loginContext.login();
        } catch (LoginException e1) {
          // TODO Auto-generated catch block
          throw new RuntimeException(e1);
        }
       
      }
      try {
        Subject subject = loginContext.getSubject();
        Subject.doAsPrivileged(subject, new PrivilegedExceptionAction() {
          public Object run() throws Exception {
            wrapped.handle(request, response);
            return null;
          }
View Full Code Here

Examples of javax.security.auth.Subject

                        if (!storedUser.equals(user)) throw new SecurityException("xmlBlaster responds: Unknown user " + user + ",  please try with user '" + storedUser + "'");
                        if (!storedPassword.equals(password)) throw new SecurityException("xmlBlaster responds: Bad password, please try again");

                        Set principals = new HashSet();
                        principals.add(new javax.management.remote.JMXPrincipal(user));
                        return new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
                     }
                  };
                  props.put("jmx.remote.authenticator", auth); // JMXConnectorServer.AUTHENTICATOR
               }
               else {
View Full Code Here

Examples of javax.security.auth.Subject

      if (password != null)
      {
         passwordChars = password.toCharArray();
      }

      Subject subject = new Subject();

      if (authenticationManager.isValid(principal, passwordChars, subject))
      {
         // Warning! This "taints" thread local. Make sure you pop it off the stack as soon as
         //          you're done with it.
View Full Code Here

Examples of javax.security.auth.Subject

     *        invocation
     * @return result of the next invocation (to chain interceptors)
     * @throws Exception if interceptor fails
     */
    public Object intercept(final EasyBeansInvocationContext invocationContext) throws Exception {
        Subject runAsSubject = invocationContext.getFactory().getBeanInfo().getSecurityInfo().getRunAsSubject();
        Subject previousSubject = SecurityCurrent.getCurrent().getSecurityContext().enterRunAs(runAsSubject);
        try {
            return invocationContext.proceed();
        } finally {
            SecurityCurrent.getCurrent().getSecurityContext().endsRunAs(previousSubject);
        }
View Full Code Here

Examples of javax.security.auth.Subject

     * Sets the name of the run-as security role.
     * @param runAsRole the name of the role.
     */
    public void setRunAsRole(final String runAsRole) {
        this.runAsRole = runAsRole;
        this.runAsSubject = new Subject();

        // Structure associating a principal with its roles
        Map<Principal, List<Principal>> principals = getRunAsPrincipals();

        // Add principal name
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.