• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GroupPrincipalCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.security.auth.message.callback.GroupPrincipalCallback的典型用法代码示例。如果您正苦于以下问题:Java GroupPrincipalCallback类的具体用法?Java GroupPrincipalCallback怎么用?Java GroupPrincipalCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GroupPrincipalCallback类属于javax.security.auth.message.callback包,在下文中一共展示了GroupPrincipalCallback类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    String login = (String) request.getSession().getAttribute("login");
    String groups = (String) request.getSession().getAttribute("groups");

    CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, login);
    GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{groups});
    Callback[] callbacks = new Callback[]{callerPrincipalCallback, groupPrincipalCallback};

    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new AuthException(e.getMessage());
    }

    return AuthStatus.SUCCESS;
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:22,代码来源:SessionSAM.java


示例2: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, "");
    GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{UserGroupMapping.GUEST_ROLE_ID});
    Callback[] callbacks = {callerPrincipalCallback, groupPrincipalCallback};

    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new AuthException(e.getMessage());
    }

    return AuthStatus.SUCCESS;

}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:20,代码来源:GuestSAM.java


示例3: updateSubjectPrincipal

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
/**
 * Updates the principal for the subject. This is done through the
 * callbacks.
 *
 * @param subject
 *            subject
 * @param jwtPayload
 *            JWT payload
 * @throws AuthException
 * @throws GeneralSecurityException
 */
private void updateSubjectPrincipal(final Subject subject,
    final JsonObject jwtPayload)
        throws GeneralSecurityException {

    try {
        final String iss = googleWorkaround(jwtPayload.getString("iss"));
        handler.handle(
            new Callback[] {
                new CallerPrincipalCallback(subject,
                    UriBuilder.fromUri(iss).userInfo(jwtPayload.getString("sub")).build()
                        .toASCIIString()),
                new GroupPrincipalCallback(subject, new String[] {
                    iss
                        })
        });
    } catch (final IOException
        | UnsupportedCallbackException e) {
        // Should not happen
        Log.getInstance().log(Level.SEVERE, "updatePrincipalException", e.getMessage());
        Log.getInstance().throwing(this.getClass().getName(), "updateSubjectPrincipal", e);
        throw new AuthException(MessageFormat.format(Log.r("updatePrincipalException"), e.getMessage()));
    }
}
 
开发者ID:trajano,项目名称:openid-connect,代码行数:35,代码来源:OpenIdConnectAuthModule.java


示例4: updateSubjectPrincipal

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
/**
 * Updates the principal for the subject. This is done through the
 * callbacks.
 *
 * @param subject
 *            subject
 * @param jwtPayload
 *            JWT payload
 * @throws AuthException
 * @throws GeneralSecurityException
 */
private void updateSubjectPrincipal(final Subject subject,
    final JsonObject jwtPayload,
    final ValidateContext context) throws GeneralSecurityException {

    try {
        final String iss = googleWorkaround(jwtPayload.getString("iss"));
        context.getHandler()
            .handle(new Callback[] {
                new CallerPrincipalCallback(subject, UriBuilder.fromUri(iss)
                    .userInfo(jwtPayload.getString("sub"))
                    .build()
                    .toASCIIString()),
                new GroupPrincipalCallback(subject, new String[] {
                    iss
                        })
        });
    } catch (final IOException
        | UnsupportedCallbackException e) {
        // Should not happen
        LOG.log(Level.SEVERE, "updatePrincipalException", e.getMessage());
        LOG.throwing(this.getClass()
            .getName(), "updateSubjectPrincipal", e);
        throw new AuthException(MessageFormat.format(Log.r("updatePrincipalException"), e.getMessage()));
    }
}
 
开发者ID:trajano,项目名称:openid-connect,代码行数:37,代码来源:CallbackRequestProcessor.java


