Search in sources :

Example 1 with ExtendedGSSCredential

use of com.sun.security.jgss.ExtendedGSSCredential in project jdk8u_jdk by JetBrains.

the class Context method impersonate.

public Context impersonate(final String someone) throws Exception {
    try {
        GSSCredential creds = Subject.doAs(s, new PrivilegedExceptionAction<GSSCredential>() {

            @Override
            public GSSCredential run() throws Exception {
                GSSManager m = GSSManager.getInstance();
                GSSName other = m.createName(someone, GSSName.NT_USER_NAME);
                if (Context.this.cred == null) {
                    Context.this.cred = m.createCredential(GSSCredential.INITIATE_ONLY);
                }
                return ((ExtendedGSSCredential) Context.this.cred).impersonate(other);
            }
        });
        Context out = new Context();
        out.s = s;
        out.cred = creds;
        out.name = name + " as " + out.cred.getName().toString();
        return out;
    } catch (PrivilegedActionException pae) {
        Exception e = pae.getException();
        if (e instanceof InvocationTargetException) {
            throw (Exception) ((InvocationTargetException) e).getTargetException();
        } else {
            throw e;
        }
    }
}
Also used : LoginContext(javax.security.auth.login.LoginContext) ExtendedGSSContext(com.sun.security.jgss.ExtendedGSSContext) GSSContext(org.ietf.jgss.GSSContext) GSSName(org.ietf.jgss.GSSName) ExtendedGSSCredential(com.sun.security.jgss.ExtendedGSSCredential) GSSCredential(org.ietf.jgss.GSSCredential) PrivilegedActionException(java.security.PrivilegedActionException) GSSManager(org.ietf.jgss.GSSManager) PrivilegedActionException(java.security.PrivilegedActionException) GSSException(org.ietf.jgss.GSSException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ExtendedGSSContext (com.sun.security.jgss.ExtendedGSSContext)1 ExtendedGSSCredential (com.sun.security.jgss.ExtendedGSSCredential)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 LoginContext (javax.security.auth.login.LoginContext)1 GSSContext (org.ietf.jgss.GSSContext)1 GSSCredential (org.ietf.jgss.GSSCredential)1 GSSException (org.ietf.jgss.GSSException)1 GSSManager (org.ietf.jgss.GSSManager)1 GSSName (org.ietf.jgss.GSSName)1