本文整理汇总了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;
}
示例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;
}
示例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()));
}
}
示例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()));
}
}
示例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" )));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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) });
}
示例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;
}