示例5: testGroupPrincipalCallback

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Test
public void testGroupPrincipalCallback() throws Exception
{   
   JASPICallbackHandler cbh = new JASPICallbackHandler();
    
   GroupPrincipalCallback gpc = new GroupPrincipalCallback( subject, new String[] { "role1", "role2" } );
   
   cbh.handle( new Callback[] { gpc } ); 
   
   SecurityContext currentSC = SecurityContextAssociation.getSecurityContext();
   
   assertNotNull( "subject is not null" , gpc.getSubject() ); 
   assertEquals( subject, currentSC.getUtil().getSubject() );
   
   RoleGroup roles = currentSC.getUtil().getRoles();
   
   assertEquals( 2, roles.getRoles().size() );
   assertTrue( roles.containsRole( new SimpleRole( "role1" )));
   assertTrue( roles.containsRole( new SimpleRole( "role2" )));
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:21,代码来源:JASPICallbackHandlerUnitTestCase.java


示例6: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
        throws AuthException {

    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();

    try {
        response.getWriter().write("validateRequest invoked\n");

        handler.handle(new Callback[] { 
            new CallerPrincipalCallback(clientSubject, "test"),
            new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) });
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }

    return SUCCESS;
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:19,代码来源:TestLifecycleAuthModule.java


示例7: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
        throws AuthException {

    try {
        handler.handle(new Callback[] { 
            new CallerPrincipalCallback(clientSubject, "test"),
            new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) });
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }

    // Wrap the request - the resource to be invoked should get to see this
    messageInfo.setRequestMessage(new TestHttpServletRequestWrapper(
        (HttpServletRequest) messageInfo.getRequestMessage())
    );

    // Wrap the response - the resource to be invoked should get to see this
    messageInfo.setResponseMessage(new TestHttpServletResponseWrapper(
        (HttpServletResponse) messageInfo.getResponseMessage())
    );

    return SUCCESS;
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:25,代码来源:TestWrappingServerAuthModule.java


示例8: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
        throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();

    Callback[] callbacks;

    if (request.getParameter("doLogin") != null) {

        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, "test"),
                new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) };
    } else {

        // The JASPIC protocol for "do nothing"
        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) };
    }

    try {
        handler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }

    return SUCCESS;
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:27,代码来源:TestServerAuthModule.java


示例9: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {
	
	HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();
	
	try {
		response.getWriter().write("validateRequest invoked\n");
		
		handler.handle(new Callback[] { 
				new CallerPrincipalCallback(clientSubject, "test"),
				new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) 
		});
	} catch (IOException | UnsupportedCallbackException e) {
		throw (AuthException) new AuthException().initCause(e);
	}

	return SUCCESS;
}
 
开发者ID:arjantijms,项目名称:jaspic-capabilities-test,代码行数:19,代码来源:TestLifecycleAuthModule.java


示例10: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {
	
	try {
		handler.handle(new Callback[] { 
			new CallerPrincipalCallback(clientSubject, "test"),
			new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) 
		});
	} catch (IOException | UnsupportedCallbackException e) {
		throw (AuthException) new AuthException().initCause(e);
	}

	
	// Wrap the request - the resource to be invoked should get to see this
	messageInfo.setRequestMessage(
		new TestHttpServletRequestWrapper((HttpServletRequest) messageInfo.getRequestMessage())
       );
	
	// Wrap the response - the resource to be invoked should get to see this
	messageInfo.setResponseMessage(
		new TestHttpServletResponseWrapper((HttpServletResponse) messageInfo.getResponseMessage())
	);

	return SUCCESS;
}
 
开发者ID:arjantijms,项目名称:jaspic-capabilities-test,代码行数:26,代码来源:TestWrappingServerAuthModule.java


示例11: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
        throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();

    Callback[] callbacks;

    if (request.getParameter("doLogin") != null) {
        callbacks = new Callback[]{new CallerPrincipalCallback(clientSubject, "test"),
                new GroupPrincipalCallback(clientSubject, new String[]{"architect"})};
    } else {
        callbacks = new Callback[]{new CallerPrincipalCallback(clientSubject, (Principal) null)};
    }

    try {
        handler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }

    cdi(messageInfo, "vr");

    return SUCCESS;
}
 
开发者ID:apache,项目名称:tomee,代码行数:26,代码来源:TheServerAuthModule.java


示例12: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();

    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    String authorization = request.getHeader("Authorization");
    String[] splitAuthorization = authorization.split(" ");
    String jwt = splitAuthorization[1];

    JWTokenUserGroupMapping jwTokenUserGroupMapping = JWTokenFactory.validateAuthToken(key, jwt);

    if (jwTokenUserGroupMapping != null) {

        UserGroupMapping userGroupMapping = jwTokenUserGroupMapping.getUserGroupMapping();
        CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, userGroupMapping.getLogin());
        GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{userGroupMapping.getGroupName()});
        Callback[] callbacks = new Callback[]{callerPrincipalCallback, groupPrincipalCallback};

        try {
            callbackHandler.handle(callbacks);
        } catch (IOException | UnsupportedCallbackException e) {
            throw new AuthException(e.getMessage());
        }

        JWTokenFactory.refreshTokenIfNeeded(key, response, jwTokenUserGroupMapping);

        return AuthStatus.SUCCESS;
    }

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    return AuthStatus.FAILURE;

}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:37,代码来源:JWTSAM.java


