当前位置: 首页>>代码示例>>Java>>正文


Java GroupPrincipalCallback类代码示例

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


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


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