List of usage examples for org.apache.shiro.codec Base64 decodeToString
public static String decodeToString(byte[] base64Encoded)
From source file:com.blazarquant.bfp.core.security.util.SecurityUtilImpl.java
License:Apache License
@Override public long decodeConfirmationKey(String confirmationKey) throws DecodingException { String[] elements = Base64.decodeToString(confirmationKey).split(KEY_DELIMITER); if (elements.length != 3) { throw new IllegalArgumentException("Illegal confirmation key. Please contact with admin."); }//from w w w. j a v a2 s. co m return Long.parseLong(elements[0]); }
From source file:com.blazarquant.bfp.core.security.util.SecurityUtilImpl.java
License:Apache License
@Override public String decodeMessage(String message) { return Base64.decodeToString(message); }
From source file:com.infinities.skyport.vnc.impl.BasicHttpAuthenticationFilter.java
License:Apache License
protected String[] getPrincipalsAndCredentials(String scheme, String encoded) { String decoded = Base64.decodeToString(encoded); return decoded.split(":"); }
From source file:com.once.crosscloud.utils.EndecryptUtils.java
License:Apache License
/** * base64 /* w w w .j a v a 2 s . c o m*/ * @param cipherText * @return */ public static String decryptBase64(String cipherText) { return Base64.decodeToString(cipherText); }
From source file:com.sonatype.security.ldap.api.AbstractLdapPlexusResource.java
License:Open Source License
private CConnectionInfo decode(final CConnectionInfo connectionInfo) { if (connectionInfo == null) { return null; }/*from w ww. j av a 2s . com*/ if (connectionInfo.getSystemUsername() != null) { connectionInfo.setSystemUsername(Base64.decodeToString(connectionInfo.getSystemUsername())); } if (connectionInfo.getSystemPassword() != null) { connectionInfo.setSystemPassword(Base64.decodeToString(connectionInfo.getSystemPassword())); } return connectionInfo; }
From source file:com.sonatype.security.ldap.api.LdapRestTestUtils.java
License:Open Source License
public static void compare(LdapServerConfigurationDTO dto, CLdapServerConfiguration ldapServer) { Assert.assertEquals(dto.getId(), ldapServer.getId()); Assert.assertEquals(dto.getName(), ldapServer.getName()); Assert.assertEquals(dto.getConnectionInfo().getAuthScheme(), ldapServer.getConnectionInfo().getAuthScheme()); Assert.assertEquals(dto.getConnectionInfo().getBackupMirrorHost(), ldapServer.getConnectionInfo().getBackupMirrorHost()); Assert.assertEquals(dto.getConnectionInfo().getBackupMirrorPort(), ldapServer.getConnectionInfo().getBackupMirrorPort()); Assert.assertEquals(dto.getConnectionInfo().getBackupMirrorProtocol(), ldapServer.getConnectionInfo().getBackupMirrorProtocol()); Assert.assertEquals(dto.getConnectionInfo().getCacheTimeout(), ldapServer.getConnectionInfo().getCacheTimeout()); Assert.assertEquals(dto.getConnectionInfo().getConnectionRetryDelay(), ldapServer.getConnectionInfo().getConnectionRetryDelay()); Assert.assertEquals(dto.getConnectionInfo().getConnectionTimeout(), ldapServer.getConnectionInfo().getConnectionTimeout()); Assert.assertEquals(dto.getConnectionInfo().getHost(), ldapServer.getConnectionInfo().getHost()); Assert.assertEquals(dto.getConnectionInfo().getPort(), ldapServer.getConnectionInfo().getPort()); Assert.assertEquals(dto.getConnectionInfo().getProtocol(), ldapServer.getConnectionInfo().getProtocol()); Assert.assertEquals(dto.getConnectionInfo().getRealm(), ldapServer.getConnectionInfo().getRealm()); Assert.assertEquals(dto.getConnectionInfo().getSearchBase(), ldapServer.getConnectionInfo().getSearchBase()); Assert.assertEquals(ldapServer.getConnectionInfo().getSystemUsername(), Base64.decodeToString(dto.getConnectionInfo().getSystemUsername())); Assert.assertEquals(AbstractLdapPlexusResource.FAKE_PASSWORD, Base64.decodeToString(dto.getConnectionInfo().getSystemPassword())); Assert.assertEquals(dto.getUserAndGroupConfig().getEmailAddressAttribute(), ldapServer.getUserAndGroupConfig().getEmailAddressAttribute()); Assert.assertEquals(dto.getUserAndGroupConfig().getGroupBaseDn(), ldapServer.getUserAndGroupConfig().getGroupBaseDn()); Assert.assertEquals(dto.getUserAndGroupConfig().getGroupIdAttribute(), ldapServer.getUserAndGroupConfig().getGroupIdAttribute()); Assert.assertEquals(dto.getUserAndGroupConfig().getGroupMemberAttribute(), ldapServer.getUserAndGroupConfig().getGroupMemberAttribute()); Assert.assertEquals(dto.getUserAndGroupConfig().getGroupMemberFormat(), ldapServer.getUserAndGroupConfig().getGroupMemberFormat()); Assert.assertEquals(dto.getUserAndGroupConfig().getGroupObjectClass(), ldapServer.getUserAndGroupConfig().getGroupObjectClass()); Assert.assertEquals(dto.getUserAndGroupConfig().getUserBaseDn(), ldapServer.getUserAndGroupConfig().getUserBaseDn()); Assert.assertEquals(dto.getUserAndGroupConfig().getUserIdAttribute(), ldapServer.getUserAndGroupConfig().getUserIdAttribute()); Assert.assertEquals(dto.getUserAndGroupConfig().getUserMemberOfAttribute(), ldapServer.getUserAndGroupConfig().getUserMemberOfAttribute()); Assert.assertEquals(dto.getUserAndGroupConfig().getUserObjectClass(), ldapServer.getUserAndGroupConfig().getUserObjectClass()); Assert.assertEquals(dto.getUserAndGroupConfig().getUserPasswordAttribute(), ldapServer.getUserAndGroupConfig().getUserPasswordAttribute()); Assert.assertEquals(dto.getUserAndGroupConfig().getUserRealNameAttribute(), ldapServer.getUserAndGroupConfig().getUserRealNameAttribute()); }
From source file:com.sonatype.security.ldap.api.LdapServerLoginTestPlexusResource.java
License:Open Source License
protected Object doPut(Context context, Request request, Response response, Object payload) throws ResourceException, InvalidConfigurationException { if (payload == null) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Missing payload"); }//from w w w . j ava2 s. co m LdapServerLoginTestRequest ldapServerLoginTestRequest = (LdapServerLoginTestRequest) payload; if (ldapServerLoginTestRequest.getData() == null) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Payload is empty"); } if (ldapServerLoginTestRequest.getData().getConfiguration() == null) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Payload configuration is empty"); } // validate String username = Base64.decodeToString(ldapServerLoginTestRequest.getData().getUsername()); if (StringUtils.isEmpty(username)) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Missing username argument."); } String password = Base64.decodeToString(ldapServerLoginTestRequest.getData().getPassword()); if (StringUtils.isEmpty(password)) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Missing password argument."); } // get the ldap model object CLdapServerConfiguration ldapServer = toLdapModel(ldapServerLoginTestRequest.getData().getConfiguration()); if (ldapServer.getId() == null && request.getResourceRef() != null) { ldapServer.setId(request.getResourceRef().getQueryAsForm().getFirstValue("ldapServerId")); } replaceFakePassword(ldapServer.getConnectionInfo(), ldapServer.getId(), ldapConfigurationManager); // try the login try { this.ldapManager.authenticateUserTest(username, password, ldapServer); } catch (Exception e) { throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Login attempt failed: " + e.getMessage(), e, this.getErrorResponse("*", this.buildExceptionMessage("Error connecting to LDAP Server: ", e))); } // success response.setStatus(Status.SUCCESS_NO_CONTENT); return null; }
From source file:com.zht.common.shiro.util.EndecryptUtils.java
License:Apache License
/** * base64 /*from w ww. jav a2s .c o m*/ * @param cipherText * @return */ public static String decryptBase64(String cipherText) { if (cipherText == null) { return null; } return Base64.decodeToString(cipherText); }
From source file:io.airlift.http.server.security.HttpAuthenticatingFilter.java
License:Apache License
/** * Creates an AuthenticationToken for use during login attempt with the provided credentials in the http header. * <p/>//from w w w. j a v a 2s . co m * This implementation: * <ol><li>acquires the username and password based on the request's * {@link #getAuthzHeader(javax.servlet.ServletRequest) authorization header} via the * {@link #getPrincipalsAndCredentials(String, javax.servlet.ServletRequest) getPrincipalsAndCredentials} method</li> * <li>The return value of that method is converted to an <code>AuthenticationToken</code> via the * {@link #createToken(String, String, javax.servlet.ServletRequest, javax.servlet.ServletResponse) createToken} method</li> * <li>The created <code>AuthenticationToken</code> is returned.</li> * </ol> * * @param request incoming ServletRequest * @param response outgoing ServletResponse * @return the AuthenticationToken used to execute the login attempt */ protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) { String authorizationHeader = getAuthzHeader(request); if (authorizationHeader == null || authorizationHeader.length() == 0) { // Create an empty authentication token since there is no // Authorization header. return createToken("", "", request, response); } if (log.isDebugEnabled()) { log.debug("Attempting to execute login with headers [" + authorizationHeader + "]"); } //String[] prinCred = getPrincipalsAndCredentials(authorizationHeader, request); String[] authTokens = authorizationHeader.split(" "); if (authTokens == null || authTokens.length < 2) { return createToken("", "", request, response); } String scheme = authTokens[0]; String encoded = authTokens[1]; // //Authorization: Bearer AbCdEf123456 //Authorization: Basic AbCdEf123456 // AuthenticationToken token; // // Depending on the scheme we do different things // //Authorization: Bearer AbCdEf123456 //Authorization: Basic AbCdEf123456 // // If we have a Bearer token then we need to do all sorts of other stuff // if (scheme.toLowerCase().equals("basic")) { // //Authorization: Basic AbCdEf123456 // String[] prinCred = Base64.decodeToString(encoded).split(":", 2); if (prinCred == null || prinCred.length < 2) { // Create an authentication token with an empty password, // since one hasn't been provided in the request. String username = prinCred == null || prinCred.length == 0 ? "" : prinCred[0]; token = createToken(username, "", request, response); } String username = prinCred[0]; String password = prinCred[1]; token = createToken(username, password, request, response); } else { // //Authorization: Bearer AbCdEf123456 // // xxx.yyy.zzz => [JWT Header].[JWT Claims Set].[JWT Signature] // token = new BearerAuthenticationToken(encoded); } return token; }
From source file:org.apache.jena.fuseki.authc.BasicHttpAuthenticationFilter.java
License:Apache License
/** * Returns the username and password pair based on the specified <code>encoded</code> String obtained from * the request's authorization header./*from ww w . java2 s .c o m*/ * <p/> * Per RFC 2617, the default implementation first Base64 decodes the string and then splits the resulting decoded * string into two based on the ":" character. That is: * <p/> * <code>String decoded = Base64.decodeToString(encoded);<br/> * return decoded.split(":");</code> * * @param scheme the {@link #getAuthcScheme() authcScheme} found in the request * {@link #getAuthzHeader(javax.servlet.ServletRequest) authzHeader}. It is ignored by this implementation, * but available to overriding implementations should they find it useful. * @param encoded the Base64-encoded username:password value found after the scheme in the header * @return the username (index 0)/password (index 1) pair obtained from the encoded header data. */ protected String[] getPrincipalsAndCredentials(String scheme, String encoded) { String decoded = Base64.decodeToString(encoded); return decoded.split(":", 2); }