示例13: notifyContainerAboutLogin

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
public static void notifyContainerAboutLogin(Subject clientSubject, CallbackHandler handler, String username, List<String> roles) {

        try {
            // 1. Create a handler (kind of directive) to add the caller principal (AKA user principal =basically user name, or user id) that
            // the authenticator provides.
            //
            // This will be the name of the principal returned by e.g. HttpServletRequest#getUserPrincipal
            //
            // 2 Execute the handler right away
            //
            // This will typically eventually (NOT right away) add the provided principal in an application server specific way to the JAAS 
            // Subject.
            // (it could become entries in a hash table inside the subject, or individual principles, or nested group principles etc.)

            handler.handle(new Callback[]{new CallerPrincipalCallback(clientSubject, username)});

            if (!isEmpty(roles)) {
                // 1. Create a handler to add the groups (AKA roles) that the authenticator provides.
                //
                // This is what e.g. HttpServletRequest#isUserInRole and @RolesAllowed for
                //
                // 2. Execute the handler right away
                //
                // This will typically eventually (NOT right away) add the provided roles in an application server specific way to the JAAS 
                // Subject.
                // (it could become entries in a hash table inside the subject, or individual principles, or nested group principles etc.)

                handler.handle(new Callback[]{new GroupPrincipalCallback(clientSubject, roles.toArray(new String[roles.size()]))});
            }

        } catch (IOException | UnsupportedCallbackException e) {
            // Should not happen
            throw new IllegalStateException(e);
        }
    }
 
开发者ID:rdebusscher,项目名称:octopus-jsr375,代码行数:36,代码来源:Jaspic.java


示例14: setupUser

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
/**
 * Setup the information associated with a user
 * @param subject the subject to set up
 * @param userId the user's id
 */
protected void setupUser(Subject s, String userId)
        throws IOException, UnsupportedCallbackException
{
    // get the set of groups from the resolver
    String[] groupNames = groupManager.getGroupsForUser(userId);

    // create a principal with the user and the groups they belong to
    Principal p = new UserGroupPrincipal(userId, groupNames);

    // use a callback to set the principal and groups for this user
    handler.handle(new Callback[] {
                new CallerPrincipalCallback(s, p),
                new GroupPrincipalCallback(s, groupNames) });
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:20,代码来源:WonderSAM.java


示例15: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
        throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();

    Callback[] callbacks;

    if (request.getParameter("doLogin") != null) {

        // For the test perform a login by directly "returning" the details of the authenticated user.
        // Normally credentials would be checked and the details fetched from some repository

        callbacks = new Callback[] { 
            // The name of the authenticated user
            new CallerPrincipalCallback(clientSubject, "test"), 
            // the roles of the authenticated user
            new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) 
        };
    } else {

        // The JASPIC protocol for "do nothing"
        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) };
    }

    try {

        // Communicate the details of the authenticated user to the container. In many
        // cases the handler will just store the details and the container will actually handle
        // the login after we return from this method.
        handler.handle(callbacks);

    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }

    return SUCCESS;
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:39,代码来源:TestServerAuthModule.java


示例16: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {
	
	HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
	
	System.out.println("Session = " + request.getSession().getId());
	System.out.println("\n\n**** validateRequest ****\n\n");
	
	Callback[] callbacks;
	
	if (request.getParameter("doLogin") != null) {
		
		System.out.println("\n\n**** doLogin ****\n\n");
		
		callbacks = new Callback[] { 
			new CallerPrincipalCallback(clientSubject, "test"),
			new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) 
		};
	} else {
		
		System.out.println("\n\n**** do nothing ****\n\n");
		
		// The JASPIC protocol for "do nothing"
		callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) };
	}
	
	try {
		handler.handle(callbacks);
	} catch (IOException | UnsupportedCallbackException e) {
		throw (AuthException) new AuthException().initCause(e);
	}

	return SUCCESS;
}
 
开发者ID:arjantijms,项目名称:jaspic-capabilities-test,代码行数:35,代码来源:TestServerAuthModule.java


示例17: handle

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (final Callback callback : callbacks) {
        // jaspi to server communication
        if (callback instanceof CallerPrincipalCallback) {
            callerPrincipal = ((CallerPrincipalCallback) callback).getPrincipal();
        } else if (callback instanceof GroupPrincipalCallback) {
            groupsArray = ((GroupPrincipalCallback) callback).getGroups();
        } else if (callback instanceof PasswordValidationCallback) {
            final PasswordValidationCallback passwordValidationCallback = (PasswordValidationCallback) callback;
            final String userName = passwordValidationCallback.getUsername();
            final char[] password = passwordValidationCallback.getPassword();

            final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class);
            try {
                final Object loginObj = securityService.login(securityRealmName, userName, password == null ? "" : new String(password));
                securityService.associate(loginObj);
                callerPrincipal = securityService.getCallerPrincipal();
                passwordValidationCallback.setResult(true);
            } catch (final LoginException e) {
                passwordValidationCallback.setResult(false);
            }
        }
        // server to jaspi communication
        else if (callback instanceof CertStoreCallback) { //NOPMD
            // TODO implement me
        } else if (callback instanceof PrivateKeyCallback) { //NOPMD
            // TODO implement me
        } else if (callback instanceof SecretKeyCallback) { //NOPMD
            // TODO implement me
        } else if (callback instanceof TrustStoreCallback) { //NOPMD
            // TODO implement me
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:37,代码来源:ConnectorCallbackHandler.java


示例18: addPrincipalsToSubject

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
private void addPrincipalsToSubject(Subject clientSubject, UserAccount account) throws IOException,
    UnsupportedCallbackException {
  handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, account.getEmail()),
      new GroupPrincipalCallback(clientSubject, account.getRoles().toArray(new String[0])) });
}
 
开发者ID:erik-wramner,项目名称:YubikeyAuth,代码行数:6,代码来源:YubiAuthModule.java


示例19: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
/**
 * <p>
 * Checks for the presence of the cookie, if it is present it will use that
 * as the subject if not it will redirect to a login screen.
 * </p>
 * {@inheritDoc}
 */
@Override
public AuthStatus validateRequest(final MessageInfo messageInfo,
    final Subject client,
    final Subject serviceSubject)
        throws AuthException {

    final HttpServletRequest req = (HttpServletRequest) messageInfo.getRequestMessage();
    final HttpServletResponse resp = (HttpServletResponse) messageInfo.getResponseMessage();
    try {

        final String localRequestUri = req.getRequestURI().substring(req.getContextPath().length());

        if (LOGIN_ENDPOINT.equals(localRequestUri)) {
            return handleLoginEndpoint(req, resp);
        }

        if (LOGOUT_ENDPOINT.equals(localRequestUri)) {
            return handleLogoutEndpoint(req, resp);
        }

        // Allow if authentication is not required.
        if (!mandatory) {
            return AuthStatus.SUCCESS;
        }

        // require SSL if mandatory
        if (!req.isSecure()) {
            resp.sendError(HttpURLConnection.HTTP_FORBIDDEN, "SSL Required");
            return AuthStatus.SEND_FAILURE;
        }

        final String subject = getSubject(req);

        // Check if there is no subject then redirect to login endpoint
        if (subject == null) {
            return handleRedirectToLoginEndpoint(req, resp);
        }

        handler.handle(new Callback[] {
            new CallerPrincipalCallback(client, subject),
            new GroupPrincipalCallback(client, GROUPS)
        });
        return AuthStatus.SUCCESS;

    } catch (final IOException
        | ServletException
        | UnsupportedCallbackException e) {
        LOG.throwing(TestServerAuthModule.class.getName(), "validateRequest", e);
        throw new AuthException(e.getMessage());
    }
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:59,代码来源:TestServerAuthModule.java


示例20: validateRequest

import javax.security.auth.message.callback.GroupPrincipalCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
        throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    Callback[] callbacks;
    
    Principal userPrincipal = request.getUserPrincipal();
    if (userPrincipal != null && request.getParameter("continueSession") != null) {
        
        // ### If already authenticated before, continue this session
        
        // Execute protocol to signal container registered authentication session be used.
        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, userPrincipal) };
        
    } else if (request.getParameter("doLogin") != null) {
        
        // ### If not authenticated before, do a new login if so requested

        // For the test perform a login by directly "returning" the details of the authenticated user.
        // Normally credentials would be checked and the details fetched from some repository

        callbacks = new Callback[] {
                // The name of the authenticated user
                new CallerPrincipalCallback(clientSubject, "test"),
                // the roles of the authenticated user
                new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) };

        // Tell container to register an authentication session.
        messageInfo.getMap().put("javax.servlet.http.registerSession", TRUE.toString());
    } else {
        
        // ### If no registered session and no login request "do nothing"
        
        // The JASPIC protocol for "do nothing"
        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) };
    }

    try {

        // Communicate the details of the authenticated user to the container. In many
        // cases the handler will just store the details and the container will actually handle
        // the login after we return from this method.
        handler.handle(callbacks);

    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }

    return SUCCESS;
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:53,代码来源:TestServerAuthModule.java



注:本文中的javax.security.auth.message.callback.GroupPrincipalCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GenotypeBuilder类代码示例发布时间:2022-05-22
下一篇:
Java VersionMessage类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap